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
10
votes
2 answers

How to use geopanda or shapely to find nearest point in same geodataframe

I have a geodataframe showing ~25 locations represented as point geometry. I am trying to come up with a script that goes through each point, identifies the nearest location and returns the name of the nearest location and the distance. I can easily…
rzt101
  • 127
  • 1
  • 1
  • 6
10
votes
1 answer

How to merge 2 Shapely objects?

I try to merge two Shapely Objects in my Python Project. There is a sort of kind of manual that describes some features of Shapely such as cascaded_union() but I that only works for Polygons. The shapely.ops.unary_union() method should work for…
Martin Fake
  • 559
  • 5
  • 10
9
votes
1 answer

Calculate all distances between two GeoDataFrame (of points) in GeoPandas

This is quite simple case, but I did not find any easy way to do it so far. The idea is to get a set of distances between all the points defined in a GeoDataFrame and the ones defined in another GeoDataFrame. import geopandas as gpd import pandas as…
Leonard
  • 2,510
  • 18
  • 37
9
votes
3 answers

Fast way to find the closest polygon to a point

I have a list of Shapely polygons and a point like so: from shapely.geometry import Point, Polygon polygons = [Polygon(...), Polygon(...), ...] point = Point(2.5, 5.7) and I want to find the closest polygon in the list to that point. I'm already…
SalmaFG
  • 2,022
  • 3
  • 23
  • 36
9
votes
2 answers

Shapely import error: No module named 'shapely'

I've installed shapely with pip install shapely and importing it as from shapely.geometry import Point. I get this error: from shapely.geometry import Point ModuleNotFoundError: No module named 'shapely' I'm n MacOS High Sierra. All other…
Daniela
  • 861
  • 5
  • 11
  • 28
9
votes
1 answer

Polygon perimeter

Given a polygon which is constructed like this: from shapely.geometry import Polygon print Polygon([(0,0), (4,0), (2,4)]).area this correctly computes the area of the triangle. However, if i replace the area attribute with 'perimeter' I get the…
twistedqbit
  • 105
  • 1
  • 6
9
votes
2 answers

Geopandas Dataframe Points to Polygons

I have a geopandas dataframe made up of an id and a geometry column which is populated by 2D points. I want to join the points for each unique id to create a polygon, so that my new dataframe will have polygons as its geometry. My code currently…
GSam11
  • 101
  • 1
  • 1
  • 7
9
votes
1 answer

Merging a list of Polygons to Multipolygons

I have a list of shapely polygons myList = [[], [], []] How would I create a…
four-eyes
  • 10,740
  • 29
  • 111
  • 220
9
votes
1 answer

Plot unions of polygons in matplotlib

I am trying to plot the union of a couple of polygons in matplotlib, with a certain level of alpha. My current code below has a darker color at the intersections. Would there be anyway to make the intersections the same color with other…
Yuxiang Wang
  • 8,095
  • 13
  • 64
  • 95
9
votes
2 answers

How to simplify boundary geometries in shapely

I'm working with shapely to do GIS, but I'm running into memory errors when loading the geometry of each zip code into memory because the geometry is so jagged and complicated. I'd like to make the shape smaller in memory by reducing the number of…
Michael K
  • 2,196
  • 6
  • 34
  • 52
9
votes
4 answers

shapely and matplotlib point-in-polygon not accurate with geolocation

I am testing the point-in-polygon function with matplotlib and shapely. Here is a map contains a Bermuda triangle polygon. Google maps's point-in-polygon functions clearly shows testingPoint and testingPoint2 are inside of the polygon which is a…
Chung
  • 1,063
  • 1
  • 13
  • 21
9
votes
2 answers

Geoalchemy2 query all users within X meteres

I have an app that takes an address string, sends it to Google Maps API and gets lat/long co-ordinates, I then want to show the all users within X meteres of this point (there lat/long is stored in my database), I then want to filter the result to…
Crooksey
  • 908
  • 3
  • 11
  • 22
9
votes
2 answers

Polygon touches in more than one point with Shapely

I have a list of Shapely polygons in Python. To find out which polygon touch is easy, using the .touches() method. However, I need something that returns True only when the polygons share more than one point (in other words shares a border). Let me…
XerXes
  • 723
  • 1
  • 9
  • 17
8
votes
1 answer

How to use Shapely for subtracting two polygons

I am not really sure how to explain this but I have 2 polygons, Polygon1 and Polygon2. These polygons overlapped with each other. How to do I get Polygon2 using Shapely without the P from Polygon1.
simple guy
  • 633
  • 1
  • 6
  • 19