Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identifier field for features #15

Open
mainakae opened this issue Jun 15, 2015 · 3 comments
Open

identifier field for features #15

mainakae opened this issue Jun 15, 2015 · 3 comments

Comments

@mainakae
Copy link

Hello again,

In the GeoJSON specification, it's contemplated the possibility of having an identifier field in the GeoJSON objects, stored in the id field. It would be great to have GeoJSON.js accept another parameter to specify which field should be parsed into that identifier. As of now, it can be done by iterating the results and moving the id field from properties to the feature.

Thanks for your time,
Pedro.

@jkhoel
Copy link

jkhoel commented May 20, 2017

I have modified my local copy to account for this. It sets feature no.1 as id: 0, no.2 as 1 etc..
I could do a pull request for this change - and in my use case it would suffice. However I wanted to ask if anyone has ever had a need for this ID beeing anything other than just a sequencial number.

@caseycesari caseycesari changed the title ENHACEMENT: identifier field for features identifier field for features Feb 14, 2019
@tormi
Copy link

tormi commented Nov 25, 2020

However I wanted to ask if anyone has ever had a need for this ID beeing anything other than just a sequencial number.

Yes, this could come from input json and should be dealt with as include for properties.

@theshanergy
Copy link

theshanergy commented Jan 13, 2023

Just in case anyone else stumbles on this in need of a solution, here is how to move the 'id' field out of properties and put it in the feature root. It would be nice if GeoJSON.js handled this natively however.

// Parse data into GeoJSON.
const geojson = GeoJSON.parse(data, { Point: ['lat', 'lng'] })

// Move 'id' from properties to feature.
geojson.features = geojson.features.map(({ properties: { id, ...otherProperties }, ...rest }) => ({ id, properties: otherProperties, ...rest }))

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

No branches or pull requests

5 participants