1,196 questions
2
votes
2
answers
76
views
How to detect shared edges with Shapely
I have a group of triangles that will tile an area, one possible configuration is shown in the included image. I want to find out how many edges each triangle shares with adjacent triangles. So a ...
2
votes
1
answer
99
views
Locate where a map boundary is in the world with my created shapefile
I made a shapefile containing the boundaries of all the worlds countries and some of their regions (like the states in the US, Canadian provinces, etc). I've been trying to set a boundary box of my ...
Advice
0
votes
2
replies
63
views
How do I set the matplotlib co-ordinate system to SVG
A synopsis of my code.
import matplotlib.pyplot as plt
import shapely.plotting
from shapely.geometry import Polygon
facing = 'north'
shape = 'triangle'
polygon = Polygon(((1, 17), (9, 1), (17,...
Advice
3
votes
5
replies
177
views
Computing line intersection points on trapezoid-type grid
I need to compute ~2 million coordinates (64-bit float tuples)
They're the intersection points of lines that form a trapezoid-shaped grid (see visual below)
The shape of the trapezoid is different ...
Advice
2
votes
4
replies
171
views
Buffer a polyline by variable distance
I have a list of points (x,y) that constitute a polyline, each point also has a value (m).
I want a polygon which is the buffer of the polyline with variable distance m. So at each point, the polygon ...
-1
votes
1
answer
282
views
How to merge many nearly parallel line segments into a single density-weighted segment (Python/Shapely)?
I have a dataset of line segments derived from many GPS traces, where users have followed the same roads but their paths aren’t identical (think of thousands of cars driving along a road, each with ...
1
vote
1
answer
159
views
Can't convert geometry from back to WKT after exporting from MySQL
I have a MySQL table with a multipolygon column, which has OSM geometry for each country's territorial waters. This is exported (by AWS) to a parquet file every night, which I then download - but I ...
1
vote
1
answer
140
views
How to build a correct cartopy feature around the south pole?
I want to build a cartopy feature for Antartica in palaeo geography. I have the lon/lat of the coastline.
I cant find a way to have a nice plot in any projection.
Here is an example that plot a simple ...
0
votes
1
answer
98
views
Calculate overlap in cluster area between multiple clusters
I have a raster image. Using scipy, I am clustering pixels that belong to each peak in the histogram that corresponds to the values in the image. I am able to detect two clear peaks that are clearly ...
0
votes
1
answer
93
views
Converting user-drawn polygons on a Cartopy map to a binary mask in Python?
I'm trying to make a program using Tkinter, Cartopy and Matplotlib that would allow users to draw polygons on a map. Once the polygon is closed (right click), I want to convert it to a mask where ...
1
vote
1
answer
131
views
Star-center of a star convex shape
I'm working with 2D shapes represented by their boundary contours (as ordered x,y coordinates), and I want to check if a shape is star-convex. If it is, I'd like to find a star center — i.e., a point ...
0
votes
2
answers
183
views
Elegantly handling python type hint for Shapely polygon.exterior.coords
I'm using Python 3.12 and I would like to return polygon.exterior.coords as a type of list[tuple[float, float]] so that I can correctly enforce typing later in the program. I'm wondering if there is ...
8
votes
0
answers
268
views
Diagram of road intersection flows (Sankey or other)
I'm trying to make a road intersection flow diagram in Python. The problem is, that none of the Sankey-specific modules that I managed to find support setting coordinates of the nodes and rotation of ...
1
vote
1
answer
271
views
How can I fix Singular Matrix Warning when computing a concave hull with alphashape?
The actual warning printed is "WARNING:root:Singular matrix. Likely caused by all points lying in an N-1 space." This is a surprise to me, since my points clearly populate a 2D area and are ...
2
votes
2
answers
81
views
How to calculate distances within boundary of a polygon in geopandas?
I've got two geopandas geodataframes. One is a series of points of locations. Locations of bus stops, for example. Let's call it bus_stops
I've then got another geodataframe where geometry column is ...
2
votes
1
answer
189
views
Graph traversal algorithm using shapely geometry points
I am trying to create a path planning algorithm for a robotic mower to cut all the grass in a defined area while avoiding obstacles or restricted areas. I am using the Python Shapely library to define ...
0
votes
0
answers
207
views
Shapely intersection function not giving desired result
I am using python to work on polygons. I want to find intersection of two polygons and then find the intersection of the intersected polygon with two lines.the intersection of a polygon with a line ...
0
votes
2
answers
57
views
How can I find the following vertice in a shapely polygon in a specific direction from a calculated nearest_point?
I have a polygon "poly" and a point "A". With the nearest_point function I can calculate the nearest point "p1" on the polygon to the point "A". Now I would ...
0
votes
1
answer
95
views
Clearing a subplot to update with a new one
I have some radiobuttons to select colour and width of a linestring in an embedded plot. I can't get the plot to clear when I select a new colour or width and the new plot is placed below the original ...
1
vote
1
answer
96
views
Force direction of line vector
I have a line vector where each segment has a randomly assigned direction. The image shows an example (which consists of two connected lines),
How to set the direction of each line so that it is ...
2
votes
1
answer
235
views
Problems obtaining an intersected linestring using GeoPandas
I am having an issue obtaining a linestring from an intersection with a polygon using GeoPandas. The linestring is self-intersecting, which is what is causing my issues.
A line intersecting a polygon:
...
0
votes
1
answer
170
views
Create geojson polygon from point feature collection
I have this feature collection with a lot of points that form a shape:
I need to create a polygon feature collection with this shape, I tried using the shapely multipoint.convex_hull method but the ...
0
votes
1
answer
104
views
Overlapping Polygon in Latitude/Longitude Space
I have a set of longitudes and latitudes for which I need to create an enclosing Polygon. In some cases, these sets of points overlap and creating a Polygon has been giving me a lot of trouble. I have ...
0
votes
1
answer
75
views
Turning a grid map array into a shapely object
I have a (2000x2000) python array of 0's and 1's that represent whether a cell is free or not. I'd like to turn this dense representation into a shapely object.
For example, an array of the type:
0 0 ...
-1
votes
1
answer
264
views
Connect disjointed shapely multilinestring
In a shapely MultiLineString, I have LineStrings that may be disjointed. What is the best way of connecting it?
I have attached an image example, where I need the blue line to be connected to the ...
0
votes
2
answers
139
views
How to get original indicies of a polygon after applying shapely.simplify?
This Python script:
from shapely import simplify, points, contains, Point
circle = Point(0, 0).buffer(1.0, quad_segs=8).exterior
simple = simplify(circle, 0.1)
simplifies polygon circle (red) and ...
0
votes
1
answer
126
views
Which Shapely predicate should be used to distinquish between these LinearRings
In my project there are two use-cases. The red and blue shapes are not overlapping in the first case, but they do in the second.
case #1
case #2
In my test code I tried various predicates from ...
0
votes
1
answer
182
views
Shapely multilinestring: depth first search
I have a Shapely multiline string that has multiple branches that I want removed. I've attached an image where the red is the main line that I want to keep and the black are to be removed.
I can't ...
0
votes
1
answer
102
views
ST_Intersection behaviour
I have a linestring which traces part of it's path back over itself (a there and back trajectory). When I try to intersect this linestring with a polygon to try to get the distance travelled within ...
1
vote
3
answers
221
views
Efficiently Finding Nearest Non-Colliding Position for a Rectangle in 2D Space?
I’ve been struggling with a problem related to collision detection and positioning in a 2D space, and I could really use some guidance on achieving good performance.
I have a rectangular boundary (...
1
vote
1
answer
41
views
Incorrect leftover point when subtracting overlap between two polygons
I identify polygons that intersect, then compute their intersection and remove them from the first polygon. I get a weird left-over point. If I just take the difference between the polygons, this ...
0
votes
1
answer
53
views
Python Shapely - Selection of a given part of a Geopandas geometries
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. ...
2
votes
2
answers
416
views
How to calculate the center-line or baseline of a polygon
I work on a segmentation model for historical documents. My dataset has the text lines as polygons but for a usable model training I need also the center-lines or baselines of the polygons.
As an ...
2
votes
3
answers
664
views
Simplify Polygon shapefile to reduce file size in python
I have a polygon shapefile which was vectorized from a raster layer (second image). This shapefile contains thousands of features with just one column which represent polygon level (ranging 1-5). The ...
1
vote
0
answers
91
views
Python matplotlib offset
I'm trying to plot dxf file on matplotlib plot. Shape is drawn correctly but my offset unfortunately no.
This is my shape:
My shape
And code I wrote:
def draw_outside_offset(self, offset=6.0):
...
1
vote
0
answers
90
views
Calculate the polygon angle based on point inside?
I have one polygon and want to calculate the wind direction based on the long boundary and point inside. The point is the wind's starting point and the direction follows the long distance to the short ...
0
votes
1
answer
276
views
Is there a way to make a Shapely polygon compatible with BigQuery when an Invalid geography value error occurs
I have a geopandas file with one of the columns being a shapely polgyon. Here is what it looks like.
I tried to upload it to BiQuery using pandas_gbq.to_gbq(df,..., table_schema=[{'name': 'name', '...
0
votes
1
answer
220
views
TypeError: 'MultiPolygon' object is not iterable with Plotly Choropleth
I am trying to make a choropleth map from county level FIPS data using this example from plotly.
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
df_sample = pd.read_csv('...
-1
votes
1
answer
235
views
Is there a way to get a slice out of a shapely LineString?
I am interested in getting a LineString that is a cutout from an original Shapely LineString. Basically I want the geometry of the red line in the image which is between the two cyan points. I know ...
2
votes
3
answers
541
views
Iterate over Polygon vertices as Points with Shapely?
Shapely's Polygon and LinearRing are not iterable (any longer, if I remember the history correctly). I often need to iterate over their vertices as Point objects (not tuple), and my current solution ...
0
votes
1
answer
130
views
geopandas.explore plot the wrong cordinates
I've been working on a georeferenced data set using geopandas library, when I use gdf.plot() the figure I get is right,in the sense that latitude and longitude of the POINTS being ploted match the ...
0
votes
1
answer
62
views
Why invoking a python program in another python program will make aboriginal program slower?
In my tool hydrotopo, when I run find_edge_nodes to find topological relations for about 100,000 linestrings, it only costs about 10 seconds; but in code below, find_edge_nodes will cost about 30min:
#...
0
votes
1
answer
591
views
Reduce size of GeoJSON Multipolygon data
What I currently do:
Read .shp file using GeoPandas (Python), parse it to GeoJSON and write the data into MongoDB
(Create a 2D-Sphere Index on the collection for efficient querying.)
Query a subset ...
0
votes
4
answers
399
views
Calculating an average of multiple polygons
I would like to "average" several polygons having a substantial intersection, e.g. these three:
Preferably using a Python library, e.g. Shapely. I don't see a suitable function there, which ...
1
vote
0
answers
827
views
How to convert dwg file into shapefile using ezdxf, geopandas and shapely with no missing data
I am new to CAD and GIS and developing a functionality to convert dwg into shapefile using python libraries- ezdxf, geopandas and shapely. I am encountering issues during conversion, the code is ...
1
vote
1
answer
146
views
Polygons elongation ratio calculation with geopandas - problem with creating a geodataframe with results
I have a polygon shapefile (actually, there are 170 such files) and want to calculate the elongation ratio for each polygon. The elongation ratio is the ratio of the short to the long side of the ...
1
vote
2
answers
126
views
Shapely examples in the documentation not working
I am looking at the shapely documentation for transform with the following examples:
>>> from shapely import Point
>>> from shapely.ops import transform
>>> transform(Point(...
-2
votes
1
answer
186
views
Calculating shortest path between two points along a rail network
I would like to calculate the shortest path from mines to ports, along the rail network. Since the mines and ports are not directly on the network, I first worked out the nearest rail point for each ...
0
votes
0
answers
158
views
Monitor whether the planned route is being executed
I have a route that has several coordinates that would basically be point A to point B, point B to point C,..., until the route is completed. I receive coordinate data from a tracker on the route ...
-1
votes
2
answers
523
views
Straighten a Polygon into a line with Geopandas/Shapely
I'm using Python. geopandas and shapelly to process the geometries of a road intersection.
The geojson has a list of Polygons that I want to straighten into Lines, something like this:
Does anyone ...