question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create geometries with different number of points in a vectorized way

See original GitHub issue

I have found this open-source project by looking for a vectorized geospatial python library. I am impressed about how the library can handle geospatial processing with full vectorization. However, I could not figure out how to create geometries with different number of points in a vectorized way. A very simple example.

I can create two polygons in one call, if the polygons have the same number of points.

pygeos.polygons(
    [
        [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]],
        [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]]
    ]
)

However, if I put two polygons with different number of points, it will not work.

pygeos.polygons(
    [
        [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]],
        [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]
    ]
)

I will get a type error: TypeError: One of the arguments is of incorrect type. Please provide only Geometry objects.

Is this a design choice? Or does it have to do with the limitations of ufunc in numpy? Or maybe I have not found the correct usage of this library. In that case I apologise for not being able to find the relevant information in the documentation.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
caspervdwcommented, May 19, 2021

This issue has been addressed in our latest release 0.10.

0reactions
caspervdwcommented, May 20, 2021

That’s right, the direct route from coordinates + indices to polygons is not available. This is not possible for the generic case for polygons with holes (you would have to specify in which hole in which polygon the coordinate would have to go).

Hence the two-step procedure. It is conceivable to implement this specifically for the polygons without holes case (by far the most common one) by propagating indices to the internal linearrings constructor over here:

https://github.com/pygeos/pygeos/blob/3fa59c7c52519ee1eb10f9ba7e49ced306201e9f/pygeos/creation.py#L223

Read more comments on GitHub >

github_iconTop Results From Across the Web

Geometries (shapely) — Spatial Data Programming with Python
Vector layers—points, lines, and polygons, associated with attributes ... Another method of creating shapely geometries is to pass lists of ...
Read more >
Spatial Points Lines Polygons in Python - PyGIS
Learn how to create new vector data (shapefile), and assign a projection (CRS). This includes an example of plotting latitude longitude data stored...
Read more >
Vector Geometry - Scriptographer.org
Vector geometry is a first class citizen in Scriptographer. ... In this way we can add the same vector to many points, as...
Read more >
Creating multiple separate vector lines from list of coordinate ...
Now import it in QGIS, but specify it should take the geometry from ... Points to path allows you to sort and group...
Read more >
Efficiently match point to geometry (point in poly) for large ...
Not having to loop over every polygon (this will get unwieldy as P increases) · Using a different algorithm for the point-in-poly. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found