# Questions tagged [shapely]

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

818 questions
Filter by
Sorted by
Tagged with
35 views

### Find points which fall within specified distance to POI using Python

I have created a test shapefile containing 15 point features in EPSG:2157 and exported it geojson. Each point has been assigned an ID - e.g. 1, 2 ,3 , etc. They look like so: I now want to use ...
1 vote
51 views

### Finding distance between points using Python

I have a shapefile containing 10 test points like so: The spatial reference is 2157 - Irish Transverse Mercator I am wanting to find the distance between each point in Python. Ideally, something like ...
29 views

### Get part of LineString with specific distance from starting point

I have a LineString AB and a Point C which lies on the LineString AB. I need measure out specific distance (say, 10 meters) along LineString AB either side of the point C and get resulting LineString ...
28 views

### Polygon cordinates to array

I have an array of Polygons where each object looks like this {'type': 'Polygon', 'coordinates': (((-98.03706782884247, 44.72279408402323), (-98.03706782884247, 44.71524098343729), (-98.02951472825653,...
• 123
47 views

### shapely 2.0 warning Convert the '.coords' to a NumPy array instead related to appending pandas with dictionary

In my code I append a single row to a geopandas dataframe as a dictionary. Although the code works, it prints this warning message below related to the future shapely 2.0 upgrade (https://shapely....
39 views

### Generate random polygons within another polygon using shapely in python

I have a use case where given a polygon on the US map, I need to generate n rectangles within the polygon defined on the US map. I have been trying stuff with shapely, but stuck. So the code would ...
• 123
36 views

### Iterating over each pair of coordinates in Multipart geometry using Shapely

This question is related to Access each (x, y) within Multipart gdf.geometry.interiors. With a MultiPart geometry.interiors: from shapely.geometry import Polygon exterior = [(2, 8), (7, 8), (7, 3), (...
• 123
1 vote
30 views

### Calculating the joint area of two circles centered by two coordinates with 1 kilometer radius

The coordinates are (116.437017,39.91525) and (116.437591,39.91548) for example in Gaode Map (https://lbs.amap.com/tools/picker). I want to draw two circles using Point(lon, lat).buffer() in shapely ...
1 vote
26 views

### GeoPandas geoseries area function - units?

I have a GeoPandas DataFrame. I apply a couple of functions to the GeoDataFrame. Buffer - https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.buffer.html This creates a set of ...
• 345
28 views

### 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 ...
• 3,278
28 views

### Receiving Infinity in LineString using shapely and pyproj

I am try get linestring so I can measure the distance and time. Here in this linestring I am getting nan distance and time. data: path = [[29.87819, 121.54944999999998], [24.23111845, 119....
50 views

### How to smooth the Linestring after adding additional point?

Actually I am tracking vessel, where I am already having path, and current position. Now the trouble is, obviously the vessel will not be on same coordinates as provided in the path.So I want to ...
61 views

### Clip lower value polygons with larger value polygons in shapefile

I have a dataset of circular polygons that correspond to tree crowns. Many polygons overlap with each other, and some are even completely covered by larger polygons (or larger polygons covered by many ...
• 50
1 vote
68 views

### Holes closing near extent boarder

I have a shapefile that looks like this: the yellow polygone is a sqare of full extent size (not separate polygons) with class 0. Polygons of other colors have another classes (1, 2). If to look ...
24 views

### Finding Maximal lines from multiple parallel lines

I have a lot of parallel lines in a list, and I am looking for a way to get the maximal lines that include individual lines. For example, let's say I have 10 lines. l1 = LineString(((0, 0), (8, 8))) ...
• 101
16 views

### ST_AsRaster equivalent function in Python

I have a table in PostgreSQL such as the one below. fid name rating geometry osgb43210 Smith Street 1 POLYGON ((507300.52 428808.91, 507299.2 428814.15, 507298.48 428813.98, 507299.37 428808.68, ...
• 37
1 vote
18 views

### Nonuniform scaling during point registration

I am using shapely and would like to register between 2D rectangles. Specifically, I would like to find the match between "L"s of triangles (three consecutive points mapped to three ...
• 111
1 vote
176 views

### Shapely intersection between LineString and multiple Polygons

I am trying to get a function to return True when a LineString intersects with any polygon in a list of polygons. Currently, I am using a for loop to iterate through all the polygons and check one by ...
142 views

### "Has no attribute geometry" error when creating polygon with Shapely

In Shapely I am getting an error: "has no attribute geometry" when I try to create a Polygon from a list with QgsPoint: from shapely.geometry import Polygon points = [<QgsPoint: PointZ ...
• 79
1 vote
44 views

### Finding intersection between polygons in one shapefile using Shapely

I'm trying to repair invalid geometries in my shapefile. Before using object.buffer(0) method to repair them I need to extract geometries that intersect in-between with their whole surface cause I ...
• 33
233 views

### Using Shapely methods (explain_validity and make_valid) on shapefile

I'm trying to find and repair invalidity in my polygons. I have already found out that 10 polygons have self-intersection problems in QGIS, trying the same thing with shapely. This is my code: import ...
• 33
1 vote
93 views

### Measure distance between points in python

I am trying to determine a rough distance between points in my shapefile. The shapefile I am working with has 28 million points in the structure x y z. I am hoping to find the most common distance ...
1 vote
48 views

### Equivalent of PostGIS ST_LineSubstring in Python: GeoPandas/shapely or any alternatives [closed]

I have a table in a db where I'm running some spatial queries but would like to move this to Python using GeoPandas, shapely etc. Example: ST_LineSubstring(geom, 0.005, 0.995) Which Computes the ...
• 37
1 vote
63 views

### How to write Shapely polygons (or a multipolygon) to a PostGIS polyhedralsurface

Context In a Python script, I have a 3D square pyramid composed of 4 triangles (a list of 4 Shapely 3D polygons) that I need to store within a PostgreSQL database (+PostGIS). Here's what this pyramid ...
• 6,748
87 views

### Constructing shapely Points from pandas series

I am new to geospatial analysis including geopandas and shapely. My requirement is to do a point in a polygon operation using a spark dataframe and pandas UDF (for performance reasons). The spark ...
1 vote
107 views

### Shapely split() function return the line to split

Probably the problem is related to floating point, but I need to find a solution and I'm running out of ideas. from matplotlib import pyplot as plt from shapely.ops import nearest_points line = wkt....
51 views

### 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 ...
• 31
1 vote
187 views

### Creating buffer spaces in meters around LineString line in KML using Python

Any suggestions to create buffer spaces on KML LineString using Python? I tried with few libraries.. geojson shapely kml2geojson Here, converted KML to GeoJSON and added buffer space on the ...
37 views

### What projection to use for checking how near a point is to a polygon?

I'm using Shapely to do some GIS analysis in Python. I have a Polygon and a Point, both in EPSG 3857 (web Mercator). I want to check whether the point is within a given distance (in metres) of the ...
• 171
133 views

### Converting dataframe with WKT column to spatial dataframe in ArcGIS API for Python

I am querying a data set from an Oracle spatial server with the geometry field in a WKT format, and I am running into issues trying to convert it to a spatial dataframe using the ArcGIS API. Going ...
1 vote
146 views

### Exploding LineString into segments using Shapely

I am trying to find explode lines tool in QGIS equivalent in shapely or geopandas (which uses shapely anyway). does anyone know this? note that geopandas.GeoDataFrame.explode() does not work because ...
• 680
1 vote
105 views

### Minimum distance between Point and LineString

I'm experimenting a different solution to find a point on a line that identify a minimum distance between the line and another point not on the line. I have a point and a line: p_not_on_linestring = ...
1 vote
79 views

### Incorrect plotting of point and line

I'm learning how I can plot shapely's geometries with matplotlib. I have the point and line below: point = Point(-170.212027219433033, 80.62335710279816) linestring = LineString([(-0.446866298572111, -...
1 vote
64 views

### Creating a Polygon, with a hole, in Shapely

So I have two polygons: (i) An outer polygon, and (ii) an inner Polygon representing the 'hole'. I'm trying to merge these two to give a single Polygon, with the hole. For easy illustration, the outer ...
1 vote
53 views

### A faster way to extract geometry xy of geodataframe

I need a faster way to extract geometry xy of a large dataset which is in a geodataframe format. I have developed a lambda function as below to do that but I need a faster way. The following is a ...
• 111
92 views

### Splitting line on intersection to another line using Shapely

I'm finding a solution for split a LineString on intersection to another LineString. My first solution is: from shapely import wkt from shapely.ops import split first_line = wkt.loads('LINESTRING (28....
87 views

### Find minimum distance to US coastline in Python

I have the following code in Python: import geopandas as gpd world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')) us = world[world['name']=='United States of America'].dissolve(by='...
• 123
145 views

### Check if geometry field in GeoPandas geodataframe have any row with specific type

This question is related to: Filtering by geometry type in GeoPandas I need to check if my geodataframe contains 'MultiPolygon' type. Below is my attempt, but it doesn't work. According to ...
• 105
167 views

### Converting a WKT column to type Geom

I have the following table in my MariaDB database: This table contains a column called 'coordinates' (type: LONGTEXT) with a wkt representation of either a MultiPolygon or a Polygon. I am attempting ...
159 views

### Snap points to polygon/lines in python shapely?

I have a shapefile of point features And a shapefile of polygons features I would like to snap these points to the polygons, as they are often just outside the polygons and cannot be spatially ...
• 439
1 vote
48 views

### Splitting many polygons by many lines

I have many polygons that need to be cut by lines we have set up to split those polygons. Some polygons may not have any lines to split them, others will have only 1 line, while others may have ...
• 135
1 vote
164 views

### Project a shapely geometry over a linestring

I'm looking for the most exact way to project a shapely polygon over a line. I assume that any projected point of the polygon is inside the linestring. My first idea is to densify the boundary of the ...
• 1,892
147 views

### How to determine the order of shapely's intersection function between two LineStrings

I want to find all the Point intersections between two shapely LineStrings. It is possible that there are multiple intersections and hence the output can be a MultiPoint. How do I know that the output ...
• 311
1 vote
94 views

### Compute the distance from a point to polygon given the point and direction

I want to compute the distance from a point to a polygon given the point and direction. Currently I am using shapely and defining a "somewhat" infinite line string. This is not ideal as I ...
• 311
359 views

### Error converting geometry column from string type - GeoPandas

I have a pandas DataFrame with geometry column with Polygons. I am trying to convert it to a geopandas dataframe and need to change the column type of geometry from string. I get this error when ...
• 345
201 views

### Creating geometry from GeoJSON but received empty result

Below is my function, the idea is to read a polygon shapefile, and generate some random points (get their coordinates) within each of the polygon feature in the shapefile. from shapely.geometry import ...
63 views

### Writing a dataframe, with shapely object, to database

I find such limited resources for my problems and have looked for a similar problem online, but didn't have any luck. I have the following Pandas, not geopandas, dataframe: RecAreaName ...
218 views

### Filling gaps within a multipolygon using Python

I would like to know how can I fill the gaps within a multipolygon. The convex hull isn't the proper solution, since they change the geometry completely. I have attached a sample figure of such a ...
• 315