Skip to content

Commit

Permalink
FeatureCollection.save(): fix rasterio/fiona CRS consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
amitar committed Jan 25, 2025
1 parent 5233a7a commit 473fce0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions telluric/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,11 @@ def save(self, filename, driver=None, schema=None):
crs = self.crs

# https://github.com/rasterio/rasterio/issues/2453
crs = crs.to_dict()
# https://github.com/rasterio/rasterio/issues/3282 (to_dict() is lossy in rasterio)
# We should switch to fiona 1.9.x and convert to fiona.crs.CRS
crs_wkt = crs.to_wkt()

with fiona.open(filename, 'w', driver=driver, schema=schema, crs=crs) as sink:
with fiona.open(filename, 'w', driver=driver, schema=schema, crs_wkt=crs_wkt) as sink:
for feature in self:
new_feature = self._adapt_feature_before_write(feature)
sink.write(new_feature.to_record(crs))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def test_feature_collection_with_dates_serializes_correctly():
with tempfile.TemporaryDirectory() as path:
file_path = os.path.join(path, "test_dates.shp")
with fiona.open(
file_path, mode='w', driver="ESRI Shapefile", schema=schema, crs=feature.crs.to_dict()
file_path, mode='w', driver="ESRI Shapefile", schema=schema, crs_wkt=feature.crs.to_wkt()
) as sink:
sink.write(mapping(feature))

Expand Down

0 comments on commit 473fce0

Please sign in to comment.