Questions tagged [shapely]
Shapely is an open source Python package for construction and analysis of 2D planar geometric objects common to geographic information systems.
953 questions
4
votes
2
answers
337
views
GeoPandas does not detect unclosed polygons as invalid, unlike OGR
With GDAL 3.12.0dev-c93ac7701e7c5b3b5537598f2dea1e8a382cc81a, released 2025/08/08 I can extract some invalid unclosed rings in a shapefile, but I cannot get GeoPandas to extract them.
In order to play ...
2
votes
1
answer
163
views
Is GeoPandas is_valid_reason method the same as shapely explain_validity?
I've come across both geopandas.GeoSeries.is_valid_reason and shapely.validation.explain_validity, and I'm wondering if they are the same (i.e. if the same checks / the same code is executed under the ...
2
votes
1
answer
237
views
Efficiently remove holes from complex polygons while preserving geometry
Problem
I have a polygon dataset containing many features with holes of various sizes. For my downstream modeling workflow, I need polygons without any holes. The challenge is to remove these holes ...
1
vote
0
answers
81
views
Need suggestions for speeding up spatial filtering in GeoPandas over large AOI
I have a script that performs post-processing on a large AOI by filtering shapefiles of points, lines, and polygons using buffers and area thresholds. While the logic works fine, the execution time is ...
1
vote
1
answer
148
views
Connect point to closest line and split line at connection point
I am working in python using geopandas and shapley.
Conceptual Description: I have a shapefile of points and a shapefile of lines, in my case a road network. For each point, I would like to identify ...
3
votes
2
answers
234
views
Which Shapely / GeoPandas function to use to merge non end-to-end touching LineString geometries
I have a dataframe of linestring geometries and would like to merge all the linestrings that touch and intersect into a clusters of unified geometries, with all isolated lines remaining the same.
To ...
0
votes
1
answer
166
views
Automatically convert shapefile to DWG via QGIS Python
I have written a small Python script that takes a KMZ line and creates a region boundary. This region is then used to import shapefile data that falls within the created boundary. I want to then ...
0
votes
1
answer
119
views
Why is my output is in Series after creating LineStrings from grouped ID?
I want to group the points by userid then create a LineString for each userid. Here's the GeoDataframe:
My goal is to store the results in a Geodataframe. Here's the code which I actually obtained ...
1
vote
1
answer
125
views
Get the 3D centroid of a GeoDataFrame
I have a 3D GeoDataFrame (GeoPandas 1.0.1) that I'd like to extract the 3D centroid from.
Currently, this is not working because it drops the 3rd dimension:
from shapely.geometry import Point
import ...
0
votes
1
answer
45
views
Using the affinity module with a vector of transformations
I need to transform a GeoSeries with another vector of transformation of the same length.
For example I can do the following:
before = gdp.GeoSeries([box(0, 0, 1, 1), box(10, 10, 11, 11)])
after = ...
2
votes
0
answers
48
views
Checking for self-intersection in Shapely MultiPolygon [duplicate]
I have a MultiPolygon in Shapely which potentially might have millions of Polygons. I need to find out if such a MultiPolygon has any self-intersection - I don't need to find the intersection itself, ...
2
votes
1
answer
204
views
Merging collinear sides (a.k.a. deleting collinear vertices) of a Polygon or LinearRing in Shapely
If two Polygons have partly overlapping sides, a union of these Polygons is a Polygon with collinear sides/vertices. Is there a method to merge those sides by deleting the middle vertex? I thought ...
2
votes
2
answers
470
views
Multilinestrings to Linestring using Python
I have a geodataframe (download link) that contains the geometry of bus lines. It is a Multilinestring. I need to transform the geometry into a single Linestring.
My first idea was to use .explode (...
6
votes
1
answer
176
views
Add extra vertices on LineString where they cross Polygon edges
I have two GeoPandas GeoDataFrames; one containing Polygons, and the other LineStrings:
Corresponding sample data:
import geopandas as gpd
from shapely.geometry import Polygon, LineString
gdf1 = gpd....
1
vote
1
answer
56
views
Buffer function and Projection [closed]
I've got a geopandas (EPSG:4326) that when I plot, this is the result (a road intersection):
What I'm trying to achieve is to "trim" these geometries around the center of the intersection. ...