Questions tagged [shapely]

PostGIS-ish operations outside a database context for Pythoneers and Pythonistas.

Shapely is a BSD-licensed Python package (see Shapely · PyPI) for manipulation and analysis of planar geometric objects. It is based on the widely deployed GEOS (the engine of PostGIS) and JTS (from which GEOS is ported) libraries. This C dependency is traded for the ability to execute with blazing speed. Shapely is not concerned with data formats or coordinate systems, but can be readily integrated with packages that are. For more details, see the Shapely manual.

1113 questions
5
votes
1 answer

Why is Shapely plotting two lines when I change a coordinate?

I'm trying to understand how Shapely works. I can draw a simple line with the following code: import matplotlib.pyplot as plt A = Point(0,0) B = Point(1,1) AB = LineString([A,B]) plt.plot(AB) However when I alter the coordinates: A =…
Falc
  • 307
  • 2
  • 14
5
votes
3 answers

Convert a column of GeoJSON-like strings to geometry objects in GeoPandas

I have a column in a GeoPandas dataframe with strings like this one '{type=Point, coordinates=[37.55, 55.71]}' or this '{type=MultiPoint, coordinates=[[37.6, 55.4]]}'. It can be a polygon or any other geometry as well. Then there are a few points in…
James Flash
  • 528
  • 7
  • 15
5
votes
1 answer

How can I efficiently save data from geopandas to django (converting from shapely to geodjango)?

I am manipulating GIS data w/ geopandas and storing it in various Django models. geopandas uses shapely under-the-hood while Django does not. Here is some code: import geopandas as gpd from django.contrib.gis.db import models class…
trubliphone
  • 4,132
  • 3
  • 42
  • 66
5
votes
1 answer

Creating an ASCII art world map

I'd like to render an ASCII art world map given this GeoJSON file. My basic approach is to load the GeoJSON into Shapely, transform the points using pyproj to Mercator, and then do a hit test on the geometries for each character of my ASCII art…
rgov
  • 3,516
  • 1
  • 31
  • 51
5
votes
2 answers

Access individual points in Shapely MultiPoint

I am working with the Shapely library in Python. I find the intersection of two lines, the return value is given as a MultiPoint object. How do I deconstruct the object to get the individual points in the intersection? Here is the code: from…
Chris B
  • 75
  • 1
  • 1
  • 7
5
votes
3 answers

Install Shapely in Python 3

I cant install the shapely module in my anaconda prompt. pip install --upgrade setuptools pip install shapely Command "python setup.py egg_info" failed with error code 1 in…
Sim re
  • 73
  • 1
  • 2
  • 8
5
votes
1 answer

Shapely: intersection point between line and polygon in 3D

Last time I used shapely, I really had this nice import-and-fly-feeling. However recently, I run into a rather non-intuitive behavior in this module, as I tried to find the intersection between a line segment and a triangle in 3D space. Let's define…
snake_charmer
  • 2,845
  • 4
  • 26
  • 39
5
votes
1 answer

Obtaining the center of a WKT polygon

I'm using pandas, and a dataset I obtained has a location column in a WKT format. For example: hospital.get_value(1,'WKT') POLYGON ((-58.4932 -34.5810,-58.4925 -34.5815,-58.4924 -34.5817)) There's a lot more points and with bigger precision in this…
martincito
  • 71
  • 1
  • 5
5
votes
2 answers

Get all lattice points lying inside a Shapely polygon

I need to find all the lattice points inside and on a polygon. Input: from shapely.geometry import Polygon, mapping sh_polygon = Polygon(((0,0), (2,0), (2,2), (0,2))) Output: (0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1), (0, 2), (1, 2), (2,…
Beginner
  • 1,202
  • 2
  • 20
  • 29
5
votes
1 answer

gis calculate distance between point and polygon / border

I want to calculate the distance between a point and the border of a country using python / shapely. It should work just fine point.distance(poly) e.g. demonstrated here Find Coordinate of Closest Point on Polygon Shapely but using geopandas I face…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
5
votes
3 answers

OSError when trying to pip install shapely inside docker container

Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so'] using the python:3.5.1 image I am trying to run a container that includes among other things it installs in requirements.txt shapely. When the docker…
lathomas64
  • 1,612
  • 5
  • 21
  • 47
5
votes
1 answer

Shapely intersections vs shapely relationships - inexact?

I wonder if I am thinking the wrong way or if this is a bug: I have a linestring and a polygon, I create the intersection points of the line and the polygon's boundary These intersection points should intersect (at least touch) the polygon's…
sal
  • 1,199
  • 1
  • 13
  • 31
5
votes
1 answer

Shapely extending line feature

I have a Polygon and a MultiLineString in Shapely. I would like to extend the LineString segment that does not reach the polygon boundary so that it does indeed reach the polygon boundary. It's okay if it extends past because I can easily clip it to…
AJG519
  • 3,249
  • 10
  • 36
  • 62
5
votes
2 answers

ValueError: No Shapely geometry can be created from null value

I get this error while using cascaded_union (I have also tried unary_union which produces the same error): ValueError: No Shapely geometry can be created from null value I have validated that my polygons are valid. Initially polyB isn't valid, but…
Mark Hebert
  • 919
  • 1
  • 9
  • 15
5
votes
1 answer

shapely.geos.ReadingError: Could not create geometry because of errors while reading input

I'm getting the error in the title when I try to use shapely.wkt.loads on the following input: POLYGON((-93.577695846689437 40.813390731817726,-93.577674865779628 40.813444137603014,-93.577722549304582 40.8136196133706,-93.577945709640048…
user2497586