Questions tagged [shapely]

Shapely is an open source Python package for construction and analysis of 2D planar geometric objects common to geographic information systems.

Shapely

Python package for manipulation and analysis of geometric objects in the Cartesian plane

Shapely is a BSD-licensed Python package 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. Shapely is not concerned with data formats or coordinate systems, but can be readily integrated with packages that are.

Please see the Shapely Manual and GitHub Repo.

935 questions
18
votes
1 answer

Returning percentage of area of polygon intersecting another polygon using shapely

Using the shapely library, suppose I have a shp file V and another shp file Z. For each polygon v in V, and for each polygon z in Z, I would like to know what percentage of the area of z falls within (intersects) v.
Dervin Thunk
  • 545
  • 1
  • 4
  • 11
11
votes
2 answers

Shapely - convert polygons to lines?

Given a shapefile with polygons, how do I convert the polygons to individual lines instead? I know how to do this in QGIS, but I'm looking for a Shapely function which does the same thing.
9
votes
1 answer

Buffer to linestring in shapely

I have a linestring in shapely which I'm converting into buffer. >>> from shapely.geometry import LineString >>> line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)]) >>> dilated = line.buffer(0.5) Now I'm trying to convert the…
Rahul
  • 469
  • 2
  • 8
  • 16
6
votes
1 answer

Break a shapely Linestring at multiple points

This code below was modified from the one I found here which splits a shapely Linestring into two segments at a point defined along the line. I have also checked other questions but they don't address my query directly. However I will like to extend…
Nobi
  • 175
  • 1
  • 5
5
votes
2 answers

How to calculate distance between two points on a MultiLineString in Shapely?

from shapely.geometry import MultiLineString coords = [((0, 0), (3, 3)), ((-1, 0), (1, 0))] lines = MultiLineString(coords) pt1 = lines.interpolate(1) pt2 = lines.interpolate(2) How would I find the distance, along the line, between these two…
Alex
  • 939
  • 15
  • 29
4
votes
2 answers

Clamp LineString to Polygon

I'm trying to constrain a LineString to a Polygon. Here's an example of what I'm looking for: In the left figure (the input), the green LineString travels beyond the border of the Polygon for a bit before returning and continuing inside. In the…
Lexelby
  • 81
  • 3
3
votes
0 answers

Split line at regular intervals in shapely

I have been trying to use Shapely to split a shapefile with multiple features at regular intervals. I have used the split function to do this. I can easily create the points at which the lines should be split, but when I then split nothing…
2
votes
1 answer

Dragging a polygon in shapely

If I have a polygon and I translate it in a direction n to a new location, how can I create a new polygon formed by the act of translation? To take a simple example consider the rectangle below with vertices a,b,c,d, being dragged in the…
NNN
  • 171
  • 7
2
votes
1 answer

Validity of LinearRing in shapely

Consider the following code: import numpy as np from shapely.geometry.polygon import LinearRing llpts = np.asarray([[18.5165 , 73.82883333], [18.51678333, 73.8279 ], [18.5156 , 73.82848333], [18.51586667, 73.82755 …
NNN
  • 171
  • 7
1
vote
0 answers

Install shapely from source using regular installs

I am trying to install shapely (2.0) from source with custom GEOS library. And I need to build from a local directory cloned from git. One aspect in the instructions that really confuses me is the use of "development mode" with pip install -e ... in…
tinlyx
  • 11,057
  • 18
  • 71
  • 119
1
vote
2 answers

Definition of multipolygon distance in Shapely

It is not clear to me from the Shapely documentation what is the precise definition of distance between two Multipolygons. I believe I read somewhere that the distance between two Polygons A and B is defined as the minimum distance from the boundary…
Chris
  • 171
  • 6
1
vote
1 answer

Merging a LineString with a MultiLineString

Is it possible to use shapely or some other python software to merge a LineString with a MultiLineString? Shapely's ops.linemerge fails here. I am attempting to merge segments of the same road, represented in different rows of the NYC streets…
zadrozny
  • 298
  • 1
  • 4
  • 14
1
vote
1 answer

Test if end of one line is contains in another line in shapely

I have two lines and I need to test that one line's endpoint lies on the interior of another line. I cannot figure out a way to do this, or my geometry is not correct somehow. I have tried using the spatial predicates directly on the lines, and also…
wfgeo
  • 3,538
  • 2
  • 24
  • 47
1
vote
1 answer

Apparent miscalculation of intersection area

I am trying to calculate the fraction of one area inside another. I confess to not understanding geopandas vs shapely shapes too well. But an example should show my confusion. My python calculation says that the area of intersection (bounded by red)…
Tom
  • 21
  • 2
1
vote
0 answers

Splitting polygons with multiple lines

I work in an Architecture Analytics firm where all our internal representation of floorplans is based on shapely. We have some open spaces (typically kitchen/living room, but also office space) that we need to split into different functional…
Ricardo
  • 141
  • 3
1
2