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
4
votes
1 answer

numpy meshgrid to Shapely polygons

I'm trying to create a numpy meshgrid and convert it to Shapely polygons. I can likely solve this with a very brute force method but it feels like there has to be a good trick to accomplish this but I haven't come up with it, yet. This gets me the…
BryceH
  • 2,740
  • 2
  • 21
  • 24
4
votes
2 answers

Can I set the order of points in a shapely Polygon?

I have a group of Polygon objects and need to iterate through each of their edges in a repeatable way. My preferred method is anti-clockwise from the closest point to the lower left corner of the bounding box. I can ensure the polygon points are…
Jamie Bull
  • 12,889
  • 15
  • 77
  • 116
4
votes
1 answer

Removing duplicate geometries in Shapely

I have a list of Shapely polygons. From that list I want to extract only unique polygons removing the duplicates. How to do it in a faster way? (My list contains thousands of polygons) from shapely.geometry import Polygon lists =…
Borys
  • 1,323
  • 6
  • 16
  • 40
4
votes
2 answers

Count number of points in multipolygon shapefile using Python

I have a polygon shapefile of the U.S. made up of individual states as their attribute values. In addition, I have arrays storing latitude and longitude values of point events that I am also interested in. Essentially, I would like to 'spatial…
wuffwuff
  • 730
  • 2
  • 9
  • 19
4
votes
1 answer

How do I add two polygons in Python using Shapely?

I don't know how to add two polygons in Python using Shapely. By adding I mean for instance if I was adding two squares with height 4 and width 2, and they had the same coordinates, it should return a square that has height 8 and width 2. I have…
RGS2014
  • 71
  • 1
  • 4
4
votes
1 answer

Removing numpy meshgrid points outside of a Shapely polygon

I have a 10 x 10 grid that I would like to remove points outside of a shapely Polygon: import numpy as np from shapely.geometry import Polygon, Point from descartes import PolygonPatch gridX, gridY = np.mgrid[0.0:10.0, 0.0:10.0] poly =…
camdenl
  • 1,159
  • 4
  • 21
  • 32
4
votes
1 answer

Find holes in a union of rectangles?

I have a number of random rectangles (black) in and around a unit square (red) and need to extract all the polygonal regions inside the unit square that are not covered by any rectangle. It looks like this can be done with Shapely and I've gotten…
nickponline
  • 25,354
  • 32
  • 99
  • 167
4
votes
1 answer

Apply a pairwise shapely function on two numpy arrays of shapely objects

I have two arrays of different length. One contains shapely polygons, the other contains shapely points. I want to run the a_polygon.contains(a_point) shapely function for every possible combination of elements in both arrays. I was looking at this…
Jaqo
  • 329
  • 1
  • 5
  • 15
4
votes
1 answer

Optimal way of aggregating geographic points with Python/Shapely

I would like to convert a long list of lat/long coordinates to the US state (or county) they belong to. One possible solution, given that I have the state geometries, is to check each points against all the states. for point in points: for state…
themiurgo
  • 1,550
  • 2
  • 13
  • 16
4
votes
2 answers

shapely polygon_.buffer(0) "loses" half my bowtie

I've seen online that buffer(0) should "fix" bowties. Shapely finds the intersection point of the bowtie, but only keeps the top-right portion. Looking for a workaround, I tried reversing the order of my points. Surprisingly (to me), the same…
Shay
  • 1,368
  • 11
  • 17
4
votes
1 answer

Unable to run app on heroku using Flask and Shapely

I have developed a small app which requires the Shapely python library. I installed it on windows via the .exe file so it automatically put the necessary DLL files (geos.dll , geos_c.dll) in Python27\Lib\site-packages\shapely\DLLs. When i tried to…
Rijul Jain
  • 361
  • 1
  • 3
  • 4
3
votes
1 answer

Shapely intersection: parallel planes

I'm working on determining relationships (boundary/interior intersections) between two 3D objects (triangular faces) and stumbled on Shapely, which I am interested in using instead of implementing my own point/segment/ray/triangle intersection…
squishy
  • 33
  • 1
  • 3
3
votes
1 answer

Shapely RuntimeWarning: invalid value encountered in intersection

Got this warning when trying to calculate the intersection between two geometry objects. >>> shapely.intersection(LineString([(0, 0), (1, 1)], LineString([(2.5, 2.5), (3, 3)])) .../lib/python3.9/site-packages/shapely/set_operations.py:133:…
Anas
  • 91
  • 1
  • 8
3
votes
2 answers

How to smooth adjacent polygons in Python?

I'm looking for a way to smooth polygons such that adjacent/touching polygons remain touching. Individual polygons can be smoothed easily, e.g., with PAEK or Bezier interpolation…
Thijs
  • 433
  • 8
3
votes
1 answer

Getting "AttributeError: module 'shapely.geos' has no attribute 'lgeos'"

I am trying to do this exercise from momepy (https://github.com/pysal/momepy/blob/main/docs/user_guide/getting_started.ipynb), but on the third codeblock f, ax = plt.subplots(figsize=(10, 10)) buildings.plot(ax=ax) ax.set_axis_off() plt.show() I…
Reuben
  • 81
  • 9