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
112
votes
9 answers

Extract points/coordinates from a polygon in Shapely

How do you get/extract the points that define a shapely polygon? Thanks! Example of a shapely polygon from shapely.geometry import Polygon # Create polygon from lists of points x = [list of x vals] y = [list of y vals] polygon = Polygon(x,y)
ryanjdillon
  • 17,658
  • 9
  • 85
  • 110
111
votes
12 answers

Could not find library geos_c or load any of its variants

I use Python in Fedora 19. I wanted to run the following line: import shapely.geometry but the following error appears: OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so'] I installed the package…
user2947767
  • 1,281
  • 2
  • 9
  • 9
88
votes
9 answers

How do I plot Shapely polygons and objects using Matplotlib?

I want to use Shapely for my computational geometry project. I need to be able to visualize and display polygons, lines, and other geometric objects for this. I've tried to use Matplotlib for this but I am having trouble with it. from…
ebeb9
  • 899
  • 2
  • 9
  • 16
78
votes
3 answers

Make a union of polygons in GeoPandas, or Shapely (into a single geometry)

I am trying to find the union of two polygons in GeoPandas and output a single geometry that encompasses points from both polygons as its vertices. The geopandas.overlay function gives me polygons for each individual union but I would like a single…
p-robot
  • 4,652
  • 2
  • 29
  • 38
62
votes
4 answers

Check if geo-point is inside or outside of polygon

I am using python and I have defined the latitudes and longitudes (in degrees) of a polygon on the map. My goal is to check if a generic point P of coordinates x,y falls within such polygon. I would like therefore to have a function that allows me…
Federico Gentile
  • 5,650
  • 10
  • 47
  • 102
54
votes
6 answers

Fix invalid polygon in Shapely

Shapely defines a Polygon as invalid if any of its segments intersect, including segments that are colinear. Many software packages will create a region or area with a "cutout" as shown here which has colinear segments: >>> pp = Polygon([(0,0),…
jpcgt
  • 2,138
  • 2
  • 19
  • 34
52
votes
3 answers

Faster way of polygon intersection with shapely

I have a large number of polygons (~100000) and try to find a smart way of calculating their intersecting area with a regular grid cells. Currently, I am creating the polygons and the grid cells using shapely (based on their corner coordinates).…
HyperCube
  • 3,870
  • 9
  • 41
  • 53
49
votes
1 answer

Shapely: Polygon from String?

I have saved string representations of some Shapely Polygons: 'POLYGON ((51.0 3.0, 51.3 3.61, 51.3 3.0, 51.0 3.0))' Is there some fast way of directly converting it back to the Polygon type? Or do I need to manually parse the strings to create…
Valeria
  • 1,508
  • 4
  • 20
  • 44
48
votes
2 answers

Coordinates of the closest points of two geometries in Shapely

There is a polyline with a list of coordinates of the vertices = [(x1,y1), (x2,y2), (x3,y3),...] and a point(x,y). In Shapely, geometry1.distance(geometry2) returns the shortest distance between the two geometries. >>> from shapely.geometry import…
Asif Rehan
  • 983
  • 2
  • 8
  • 25
47
votes
3 answers

Calculate overlapped area between two rectangles

I want to calculate the overlapped area "THE GRAY REGION" between red and blue rectangles. Each rectangle is defined by its four corner coordinates. The resulted unit of the overlapped area is unit square. I could not imagine how can I do it? Any…
Eric Bal
  • 1,115
  • 3
  • 12
  • 16
46
votes
5 answers

How to create a shapely Polygon from a list of shapely Points?

I want to create a polygon from shapely points. from shapely import geometry p1 = geometry.Point(0,0) p2 = geometry.Point(1,0) p3 = geometry.Point(1,1) p4 = geometry.Point(0,1) pointList = [p1, p2, p3, p4, p1] poly =…
Sounak
  • 4,803
  • 7
  • 30
  • 48
32
votes
3 answers

Find coordinate of the closest point on polygon in Shapely

Say I have the following Polygon and Point: >>> poly = Polygon([(0, 0), (2, 8), (14, 10), (6, 1)]) >>> point = Point(12, 4) I can calculate the point's distance to the polygon... >>> dist = point.distance(poly) >>>…
AJG519
  • 3,249
  • 10
  • 36
  • 62
29
votes
3 answers

Shapely point geometry in geopandas df to lat/lon columns

I have a geopandas df with a column of shapely point objects. I want to extract the coordinate (lat/lon) from the shapely point objects to generate latitude and longitude columns. There must be an easy way to do this, but I cannot figure it out. I…
jtam
  • 814
  • 1
  • 8
  • 24
29
votes
9 answers

Shapely OSError: Could not find lib c or load any of its variants []

I'm just trying to use the demo code. I run the following in Jupyter Notebook: from shapely.geometry import shape Which gives me the following: OSError Traceback (most recent call…
Huey
  • 2,714
  • 6
  • 28
  • 34
28
votes
3 answers

Check if a polygon is a multipolygon in Shapely

How can I check if a polygon entity is actually a multipolygon? I've tried: if len(polygon) > 1: but then get the error: TypeError: object of type 'Polygon' has no len() I've tried Nill, None and others, nothing worked.
Yair
  • 859
  • 2
  • 12
  • 27
1
2 3
74 75