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.

No Shapely geometry can be created from null value

See original GitHub issue

Expected behavior and actual behavior.

Expected behaviour: no error Actual behaviour:

TopologyException: assigned depths do not match at 882.50000000000011 1241.5
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-69-fe56313cbba3> in <module>
----> 1 line.parallel_offset(distance=2.5, side='left')

~/anaconda3/lib/python3.6/site-packages/shapely/geometry/linestring.py in parallel_offset(self, distance, side, resolution, join_style, mitre_limit)
    144         try:
    145             return geom_factory(self.impl['parallel_offset'](
--> 146                 self, distance, resolution, join_style, mitre_limit, side))
    147         except OSError:
    148             raise TopologicalError()

~/anaconda3/lib/python3.6/site-packages/shapely/geometry/base.py in geom_factory(g, parent)
     74     # Abstract geometry factory for use with topological methods below
     75     if not g:
---> 76         raise ValueError("No Shapely geometry can be created from null value")
     77     ob = BaseGeometry()
     78     geom_type = geometry_type_name(g)

ValueError: No Shapely geometry can be created from null value

Steps to reproduce the problem.

import shapely
line = shapely.geometry.linestring.LineString([(884.0, 1240.0),(883.0, 1239.0),(882.0, 1239.0),(881.0, 1240.0)])                                                                                   
line.parallel_offset(distance=2.5, side='left') 

The weird thing is that the problem does not show if distance=2.499999999999 or distance=2.5000000000001

Operating system

Distributor ID: Ubuntu Description: Ubuntu 16.04.6 LTS Release: 16.04 Codename: xenial

Shapely version and provenance

Shapely==1.6.4.post2 installed from PyPI using pip

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Jan 3, 2022

With latest main branch, we correctly raise the GEOS error instead of the confusing “No Shapely geometry can be created from null value” error:

>>> from shapely.geometry import LineString
>>> line = LineString([(884.0, 1240.0),(883.0, 1239.0),(882.0, 1239.0),(881.0, 1240.0)])
>>> line.parallel_offset(distance=2.5, side='left')
...
GEOSException: TopologyException: assigned depths do not match at 882.50000000000011 1241.5

So I think we label / close this as an upstream GEOS issue?

0reactions
jorisvandenbosschecommented, Dec 3, 2022

In addition, with GEOS 3.11, this now works without exception:

>>> from shapely.geometry import LineString
>>> line = LineString([(884.0, 1240.0),(883.0, 1239.0),(882.0, 1239.0),(881.0, 1240.0)])
>>> line.parallel_offset(distance=2.5, side='left')
<LINESTRING (885.768 1238.232, 884.768 1237.232, 884.586 1237.067, 884.389 1...>

GEOS 3.11 will be included in the shapely 2.0 wheels (and with conda you also already use this with shapely 1.8.5).

Closing as fixed upstream in GEOS.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: No Shapely geometry can be created from null value
I have validated that my polygons are valid. Initially polyB isn't valid, but it is converted to a valid polygon using buffer(0) ....
Read more >
Dissolve causes 'No Shapely geometry can be created from ...
python - Dissolve causes 'No Shapely geometry can be created from null value' in geopandas - Geographic Information Systems Stack Exchange. ...
Read more >
GIS: Dissolve causes 'No Shapely geometry can be ... - YouTube
GIS: Dissolve causes ' No Shapely geometry can be created from null value ' in geopandasHelpful? Please support me on Patreon: ...
Read more >
ValueError: No Shapely geometry can be created from null value
I have validated that my polygons are valid. Initially polyB isn't valid, but it is converted to a valid polygon using buffer(0) ....
Read more >
No Shapely geometry can be created from null value
"ValueError: No Shapely geometry can be created from null value" Script to reproduce the problem : from shapely.wkt import loads from shapely.geometry ...
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