Skip to content

Commit

Permalink
Removing ShapelyDeprecationWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed Nov 3, 2022
1 parent e07d3e3 commit fdefb36
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion geodataflow/eogeo/productcatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,5 @@ def _normalize_product(product_type: str, product: object) -> object:
"""
Normalize properties of specified EOProduct from different EO Providers.
"""
setattr(product.geometry, 'srid', 4326)
product.geometry = product.geometry.with_srid(4326)
return product
14 changes: 10 additions & 4 deletions geodataflow/geoext/commonutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import pyproj as pj
from shapely.geometry.polygon import Polygon
from shapely.geometry.base import BaseGeometry
from shapely.geos import lgeos
from shapely.ops import transform

from geodataflow.core.capabilities import StoreCapabilities
Expand Down Expand Up @@ -354,7 +355,7 @@ def create_transform_function(source_crs: Union[int, str, pj.CRS],
def transform_fn_(geometry: BaseGeometry) -> BaseGeometry:
if transform_fn:
geometry = transform(transform_fn, geometry)
setattr(geometry, 'srid', target_srid)
geometry = geometry.with_srid(target_srid)

return geometry

Expand All @@ -365,12 +366,14 @@ def get_srid(obj: Union[int, object, pj.CRS]) -> int:
"""
Returns the SRID of this Geometry.
"""
if hasattr(obj, 'srid'):
return getattr(obj, 'srid')
if isinstance(obj, int):
return obj
if isinstance(obj, BaseGeometry):
return lgeos.GEOSGetSRID(obj._geom)
if isinstance(obj, pj.CRS):
return obj.to_epsg()
if hasattr(obj, 'srid'):
return getattr(obj, 'srid')

return 0

Expand All @@ -381,7 +384,10 @@ def set_srid(geometry, obj: Union[int, object, pj.CRS]):
"""
srid = GeometryUtils.get_srid(obj)
if srid:
setattr(geometry, 'srid', srid)
if isinstance(geometry, BaseGeometry):
lgeos.GEOSSetSRID(geometry._geom, srid)
else:
setattr(geometry, 'srid', srid)

return geometry

Expand Down
7 changes: 3 additions & 4 deletions geodataflow/geoext/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def geometry(self):
"""
envelope = self.get_envelope()
geometry = GeometryUtils.create_geometry_from_bbox(*envelope)
setattr(geometry, 'srid', self.get_spatial_srid())
geometry = geometry.with_srid(self.get_spatial_srid())
return geometry

@property
Expand Down Expand Up @@ -270,7 +270,7 @@ def clamp_geometry(self, geometry, padding_val: int = 0, minimum_ts: int = 0):
return envelope

geometry = GeometryUtils.create_geometry_from_bbox(*envelope)
setattr(geometry, 'srid', info.get('srid'))
geometry = geometry.with_srid(info.get('srid'))
return geometry

def warp(self,
Expand All @@ -285,8 +285,7 @@ def warp(self,

if isinstance(output_geom, list):
output_geom = GeometryUtils.create_geometry_from_bbox(*output_geom)
setattr(output_geom,
'srid', GeometryUtils.get_srid(output_crs) if output_crs else info.get('srid'))
output_geom = output_geom.with_srid(GeometryUtils.get_srid(output_crs) if output_crs else info.get('srid'))

if output_geom:
source_crs = GeometryUtils.get_spatial_crs(info.get('srid'))
Expand Down
2 changes: 1 addition & 1 deletion geodataflow/geoext/featurestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def features(self) -> Iterable:
for feature in feature_layer.features():
geometry = feature.GetGeometryRef()
geometry = shapely_wkb_loads(bytes(geometry.ExportToWkb()))
setattr(geometry, 'srid', schema_def.srid)
geometry = geometry.with_srid(schema_def.srid)

feature = type('Feature', (object,), {
'type': 'Feature',
Expand Down
2 changes: 1 addition & 1 deletion geodataflow/pipeline/filters/RasterClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run(self, data_store, processing_args):
clipping_geoms = [transform_fn(g) for g in clipping_geoms]
else:
for g in clipping_geoms:
setattr(g, 'srid', schema_def.srid)
g = g.with_srid(schema_def.srid)

for dataset in data_store:
for g in clipping_geoms:
Expand Down
2 changes: 1 addition & 1 deletion geodataflow/pipeline/filters/TableUnpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def run(self, feature_store, processing_args):
#
for index, row in data_frame.iterrows():
geometry = row['geometry']
setattr(geometry, 'srid', schema_def.srid)
geometry = geometry.with_srid(schema_def.srid)

feature = type('Feature', (object,), {
'type': 'Feature',
Expand Down

0 comments on commit fdefb36

Please sign in to comment.