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.

`pygeos.set_precision` creates empty geometries

See original GitHub issue

If you round a LineString until you get a single coordinate value, pygeos.set_precision returns an empty geometry. Shouldn’t it return a single point instead?

geometry = pygeos.linestrings([np.array([0.01, 0.02]), np.array([0.03, 0.04]), np.array([0.05, 0.06])])
# <pygeos.Geometry LINESTRING (0.01 0.02, 0.03 0.04, 0.05 0.06)>

pygeos.set_precision(geometry, 1)
# <pygeos.Geometry LINESTRING EMPTY>

Expected result:

# <pygeos.Geometry POINT (0 0)>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Sep 15, 2021

that’s why I was using pygeos.make_valid function afterwards to fix them.

And I see that using make_valid on the LineString with 2 equal vertices, indeed gives a Point instead of an empty LineString (as set_precision does). You could certainly bring it up with the GEOS project if they have a reasoning for collapsing to empty geometries instead of collapsing to a “lower dimension geometry” in set_precision (while having a different logic in make_valid).

0reactions
carlosg-mcommented, Sep 15, 2021

In general, “naively” rounding the coordinates has the risk to give identical vertices that don’t get collapsed, resulting in invalid geometries. pygeos.set_precision includes some logic to keep the result as valid geometries.

Yes, in my use case I was able to find some examples of invalid linestring with duplicate coordinates, that’s why I was using pygeos.make_valid function afterwards to fix them.

However I don’t know what kinds of other problems this approach might cause to polygons for example, and if they are fixable. But the idea here was to include as many geometries as possible during analysis.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set operations — pygeos documentation - Read the Docs
Returns the union of multiple polygons of a geometry collection. This is an optimized version of union which assumes the polygons to be...
Read more >
Allow creating empty geometries in constructive functions #149
In general, the question is how we can facilitate creating empty geometries in PyGEOS. Currently, if you want to create an empty geometry,...
Read more >
Truncating points precision - python - GIS Stack Exchange
I have geopandas with CRS in meters (ITM {'init' :'epsg:2039'}) . I converted the geometry from espg:4326 so I have very high precision...
Read more >
Missing and empty geometries - GeoPandas
Missing and empty geometries#. GeoPandas supports, just like in pandas, the concept of missing values (NA or null values). But for geometry values, ......
Read more >
COVID-19 New Cases in Italy prediction (arima) | Kaggle
Pandas profiling is a Python library that generates a detailed report of a ... fontweight='bold') # empty array for the data range sm....
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