Shapely Polygon creating empty polygon
MRAB
python at mrabarnett.plus.com
Tue Jan 4 19:47:02 EST 2022
On 2022-01-04 22:57, Israel Brewster wrote:
> I’m running into an issue with shapely that is baffling me. Perhaps someone here can help out?
>
> When running shapely directly from a python 3.8 interpreter, it works as expected:
>
>>>> import shapely
>>>> shapely.__version__
> '1.8.0'
>>>> from shapely.geometry import Polygon
>>>> bounds = [-164.29635821669632, 54.64251856269729, -163.7631779798799, 54.845450778742546]
>>>> print(Polygon.from_bounds(*bounds))
> POLYGON ((-164.2963582166963 54.64251856269729, -164.2963582166963 54.84545077874255, -163.7631779798799 54.84545077874255, -163.7631779798799 54.64251856269729, -164.2963582166963 54.64251856269729))
>
> However, if I put this exact same code into my Flask app (currently running under the Flask development environment) as part of handling a request, I get an empty polygon:
>
>>>> import shapely
>>>> print(shapely.__version__)
>>>> from shapely.geometry import Polygon
>>>> print(Polygon.from_bounds(*bounds))
In that piece of code you didn't set 'bounds'. It might be worth setting
it or at least printing it out to double-check.
>
> Output:
>
> 1.8.0
> POLYGON EMPTY
>
> In fact, *any* attempt to create a polygon gives the same result:
>>>> test = Polygon(((1, 1), (2, 1), (2, 2)))
>>>> print(test)
> POLYGON EMPTY
>
Did you try that piece of code both in Flask and from the command line,
again to double-check.
> What am I missing here? Why doesn’t it work as part of a Flask request call?
>
More information about the Python-list
mailing list