Skip to content

Åuto-generation and promotion options for Feature Ids - #109

Merged
mourner merged 3 commits into
masterfrom
106-feature-ids
Jul 25, 2018
Merged

Åuto-generation and promotion options for Feature Ids#109
mourner merged 3 commits into
masterfrom
106-feature-ids

Conversation

@asheemmamoowala

@asheemmamoowala asheemmamoowala commented Jul 10, 2018

Copy link
Copy Markdown

This PR adds two options for assigning ids to features - promoteId and generateId. Both options will ignore and replace the existing id field on features. This options can be used to consistently populate the feautre.id for GeoJSON data.

promoteId

This option allows promoting a named feature property to be used as the id value. 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"}} } ```

generateId

When 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 features array of a FeatureCollection.

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

Comment thread README.md Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs an indentation fix.

Comment thread src/convert.js
geometry = [];
convertLine(coords[i], geometry, tolerance, false);
features.push(createFeature(geojson.id, 'LineString', geometry, geojson.properties));
features.push(createFeature(id, 'LineString', geometry, geojson.properties));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/convert.js
for (i = 0; i < geojson.geometry.geometries.length; i++) {
convertFeature(features, {
id: geojson.id,
id: id,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with geometry collections — the split parts won't get the same id with auto-id-generation.

…o all features split from a GeometryCollection.
Comment thread src/convert.js
geometry: geojson.geometry.geometries[i],
properties: geojson.properties
}, options);
}, options, index);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should ensure that split geometry collections use the index of the original GeoJSON feature as their id in the auto-generated Id case.

@mourner

mourner commented Jul 27, 2018

Copy link
Copy Markdown
Member

Released in v3.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants