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

Using Geopandas, how do I select all points not within a polygon?

I have a DataFrame containing Chicago addresses which I've geocoded into latitude and longitude values, and then into Point objects (making the DataFrame a GeoDataFrame). A small fraction have been incorrectly geocoded with LatLong values outside of…
MattTriano
  • 1,532
  • 2
  • 16
  • 15
16
votes
1 answer

GeoPandas: How to obtain bounding boxes for every geometry in a geodataframe

I am using GeoPandas in python and have a valid GeoDataframe of polygons. 0 POLYGON Z ((68.70999999999999 623.1 0, 35.71 6... 1 POLYGON Z ((221.33 645.02 0, 185.7 640.33 0, 1... 2 POLYGON Z ((150.3 650 0, 160.9 650 0, 150.58…
krishnab
  • 9,270
  • 12
  • 66
  • 123
15
votes
2 answers

3D Geometry Package for Python

I am trying to find a good 3D geometry library for Python that has similar operations and functionality to Shapely. http://toblerity.org/shapely/manual.html Shapely is great, and has exactly what I need, especially around the creation and…
Akol
  • 171
  • 1
  • 1
  • 4
15
votes
1 answer

Intersection of Two LineStrings Geopandas

Let's say I have the following to GeoDataFrames of linestrings, one of which represents roads and one of which represents contour lines. >>> import geopandas as gpd >>> import geopandas.tools >>> import shapely >>> from shapely.geometry import * >>>…
AJG519
  • 3,249
  • 10
  • 36
  • 62
15
votes
2 answers

What is the difference between Polygon.contains and Polygon.within?

The Docstring says: Polygon.contains Returns True if the geometry contains the other, else False Polygon.within Returns True if geometry is within the other, else False How are they different?
Sounak
  • 4,803
  • 7
  • 30
  • 48
15
votes
3 answers

Polygon intersection error in Shapely: "shapely.geos.TopologicalError: The operation 'GEOSIntersection_r' produced a null geometry"

I have been trying to debug this problem but unable to do so. I am trying to find the intersection of two Polygon objects. It works most of the time but for the following case, it raises the following exception: P1 area: 13.125721955 P2 area:…
Nik
  • 5,515
  • 14
  • 49
  • 75
14
votes
1 answer

Convert Geopandas Multipolygon to Polygon

I have a geodataframe with a Multipolygon geometry: I would like to convert them to Polygons i.e. fill in the holes of multipolygon and make it a single polygon. I have tried the code from this similar question: from shapely.geometry import…
SCool
  • 3,104
  • 4
  • 21
  • 49
14
votes
3 answers

Calculate Polygon area in planar units (e.g. square-meters) in Shapely

I am using Python 3.4 and shapely 1.3.2 to create a Polygon object out of a list of long/lat coordinate pairs which I transform into a well-known-text string in order to parse them. Such a Polygon might look like: POLYGON ((-116.904 43.371, -116.823…
Dirk
  • 9,381
  • 17
  • 70
  • 98
13
votes
2 answers

Shapely .contains() method but including boundaries?

I'm working with Shapely polygons and I need a way to delete all smaller polygons contained within a bigger polygon. I tried using the .contains() method which Shapely provides, but the method doesn't return True if a given smaller polygon isn't…
kfilipcic
  • 130
  • 1
  • 7
13
votes
2 answers

How to create GeometryCollection from geojson with python shapely?

I want to calculate areas of geometries and some of these geometries can be geometry collections. But I can't do this because shapely doesn't create geometry collection from geojson. Here is the sample code: import sys import shapely from…
kz_sergey
  • 677
  • 5
  • 19
13
votes
2 answers

Interpolating every X distance along multiline in shapely

If I have a shapely multiline object that contains many lines whose total length each is 50km (when traced from the origin), and I want to interpolate along the multiline every X meters (let's say 100m), returning shapely point objects every 100m,…
traggatmot
  • 1,423
  • 5
  • 26
  • 51
13
votes
2 answers

How to deal with rounding errors in Shapely

I have a case which is based on projecting a point on a line and then separate this line on it. My use case is slightly more complicated, but my problem can be reproduced with the following code: from shapely import * line1 = LineString([(1,1.2),…
Fabzi
  • 626
  • 5
  • 15
12
votes
3 answers

how to convert geojson to shapely polygon?

i have a geoJSON geo = {'type': 'Polygon', 'coordinates': [[[23.08437310100004, 53.15448536100007], [23.08459767900007, 53.15448536100007], [23.08594514600003, 53.153587050000056], (...) [23.08437310100004, 53.15448536100007]]]} and i…
adamDud
  • 309
  • 1
  • 3
  • 10
12
votes
4 answers

How to get the endpoint of a LineString in Shapely

Linestring1 = LINESTRING (51.2176008 4.4177154, 51.21758 4.4178548, **51.2175729 4.4179023**, *51.21745162000732 4.41871738126533*) Linestring2 = LINESTRING (*51.21745162000732 4.41871738126533*, **51.2174025 4.4190475**, 51.217338 4.4194807,…
Wout VC
  • 327
  • 1
  • 4
  • 8
12
votes
4 answers

Draw perpendicular line of fixed length at a point of another line

I have two points A (10,20) and B (15,30). The points generate a line AB. I need to draw a perpendicular line, CD, on point B with a length of 6 (each direction 3 units) in Python. I already have some properties of line AB using the following…
Sourav
  • 816
  • 3
  • 11
  • 26
1 2
3
74 75