Turfjs / Turfjs/turf

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

Open
#2,403 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

@turf/polygonize
Dominant language
TypeScript
Stars
10.5k
Forks
1k
Avg merge
1h 11m
Merged PRs (30d)
4

Description

Please provide the following when reporting an issue:

  • The version of Turf you are using, and any other relevant versions.
  • GeoJSON data as a gist file or geojson.io (filename extension must be .geojson).
  • 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the @turf/polygonize entry point and reproduce the supplied MultiLineString example from the issue. Compare its FeatureCollection with the Shapely expected geometry, then add coverage for a polygon containing a hole; done means the outer rectangle is returned with the hole and the duplicate inner polygons are absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.