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
12
votes
3 answers

What is the most efficient way to convert numpy arrays to Shapely Points?

I have a function that outputs a grid of points as x and y numpy arrays for interpolation, but before I interpolate, I want to use Geopandas to perform an intersection with my research boundary (otherwise half of my interpolation points fall in the…
Ryan
  • 1,032
  • 1
  • 10
  • 23
12
votes
2 answers

Shapely unable to split line on point due to precision issues

I am trying to interpolate a point onto a LineString in Shapely and then split the linestring accordingly. However, due to a precision error, Shapely thinks that the interpolated point is not on the linestring, and therefore the split operation does…
atkat12
  • 3,840
  • 7
  • 22
  • 22
12
votes
1 answer

Create new shapely polygon by subtracting the intersection with another polygon

I have two shapely MultiPolygon instances (made of lon,lat points) that intersect at various parts. I'm trying to loop through, determine if there's an intersection between two polygons, and then create a new polygon that excludes that intersection.…
edub
  • 659
  • 4
  • 8
  • 19
12
votes
2 answers

Splitting self-intersecting polygon only returned one polygon in Shapely

I am using Python 3.5 64 bit in Windows 7 64 bit, shapely version 1.5.13. I have the following code that returned me a self-intersecting polygon: import numpy as np from shapely.geometry import Polygon, MultiPolygon import matplotlib.pyplot as…
Yuxiang Wang
  • 8,095
  • 13
  • 64
  • 95
12
votes
1 answer

Finding largest inscribed rectangle of a polygon with Shapely

I am trying to locate millions of points inside a half-dozen polygons. Here's my code: def find_shape(longitude,latitude): if longitude != 0 and latitude != 0: point = shapely.geometry.Point(longitude,latitude) else: return…
Martin Burch
  • 2,726
  • 4
  • 31
  • 59
12
votes
1 answer

Determine if Shapely point is within a LineString/MultiLineString

I am trying to use Shapely's within function to do a 'spatial join' of a LineString and a Point file (FYI, the point file was generated using the interpolate function on the LineString). Problem is - nothing is being returned. # this condition is…
user14696
  • 657
  • 2
  • 10
  • 30
12
votes
3 answers

Is there an envelope class in shapely?

I found the envelope class in Java's JTS library very handy. An envelope holds the minimal and maximal coordinates of a geometry and is also called bounding box sometimes. I wanted to get the common envelope of a number of shapely points. In JTS you…
linqu
  • 11,320
  • 8
  • 55
  • 67
12
votes
1 answer

Polygon Intersection with Line | Python Shapely

I have been trying to use shapely to find the intersection of a line and a polygon, but I'm having issues with some floating point numbers. Example code: polygon = [(4.0, -2.0), (5.0, -2.0), (4.0, -3.0), (3.0, -3.0), (4.0, -2.0)] shapely_poly =…
lisaah
  • 623
  • 1
  • 4
  • 14
11
votes
2 answers

Convert Multipolygon to Polygon in Python

Is it possible to convert a Multipolygon into a Polygon which fills all holes or missing inner areas using Shapely? I have been trying since a while but I can't find it in the documentation. The following image I show an example of a multipolygon…
Alberto Bonsanto
  • 17,556
  • 10
  • 64
  • 93
11
votes
4 answers

Estimating an area of an image generated by a set of points (Alpha shapes??)

I have a set of points in an example ASCII file showing a 2D image. I would like to estimate the total area that these points are filling. There are some places inside this plane that are not filled by any point because these regions have been…
Dalek
  • 4,168
  • 11
  • 48
  • 100
11
votes
4 answers

Error importing Polygon from shapely.geometry.polygon

In my Anaconda 2.2 64bit with Python 3.4.3 the following line works well: import shapely But the following line: from shapely.geometry.polygon import Polygon returns the following error: OSError: [WinError 126] The specified module could not be…
stenci
  • 8,290
  • 14
  • 64
  • 104
11
votes
1 answer

Using cascaded_union to combine shapes gives "ValueError: No Shapely geometry can be created from null value"

I have a cluster of seven overlapping circles and ellipses that I'm trying to combine into one shape, but when I run cascaded_union() I get the error: ValueError: No Shapely geometry can be created from null value Here's what I have written so…
user3555455
  • 487
  • 2
  • 7
  • 14
10
votes
2 answers

Shapely polygon to binary mask

I have seen this question asked but have not really been able to find a full response. I have a simple shapely polygon, called polygon. I would like to extract this polygon as a binary mask (ideally a numpy array). How would I go about doing this? I…
hex93
  • 319
  • 3
  • 15
10
votes
3 answers

Cannot make GeoDataFrame from Shapely Polygons: NotImplementedError: A polygon does not itself provide the array interface. Its rings do

This is code that used to work previously, but doesn't anymore: import geopandas as gp from shapely.geometry import Polygon a = Polygon([(0, 0), (0, 1), (1, 1), (1, 0)]) b = Polygon([(0, 1), (0, 2), (1, 2), (1, 1)]) c = Polygon([(1, 0), (1, 1), (2,…
bsuw
  • 101
  • 1
  • 3
10
votes
2 answers

How to get a list of every Point inside a MultiPolygon using Shapely

I have the following MultiPolygon: MULTIPOLYGON ( ( (10.8849956 49.8901705, 10.8849507 49.8902499, 10.884969 49.8902588, 10.8851033 49.8903298, 10.8851183 49.8903132, 10.88512882654868 49.8903054, 10.8851246 49.8903054, 10.8851246 49.8902754,…
Thurse
  • 253
  • 1
  • 3
  • 16