Closed aruscha-k closed 4 months ago
Interesting. When I run it, it works:
(.venv) ➜ centerline git:(master) python
Python 3.12.2 (main, Feb 21 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from shapely.geometry import Polygon
>>> from centerline.geometry import Centerline
>>> polygon = Polygon([[0, 0], [0, 4], [4, 4], [4, 0]])
>>> attributes = {"id": 1, "name": "polygon", "valid": True}
>>> centerline = Centerline(polygon, **attributes)
>>> centerline.id == 1
True
>>> centerline.name
'polygon'
>>> centerline.geometry.geoms
<shapely.geometry.base.GeometrySequence object at 0x7f8916437aa0>
Do you have an idea what might be the cause on your end?
No unfortunately not. I'm assuming some version mismatch between Shapely and pygeos, even though I tried a lot of combinations, I sadly never got it to run. I had the same issue with the centerline function from pygeoops, which I only got to work because someone posted working versions of the libraries somewhere, so I'm guessing the same for this library.
When trying to get the basic example from readme running,
I get the following error: TypeError: One of the arguments is of incorrect type. Please provide only Geometry objects.
Python 3.10, shapely 2.0.3., pygeos 0.14, GDAL 3.4.1
The whole stack: TypeError Traceback (most recent call last) Cell In[41], line 7 4 polygon = Polygon([[0, 0], [0, 4], [4, 4], [4, 0]]) 5 attributes = {"id": 1, "name": "polygon", "valid": True} ----> 7 centerline = Centerline(polygon, **attributes)
File /opt/homebrew/Caskroom/miniconda/base/envs/parkplatz2/lib/python3.10/site-packages/centerline/geometry.py:44, in Centerline.init(self, input_geometry, interpolation_distance, **attributes) 41 self._min_x, self._min_y = self._get_reduced_coordinates() 42 self.assign_attributes_to_instance(attributes) ---> 44 self.geometry = MultiLineString(lines=self._construct_centerline())
File /opt/homebrew/Caskroom/miniconda/base/envs/parkplatz2/lib/python3.10/site-packages/centerline/geometry.py:88, in Centerline._construct_centerline(self) 85 linestring = LineString((starting_point, ending_point)) 86 linestrings.append(linestring) ---> 88 str_tree = STRtree(linestrings) 89 linestrings_indexes = str_tree.query(self._input_geometry, "contains") 90 contained_linestrings = [linestrings[i] for i in linestrings_indexes]
File /opt/homebrew/Caskroom/miniconda/base/envs/parkplatz2/lib/python3.10/site-packages/shapely/strtree.py:82, in STRtree.init(self, geoms, node_capacity) 79 self.geometries = np.array(geoms, dtype=np.object, copy=True) 81 # initialize GEOS STRtree ---> 82 self._tree = lib.STRtree(self.geometries, node_capacity)