mattijn / topojson

Encode spatial data as topology in Python! 🌍 https://mattijn.github.io/topojson
BSD 3-Clause "New" or "Revised" License
177 stars 27 forks source link

BUG: `Topology.to_gdf` should keep the original index #164

Closed Zeroto521 closed 2 years ago

Zeroto521 commented 2 years ago

The index of returning Topology.to_gdf is not equal to the inputting one.

import geopandas as gpd

from topojson import Topology

df = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres")).query(
    'continent == "Africa"'
)

result = Topology(df, 1).to_gdf(crs=df.crs)
print(df.index)
# Int64Index([  1,   2,  11,  12,  13,  14,  15,  25,  26,  48,  49,  50,  51,
#              52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,
#              65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  78,  80,
#              81,  82, 154, 162, 163, 164, 165, 166, 167, 168, 169, 176],
#            dtype='int64')
print(result.index)  # should be `df.index`
# RangeIndex(start=0, stop=51, step=1)

Package versions

mattijn commented 2 years ago

Thanks for raising the issue. Please see https://github.com/mattijn/topojson/pull/165 where I've implemented this enhancement as feature. Will that work for you?

Zeroto521 commented 2 years ago

Thanks for fixing that problem.