Closed Mr-Ixolate closed 4 months ago
Thanks for raising the issue! It is a good request and this is already happening if it is a geodataframe, see around here: https://github.com/mattijn/topojson/blob/main/topojson/core/extract.py#L533.
Just make sure that you only do this if the index of the full collection is unique. If you want to do a PR, which will be much appreciated!, you can do this with a simple if/else condition.
Hope that helps! And thanks again for raising the issue!
What would be the expectation if duplicate ids were found?
Edit: shouldn't have tried to type this on mobile
Maybe best using a new parameter in the Topology()
class?
Like:
ignore_index
: bool
, default False
And then do your suggested option 1 if False
(default) and if True
your option 2?
Released as of v1.9
I've been using geojson to extract some space data from another format which already has a unique id for each shape that I am extracting. I use that id as the id for the feature and combine those into a feature collection.
However, when I use the
Topology
and.to_json()
the output has replaced the id already provided with a generic"0"
or"feature_00"
.Ideally it would retain the ids.
Example script
Code
Haven't dived too deep yet, but the id in the topojson feature looks like it comes from the key in the data dict. https://github.com/mattijn/topojson/blob/5af019cb409859a01eda2964b901c996a4d6eb8f/topojson/core/extract.py#L463-L465
There is probably a better way of doing this but I changed the line to this and it seemed to work.
Will have a look at forking in a bit.