Questions tagged [shapely]
Shapely is an open source Python package for construction and analysis of 2D planar geometric objects common to geographic information systems.
921
questions
1
vote
1
answer
29
views
Splitting a MultiLineString with Shapely Split preserving the original MultiLineString composition
I have a gdf with Streets. I want to split a street with other streets (left side: Split the brown line at intersection with the green line):
Whenever i split it (using shapely split()) I recieve all ...
0
votes
0
answers
22
views
Vectorised distance function for non-continuous lines
I have a function that works out the distance for two countries' shared border, it works fine for any border that is continuous, but (I think) it also adds up empty space between the end of one line ...
1
vote
0
answers
37
views
Implementing undershoot correction in GeoPandas
I am trying to implement an undershoot fixer using GeoPandas and Shapely like the solution from Snapping in Geopandas
My other thought is that it might reasonable to identify and extend the undershot ...
0
votes
0
answers
30
views
MySQL WKB geometry corrupted after QGIS manipulation - Unknown WKB type 535
I have a quite complex issue.
I have been using MySQL (MariaDB to be specific) for storing shapely geometries. All went well until the customer wanted to slightly change the position of one point.
...
0
votes
0
answers
44
views
Check for ESRI geometry validity using shapely or similar
I have a geopandas dataframe in Python. Is there a way to check geometry validity under the ESRI scheme as opposed to the OGC spec using shapely/geopandas/some hacky way, or am I constrained to using ...
0
votes
1
answer
76
views
Difference between "ESRI" and "OGC" validity
When I use the Check Geometry tool in ArcGIS Pro, it asks whether I want to validate using ESRI or OGC methods. What is the difference between these two methods?
edit
I originally asked a second ...
1
vote
1
answer
101
views
Validate GeoJSON geometries using geojson Python package via Fiona
I have an application that allows users to submit a shapefile or GeoJSON file. I would like to use Python to validate the files and geometries within them to make sure I process valid geoms. Im having ...
0
votes
2
answers
85
views
Determining minx/miny/maxx/maxy for shape from polygon in GeoJSON file
I have implemented the following code to search a GeoJSON file for a point (not asking for a code review or critique):
#!/usr/local/bin/python3.11
import os
import sys
import fiona
import shapely
def ...
1
vote
1
answer
86
views
Finding intersection of two geospatial vector data in shapefile format using Python and GeoPandas
I have two geospatial shapefiles.
1. The first one is a contour shapefile, generated via following code
rasterDs = gdal.Open('raster.tif')
rasterBand = rasterDs.GetRasterBand(1)
contourPath="...
0
votes
0
answers
70
views
Dissolve lines that intersect after attending some dataframe (atributte table) conditions
I need to dissolve all Linestrings from a geodataframe that intersects each other after attending some tabular conditions: 1)have the same ID and 2) have the same opening year.
I am working with ...
2
votes
2
answers
36
views
Find the length of linestring shared between polygons
I would like to find the common area between my polygons, in this example my polygons touch and share a line
df = GeoDataFrame.from_file('path')
df
...
0
votes
1
answer
62
views
How to visualize a list of coordinates in [x.y] format?
I have a JSON file with coordinates representing roads stored in a list of lists. The coordinates are stored as [longitude, latitude] in a key called path. Example:
[[14.322689, 51.178513],
[14....
1
vote
2
answers
79
views
Interpolated Point on Line is not actually on Line?
I am trying to debug a problem and am not sure if it is my code or if there's a bug with shapely.
I have two geodataframes: one with points and one with lines. For each point in the points ...
1
vote
1
answer
65
views
Incorrect geometry check from OGR and shapely
I have multipolygon and trying to check for validity. Both OGR(.IsValid()) and shapely (is_valid) return True. But if I open the same geometry with QGIS and check with theCheck Geometries plugin it ...
-1
votes
1
answer
116
views
Splitting polygon between its neighbor polygons with Voronoi algorithm using Python [closed]
I would like to split the area of my concerned polygon (the blue one in the middle) between his neighbors polygons and affect each splitted area to a neighbor
My data looks like:
affectid
t
geometry
...
-1
votes
1
answer
88
views
Matching correctly two same polygons that come from different shapefiles [closed]
I am trying to match two polygons that come from two different shapefiles, The one with the border (black line, MULTILINESTRING) and the one with blue color (multiple polygons) in the picture.
This ...
0
votes
1
answer
61
views
Generate lines from given azimuth and points in GeoPandas
I am reading a points shapefile containing the azimuth information in the attribute table, and I want to generate lines from these data. I have tried to use shapely.Point as a tool, however it can't ...
1
vote
1
answer
116
views
Create Polygon out of minX, minY, maxX, maxY
I have a pandas dataframe with the min and max values from two polygons. How can I create two geometries (Polygons) out of these values using Geopandas or Shapely?
0
votes
1
answer
147
views
Two shapely methods to test if a point is within a polygon are failing [closed]
I am iterating through the polygons in a Fiona collection and am not finding my point is within any of the polygons. I am using the shapefile from here. Can you see the problem?
[How can I ...
2
votes
2
answers
866
views
Change GeoPandas geometry from GeometryCollection to MultiPolygon
I have a GeoPandas dataframe where the features have a Geometry type of 'GeometryCollection'.
It looks like each feature is in fact just a simple polygon, so I'd like to convert the GeometryCollection ...
0
votes
0
answers
110
views
Exporting polygons from GeoPandas to GeoJSON - end point is not the starting point
I'm quite new to working with GeoPandas, and I try to export the file to GeoJSON, to later display it on a map using Google Maps Platform.
While GeoPandas Polygons do not have to end in the same point ...
2
votes
1
answer
145
views
Fast quasi-recursive polygon intersection algorithm?
I'm trying to make a map which is colored based on the distance to a target point. I've done this by creating a series of concentric rings.
These rings are created by buffering out from the target ...
1
vote
0
answers
151
views
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 ...
1
vote
1
answer
50
views
Does geopandas handle shapefiles (in lat/lon) that straddle the anti-meridian properly?
I have been looking for a way to check if a point lies within a shapefile. i had some code that worked for the most part (using shapely and fiona) but my understanding is that it will exhibit ...
0
votes
1
answer
61
views
How to know the origins of the result of shapely's symmetric_difference?
Suppose I have two line geometries:
import shapely
line1 = shapely.geometry.LineString([(0, 0), (2, 0)])
line2 = shapely.geometry.LineString([(1, 0), (3, 0)])
shapely.symmetric_difference(line1, ...
1
vote
1
answer
71
views
Controlling the grid_size in geopandas' symmetric_difference method
Operations in Shapely
Suppose I have these two line geometries:
import shapely
link_12 = shapely.wkb.loads(b"\x01\x02\x00\x00\x00$\x00\x00\x00\xcc\xd4\x02\x96q\xb9-A\x8a+\xd1)\xda\x801A\xb1\xf3\...
2
votes
1
answer
309
views
Python length of roads inside polygons
I have two datasets: one about each road in a country (and its linestring), and another one about the polygons of each region. I want to estimate the length of each road in the polygon that is ...
1
vote
3
answers
273
views
Isolating the intersecting polygon where all polygons intersect in Python with the shapely library
New to working with shapely and I'm trying to find the intersection of multiple polygons where all (or as many as possible) intersect at a single point to produce a single polygon as below:
The ...
0
votes
0
answers
44
views
Convert XYZ coordinates to coordinates along profile using arbitrary coordinates
This is a seismic-related question. I have the surface trace of a 2D seismic line as LineString (XYZ coordinates). In addition, I have the interpretation of a horizon as XYZ coordinates along the line ...
4
votes
1
answer
138
views
Custom Shapely Cap style
I am currently using shapely and geopandas to parse through a shapefile containing lines to build a rail network.
I am using shapely to create a buffer to identify sections of track that cannot be ...
3
votes
1
answer
245
views
How to extract polygon from multipolygon that has most positive point in Shapely?
I would like to select a polygon within a multipolygon, which has the highest x coordinate of all polygons in the multipolygon. What I was thinking about was the following:
Let's first create the ...
0
votes
0
answers
108
views
Routing from somewhere along an edge in osmnx
I have an osmnx network in Python that has long edges, and points along those edges that I'd like to route to and from. Routing based on the nearest node is a non-starter because the edges are long. ...
0
votes
2
answers
382
views
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 ...
1
vote
1
answer
135
views
Trying to find nearest point on a coastline (in Python), but projection is not working as I expect
I am trying to find the nearest point on a coastline, to a station. However, I cannot get the correct answer. Here is a minimal example with an artificial coast line: the west coast (w_coast) is ...
1
vote
0
answers
20
views
GeoPandas dissolve and explode returns original input [duplicate]
Tried to avoid posting this question, but I cannot seem to find my error.
I have a stream network shapefile that has segments that need to be dissolved to their respective segment.
Using QGIS I can ...
1
vote
1
answer
579
views
GeoPandas GeoDataFrame polygon geometry - calculate area
I have a geopandas GeoDataFrame with Polygon geometry and I am calculating the area of the polygon, however, I am not sure what the unit is for the area.
import geopandas as gpd
from shapely.geometry ...
1
vote
0
answers
49
views
Adding overlapping routes when there is no overlapping route using buffer and union
I am trying to do something to do with routes, Let's say I have 3 routes rt1 and rt2 are overlapping routes that share some length but r3 does not overlap with either of them. How would I just add the ...
0
votes
1
answer
91
views
Some of the total lengths are not adding up in linestring using shapely in python and geopandas
I am working with a gtfs file with shapely and shape id and I am trying to calculate the total unique length of the routes passing by a stop.
I have a list of routes that goes through the stop and I ...
1
vote
1
answer
467
views
How to find which Shapely Polygon contains an intersection?
Intersection between a line and a Polygon is not inside the Polygon(this). Polygon does not have any interiors. My intention is to find which Polygon contains the intersection, if there are multiple(...
1
vote
0
answers
65
views
QgsGeometry.fromWkt() seems weirdly slow compared to OSGeo/Shapely
wkt = 'LineString (64763.65372879413189366 5532941.864832429215312, 64811.82167246036988217 5533046.30194362625479698, 64827.02791490274103126 5533082.7359510725364089, 64833.97425112823839299 5533108....
2
votes
2
answers
257
views
How to extract geometries with M-values from a feature layer in Python?
Problem statement
I am aware that geopandas (due to the limitations of shapely and pygeos) does not read geometries with M-values - when reading a layer that has them, geopandas now just drops those ...
0
votes
1
answer
549
views
Limiting Voronoi polygons from shapely.voronoi_polygons to a shape with extend_to
I'm trying to get some voronoi polygons from a set of coordinates distributed within a country, I don't need said polygons to extend out of the country, I tried using extend_to from voronoi_polygons ...
1
vote
1
answer
138
views
Adding names or labels to the Voronoi polygons obtained from shapely.voronoi_polygons
I currently have a dataset in CSV format with around a thousand points, each has a name, latitude and longitude, I'm using those make some Voronoi polygons which in turn I'll later plot on a folium ...
1
vote
0
answers
49
views
Mapping self-intersections of a transformed LineString
I’m using shapely to solve a problem in physic. My problem can be represented in 2D with a LineString. In order to solve my problem I need to :
Apply a transformation to the original LineString
Find ...
4
votes
1
answer
178
views
How to join geodataframe itself
My goal is to calculate the distance from a point and the nearest point, so I thought of using geopandas function sjoin_nearest. Using this function I get all the distances to zero, which is quite ...
3
votes
1
answer
404
views
Using shapely unary_union() function to union polylines in ArcGIS Pro not behaving
I am developing an ArcGIS Pro 3.1.0 toolbox (atbx) and one of the tools I'm creating is selecting a set of polylines (which are river centrelines) and merging them into a single long polyline. ...
0
votes
3
answers
373
views
Buffer and separate two polygons from upper and lower buffer line using shapely or geopandas
I want to create a buffer (20km) from a line, and then separate them into two polygons with the line is boundary between two polygons (picture demo below. The desired output would be two polygons such ...
7
votes
1
answer
2k
views
Error of MultiLineString object is not iterable
Simply I just want to convert a MultiLineString data to a list but get the error:
TypeError: 'MultiLineString' object is not iterable"
from shapely.geometry import MultiLineString
coords = [((0....
0
votes
0
answers
118
views
Shapely problems within conda environment
I was, so far, using Shapely to work with polygon data to "filter" some point within the polygon. I have tried to define a polygon like this.
from shapely.geometry import Point, Polygon
...
4
votes
1
answer
122
views
Computing parallel polygons based on given perpendicular distance in GeoPandas
Say I have a GeoPandas GeoDataFrame of polygons (i.e. the "geometry" column contains polygons of GPS coordinates only).
import geopandas as gpd
from shapely.geometry import Polygon
...