Skip to main content

All Questions

Filter by
Sorted by
Tagged with
2 votes
1 answer
116 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 (...
Daniel AG's user avatar
  • 117
0 votes
2 answers
302 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) ...
Andreas's user avatar
  • 83
2 votes
1 answer
538 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 ...
MG Fern's user avatar
  • 23
1 vote
0 answers
73 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 ...
OwO's user avatar
  • 13
1 vote
0 answers
73 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 ...
lamilam's user avatar
  • 11
3 votes
1 answer
610 views

Getting the polygons contained in closed MultiLinestring using Python

Given a set of "streets", how can I get the "blocks" contained in those streets? For example, I'd like to extract four blocks / polygons from this 2 x 2 "checkerboard": ...
zadrozny's user avatar
  • 318
0 votes
1 answer
2k views

Shapely Split a LineString based on Intersections with other LineStrings

I'm new to using Shapely, and I have some question. I have a LineString and I wish to split it based on intersections of other LineStrings. If the intersection turns out to be a single point, then we ...
M. Fire's user avatar
  • 31
1 vote
1 answer
129 views

How to split up Linestrings based on type and connectivity using Python? [closed]

I am working with a road network, where I extracted only the three main road types. In the next step, I would like to union all Linestrings based on their road type and connectivity. That means that I ...
Danny's user avatar
  • 35
1 vote
1 answer
535 views

Splitting multiple Linestrings into 1 metre parts with GeoPandas shapely

I have a GeoPandas dataframe which contains many rows and also a column named 'geometry' with the following input: geometry LINESTRING (445125.050522556 5536587.67127983, 445124.450035... I ...
coder338's user avatar
2 votes
2 answers
1k views

Merging LineString with MultiLineString with Python

Is it possible to use shapely or some other Python software to merge a LineString with a MultiLineString? Shapely's ops.linemerge fails here. I am attempting to merge segments of the same road, ...
zadrozny's user avatar
  • 318
0 votes
0 answers
300 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 ...
Rajan's user avatar
  • 101
2 votes
0 answers
2k 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 ...
sopafria554's user avatar
5 votes
2 answers
2k 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 ...
sutan's user avatar
  • 969
2 votes
1 answer
922 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....
MaxDragonheart's user avatar
-1 votes
2 answers
5k views

Finding distance from Point to LineString in meters using Python [closed]

I have tried this following method to find distance but it is giving me distance like 0.12. I don't know what that 0.12 is meant and I want the distance to be in meters or kilometers. line.distance(...
Venkatesh Telu's user avatar
2 votes
1 answer
6k views

ImportError when importing Linestring from shapely.geometry [closed]

With this code I tried to import shapely.geometry: import shapely as shp import geopandas as gpd from shapely.geometry import Polygon, Linestring However, I faced the following error: ImportError: ...
yasser abd's user avatar
3 votes
2 answers
3k views

Is there a way to "sort" points in a MultiLineString such that they seem more like a continuous LineString?

Is there a way to "sort" the points of a MultiLineString such that they follow a more sequential order? Let me illustrate what I mean with a graphical example: Input Suppose I have the ...
Felipe D.'s user avatar
  • 2,749
4 votes
1 answer
3k views

Get the outer shape of a MultiLineString

i have a bunch of shapely MultiLineStrings, which I would like to "convert" to Polygons so that the "outer" boundaries of the MultiLineStrings serve as edges. One of my ...
Ben's user avatar
  • 203
0 votes
1 answer
483 views

GeoPandas: Error plotting after clipping shapefile

I am interested in plotting data on the city of Göteborg (in English Gothenburg, Sweden). I am starting with shapefiles of Sweden and then clipping them to concentrate my study in Göteborg. # ...
Joehat's user avatar
  • 285
1 vote
1 answer
206 views

Delete polygons that have one or more side parts in common [closed]

I am trying to solve a particular case of comparison of polygons to others. I have five polygons distributed as in the figure below. The black polygon is the one with the largest area. There may be ...
Steve's user avatar
  • 19
2 votes
0 answers
667 views

Create MultiLineStrings segments between points with Python Shapely

I have a layer of LineString and MultiLineString geometries. I'm trying to create a single geometry of the LineStrings split by certain snapped points. This is an illustration of the current data that ...
user8675309's user avatar
0 votes
0 answers
390 views

Extrapolating arc via Python function

I am looking for a Python code/function that can extend an arc linestring up to a pre-defined length while maintaining the same arc of the original line. The idea is to repeat the configuration of the ...
Julianno Sambatti's user avatar
1 vote
3 answers
2k views

Python Create Dictionary with Shapely Points from Linestring coordinates

I have a Geodataframe with Linestring Z geometries as follows: id_line geometry 1 LINESTRING Z (0 0 0, 5 6 9, 1 2 3, ...) 2 LINESTRING Z (7 8 9, 9 8 7, 1 2 5, ...) each of the Linestring is made ...
MigueL's user avatar
  • 113
3 votes
1 answer
1k views

Shapely strange splits when splitting LineString and Polygon

I noticed a strange behavior while splitting a LineString with e Polygon: in the below image I have a Polygon (in green) and two lines. If I split the blue Linestring with the polygon the result of ...
Domenico V.'s user avatar
2 votes
0 answers
674 views

How to merge lines from shapefile using PyShp and Shapely and save them in a new shapefile?

I have files with line segments that cover road network of towns. The issue is that each street with specific name consists of smaller segments that I need to merge into one line covering the whole ...
krltos's user avatar
  • 223
3 votes
1 answer
670 views

Can't Form DataFrame from Parallel Offset Output

I've been developing code to take a .csv with lat-long coords and convert them to LineStrings before creating parallel offsets for them. This has been working so far, but yesterday after clearing my ...
vbray6's user avatar
  • 31
2 votes
2 answers
1k views

Shapely command error: from shapely.geometry import LineString

I am trying to run a program but getting the following error when I am using the command: from shapely.geometry import LineString Error: FileNotFoundError: Could not find module 'C:\Users\SWWB\...
Aizaz's user avatar
  • 21
0 votes
1 answer
6k views

Calculating distance between two Linestring using Python

I have two linestring, each linestring represents a rail road. I am trying to calculate minimum distance between these two linestrings. Which function is efficient to do this? I have only come across ...
Suchithra's user avatar
2 votes
1 answer
445 views

How to add intersection vertices to a ShapelyLinestring?

Assume that I have two shapely LineStrings. I want to find their intersection and then add the intersection point as vertices into the respective LineStrings. from shapely.geometry import LineString #...
J.Galt's user avatar
  • 129
2 votes
1 answer
6k views

Pandas dataframe to Shapely LineString using GroupBy & SortBy

I have a pandas dataframe that contains information to construct (poly)lines, and I want to use shapely & geopandas tools to make a SHP. In the example below, I have 3 lines differentiated by &...
a11's user avatar
  • 950
1 vote
0 answers
365 views

Points within "normal bounds" of a linestring in Python

I am working in Python (using Shapely). I have a list of Point(s) (the small circles in the image) and a LineString (the solid line with an arrow). I want to select only the points which are within ...
Sourav Kumar Agarwal's user avatar
3 votes
1 answer
2k views

How to find and remove invalid geometry in a multilinestring python geodataframe?

I have original data as a 700000's rows excel, with geometry data in hexwkb format. I want to plot it and make some spatial operations on it like intersect, distance and buffer, on a jupyter notebook. ...
danalif's user avatar
  • 171
2 votes
0 answers
839 views

Failure to write LineString record to shapefile

I have some coordinates from which I am creating a shapefile. tafo_boundary_coords = [(652316, 742792), (652161, 742920), (651897, 743166), (652210, 743477), (652298, 743448),(652375, 743458), (...
Slwd-wave540's user avatar
3 votes
1 answer
2k views

Adding points every X distance along a LineString [closed]

I have a list of LineString coords: list = [(90, 170), (99.0, 159.0), (321.0, 159.0), (300, 146), (296, 23)] which looks like this. How to interpolate a point at every X distance along the line ...
smc's user avatar
  • 215
3 votes
1 answer
2k views

Creating LineString from CSV with lat/lon coordinates of beginning and ending points

I am iterating through a CSV file of tornadoes, and for each row getting the beginning lat, beginning long, ending lat, and ending long. And I am trying to plot their line geometry on a map. I got the ...
Bryon Betts's user avatar
1 vote
0 answers
458 views

Cluster LineStrings using HDBSCAN?

I am trying to cluster a set of LineStrings (made out of lat/lon Points) with the help of HDBSCAN (using the "haversine" metric). The objective is to define the most "usual" path. I have only managed ...
Stav's user avatar
  • 31
3 votes
2 answers
2k views

Shapely floating problems with split()

Based on the answer of sgillies I want to use Shapely's interpolate() to find the points at which to split. But I experience that split() is sensitive to the points being precisely on the geometry you ...
Joost Döbken's user avatar
1 vote
1 answer
2k views

Shapely and lines intersection

Is there a way in Shapely to calculate intersections of geometries with some tolerance? Imagine we have lines that are the same, but their coordinates are written with different precision. ...
culebrón's user avatar
  • 2,344
2 votes
1 answer
696 views

Sliding box on Area Python Shapely

I have a huge area of linestrings and I want to get the features of each portion of area. All the linestring parts are stored in a python list and they are not in order. One portion of area is shown ...
mimetype's user avatar
  • 225
3 votes
1 answer
5k views

returning a LineString on selecting its midpoint

I have a list of shapely LineString, [<shapely.geometry.linestring.LineString object at 0x000001614D750CC0>, <shapely.geometry.linestring.LineString object at 0x000001614D750D68>, <...
FJ_Abbasi's user avatar
  • 611
5 votes
1 answer
8k views

Shapely multiline string to shapefile as single line

I am using shapely unary_union to dissolve multiple line strings to one line before exporting to a shapefile. The output from unary_union is a multiline string (example below which you can paste into ...
Andy's user avatar
  • 155
6 votes
1 answer
4k views

Create smooth line from zigzag line

I've vector which looks something like this My question is how I can make it smoother/straighter with less points and curves. Note: I've tried using simplify api from Shapely, but no luck. Update: ...
sagarr's user avatar
  • 266
3 votes
1 answer
4k views

Smooth linestring shapefile

Is there an algorithm to perform a smoothing of a linestring and maintain the original points?
Paulo Pires's user avatar
2 votes
1 answer
560 views

Converting branched MultiLine into series of single lines in shapely

If I have a MultiLineString representing a branched network with a common starting point (red network in pic below): Does anyone know how to convert this to a set of individual single-line strings in ...
traggatmot's user avatar
  • 2,110
2 votes
1 answer
578 views

Using forceToLineString() with GDAL and Python?

For my script I'm looking for a method to convert a MultiLineString into a simple LineString. Example: MULTILINESTRING ((0 0,0 1),(0 1,0 2),(0 2,0 3,0 4)) ==> LINESTRING (0 0,0 1,0 2,0 3,0 4) I ...
Elias's user avatar
  • 73
7 votes
1 answer
3k views

How do you fix Overlapping Lines?

I have a line dataset that contains some lines where the "end points" are actually found in the middle of the line. In the image below, the nodes are shown in green and one of the end points in red. ...
geographika's user avatar
  • 14.4k