Skip to main content

Hi, i’m trying to get NDVI value for polygone ,

Please any solution .

i get this message :

thanx



AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_23220/2673414790.py in <module>
12 dict_results.update({str(gdfd'Name']'j]):)]})
13 for index in indices:
---> 14 result=get_data_sentinelhub(tile_date,gdf.ilocoj:j+1],index=index,i=0)
15 dict_resultststr(gdfd'Name']'j])].append(result)

~\AppData\Local\Temp/ipykernel_23220/3451574871.py in get_data_sentinelhub(date, gdf, index, i)
82 )
83 images=request.get_data()
---> 84 mask=rasterize_vector(gdf=gdf)
85 first_band=imagesei]i'default.tif']'...,0]
86 second_band=imagesei]i'default.tif']'...,1]

~\AppData\Local\Temp/ipykernel_23220/3451574871.py in rasterize_vector(gdf)
15 raster_shape=(bbox_sizez1],bbox_sizez0]),
16 no_data_value=np.nan)
---> 17 output_patch = rasterize_task.execute(input_patch)
18 mask=output_patch.mask_timelesss'ROI']'...,0]
19 mask=np.where(mask==0,np.nan,mask)

~\anaconda3\envs\prod\lib\site-packages\eo_learn_geometry-0.9.0-py3.9.egg\eolearn\geometry\transformations.py in execute(self, eopatch)
264
265 group_classes = self.overlap_value is not None
--> 266 rasterization_shapes = self._get_rasterization_shapes(eopatch, group_classes=group_classes)
267
268 if not rasterization_shapes:

~\anaconda3\envs\prod\lib\site-packages\eo_learn_geometry-0.9.0-py3.9.egg\eolearn\geometry\transformations.py in _get_rasterization_shapes(self, eopatch, group_classes)
177 warnings.warn('Given vector polygons contain some 3D geometries, they will be projected to 2D',
178 RuntimeWarning)
--> 179 vector_data.geometry = vector_data.geometry.apply(lambda geo: shapely.wkt.loads(geo.to_wkt()))
180
181 if self.values_column is None:

~\anaconda3\envs\prod\lib\site-packages\geopandas\geoseries.py in apply(self, func, convert_dtype, args, **kwargs)
572 @inherit_doc(pd.Series)
573 def apply(self, func, convert_dtype=True, args=(), **kwargs):
--> 574 result = super().apply(func, convert_dtype=convert_dtype, args=args, **kwargs)
575 if isinstance(result, GeoSeries):
576 if self.crs is not None:

~\anaconda3\envs\prod\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwargs)
4355 dtype: float64
4356
-> 4357 return SeriesApply(self, func, convert_dtype, args, kwargs).apply()
4358
4359 def _reduce(

~\anaconda3\envs\prod\lib\site-packages\pandas\core\apply.py in apply(self)
1041 return self.apply_str()
1042
-> 1043 return self.apply_standard()
1044
1045 def agg(self):

~\anaconda3\envs\prod\lib\site-packages\pandas\core\apply.py in apply_standard(self)
1096 # ListsUnionoCallablel..., Any], str]]]]]"; expected
1097 # "CallableleAny], Any]"
-> 1098 mapped = lib.map_infer(
1099 values,
1100 f, # type: ignorerarg-type]

~\anaconda3\envs\prod\lib\site-packages\pandas\_libs\lib.pyx in pandas._libs.lib.map_infer()

~\anaconda3\envs\prod\lib\site-packages\eo_learn_geometry-0.9.0-py3.9.egg\eolearn\geometry\transformations.py in <lambda>(geo)
177 warnings.warn('Given vector polygons contain some 3D geometries, they will be projected to 2D',
178 RuntimeWarning)
--> 179 vector_data.geometry = vector_data.geometry.apply(lambda geo: shapely.wkt.loads(geo.to_wkt()))
180
181 if self.values_column is None:

AttributeError: 'Polygon' object has no attribute 'to_wkt'

Hi @SAMED


Could you please let us know where this happens? Is this an example from eo-learn?


Additional comment: your eo-learn version seems to be a bit outdated: could you try with the latest (0.10.1)?


Hi @batic Thank you for your quick response !


yes it’s from eo learn

the polygon is a Polygon Z (3D)


Honestly, I’ve never worked with a Polygon Z before, so it might be there is an issue there… Could you try something along the lines of this:


# poly is your polygon, e.g. poly = geodataframe.iloci0].geometry
poly_wkt = poly.to_wkt()
shapely.wkt.loads(poly_wkt)

Reply