{
  "id": 237776,
  "title": "How to create grid points automatically",
  "url": "/competitions/indoor-location-navigation/discussion/237776",
  "author_name": "",
  "post_date": "2021-05-10T09:04:08.368673400Z",
  "votes": 11,
  "comment_count": 14,
  "views": 0,
  "content": "<p>Now I'm trying to create grid points (possible waypoints) automatically because we cannot use hand labeled grid points.<br>\nMy basic idea is search all possible grid points and adopt them if they are inside the floor polygon and outside the store polygons.<br>\nBut, it takes too long time to determine inside the polygon or not…<br>\nAnyone has better idea?</p>\n<p>Below is a part of my code.<br>\nfloor_poly is a polygon of the floor and list_poly is a list of polygons of stores.</p>\n<pre><code>from sympy.geometry import Point, Polygon\nl_x = []\nl_y = []\nl_site = []\nl_fNo = []\nn_store = len(store_coord)\n\n# search for all possible grid points\nfor x in range(int(site_width)):\n    for y in range(int(site_height)):\n        point = Point(x,y)\n        # not adopt if the point is outside of the floor polygon\n        if not floor_poly.encloses_point(point):continue\n        flg_inside = True\n        # search for all stores\n        for i in range(n_store):\n            # not adopt if the point is inside the store polygon\n            if list_poly[i].encloses_point(point):\n                flg_inside = False\n                break\n        if flg_inside:\n            l_x += [x]\n            l_y += [y]\n            l_site += [site_id]\n            l_fNo += [floorNo]\ndf_waypoint_add = pd.DataFrame(data={\"x\":l_x,\"y\":l_y,\"site\":l_site,\"floorNo\":l_fNo},\n                               columns=[\"x\",\"y\",\"site\",\"floorNo\"])\n</code></pre>",
  "messages": [
    {
      "id": "1300086",
      "postDate": "05/10/2021 09:04:08",
      "content": "<p>Now I'm trying to create grid points (possible waypoints) automatically because we cannot use hand labeled grid points.<br>\nMy basic idea is search all possible grid points and adopt them if they are inside the floor polygon and outside the store polygons.<br>\nBut, it takes too long time to determine inside the polygon or not…<br>\nAnyone has better idea?</p>\n<p>Below is a part of my code.<br>\nfloor_poly is a polygon of the floor and list_poly is a list of polygons of stores.</p>\n<pre><code>from sympy.geometry import Point, Polygon\nl_x = []\nl_y = []\nl_site = []\nl_fNo = []\nn_store = len(store_coord)\n\n# search for all possible grid points\nfor x in range(int(site_width)):\n    for y in range(int(site_height)):\n        point = Point(x,y)\n        # not adopt if the point is outside of the floor polygon\n        if not floor_poly.encloses_point(point):continue\n        flg_inside = True\n        # search for all stores\n        for i in range(n_store):\n            # not adopt if the point is inside the store polygon\n            if list_poly[i].encloses_point(point):\n                flg_inside = False\n                break\n        if flg_inside:\n            l_x += [x]\n            l_y += [y]\n            l_site += [site_id]\n            l_fNo += [floorNo]\ndf_waypoint_add = pd.DataFrame(data={\"x\":l_x,\"y\":l_y,\"site\":l_site,\"floorNo\":l_fNo},\n                               columns=[\"x\",\"y\",\"site\",\"floorNo\"])\n</code></pre>",
      "rawMarkdown": "Now I'm trying to create grid points (possible waypoints) automatically because we cannot use hand labeled grid points.\nMy basic idea is search all possible grid points and adopt them if they are inside the floor polygon and outside the store polygons.\nBut, it takes too long time to determine inside the polygon or not...\nAnyone has better idea?\n\nBelow is a part of my code.\nfloor_poly is a polygon of the floor and list_poly is a list of polygons of stores.\n\n```Python\nfrom sympy.geometry import Point, Polygon\nl_x = []\nl_y = []\nl_site = []\nl_fNo = []\nn_store = len(store_coord)\n\n# search for all possible grid points\nfor x in range(int(site_width)):\n    for y in range(int(site_height)):\n        point = Point(x,y)\n        # not adopt if the point is outside of the floor polygon\n        if not floor_poly.encloses_point(point):continue\n        flg_inside = True\n        # search for all stores\n        for i in range(n_store):\n            # not adopt if the point is inside the store polygon\n            if list_poly[i].encloses_point(point):\n                flg_inside = False\n                break\n        if flg_inside:\n            l_x += [x]\n            l_y += [y]\n            l_site += [site_id]\n            l_fNo += [floorNo]\ndf_waypoint_add = pd.DataFrame(data={\"x\":l_x,\"y\":l_y,\"site\":l_site,\"floorNo\":l_fNo},\n                               columns=[\"x\",\"y\",\"site\",\"floorNo\"])\n```",
      "votes": null
    },
    {
      "id": "1300185",
      "postDate": "05/10/2021 10:18:03",
      "content": "<p>I have already tried almost the same thing with shapely package (I have no Idea which is better shapely or sympy, as I did not know both packages before this competition).<br>\nI merged all floor and site polygons with <code>unary_union</code> function and then subtract store from floor beforehand.<br>\nThe code is something like that.</p>\n<pre><code>from shapely.geometry import Point\nfrom shapely.geometry.polygon import Polygon\nimport shapely.ops as so\nfloor_polygons= so.unary_union(floor_polygons)\nstore_polygons= so.unary_union(store_polygons)\nsafe_area_polygons=floor_polygons.difference(store_polygons)\n</code></pre>\n<p><br>\nThen, I determined the points inside or not.</p>\n<pre><code>point = Point([x,y])\nif safe_area_polygons.contains(point):\n   do something\n</code></pre>\n<p>My search range and resolution for x and y values are lower than range(int(site_width)), but I am not sure it is optimal.</p>",
      "rawMarkdown": "I have already tried almost the same thing with shapely package (I have no Idea which is better shapely or sympy, as I did not know both packages before this competition).\nI merged all floor and site polygons with `unary_union` function and then subtract store from floor beforehand.\nThe code is something like that.\n\n``` \nfrom shapely.geometry import Point\nfrom shapely.geometry.polygon import Polygon\nimport shapely.ops as so\nfloor_polygons= so.unary_union(floor_polygons)\nstore_polygons= so.unary_union(store_polygons)\nsafe_area_polygons=floor_polygons.difference(store_polygons)\n``` \nThen, I determined the points inside or not.\n``` \npoint = Point([x,y])\nif safe_area_polygons.contains(point):\n   do something\n```\nMy search range and resolution for x and y values are lower than range(int(site_width)), but I am not sure it is optimal.",
      "votes": null
    },
    {
      "id": "1300380",
      "postDate": "05/10/2021 12:22:01",
      "content": "<p>You also have the floorplan images themselves that you can use (this is how I'm doing it):</p>\n<ol>\n<li><p>first remove the writing from the hallways; I did this with a script that removed any gray pixel next to a clear (hallway) pixel, and ran it 3x or so to remove all the writing. It wasn't perfect, but pretty good</p></li>\n<li><p>Now you should have a png where the transparent pixels are the hallways, and everything else is a color.</p></li>\n</ol>\n<p>Then you just have to check if your potential waypoint is on a clear hallway or not (still takes some time depending on the image package you're using, but not as much as checking all the polygons).</p>\n<p>If you're not comfortable with image manipulation, then <a href=\"https://www.kaggle.com/tomooinubushi\" target=\"_blank\">@tomooinubushi</a> 's way is probably faster for you</p>\n<p>[edit]: there are a few tricks with how to convert from meters to pixels, and what coordinate system your image packages uses, etc; I got this wrong about 3 times before getting it right, and it was tricky to tell if it was working or not :) so just be careful of that</p>",
      "rawMarkdown": "You also have the floorplan images themselves that you can use (this is how I'm doing it):\n\n1. first remove the writing from the hallways; I did this with a script that removed any gray pixel next to a clear (hallway) pixel, and ran it 3x or so to remove all the writing. It wasn't perfect, but pretty good\n\n2. Now you should have a png where the transparent pixels are the hallways, and everything else is a color.\n\nThen you just have to check if your potential waypoint is on a clear hallway or not (still takes some time depending on the image package you're using, but not as much as checking all the polygons).\n\nIf you're not comfortable with image manipulation, then @tomooinubushi 's way is probably faster for you\n\n[edit]: there are a few tricks with how to convert from meters to pixels, and what coordinate system your image packages uses, etc; I got this wrong about 3 times before getting it right, and it was tricky to tell if it was working or not :) so just be careful of that",
      "votes": null
    },
    {
      "id": "1300411",
      "postDate": "05/10/2021 12:48:36",
      "content": "<p>I would advise to use the geojson over the PNG as well, and manipulating them with Shapely.</p>\n<p>You should get more accurate floor-maps and there are some nice functions within Shapely that makes your life a lot easier.</p>\n<p>Some examples of hallway-plans I extracted using the geo-json: <a href=\"https://imgur.com/a/4gl1k64\" target=\"_blank\">https://imgur.com/a/4gl1k64</a></p>",
      "rawMarkdown": "I would advise to use the geojson over the PNG as well, and manipulating them with Shapely.\n\nYou should get more accurate floor-maps and there are some nice functions within Shapely that makes your life a lot easier.\n\nSome examples of hallway-plans I extracted using the geo-json: https://imgur.com/a/4gl1k64",
      "votes": null
    },
    {
      "id": "1300428",
      "postDate": "05/10/2021 12:56:57",
      "content": "<p>shapely did work!<br>\nIt is much faster.<br>\nThank you so much.</p>",
      "rawMarkdown": "shapely did work!\nIt is much faster.\nThank you so much.",
      "votes": null
    },
    {
      "id": "1300433",
      "postDate": "05/10/2021 13:01:07",
      "content": "<p>Thank you for your comment!<br>\nhmm… it seems to be quite difficult and tricky.<br>\nI'm looking forward to hear your solution (not only this topic) after the competition anyway :)</p>",
      "rawMarkdown": "Thank you for your comment!\nhmm... it seems to be quite difficult and tricky.\nI'm looking forward to hear your solution (not only this topic) after the competition anyway :)",
      "votes": null
    },
    {
      "id": "1300435",
      "postDate": "05/10/2021 13:02:14",
      "content": "<p>Thank you for your comment!<br>\nShapely seems to be good.<br>\nI'll try it!</p>",
      "rawMarkdown": "Thank you for your comment!\nShapely seems to be good.\nI'll try it!",
      "votes": null
    },
    {
      "id": "1302635",
      "postDate": "05/11/2021 16:32:23",
      "content": "<p>Hey! Sorry to bother, may I ask you how have you translated points from GeoJson to (x,y) waypoints? I published a <a href=\"https://www.kaggle.com/joelqv/where-are-your-predictions-located-shapely\" target=\"_blank\">notebook</a> after reading you guys. However, I have the feeling that I have wrongly computed the (x,y) coordinates.<br>\nIf you want to answer after the competition ends it is fine :).</p>",
      "rawMarkdown": "Hey! Sorry to bother, may I ask you how have you translated points from GeoJson to (x,y) waypoints? I published a [notebook](https://www.kaggle.com/joelqv/where-are-your-predictions-located-shapely) after reading you guys. However, I have the feeling that I have wrongly computed the (x,y) coordinates.\nIf you want to answer after the competition ends it is fine :).",
      "votes": null
    },
    {
      "id": "1303023",
      "postDate": "05/11/2021 21:21:17",
      "content": "<p>From what I see the scaling is a little bit off. </p>\n<p>All I can say is that introducing some constant values helps, but it can be better.</p>",
      "rawMarkdown": "From what I see the scaling is a little bit off. \n\nAll I can say is that introducing some constant values helps, but it can be better.",
      "votes": null
    },
    {
      "id": "1303058",
      "postDate": "05/11/2021 21:54:01",
      "content": "<p>I tried to scale using the floor map info but it does not seem to be correct <br>\n<code>df_result['x_scaled'] = (x_max * df_result['x']) / floor_info['map_info']['width']</code><br>\n<code>df_result['y_scaled'] = (y_max * df_result['y']) / floor_info['map_info']['height']</code></p>",
      "rawMarkdown": "I tried to scale using the floor map info but it does not seem to be correct \n`df_result['x_scaled'] = (x_max * df_result['x']) / floor_info['map_info']['width']`\n`df_result['y_scaled'] = (y_max * df_result['y']) / floor_info['map_info']['height']`",
      "votes": null
    },
    {
      "id": "1303133",
      "postDate": "05/11/2021 23:28:56",
      "content": "<p></p>\n<p><br>\n</p>\n<p></p>\n<p>upd. </p>\n<p>x_scaled = x_max - x_values[x_iter] * (x_max - x_min)/width_meter</p>\n<p>y_scaled = y_max - y_values[y_iter] * (y_max - y_min)/height_meter</p>\n<p>does the right thing with a perfect grid for me.</p>",
      "rawMarkdown": "~~The closest to being somewhat good scaling I have obtained was by doing something like~~\n\n~~df_result['x_scaled'] = (x_max * df_result['x']) + xx~~\n~~df_result['y_scaled'] = (y_max * df_result['y']) + xx~~\n\n~~But this isnt a good idea, because scaling doesnt seem to be uniform that way. I have also tried to use a different scaling for different parts of the floor, and while it gives a bit better results it is not too far from random guessing.~~\n\nupd. \n\nx_scaled = x_max - x_values[x_iter] * (x_max - x_min)/width_meter\n\ny_scaled = y_max - y_values[y_iter] * (y_max - y_min)/height_meter\n\ndoes the right thing with a perfect grid for me.",
      "votes": null
    },
    {
      "id": "1303180",
      "postDate": "05/12/2021 00:18:13",
      "content": "<p>I corrected the values as <a href=\"https://www.kaggle.com/avtobusbratiev\" target=\"_blank\">@avtobusbratiev</a> noted. <br>\nFrom the discussions in <a href=\"https://www.kaggle.com/c/indoor-location-navigation/discussion/230558\" target=\"_blank\">here</a> and <a href=\"https://www.kaggle.com/c/indoor-location-navigation/discussion/230379\" target=\"_blank\">here</a>, I should correct y values manually for some buildings, but I am too lazy to do that. It should be also noted that some train waypoints are actually inside the store.</p>",
      "rawMarkdown": "I corrected the values as @avtobusbratiev noted. \nFrom the discussions in [here](https://www.kaggle.com/c/indoor-location-navigation/discussion/230558) and [here](https://www.kaggle.com/c/indoor-location-navigation/discussion/230379), I should correct y values manually for some buildings, but I am too lazy to do that. It should be also noted that some train waypoints are actually inside the store.",
      "votes": null
    },
    {
      "id": "1303649",
      "postDate": "05/12/2021 07:10:05",
      "content": "<p>Thank you guys! The  sometimes but now after reading the discussions <a href=\"https://www.kaggle.com/tomooinubushi\" target=\"_blank\">@tomooinubushi</a> linked I understand some floor infos are not correct 😬</p>\n<p><a href=\"https://www.kaggle.com/avtobusbratiev\" target=\"_blank\">@avtobusbratiev</a> I think you have an error still in the formula.<br>\nInstead of:<br>\n<code>x_scaled = x_max - x_values[x_iter] * (x_max - x_min)/width_meter</code></p>\n<p>Should be:<br>\n<code>x_scaled = x_min + x_values[x_iter] * (x_max - x_min)/width_meter</code><br>\nDon't you think?</p>",
      "rawMarkdown": "Thank you guys! The ~~scaling corrected still seems weird~~ sometimes but now after reading the discussions @tomooinubushi linked I understand some floor infos are not correct 😬\n\n@avtobusbratiev I think you have an error still in the formula.\nInstead of:\n`x_scaled = x_max - x_values[x_iter] * (x_max - x_min)/width_meter`\n\nShould be:\n`x_scaled = x_min + x_values[x_iter] * (x_max - x_min)/width_meter`\nDon't you think?",
      "votes": null
    },
    {
      "id": "1303813",
      "postDate": "05/12/2021 08:59:45",
      "content": "<p>I will check it a bit later, but the maps for floors with correct infos seem to have a perfect grids when plotted. Even if there is some difference, I cannot see it at all. But I also rotate the polygons, so I am not sure how to answer.</p>\n<p>I will upload my notebook in a few hours.</p>",
      "rawMarkdown": "I will check it a bit later, but the maps for floors with correct infos seem to have a perfect grids when plotted. Even if there is some difference, I cannot see it at all. But I also rotate the polygons, so I am not sure how to answer.\n\nI will upload my notebook in a few hours.",
      "votes": null
    },
    {
      "id": "1304005",
      "postDate": "05/12/2021 11:25:57",
      "content": "<p>I have made an attempt of implementing the grid generator and it seems to work, you can access it by the link below.<br>\n </p>\n<p><a href=\"https://www.kaggle.com/avtobusbratiev/grid-generator\" target=\"_blank\">https://www.kaggle.com/avtobusbratiev/grid-generator</a></p>\n<p>upd. </p>\n<p>As <a href=\"https://www.kaggle.com/joelqv\" target=\"_blank\">@joelqv</a> has said earlier, maybe the scaling should depend on min, not on the max. If anybody figures out the best scaling out of those two or has any ideas how to improve it - please, let me know in the comments.</p>\n<p>upd.2</p>\n<p>One of the problems of the previous notebook was that it generated points way too close to the walls. I have tried to find a way to fix it and introduce a minimum distance from the wall in the next notebook:</p>\n<p><a href=\"https://www.kaggle.com/avtobusbratiev/shrinking-the-corridors\" target=\"_blank\">https://www.kaggle.com/avtobusbratiev/shrinking-the-corridors</a></p>",
      "rawMarkdown": "I have made an attempt of implementing the grid generator and it seems to work, you can access it by the link below.\n ~~Mistakes are expected.~~\n\nhttps://www.kaggle.com/avtobusbratiev/grid-generator\n\nupd. \n\nAs @joelqv has said earlier, maybe the scaling should depend on min, not on the max. If anybody figures out the best scaling out of those two or has any ideas how to improve it - please, let me know in the comments.\n\nupd.2\n\nOne of the problems of the previous notebook was that it generated points way too close to the walls. I have tried to find a way to fix it and introduce a minimum distance from the wall in the next notebook:\n\nhttps://www.kaggle.com/avtobusbratiev/shrinking-the-corridors",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1300185,
      "author_name": "tomooinubushi",
      "author_url": "",
      "post_date": "05/10/2021 10:18:03",
      "content": "<p>I have already tried almost the same thing with shapely package (I have no Idea which is better shapely or sympy, as I did not know both packages before this competition).<br>\nI merged all floor and site polygons with <code>unary_union</code> function and then subtract store from floor beforehand.<br>\nThe code is something like that.</p>\n<pre><code>from shapely.geometry import Point\nfrom shapely.geometry.polygon import Polygon\nimport shapely.ops as so\nfloor_polygons= so.unary_union(floor_polygons)\nstore_polygons= so.unary_union(store_polygons)\nsafe_area_polygons=floor_polygons.difference(store_polygons)\n</code></pre>\n<p><br>\nThen, I determined the points inside or not.</p>\n<pre><code>point = Point([x,y])\nif safe_area_polygons.contains(point):\n   do something\n</code></pre>\n<p>My search range and resolution for x and y values are lower than range(int(site_width)), but I am not sure it is optimal.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1300428,
          "author_name": "iwatatakuya",
          "author_url": "",
          "post_date": "05/10/2021 12:56:57",
          "content": "<p>shapely did work!<br>\nIt is much faster.<br>\nThank you so much.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1302635,
          "author_name": "joelqv",
          "author_url": "",
          "post_date": "05/11/2021 16:32:23",
          "content": "<p>Hey! Sorry to bother, may I ask you how have you translated points from GeoJson to (x,y) waypoints? I published a <a href=\"https://www.kaggle.com/joelqv/where-are-your-predictions-located-shapely\" target=\"_blank\">notebook</a> after reading you guys. However, I have the feeling that I have wrongly computed the (x,y) coordinates.<br>\nIf you want to answer after the competition ends it is fine :).</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1303023,
          "author_name": "avtobusbratiev",
          "author_url": "",
          "post_date": "05/11/2021 21:21:17",
          "content": "<p>From what I see the scaling is a little bit off. </p>\n<p>All I can say is that introducing some constant values helps, but it can be better.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1303058,
          "author_name": "joelqv",
          "author_url": "",
          "post_date": "05/11/2021 21:54:01",
          "content": "<p>I tried to scale using the floor map info but it does not seem to be correct <br>\n<code>df_result['x_scaled'] = (x_max * df_result['x']) / floor_info['map_info']['width']</code><br>\n<code>df_result['y_scaled'] = (y_max * df_result['y']) / floor_info['map_info']['height']</code></p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1303133,
          "author_name": "avtobusbratiev",
          "author_url": "",
          "post_date": "05/11/2021 23:28:56",
          "content": "<p></p>\n<p><br>\n</p>\n<p></p>\n<p>upd. </p>\n<p>x_scaled = x_max - x_values[x_iter] * (x_max - x_min)/width_meter</p>\n<p>y_scaled = y_max - y_values[y_iter] * (y_max - y_min)/height_meter</p>\n<p>does the right thing with a perfect grid for me.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1303180,
          "author_name": "tomooinubushi",
          "author_url": "",
          "post_date": "05/12/2021 00:18:13",
          "content": "<p>I corrected the values as <a href=\"https://www.kaggle.com/avtobusbratiev\" target=\"_blank\">@avtobusbratiev</a> noted. <br>\nFrom the discussions in <a href=\"https://www.kaggle.com/c/indoor-location-navigation/discussion/230558\" target=\"_blank\">here</a> and <a href=\"https://www.kaggle.com/c/indoor-location-navigation/discussion/230379\" target=\"_blank\">here</a>, I should correct y values manually for some buildings, but I am too lazy to do that. It should be also noted that some train waypoints are actually inside the store.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1303649,
          "author_name": "joelqv",
          "author_url": "",
          "post_date": "05/12/2021 07:10:05",
          "content": "<p>Thank you guys! The  sometimes but now after reading the discussions <a href=\"https://www.kaggle.com/tomooinubushi\" target=\"_blank\">@tomooinubushi</a> linked I understand some floor infos are not correct 😬</p>\n<p><a href=\"https://www.kaggle.com/avtobusbratiev\" target=\"_blank\">@avtobusbratiev</a> I think you have an error still in the formula.<br>\nInstead of:<br>\n<code>x_scaled = x_max - x_values[x_iter] * (x_max - x_min)/width_meter</code></p>\n<p>Should be:<br>\n<code>x_scaled = x_min + x_values[x_iter] * (x_max - x_min)/width_meter</code><br>\nDon't you think?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1303813,
          "author_name": "avtobusbratiev",
          "author_url": "",
          "post_date": "05/12/2021 08:59:45",
          "content": "<p>I will check it a bit later, but the maps for floors with correct infos seem to have a perfect grids when plotted. Even if there is some difference, I cannot see it at all. But I also rotate the polygons, so I am not sure how to answer.</p>\n<p>I will upload my notebook in a few hours.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1300380,
      "author_name": "chris62",
      "author_url": "",
      "post_date": "05/10/2021 12:22:01",
      "content": "<p>You also have the floorplan images themselves that you can use (this is how I'm doing it):</p>\n<ol>\n<li><p>first remove the writing from the hallways; I did this with a script that removed any gray pixel next to a clear (hallway) pixel, and ran it 3x or so to remove all the writing. It wasn't perfect, but pretty good</p></li>\n<li><p>Now you should have a png where the transparent pixels are the hallways, and everything else is a color.</p></li>\n</ol>\n<p>Then you just have to check if your potential waypoint is on a clear hallway or not (still takes some time depending on the image package you're using, but not as much as checking all the polygons).</p>\n<p>If you're not comfortable with image manipulation, then <a href=\"https://www.kaggle.com/tomooinubushi\" target=\"_blank\">@tomooinubushi</a> 's way is probably faster for you</p>\n<p>[edit]: there are a few tricks with how to convert from meters to pixels, and what coordinate system your image packages uses, etc; I got this wrong about 3 times before getting it right, and it was tricky to tell if it was working or not :) so just be careful of that</p>",
      "votes": null,
      "replies": [
        {
          "id": 1300433,
          "author_name": "iwatatakuya",
          "author_url": "",
          "post_date": "05/10/2021 13:01:07",
          "content": "<p>Thank you for your comment!<br>\nhmm… it seems to be quite difficult and tricky.<br>\nI'm looking forward to hear your solution (not only this topic) after the competition anyway :)</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1300411,
      "author_name": "group16",
      "author_url": "",
      "post_date": "05/10/2021 12:48:36",
      "content": "<p>I would advise to use the geojson over the PNG as well, and manipulating them with Shapely.</p>\n<p>You should get more accurate floor-maps and there are some nice functions within Shapely that makes your life a lot easier.</p>\n<p>Some examples of hallway-plans I extracted using the geo-json: <a href=\"https://imgur.com/a/4gl1k64\" target=\"_blank\">https://imgur.com/a/4gl1k64</a></p>",
      "votes": null,
      "replies": [
        {
          "id": 1300435,
          "author_name": "iwatatakuya",
          "author_url": "",
          "post_date": "05/10/2021 13:02:14",
          "content": "<p>Thank you for your comment!<br>\nShapely seems to be good.<br>\nI'll try it!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1304005,
      "author_name": "avtobusbratiev",
      "author_url": "",
      "post_date": "05/12/2021 11:25:57",
      "content": "<p>I have made an attempt of implementing the grid generator and it seems to work, you can access it by the link below.<br>\n </p>\n<p><a href=\"https://www.kaggle.com/avtobusbratiev/grid-generator\" target=\"_blank\">https://www.kaggle.com/avtobusbratiev/grid-generator</a></p>\n<p>upd. </p>\n<p>As <a href=\"https://www.kaggle.com/joelqv\" target=\"_blank\">@joelqv</a> has said earlier, maybe the scaling should depend on min, not on the max. If anybody figures out the best scaling out of those two or has any ideas how to improve it - please, let me know in the comments.</p>\n<p>upd.2</p>\n<p>One of the problems of the previous notebook was that it generated points way too close to the walls. I have tried to find a way to fix it and introduce a minimum distance from the wall in the next notebook:</p>\n<p><a href=\"https://www.kaggle.com/avtobusbratiev/shrinking-the-corridors\" target=\"_blank\">https://www.kaggle.com/avtobusbratiev/shrinking-the-corridors</a></p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1300086": "Now I'm trying to create grid points (possible waypoints) automatically because we cannot use hand labeled grid points.\nMy basic idea is search all possible grid points and adopt them if they are inside the floor polygon and outside the store polygons.\nBut, it takes too long time to determine inside the polygon or not...\nAnyone has better idea?\n\nBelow is a part of my code.\nfloor_poly is a polygon of the floor and list_poly is a list of polygons of stores.\n\n```Python\nfrom sympy.geometry import Point, Polygon\nl_x = []\nl_y = []\nl_site = []\nl_fNo = []\nn_store = len(store_coord)\n\n# search for all possible grid points\nfor x in range(int(site_width)):\n    for y in range(int(site_height)):\n        point = Point(x,y)\n        # not adopt if the point is outside of the floor polygon\n        if not floor_poly.encloses_point(point):continue\n        flg_inside = True\n        # search for all stores\n        for i in range(n_store):\n            # not adopt if the point is inside the store polygon\n            if list_poly[i].encloses_point(point):\n                flg_inside = False\n                break\n        if flg_inside:\n            l_x += [x]\n            l_y += [y]\n            l_site += [site_id]\n            l_fNo += [floorNo]\ndf_waypoint_add = pd.DataFrame(data={\"x\":l_x,\"y\":l_y,\"site\":l_site,\"floorNo\":l_fNo},\n                               columns=[\"x\",\"y\",\"site\",\"floorNo\"])\n```",
    "1300185": "I have already tried almost the same thing with shapely package (I have no Idea which is better shapely or sympy, as I did not know both packages before this competition).\nI merged all floor and site polygons with `unary_union` function and then subtract store from floor beforehand.\nThe code is something like that.\n\n``` \nfrom shapely.geometry import Point\nfrom shapely.geometry.polygon import Polygon\nimport shapely.ops as so\nfloor_polygons= so.unary_union(floor_polygons)\nstore_polygons= so.unary_union(store_polygons)\nsafe_area_polygons=floor_polygons.difference(store_polygons)\n``` \nThen, I determined the points inside or not.\n``` \npoint = Point([x,y])\nif safe_area_polygons.contains(point):\n   do something\n```\nMy search range and resolution for x and y values are lower than range(int(site_width)), but I am not sure it is optimal.",
    "1300380": "You also have the floorplan images themselves that you can use (this is how I'm doing it):\n\n1. first remove the writing from the hallways; I did this with a script that removed any gray pixel next to a clear (hallway) pixel, and ran it 3x or so to remove all the writing. It wasn't perfect, but pretty good\n\n2. Now you should have a png where the transparent pixels are the hallways, and everything else is a color.\n\nThen you just have to check if your potential waypoint is on a clear hallway or not (still takes some time depending on the image package you're using, but not as much as checking all the polygons).\n\nIf you're not comfortable with image manipulation, then @tomooinubushi 's way is probably faster for you\n\n[edit]: there are a few tricks with how to convert from meters to pixels, and what coordinate system your image packages uses, etc; I got this wrong about 3 times before getting it right, and it was tricky to tell if it was working or not :) so just be careful of that",
    "1300411": "I would advise to use the geojson over the PNG as well, and manipulating them with Shapely.\n\nYou should get more accurate floor-maps and there are some nice functions within Shapely that makes your life a lot easier.\n\nSome examples of hallway-plans I extracted using the geo-json: https://imgur.com/a/4gl1k64",
    "1300428": "shapely did work!\nIt is much faster.\nThank you so much.",
    "1300433": "Thank you for your comment!\nhmm... it seems to be quite difficult and tricky.\nI'm looking forward to hear your solution (not only this topic) after the competition anyway :)",
    "1300435": "Thank you for your comment!\nShapely seems to be good.\nI'll try it!",
    "1302635": "Hey! Sorry to bother, may I ask you how have you translated points from GeoJson to (x,y) waypoints? I published a [notebook](https://www.kaggle.com/joelqv/where-are-your-predictions-located-shapely) after reading you guys. However, I have the feeling that I have wrongly computed the (x,y) coordinates.\nIf you want to answer after the competition ends it is fine :).",
    "1303023": "From what I see the scaling is a little bit off. \n\nAll I can say is that introducing some constant values helps, but it can be better.",
    "1303058": "I tried to scale using the floor map info but it does not seem to be correct \n`df_result['x_scaled'] = (x_max * df_result['x']) / floor_info['map_info']['width']`\n`df_result['y_scaled'] = (y_max * df_result['y']) / floor_info['map_info']['height']`",
    "1303133": "~~The closest to being somewhat good scaling I have obtained was by doing something like~~\n\n~~df_result['x_scaled'] = (x_max * df_result['x']) + xx~~\n~~df_result['y_scaled'] = (y_max * df_result['y']) + xx~~\n\n~~But this isnt a good idea, because scaling doesnt seem to be uniform that way. I have also tried to use a different scaling for different parts of the floor, and while it gives a bit better results it is not too far from random guessing.~~\n\nupd. \n\nx_scaled = x_max - x_values[x_iter] * (x_max - x_min)/width_meter\n\ny_scaled = y_max - y_values[y_iter] * (y_max - y_min)/height_meter\n\ndoes the right thing with a perfect grid for me.",
    "1303180": "I corrected the values as @avtobusbratiev noted. \nFrom the discussions in [here](https://www.kaggle.com/c/indoor-location-navigation/discussion/230558) and [here](https://www.kaggle.com/c/indoor-location-navigation/discussion/230379), I should correct y values manually for some buildings, but I am too lazy to do that. It should be also noted that some train waypoints are actually inside the store.",
    "1303649": "Thank you guys! The ~~scaling corrected still seems weird~~ sometimes but now after reading the discussions @tomooinubushi linked I understand some floor infos are not correct 😬\n\n@avtobusbratiev I think you have an error still in the formula.\nInstead of:\n`x_scaled = x_max - x_values[x_iter] * (x_max - x_min)/width_meter`\n\nShould be:\n`x_scaled = x_min + x_values[x_iter] * (x_max - x_min)/width_meter`\nDon't you think?",
    "1303813": "I will check it a bit later, but the maps for floors with correct infos seem to have a perfect grids when plotted. Even if there is some difference, I cannot see it at all. But I also rotate the polygons, so I am not sure how to answer.\n\nI will upload my notebook in a few hours.",
    "1304005": "I have made an attempt of implementing the grid generator and it seems to work, you can access it by the link below.\n ~~Mistakes are expected.~~\n\nhttps://www.kaggle.com/avtobusbratiev/grid-generator\n\nupd. \n\nAs @joelqv has said earlier, maybe the scaling should depend on min, not on the max. If anybody figures out the best scaling out of those two or has any ideas how to improve it - please, let me know in the comments.\n\nupd.2\n\nOne of the problems of the previous notebook was that it generated points way too close to the walls. I have tried to find a way to fix it and introduce a minimum distance from the wall in the next notebook:\n\nhttps://www.kaggle.com/avtobusbratiev/shrinking-the-corridors"
  },
  "source": "meta"
}