New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tesselation fails at Generating input point array... with ValueError: need at least one array to concatenate #297
Comments
While debugging the source code, I found that the This is converted within Ah ha!!! I found that the After fixing that, I get an error
So, essentially, I have come to realize that using this function requires the coordinates to be in some meters-based CRS. |
Hi @bramson, thank you for the report. Yes, a lot of operations in Tessellation (including the Voronoi tessellation) are distance-based. With geometries in lat/lon, distance has no meaning so momepy expects projected CRS. The second error is still related to this, I would recommend reprojecting your geometries to some local projection, like EPSG:2451.
This is a good point. I'll add a note to the documentation and a check to the code, so it emits a warning. |
ValueError: need at least one array to concatenate Hi, I am getting the same error, but in my case, my dataset was in a projected CRS, EPGS: '3857'. I am working with the Open Building dataset from Google. With polygons with more than 85% confidence (around 300k polygons) is okay, but when I decrease the confidence, and then increase the number of polygons(max number 2M 300k for my research area), I start to get this error. ---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[13], line 1
----> 1 tessellation = momepy.Tessellation(Buildings_Lima[:50], "uID", limit, verbose=True, segment=0.1)
2 tessellation = tessellation.tessellationls
File [~/anaconda3/envs/momepy_env/lib/python3.11/site-packages/momepy/elements.py:259](https://vscode-remote+rs4-002ecode-002ebunsencloud-002ede.vscode-resource.vscode-cdn.net/config/workspace/MoMepy_lima/MorphoMetric_Lima/~/anaconda3/envs/momepy_env/lib/python3.11/site-packages/momepy/elements.py:259), in Tessellation.__init__(self, gdf, unique_id, limit, shrink, segment, verbose, enclosures, enclosure_id, threshold, use_dask, n_chunks)
252 # add convex hull buffered large distance to eliminate infinity issues
253 limit = (
254 gpd.GeoSeries(limit, crs=gdf.crs)
255 .translate(xoff=-centre_x, yoff=-centre_y)
256 .array[0]
257 )
--> 259 self.tessellation = self._morphological_tessellation(
260 gdf, unique_id, limit, shrink, segment, verbose
261 )
263 self.tessellation["geometry"] = self.tessellation["geometry"].translate(
264 xoff=centre_x, yoff=centre_y
265 )
File [~/anaconda3/envs/momepy_env/lib/python3.11/site-packages/momepy/elements.py:285](https://vscode-remote+rs4-002ecode-002ebunsencloud-002ede.vscode-resource.vscode-cdn.net/config/workspace/MoMepy_lima/MorphoMetric_Lima/~/anaconda3/envs/momepy_env/lib/python3.11/site-packages/momepy/elements.py:285), in Tessellation._morphological_tessellation(self, gdf, unique_id, limit, shrink, segment, verbose, check)
282 objects = objects.set_index(unique_id)
284 print("Generating input point array...") if verbose else None
--> 285 points, ids = self._dense_point_array(
286 objects.geometry.array, distance=segment, index=objects.index
287 )
289 hull = shapely.convex_hull(limit)
290 bounds = shapely.bounds(hull)
File [~/anaconda3/envs/momepy_env/lib/python3.11/site-packages/momepy/elements.py:343](https://vscode-remote+rs4-002ecode-002ebunsencloud-002ede.vscode-resource.vscode-cdn.net/config/workspace/MoMepy_lima/MorphoMetric_Lima/~/anaconda3/envs/momepy_env/lib/python3.11/site-packages/momepy/elements.py:343), in Tessellation._dense_point_array(self, geoms, distance, index)
340 points.append(shapely.get_coordinates(pts))
341 ids += [ix] * len(pts)
--> 343 points = np.vstack(points)
345 return points, ids
File <__array_function__ internals>:200, in vstack(*args, **kwargs)
File [~/anaconda3/envs/momepy_env/lib/python3.11/site-packages/numpy/core/shape_base.py:296](https://vscode-remote+rs4-002ecode-002ebunsencloud-002ede.vscode-resource.vscode-cdn.net/config/workspace/MoMepy_lima/MorphoMetric_Lima/~/anaconda3/envs/momepy_env/lib/python3.11/site-packages/numpy/core/shape_base.py:296), in vstack(tup, dtype, casting)
294 if not isinstance(arrs, list):
295 arrs = [arrs]
--> 296 return _nx.concatenate(arrs, 0, dtype=dtype, casting=casting)
File <__array_function__ internals>:200, in concatenate(*args, **kwargs)
ValueError: need at least one array to concatenate As you can see I even try with a small sample (50 polygons). The confidence of an object being a polygon is related to its size, as I have learned by exploring the dataset. Any idea about how to get out of this error? PS: I can work with polygons with high confidence, but then the number of polygons decreases and my dataset gets less representative of the city. |
@torresanton Could you dump |
I'm sharing a pickle file, and I have pypickle 1.1.0 installed A similar error happend with momepy.CheckTessellationInput ---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[7], line 1
----> 1 momepy.CheckTessellationInput(Lima_buil)
File [~/anaconda3/envs/momepy_env/lib/python3.11/site-packages/momepy/preprocessing.py:376](https://vscode-remote+rs4-002ecode-002ebunsencloud-002ede.vscode-resource.vscode-cdn.net/config/workspace/MoMepy_lima/MorphoMetric_Lima/~/anaconda3/envs/momepy_env/lib/python3.11/site-packages/momepy/preprocessing.py:376), in CheckTessellationInput.__init__(self, gdf, shrink, collapse, split, overlap)
369 sindex = shrink.sindex
370 hits = shrink.bounds.apply(
371 lambda row: list(sindex.intersection(row)), axis=1
372 )
373 od_matrix = pd.DataFrame(
374 {
375 "origin": np.repeat(hits.index, hits.apply(len)),
--> 376 "dest": np.concatenate(hits.values),
377 }
378 )
379 od_matrix = od_matrix[od_matrix.origin != od_matrix.dest]
380 duplicated = pd.DataFrame(np.sort(od_matrix, axis=1)).duplicated()
File <__array_function__ internals>:200, in concatenate(*args, **kwargs)
ValueError: need at least one array to concatenate Thanks very much!! |
@torresanton you have very tiny geometries. Mean length of perimeter is In any case, segment=0.1 is way longer than the length of each perimeter, leading to this issue. Dimensions like you have are not expected. |
I suspected something similar. Perhaps the best idea is to remove very tiny polygons and work only over a certain threshold of area and perimeter. At the moment momepy.Tessellation is working with polygons from #OpenBuildingGoogle with a confidence equal to or higher than 0.85. Thanks very much |
I mean, there are no other than those tiny polygons. This will surely not come from Google's Open Buildings like this. There has been some erroneous coordinate transformation or something like that. |
Yes, @martinfleis is right. When the open_building_dataset.csv is downloaded it doesn't have the crs parameter, and I couldn't set_crs() properly, even after figuring out the right one (<Geographic 2D CRS: EPSG:4326>Name: WGS 84). |
As the title says, Tesselation fails at the
Generating input point array....
step withValueError: need at least one array to concatenate
My code is simply:
Where
wardsPolygon
is a<class 'shapely.geometry.multipolygon.MultiPolygon'>
of Tokyo's 23 wards and'communityID'
is a column of unique IDs for each polygon in my geopadaframe callededgeDF5
, which contains Polygons of neighborhoods in the 'geometry' column (and no other columns).I don't want space between adjacent polygons; I want a partition (every point is in some polygon), so I set the shrink to 0.
Here's the output:
The result of checking the input is:
So, why isn't this working and what do I need to do to make it work?
The text was updated successfully, but these errors were encountered: