turf icon indicating copy to clipboard operation
turf copied to clipboard

turf.polygonize lack support for holes (Different output compared to shapely)

Open seop-archisketch opened this issue 2 years ago • 1 comments

Please provide the following when reporting an issue:

  • [x] The version of Turf you are using, and any other relevant versions.
  • [x] GeoJSON data as a gist file or geojson.io (filename extension must be .geojson).
  • [x] Snippet of source code or for complex examples use jsfiddle.
  • Installed version: 6.5.0 for @turf/polygonize and @turf/helpers
  • GeoJSON data: map.geojson
  • Input:
const lines = multiLineString([
	[
		[37.5, 37.5],
		[37.6, 37.5],
	],
	[
		[37.6, 37.5],
		[37.6, 37.6],
	],
	[
		[37.6, 37.6],
		[37.5, 37.6],
	],
	[
		[37.5, 37.6],
		[37.5, 37.5],
	],

	[
		[37.525, 37.525],
		[37.575, 37.525],
	],
	[
		[37.575, 37.525],
		[37.575, 37.575],
	],
	[
		[37.575, 37.575],
		[37.525, 37.575],
	],
	[
		[37.525, 37.575],
		[37.525, 37.525],
	],
]);
const polygonized = polygonize(lines);
  • output:
{
  "type":"FeatureCollection",
  "features":[
    {
      "type":"Feature",
      "properties":{
        
      },
      "geometry":{
        "type":"Polygon",
        "coordinates":[
          [
            [
              37.6,
              37.5
            ],
            [
              37.5,
              37.5
            ],
            [
              37.5,
              37.6
            ],
            [
              37.6,
              37.6
            ],
            [
              37.6,
              37.5
            ]
          ]
        ]
      }
    },
    {
      "type":"Feature",
      "properties":{
        
      },
      "geometry":{
        "type":"Polygon",
        "coordinates":[
          [
            [
              37.575,
              37.525
            ],
            [
              37.525,
              37.525
            ],
            [
              37.525,
              37.575
            ],
            [
              37.575,
              37.575
            ],
            [
              37.575,
              37.525
            ]
          ]
        ]
      }
    },
    {
      "type":"Feature",
      "properties":{
        
      },
      "geometry":{
        "type":"Polygon",
        "coordinates":[
          [
            [
              37.525,
              37.525
            ],
            [
              37.575,
              37.525
            ],
            [
              37.575,
              37.575
            ],
            [
              37.525,
              37.575
            ],
            [
              37.525,
              37.525
            ]
          ]
        ]
      }
    }
  ]
}
  • EXPECTED OUTPUT (AS-IS in shapely): GEOMETRYCOLLECTION (POLYGON ((100 0, 0 0, 0 100, 100 100, 100 0), (25 75, 25 25, 75 25, 75 75, 25 75)), POLYGON ((25 25, 25 75, 75 75, 75 25, 25 25)))

The second element in POLYGON represents holes.

  • Instead of getting one large rectangle with a rectangular hole, and a smaller rectangle that fits the hole, @turf/polygonize returns three polygons, two of which are the same.

seop-archisketch avatar Feb 27 '23 01:02 seop-archisketch

Any movement on this one? I ran into this recently as well and was about to log another issue when I saw this one (with almost the exact same example I had) Whilst I found a workaround for our scenario, it would be much better improved if polygonize constructed results with holes implicitly.

hf-farmqa avatar Apr 24 '24 21:04 hf-farmqa