Skip to content

Commit

Permalink
Don't set crs attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Jul 2, 2024
1 parent ac7e9e5 commit 2a7cf38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
27 changes: 14 additions & 13 deletions xvec/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,6 @@ def to_crs(
_obj = _obj.drop_indexes(variable_crs_solved.keys())

for key, crs in variable_crs_solved.items():
if crs:
_obj[key].attrs["crs"] = CRS.from_user_input(crs)
_obj = _obj.set_xindex([key], GeometryIndex, crs=crs)

return _obj
Expand Down Expand Up @@ -507,8 +505,6 @@ def set_crs(
_obj = _obj.drop_indexes(variable_crs_solved.keys())

for key, crs in variable_crs_solved.items():
if crs:
_obj[key].attrs["crs"] = CRS.from_user_input(crs)
_obj = _obj.set_xindex([key], GeometryIndex, crs=crs)

return _obj
Expand Down Expand Up @@ -698,12 +694,19 @@ def set_geom_indexes(
_obj = _obj.drop_indexes(coord_names)

for coord in coord_names:
if crs:
_obj[coord].attrs["crs"] = CRS.from_user_input(crs)
_obj = _obj.set_xindex(coord, GeometryIndex, crs=crs, **kwargs)

return _obj

def _get_crs(self, name) -> CRS | None:
if name in self._geom_indexes:
crs = self._obj.xindexes[name].crs
elif name in self._geom_coords_all:
crs = self._obj[name].attrs.get("crs", None)
else:
crs = None
return crs

def to_geopandas(self) -> GeoDataFrame | pd.DataFrame:
"""Convert this array into a GeoPandas :class:`~geopandas.GeoDataFrame`
Expand Down Expand Up @@ -777,13 +780,13 @@ def to_geopandas(self) -> GeoDataFrame | pd.DataFrame:
# ensure CRS of all columns is preserved
for c in gdf.columns:
if c in self._geom_coords_all:
gdf[c] = gpd.GeoSeries(gdf[c], crs=self._obj[c].attrs.get("crs", None))
gdf[c] = gpd.GeoSeries(gdf[c], crs=self._get_crs(c))

# if geometry is an index, reset and assign as active
index_name = gdf.index.name
if index_name in self._geom_coords_all:
if index_name in self._geom_indexes:
return gdf.reset_index().set_geometry(
index_name, crs=self._obj[index_name].attrs.get("crs", None)
index_name, crs=self._get_crs(index_name)
) # type: ignore

warnings.warn(
Expand Down Expand Up @@ -896,12 +899,10 @@ def to_geodataframe(
# ensure CRS of all columns is preserved
for c in df.columns:
if c in self._geom_coords_all:
df[c] = gpd.GeoSeries(df[c], crs=self._obj[c].attrs.get("crs", None))
df[c] = gpd.GeoSeries(df[c], crs=self._get_crs(c))

if geometry is not None:
return df.set_geometry(
geometry, crs=self._obj[geometry].attrs.get("crs", None)
) # type: ignore
return df.set_geometry(geometry, crs=self._get_crs(geometry)) # type: ignore

warnings.warn(
"No active geometry column to be set. The resulting object "
Expand Down
8 changes: 0 additions & 8 deletions xvec/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def geom_dataset(geom_dataset_no_index):
# a dataset with a geometry coordinate baked by a GeometryIndex
crs = CRS.from_user_input(26915)
ds = geom_dataset_no_index.copy()
ds["geom"].attrs["crs"] = crs
return ds.set_xindex("geom", GeometryIndex, crs=crs)


Expand All @@ -53,7 +52,6 @@ def first_geom_dataset(geom_dataset, geom_array):
.drop_indexes("geom")
.set_xindex("geom", GeometryIndex, crs=geom_dataset.xindexes["geom"].crs)
)
fg["geom"].attrs["crs"] = CRS.from_user_input(26915)
return fg


Expand All @@ -80,8 +78,6 @@ def multi_geom_dataset(geom_array, geom_array_z):
.set_xindex("geom", GeometryIndex, crs=26915)
.set_xindex("geom_z", GeometryIndex, crs=26915)
)
ds["geom"].attrs["crs"] = ds.xindexes["geom"].crs
ds["geom_z"].attrs["crs"] = ds.xindexes["geom_z"].crs
return ds


Expand All @@ -98,8 +94,6 @@ def multi_geom_multi_crs_dataset(geom_array, geom_array_z):
.set_xindex("geom", GeometryIndex, crs=26915)
.set_xindex("geom_z", GeometryIndex, crs="EPSG:4362")
)
ds["geom"].attrs["crs"] = ds.xindexes["geom"].crs
ds["geom_z"].attrs["crs"] = ds.xindexes["geom_z"].crs
return ds


Expand All @@ -117,8 +111,6 @@ def multi_geom_no_index_dataset(geom_array, geom_array_z):
.set_xindex("geom", GeometryIndex, crs=26915)
.set_xindex("geom_z", GeometryIndex, crs=26915)
)
ds["geom"].attrs["crs"] = ds.xindexes["geom"].crs
ds["geom_z"].attrs["crs"] = ds.xindexes["geom_z"].crs
return ds


Expand Down

0 comments on commit 2a7cf38

Please sign in to comment.