Skip to content

The @turf/tesselate function fails to properly process GeoJSON Polygon data that includes elevation. #2672

@Seungup

Description

@Seungup

Description

The @turf/tesselate function fails to properly process GeoJSON Polygon data that includes elevation.

Reproduction

The issue can be reproduced with the following GeoJSON file:

{
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [130.2138542686084, 36.85831846193179, 0],
        [121.54982788145819, 34.421266048716696, 0],
        [131.58908870149648, 33.113275358661966, 0],
        [130.2138542686084, 36.85831846193179, 0]
      ]
    ]
  },
  "properties": {}
}

Code Location

The problem occurs in the following code location:

const data = flattenCoords(coordinates);
const dim = 2;
const result = earcut(data.vertices, data.holes, dim);
const features: Feature<Polygon>[] = [];
const vertices: Position[] = [];
result.forEach(function (vert: any, i: number) {
const index = result[i];
vertices.push([data.vertices[index * dim], data.vertices[index * dim + 1]]);
});

Expected Behavior

The tesselate function should handle GeoJSON Polygons with elevation data correctly, as specified in RFC 7946 Section 3.1.1. According to the RFC, a position is an array of numbers with the first two elements being longitude and latitude, and an optional third element for altitude or elevation.

Actual Behavior

The tesselate function fails to process the provided GeoJSON Polygon, resulting in an error.

Additional Information

Please provide any additional information here that may be useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions