Questions tagged [shapely]

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

Shapely is a BSD-licensed Python package 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:

740 questions
76
votes
8 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
  • 13,415
  • 6
  • 73
  • 96
74
votes
10 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
  • 901
  • 1
  • 6
  • 8
57
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
  • 3,530
  • 1
  • 22
  • 34
46
votes
4 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
  • 379
  • 1
  • 3
  • 12
46
votes
2 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,448
  • 7
  • 32
  • 53
43
votes
2 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
  • 1,880
  • 2
  • 17
  • 31
34
votes
3 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…
34
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
  • 775
  • 1
  • 7
  • 22
32
votes
4 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
  • 3,733
  • 5
  • 26
  • 42
31
votes
2 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
  • 805
  • 2
  • 9
  • 13
24
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
  • 906
  • 1
  • 10
  • 24
23
votes
6 answers

OSError geos_c could not be found when Installing Shapely

I'm a newbie to making/plotting on maps with python, been trying to follow this blogpost to generate a world map (http://sciblogs.co.nz/seeing-data/2011/08/12/plotting-geographic-data-on-a-world-map-with-python/). Got stuck with a few things…
msunbot
  • 1,391
  • 2
  • 12
  • 16
22
votes
4 answers

Install Shapely: OSError: [WinError 126] The specified module could not be found

I have to install Shapely package (http://toblerity.org/shapely/project.html#installation). But when I am using: pip install Shapely I am getting this error: Collecting Shapely Using cached Shapely-1.5.17.tar.gz Complete output from command…
Beginner
  • 950
  • 1
  • 14
  • 26
22
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
  • 2,609
  • 5
  • 28
  • 53
22
votes
6 answers

Python, GEOS and Shapely on Windows 64

When trying to install Shapely on my Windows 64bit computer, I cannot get the GEOS library to work. So far, I have run the OSGeo4W installer from which I installed GDAL (I believe the geos library is included in that package). After that, I checked…
Juan Carlos Coto
  • 9,760
  • 18
  • 52
  • 95
1
2 3
49 50