pyroll-project / pyroll-export

PyRoll rolling simulation framework - data export.
https://pyroll.readthedocs.io
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

NotImplemetedError shapely.polygon.xy #5

Open GRPlan opened 4 months ago

GRPlan commented 4 months ago

In convert.py (lines 57-69)

@hookimpl(specname="convert") def convert_shapely_polygon(value: object): if isinstance(value, shapely.Polygon): return dict( area=value.area, perimeter=value.length, height=value.bounds[3] - value.bounds[1], width=value.bounds[2] - value.bounds[0], # x=np.array(value.boundary.xy[0]), # y=np.array(value.boundary.xy[1]), x=np.array(value.exterior.coords.xy[0]), y=np.array(value.exterior.coords.xy[1]), )

exterior.coords.xy should be used rather than boundary.xy

Taken from https://answers.ros.org/question/321957/shapelygeometrypolygon-to-geometry_msgspolygonstamped-shapely-polygon-representation-in-rviz/

Please check whether this is the correct way to avoid the NotImplementedError. Are there other functions that need to be changed?

axtimhaus commented 3 months ago

With installed shapely v2.0.4 I get no NotImplementedError. Can you please check your shapely version so I can try to reproduce?

GRPlan commented 3 months ago
 /opt/pyroll/Kocks/Mo_DLI/../../src/pyroll-export/pyroll/export/convert.py:65 in                  │
│ convert_shapely_polygon                                                                          │
│                                                                                                  │
│    62 │   │   │   perimeter=value.length,                                                        │
│    63 │   │   │   height=value.bounds[3] - value.bounds[1],                                      │
│    64 │   │   │   width=value.bounds[2] - value.bounds[0],                                       │
│ ❱  65 │   │   │   x=np.array(value.boundary.xy[0]),                                              │
│    66 │   │   │   y=np.array(value.boundary.xy[1]),                                              │
│    67 #            x=np.array(value.exterior.coords.xy[0]),                                      │
│    68 #            y=np.array(value.exterior.coords.xy[1]),                                      │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/shapely/geometry/base.py:212 in xy                       │
│                                                                                                  │
│   209 │   @property                                                                              │
│   210 │   def xy(self):                                                                          │
│   211 │   │   """Separate arrays of X and Y coordinate values"""                                 │
│ ❱ 212 │   │   raise NotImplementedError                                                          │
│   213 │                                                                                          │
│   214 │   # Python feature protocol                                                              │
│   215                                                          

Error message with shapely 2.0.1

In shapely 2.0.4 the implementation of function xy did not change and after update I still get the same error.

axtimhaus commented 3 months ago

Strange. I can not reproduce the error. Usually, the boundary of a Polygon should be a LineString, which supports the xy property. Can you please check the type of the object provided by boundary in your case?

GRPlan commented 3 months ago

BugXY.zip

Probably this notebook helps to understand the issue.

With the modified convert.py the notebook runs without any problems.

But there is a invalid value encountered in cast warning during conversion to pandas dataframe

RichardPfr commented 1 month ago

We changed the convert.py according to the suggestions made by @GRPlan , as we could finally also reproduce the error.

Thanks for that.