{
  "id": 28182,
  "title": "non-noded intersection --> code share ?",
  "url": "/competitions/dstl-satellite-imagery-feature-detection/discussion/28182",
  "author_name": "",
  "post_date": "2017-01-27T16:31:20.267Z",
  "votes": 2,
  "comment_count": 9,
  "views": 264,
  "content": "<p>Hello,</p>\n\n<p>Does anybody have a python code solving the \"non-noded intersection\" exception?</p>\n\n<p>I tried to use shapely to identify which of my polygons are affected, \nbut I clearly didn't succeed as I am still getting this error despite a precision rounded to 8 decimals and all my polygons passing the \"is_simple and is_valid\" test.</p>\n\n<p>Thanks in advance for your help,\nLoic</p>\n\n<p>--</p>",
  "messages": [
    {
      "id": "158477",
      "postDate": "01/27/2017 16:31:20",
      "content": "<p>Hello,</p>\n\n<p>Does anybody have a python code solving the \"non-noded intersection\" exception?</p>\n\n<p>I tried to use shapely to identify which of my polygons are affected, \nbut I clearly didn't succeed as I am still getting this error despite a precision rounded to 8 decimals and all my polygons passing the \"is_simple and is_valid\" test.</p>\n\n<p>Thanks in advance for your help,\nLoic</p>\n\n<p>--</p>",
      "rawMarkdown": "Hello,\r\n\r\nDoes anybody have a python code solving the \"non-noded intersection\" exception?\r\n\r\nI tried to use shapely to identify which of my polygons are affected, \r\nbut I clearly didn't succeed as I am still getting this error despite a precision rounded to 8 decimals and all my polygons passing the \"is_simple and is_valid\" test.\r\n\r\nThanks in advance for your help,\r\nLoic\r\n\r\n--",
      "votes": null
    },
    {
      "id": "158484",
      "postDate": "01/27/2017 16:44:56",
      "content": "<p>Try to use cascaded_union (or unary_union) in order to transform set of polygons to one multipolygon, and then reduce precision of that multipolygon. ( Here is the information what cascaded_union does: <a href=\"http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union\">http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union</a>)</p>",
      "rawMarkdown": "Try to use cascaded_union (or unary_union) in order to transform set of polygons to one multipolygon, and then reduce precision of that multipolygon. ( Here is the information what cascaded_union does: http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union)",
      "votes": null
    },
    {
      "id": "158490",
      "postDate": "01/27/2017 17:27:02",
      "content": "<p>[quote=LoicQuertenmont;158477]</p>\n\n<p>Hello,</p>\n\n<p>Does anybody have a python code solving the \"non-noded intersection\" exception?</p>\n\n<p>[/quote]</p>\n\n<p>Not yet. Manually zeroing them out, based on the error message during submission :(</p>",
      "rawMarkdown": "[quote=LoicQuertenmont;158477]\r\n\r\nHello,\r\n\r\nDoes anybody have a python code solving the \"non-noded intersection\" exception?\r\n\r\n[/quote]\r\n\r\nNot yet. Manually zeroing them out, based on the error message during submission :(",
      "votes": null
    },
    {
      "id": "158502",
      "postDate": "01/27/2017 18:16:19",
      "content": "<p>like me, but I gave up at the third iteration for my last submission :-(</p>",
      "rawMarkdown": "like me, but I gave up at the third iteration for my last submission :-(",
      "votes": null
    },
    {
      "id": "158518",
      "postDate": "01/27/2017 20:17:29",
      "content": "<p>[quote=Alexey Lu;158484]</p>\n\n<p>Try to use cascaded_union (or unary_union) in order to transform set of polygons to one multipolygon, and then reduce precision of that multipolygon. ( Here is the information what cascaded_union does: <a href=\"http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union\">http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union</a>)</p>\n\n<p>[/quote]</p>\n\n<p>didn't help in my case :-(</p>",
      "rawMarkdown": "[quote=Alexey Lu;158484]\r\n\r\nTry to use cascaded_union (or unary_union) in order to transform set of polygons to one multipolygon, and then reduce precision of that multipolygon. ( Here is the information what cascaded_union does: http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union)\r\n\r\n\r\n[/quote]\r\n\r\ndidn't help in my case :-(",
      "votes": null
    },
    {
      "id": "158533",
      "postDate": "01/27/2017 21:41:56",
      "content": "<p>I had the same problem when I used openCV to detect contours. OpenCV generated polygons with zero-angle vertices: the edges at that angle were almost parallel. I used skimage.measure.findContours() method instead and it solved my problem. If you still want to use openCV and you have these polygons with needle-like vertices, you can try to detect these sharp angles and remove either angle from polygon or polygon itself from a multipolygon set. Also, on the shapely manual page I found <em>parallel_offset</em>  method that may help to solve a sharp angle problem. Hope this helps!</p>",
      "rawMarkdown": "I had the same problem when I used openCV to detect contours. OpenCV generated polygons with zero-angle vertices: the edges at that angle were almost parallel. I used skimage.measure.findContours() method instead and it solved my problem. If you still want to use openCV and you have these polygons with needle-like vertices, you can try to detect these sharp angles and remove either angle from polygon or polygon itself from a multipolygon set. Also, on the shapely manual page I found *parallel_offset*  method that may help to solve a sharp angle problem. Hope this helps!",
      "votes": null
    },
    {
      "id": "158702",
      "postDate": "01/29/2017 07:09:12",
      "content": "<p>Ok, I found the cause of my troubles,</p>\n\n<p>The thing is that my polygons are corrected after a call to buffer(0),\nand I checked that in my script via is_simple and is_valid.\nHowever, after I write them to the csv file using wkt_dumps function (with 6 or 8 decimals precision), \nthe written polygon is not necessary still valid....\nSo in order to make sure they are valid, I convert back my dump string, to a shapely polygon and cross-check that they are indeed still valid and simple.  If they aren't I repeat the buffer(0) procedure.\nThanks to this, all my polygons are now always valid and I don't have submission problems anymore.</p>\n\n<p>I think it could be useful to others.</p>",
      "rawMarkdown": "Ok, I found the cause of my troubles,\r\n\r\nThe thing is that my polygons are corrected after a call to buffer(0),\r\nand I checked that in my script via is_simple and is_valid.\r\nHowever, after I write them to the csv file using wkt_dumps function (with 6 or 8 decimals precision), \r\nthe written polygon is not necessary still valid....\r\nSo in order to make sure they are valid, I convert back my dump string, to a shapely polygon and cross-check that they are indeed still valid and simple.  If they aren't I repeat the buffer(0) procedure.\r\nThanks to this, all my polygons are now always valid and I don't have submission problems anymore.\r\n\r\nI think it could be useful to others.",
      "votes": null
    },
    {
      "id": "158736",
      "postDate": "01/29/2017 18:14:47",
      "content": "<p>Another thing is that better your prediction is =&gt; better polygons =&gt; less submission errors. </p>\n\n<p>Currently, my best result is 0.42, and, I did not get any errors during submission. Although I would admit, that it may be just an accident.</p>",
      "rawMarkdown": "Another thing is that better your prediction is => better polygons => less submission errors. \r\n\r\nCurrently, my best result is 0.42, and, I did not get any errors during submission. Although I would admit, that it may be just an accident.",
      "votes": null
    },
    {
      "id": "158812",
      "postDate": "01/30/2017 08:27:35",
      "content": "<p>is everyone using shapely to create polygons and is this the best solution for this?</p>\n\n<p>I am trying to use gdal_polygonize which is blazing fast, but it creates some very weird polygons covering whole map with many holes (on top of normal polygons), and dealing with it is not very trivial. anyone experiencing simillar behaviour?</p>",
      "rawMarkdown": "is everyone using shapely to create polygons and is this the best solution for this?\r\n\r\nI am trying to use gdal_polygonize which is blazing fast, but it creates some very weird polygons covering whole map with many holes (on top of normal polygons), and dealing with it is not very trivial. anyone experiencing simillar behaviour?",
      "votes": null
    },
    {
      "id": "158824",
      "postDate": "01/30/2017 10:01:01",
      "content": "<p>I am not using shapely to create my polygons,\nI am just using shapely to clean them up as it seems to be good and fast at this.</p>",
      "rawMarkdown": "I am not using shapely to create my polygons,\r\nI am just using shapely to clean them up as it seems to be good and fast at this.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 158490,
      "author_name": "iglovikov",
      "author_url": "",
      "post_date": "01/27/2017 17:27:02",
      "content": "<p>[quote=LoicQuertenmont;158477]</p>\n\n<p>Hello,</p>\n\n<p>Does anybody have a python code solving the \"non-noded intersection\" exception?</p>\n\n<p>[/quote]</p>\n\n<p>Not yet. Manually zeroing them out, based on the error message during submission :(</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 158484,
      "author_name": "alexlu",
      "author_url": "",
      "post_date": "01/27/2017 16:44:56",
      "content": "<p>Try to use cascaded_union (or unary_union) in order to transform set of polygons to one multipolygon, and then reduce precision of that multipolygon. ( Here is the information what cascaded_union does: <a href=\"http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union\">http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union</a>)</p>",
      "votes": null,
      "replies": [
        {
          "id": 158518,
          "author_name": "loicus",
          "author_url": "",
          "post_date": "01/27/2017 20:17:29",
          "content": "<p>[quote=Alexey Lu;158484]</p>\n\n<p>Try to use cascaded_union (or unary_union) in order to transform set of polygons to one multipolygon, and then reduce precision of that multipolygon. ( Here is the information what cascaded_union does: <a href=\"http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union\">http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union</a>)</p>\n\n<p>[/quote]</p>\n\n<p>didn't help in my case :-(</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 158502,
      "author_name": "loicus",
      "author_url": "",
      "post_date": "01/27/2017 18:16:19",
      "content": "<p>like me, but I gave up at the third iteration for my last submission :-(</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 158533,
      "author_name": "alexlu",
      "author_url": "",
      "post_date": "01/27/2017 21:41:56",
      "content": "<p>I had the same problem when I used openCV to detect contours. OpenCV generated polygons with zero-angle vertices: the edges at that angle were almost parallel. I used skimage.measure.findContours() method instead and it solved my problem. If you still want to use openCV and you have these polygons with needle-like vertices, you can try to detect these sharp angles and remove either angle from polygon or polygon itself from a multipolygon set. Also, on the shapely manual page I found <em>parallel_offset</em>  method that may help to solve a sharp angle problem. Hope this helps!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 158702,
      "author_name": "loicus",
      "author_url": "",
      "post_date": "01/29/2017 07:09:12",
      "content": "<p>Ok, I found the cause of my troubles,</p>\n\n<p>The thing is that my polygons are corrected after a call to buffer(0),\nand I checked that in my script via is_simple and is_valid.\nHowever, after I write them to the csv file using wkt_dumps function (with 6 or 8 decimals precision), \nthe written polygon is not necessary still valid....\nSo in order to make sure they are valid, I convert back my dump string, to a shapely polygon and cross-check that they are indeed still valid and simple.  If they aren't I repeat the buffer(0) procedure.\nThanks to this, all my polygons are now always valid and I don't have submission problems anymore.</p>\n\n<p>I think it could be useful to others.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 158736,
      "author_name": "iglovikov",
      "author_url": "",
      "post_date": "01/29/2017 18:14:47",
      "content": "<p>Another thing is that better your prediction is =&gt; better polygons =&gt; less submission errors. </p>\n\n<p>Currently, my best result is 0.42, and, I did not get any errors during submission. Although I would admit, that it may be just an accident.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 158812,
      "author_name": "raddar",
      "author_url": "",
      "post_date": "01/30/2017 08:27:35",
      "content": "<p>is everyone using shapely to create polygons and is this the best solution for this?</p>\n\n<p>I am trying to use gdal_polygonize which is blazing fast, but it creates some very weird polygons covering whole map with many holes (on top of normal polygons), and dealing with it is not very trivial. anyone experiencing simillar behaviour?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 158824,
      "author_name": "loicus",
      "author_url": "",
      "post_date": "01/30/2017 10:01:01",
      "content": "<p>I am not using shapely to create my polygons,\nI am just using shapely to clean them up as it seems to be good and fast at this.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "158477": "Hello,\r\n\r\nDoes anybody have a python code solving the \"non-noded intersection\" exception?\r\n\r\nI tried to use shapely to identify which of my polygons are affected, \r\nbut I clearly didn't succeed as I am still getting this error despite a precision rounded to 8 decimals and all my polygons passing the \"is_simple and is_valid\" test.\r\n\r\nThanks in advance for your help,\r\nLoic\r\n\r\n--",
    "158484": "Try to use cascaded_union (or unary_union) in order to transform set of polygons to one multipolygon, and then reduce precision of that multipolygon. ( Here is the information what cascaded_union does: http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union)",
    "158490": "[quote=LoicQuertenmont;158477]\r\n\r\nHello,\r\n\r\nDoes anybody have a python code solving the \"non-noded intersection\" exception?\r\n\r\n[/quote]\r\n\r\nNot yet. Manually zeroing them out, based on the error message during submission :(",
    "158502": "like me, but I gave up at the third iteration for my last submission :-(",
    "158518": "[quote=Alexey Lu;158484]\r\n\r\nTry to use cascaded_union (or unary_union) in order to transform set of polygons to one multipolygon, and then reduce precision of that multipolygon. ( Here is the information what cascaded_union does: http://toblerity.org/shapely/manual.html#shapely.ops.cascaded_union)\r\n\r\n\r\n[/quote]\r\n\r\ndidn't help in my case :-(",
    "158533": "I had the same problem when I used openCV to detect contours. OpenCV generated polygons with zero-angle vertices: the edges at that angle were almost parallel. I used skimage.measure.findContours() method instead and it solved my problem. If you still want to use openCV and you have these polygons with needle-like vertices, you can try to detect these sharp angles and remove either angle from polygon or polygon itself from a multipolygon set. Also, on the shapely manual page I found *parallel_offset*  method that may help to solve a sharp angle problem. Hope this helps!",
    "158702": "Ok, I found the cause of my troubles,\r\n\r\nThe thing is that my polygons are corrected after a call to buffer(0),\r\nand I checked that in my script via is_simple and is_valid.\r\nHowever, after I write them to the csv file using wkt_dumps function (with 6 or 8 decimals precision), \r\nthe written polygon is not necessary still valid....\r\nSo in order to make sure they are valid, I convert back my dump string, to a shapely polygon and cross-check that they are indeed still valid and simple.  If they aren't I repeat the buffer(0) procedure.\r\nThanks to this, all my polygons are now always valid and I don't have submission problems anymore.\r\n\r\nI think it could be useful to others.",
    "158736": "Another thing is that better your prediction is => better polygons => less submission errors. \r\n\r\nCurrently, my best result is 0.42, and, I did not get any errors during submission. Although I would admit, that it may be just an accident.",
    "158812": "is everyone using shapely to create polygons and is this the best solution for this?\r\n\r\nI am trying to use gdal_polygonize which is blazing fast, but it creates some very weird polygons covering whole map with many holes (on top of normal polygons), and dealing with it is not very trivial. anyone experiencing simillar behaviour?",
    "158824": "I am not using shapely to create my polygons,\r\nI am just using shapely to clean them up as it seems to be good and fast at this."
  },
  "source": "meta"
}