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

Syntax for creating a new, empty GeoDataFrame

I have a GeoDataFrame (let's call it Destinations) that was made from a point shapefile using GeoPandas. For every feature (correct me if the terminology is wrong) in Destinations, I need to find the nearest node on a graph and save that node to…
Borillar0821
  • 63
  • 1
  • 5
6
votes
2 answers

How to get equally spaced points on a line in Shapely

I'm trying to (roughly) equally space the points of a line to a predefined distance. It's ok to have some tolerance between the distances but as close as possible would be desirable. I know I could manually iterate through each point in my line and…
Lewis Morris
  • 1,916
  • 2
  • 28
  • 39
6
votes
1 answer

How to convert two coordinate columns to a column of Shapely points

I'm trying to perform an operation on a whole column but I'm getting a type error, I want to make a column containing a Shapely Point: crime_df = crime_df[crime_df['Latitude'].notna()] crime_df =…
TomSelleck
  • 6,706
  • 22
  • 82
  • 151
6
votes
2 answers

Geopandas: how to convert the column geometry to string?

I have a geopandas dataframe geometry idx 0 POLYGON ((-74.25559 40.91553, -74.24559 40.915... 0 1 POLYGON ((-74.25559 40.90553, -74.24559 40.905... 1 2 POLYGON ((-74.25559 40.89553, -74.24559…
emax
  • 6,965
  • 19
  • 74
  • 141
6
votes
2 answers

Python: how to create square buffers around points with a distance in meters

I have a geopandas dataframe gdf gdf ID longitude latitude geometry 0 80 103.619501 1.2810 POINT (103.619500987 1.281) 1 81 103.619501 1.2855 POINT (103.619500987 1.2855) Following this suggestion I create a square…
emax
  • 6,965
  • 19
  • 74
  • 141
6
votes
1 answer

Geopandas set geometry: ValueError for MultiPolygon "equal len keys and value"

I have 2 geodataframes with a geometry column and I copy some geometries from 1 to the other. This works well with Polygons but returns a ValueError for any (valid) MultiPolygon. Please advice how to solve this? I don't know if / how / why I should…
Wouter
  • 1,296
  • 2
  • 14
  • 32
6
votes
1 answer

Does shapely LineString intersection works wrong?

While working with shapely I faced a strange issue. There're 2 points p1 and p2, where the first one belongs to polygon and the second is not. When I tried to find intersection between the LineString containing these 2 points as endpoints with…
SliceOfTuna
  • 81
  • 1
  • 4
6
votes
0 answers

How can I plot Shapely polygons with holes?

I would like to have a function plot(shapely_objects) where shapely_objects is a list of Polygons, Points and MultiPolygons. I have something extremely similar, but it fills the holes of polygons. How can I plot Shapely polygons with…
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
6
votes
1 answer

Shapely: Split LineString at arbitrary point along edge

I'm trying to split a Shapely LineString at the nearest point to some other coordinate. I can get the closest point on the line using project and interpolate but I am unable to split the line at this point as it is not a vertex. I need to split the…
Greg Brown
  • 1,251
  • 1
  • 15
  • 32
6
votes
2 answers

shapely parallel_offset sometimes does not generate closed ring

I am using the parallel_offset function of the shapely package to get offset structures to some polygons that are closed rings. I have several polygons at once, many with similar shapes. Around 10-25% of them, however, do not generate a closed ring…
Ian
  • 1,688
  • 18
  • 35
6
votes
2 answers

Find closest line to each point on big dataset, possibly using shapely and rtree

I have a simplified map of a city that has streets in it as linestrings and addresses as points. I need to find closest path from each point to any street line. I have a working script that does this, but it runs in polynomial time as it has nested…
StefanK
  • 2,030
  • 1
  • 21
  • 26
6
votes
1 answer

Cartopy: Drawing the coastlines with a country border removed

I want to draw the outline of China in one color whilst also showing the global coastlines in another. My first attempt at doing this was as follows: import matplotlib.pyplot as plt import cartopy.crs as ccrs import cartopy.feature as feature import…
pelson
  • 21,252
  • 4
  • 92
  • 99
6
votes
3 answers

Issue installing shapely Python Package

I am running python 3.6 on windows and am attempting to install Shapely using pip install shapely==1.6b2 It is giving me the following errors Command "python setup.py egg_info" failed with error code 1 in…
Cameron Wasilewsky
  • 962
  • 2
  • 10
  • 12
6
votes
1 answer

Python shapely Polygon.contains(Point) not giving correct answer (I think)

from shapely.geometry import Polygon, Point p = Point(2,2) poly = Polygon((0,0), (0,5), (5,0), (5,5)) print poly.contains(p) This prints False, although I'm pretty sure (2,2) is within a square of length 5. Or maybe I just don't know how the…
G Bhaskar
  • 93
  • 1
  • 1
  • 4
6
votes
1 answer

centos libgeos repository missing

On centos 7.3 minimal trying to install shapely or geopandas requires access to https://github.com/libgeos/libgeos libgeos. Trying to install this via sudo yum install libgeos-dev tells me that this package is not available. It seems that I am…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292