Skip to content

kachark/geo-split

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

geo-split

geo-split is a small set of utilities to split GeoJSON geometries given in geographic coordinates. This includes handling for discontinuities at -180,180 degrees longitude.

Most GeoJSON renderers cannot distinguish the user intent for geometries with coordinates that cross -180/180 degrees longitude. Due to this, renderers will often opt to wrap them around the world, producing unintended visual artifacts. geo-split fixes this by splitting geometries around these discontinuities.

Installation

npm i geo-split

Example

Consider the polygon which crosses the antimeridian:

const polygon = {
  geometry: {
    coordinates: [
      [
        [170, 2],
        [175, 4],
        [-178, 8],
        [173, 7],
        [170, 2]
      ]
    ],
    type: "Polygon"
  },
  type: "Feature"
};

The split polygon now straddles the antimeridian:

const split = splitPolygonAntimeridian(polygon);

{
  geometry: {
    coordinates: [
      [
        [
          [170, 2],
          [175, 4],
          [180, 6.857142857142858],
          [180, 7.777777777777778],
          [173, 7],
          [170, 2],
        ],
      ],
      [
        [
          [-180, 6.857142857142858],
          [-178, 8],
          [-180, 7.777777777777778],
          [-180, 6.857142857142858],
        ],
      ],
    ],
    type: "MultiPolygon"
  },
  type: "Feature"
}

Dependencies

  • @turf/bbox-clip,
  • @turf/helpers
  • @turf/line-split

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published