Åuto-generation and promotion options for Feature Ids - #109
Conversation
| lineMetrics: false, // whether to enable line metrics tracking for LineString/MultiLineString features | ||
| promoteId: null, // name of a feature property to promote to feature.id. Cannot be used with `generateId` | ||
| generateId: false, // whether to generate feature ids. Cannot be used with `promoteId` | ||
| indexMaxZoom: 5, // max zoom in the initial tile index |
| geometry = []; | ||
| convertLine(coords[i], geometry, tolerance, false); | ||
| features.push(createFeature(geojson.id, 'LineString', geometry, geojson.properties)); | ||
| features.push(createFeature(id, 'LineString', geometry, geojson.properties)); |
There was a problem hiding this comment.
It looks like when lineMetrics is turned on, when multiline features are split into multiple features, they won't get the same id with either of id options active, while we need a single id retained across the parts.
There was a problem hiding this comment.
The for-loop uses the same id for all LineString features split here. For both options, the id is computed L32-L37 and would carry for all the line strings.
| for (i = 0; i < geojson.geometry.geometries.length; i++) { | ||
| convertFeature(features, { | ||
| id: geojson.id, | ||
| id: id, |
There was a problem hiding this comment.
Same with geometry collections — the split parts won't get the same id with auto-id-generation.
…o all features split from a GeometryCollection.
| geometry: geojson.geometry.geometries[i], | ||
| properties: geojson.properties | ||
| }, options); | ||
| }, options, index); |
There was a problem hiding this comment.
This should ensure that split geometry collections use the index of the original GeoJSON feature as their id in the auto-generated Id case.
|
Released in v3.2.0. |
This PR adds two options for assigning ids to features -
promoteIdandgenerateId. Both options will ignore and replace the existingidfield on features. This options can be used to consistently populate thefeautre.idfor GeoJSON data.promoteIdThis option allows promoting a named feature property to be used as the
idvalue. Useful when the existing data already includes unique identifiers in the feature data.Example
Setting `promoteId: "guid"` would convert ``` { "type": "Feature", "id": 0 "geometry": { "type": "Point", "coordinates": [ 0, 0] }, "properties": { "guid": 12345, "prop1": {"this": "that"} } } ``` to ``` { "id": 12345, "type":1, "geometry":[0, 0], "tags":{"guid":12345,"prop1":{"this":"that"}} } ```generateIdWhen the existing data does not have any id-like properties, this option can be used to auto assign the feature id using the feature's index in the
featuresarray of aFeatureCollection.Example
Enabling `generateId: true` would for example convert ``` { "type": "FeatureCollection", "features": [ {...}, //index 0 {...}, // 1 { // 2 "type": "Feature", "id": 0 "geometry": { "type": "Point", "coordinates": [ 0, 0] }, "properties": { "guid": 12345, "prop1": {"this": "that"} } } ] } ``` to ``` { "id": 2, "type":1, "geometry":[0, 0], "tags":{"guid":12345,"prop1":{"this":"that"}} } ```Addresses #106.
cc @ryanbaumann