# Questions tagged [shapely]

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

943 questions
Filter by
Sorted by
Tagged with
22 views

### Generalize/Denoise Multipolygons

I am looking for any Python function, that is able to denoise the area to become more spatially homogenous. In other words, I would like to vanish all small polygons beyond some tolerance. Maybe ...
• 293
57 views

### Buffer without overlaps in Python

I have a set of points with respective lat/long coordinates and each point has a given value associated with it (basically a field measurement). I would like to draw buffers of a given radius around ...
57 views

### AttributeError: 'GeoSeries' object has no attribute 'is_valid_reason' in GeoPandas

I was going over the documentation for checking on valid geometries. When I wanted to try the example for is_valid_reason, got this error: import geopandas as gpd from shapely.geometry import Polygon ...
• 826
109 views

### Detecting actual CRS when coordinate in WGS84 is known

My geodataframe includes some points of unknown coordinate reference system, each point has address as well, so I am able to find coordinates for them in WGS84. An example point is: POINT (472593....
• 21
35 views

### Finding which element of shapely geometry satisfies a predicate

I'm looking for an element of a geometry, which satisfies a predicate, e.g. intersection. Here is a code snippet: from shapely import * p0 = Polygon([(0, 0), (0, 4), (4, 4), (4, 0), (0, 0)]) p1 = ...
• 101
43 views

### Getting aspect-ratio of shapely rectangle

This snippet calculates an aspect ratio of a rectangle not constrained to be parallel to the coordinate axes: from shapely import * rect = oriented_envelope(LineString([(1, 1), (5, 1), (10, 10)])) p0 ...
• 101
116 views

### Algorithm for point to polygon distance calculations in shapely

I want to calculate the distance from a point to a polygon. If I run point.distance(polygon) Will it: Search the points that compose the exterior boundary of the polygon, select the closest point ...
75 views

### Identify outer wall of the floorplan or building [closed]

For the floor plan of the building with 2 rooms (it can have more as well) Is there Python or Java library which I can use to identify outer-wall (facade) of the building as polygon (a closed shape ...
• 111
42 views

### Read binary bytes object from Shapely to_wkb into QGIS

I've a typical case of data exported using shapely to_wkb with hex=False option. screenshot of data as shown in WKBgeom below (without SRID here). I am trying to load the data into QGIS via a virtual ...
1 vote
92 views

### Merge partially overlapping line geometries into a single line feature with QGIS, pyqgis, geopandas, shapely

I have a geopackage file with multiline features. The features are extractions from the same line geometries. Some of those extracted lines do overlap, so they partially share the same geometry. Some ...
• 1,753
43 views

### shapely.nearest_points wrong result: floating point error?

I am loading a .shp file through GeoPandas that consists of several LineStrings that should be united, but they are not. So I would like to unite them. I am using shapely.nearest_points and creating a ...
56 views

### Finding nearest points on MultiLinestring to specific points

I have a simple MultiLinestring and example points as follows: from shapely.geometry import Point, MultiLineString my_route = MultiLineString([ [(24.142982, 54.329322), (24.142753, 54.328542)], ...
• 21
32 views

### LineString length obtained from shapely differs from actual real distance [duplicate]

I want to obtain the points of a LineString that are at a distance of 25m from the first point and from the last one of said LineString. I was doing some tests to check whether or not Shapely could be ...
• 11
1 vote
85 views

### Intersecting a circle and a geodataframe

I have created a circle which I am trying to intersect with a geodataframe as follows: circle_gdf=gpd.GeoDataFrame(geometry= [circle]) joinCircle = gpd.sjoin(left_df=circle_gdf, right_df=transactions,...
• 485
162 views

### Shapely intersection cuts LineString into MultiLineString instead of LineString

I ran into a problem where shapely.intersection cuts a LineString into a MultiLinestring with lots of short lines instead of a simple LineString. The intersection is made between a circle (Polygon) ...
• 83
122 views

### Interpolate intermediate sections

I have a geodataframe with lines. I would like to create intermediate lines between two consecutive lines at a maximum distance of 1 meter For example in the image, I have the red lines and I would ...
• 317
376 views

### Rotate a polygon bounding box

I would like to rotate a bounding box given a particular angle. Here is what i get : In this example the rotated bounding box does not contain the AOI blue polygon which is an issue for me. The green ...
1 vote
65 views

### Shapely: self intersecting buffer area [closed]

In shapely I want to draw a movement profile of a person. While the person moves through the area, it "discovers" its environment step by step. I use a buffer to model this in shapely. So ...
• 203
117 views

### Checking that lines lay on polygon boundaries using PyQGIS

I have a polygon layer with one polygon and a line layer with a lot of lines. I need to check lines lie on the polygon boundaries or not and if they are add them into a graph. I couldn't think of ...
• 53
1 vote
763 views

### Is there a way to slice a polygon using shapely?

I have a geodataframe as follows: Here is the layer: # adjust the CRS gdf= gdf.to_crs({'init': 'epsg:26191'}) # compute the area in km2 gdf["area_km2"] = gdf['geometry'].area/ 10**6 I ...
• 485
598 views

### Labelling a Map

I have a map I have made using python, matplotlib, cartopy and shapely. It has a coast, county borders, lakes and rivers. I also shade in districts, in the form of polygons, on the map in order to ...
• 77
1 vote
39 views

### Displaying name of point with shapely [closed]

I want to display the names of points on my polygon with shapely. Polygon([(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)]) and Names = [A, B, C, D, A] How can I do it simply?
• 11
289 views

### Shapely "TypeError: 'LineString' object is not iterable" when creating polygon with interior ring that touches the exterior ring

I am using shapely Python package in order to create polygon from several connected lines. My code worked with a simple polygon, but failed when the polygon to be created had interior ring that ...
• 351
65 views

### unary_union() resulting in unexpected internal edges

I'm joining several together several geographic areas from a geojson file and am being left with unexpected internal edges. import geopandas as gpd from shapely.ops import unary_union utlas = gpd....
• 123
80 views

### Find the closest distance between points following a set of LineStrings

I have two datasets of Point coordinates (representing electrical installations) and would like to find the closest match between the two datasets following a given set of LineStrings (representing ...
• 101
1 vote
87 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 ...
• 61
31 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
45 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 ...
• 343
97 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. ...
121 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 ...
• 453
1 vote
269 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 ...
• 453
1 vote
619 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 ...
• 187
211 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
242 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="...
101 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 ...
• 21
51 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 ...
• 31
150 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....
• 139
1 vote
195 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 ...
• 65
1 vote
139 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 ...
• 39
249 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 ...
• 31
149 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 ...
• 31
206 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
307 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?
283 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 ...
3k 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 ...
• 115
243 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 ...
204 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
273 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 ...
• 11.1k
1 vote