Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [shapely]

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

0
votes
1answer
30 views

Extending (buffering) set of polygons into empty space only using Shapely?

I have a set of polygons of which I would like to extend the boundaries a bit into empty space, using Shapely. They are not allowed to overlap each other at all. For example creating buffers and then ...
1
vote
1answer
43 views

Removing self-intersection from invalid polygon using shapely?

This geometry is invalid: POLYGON ((234107.4999285005 581107.0000356995, 234250.1399285011 581055.220035702, 234347.470028501 581007.8300357014, 234427.899928499 580959.1000357009, 234483.1350285001 ...
0
votes
2answers
42 views

How to create a weighted square lattice as well as a weighted network graph

I am planning to create a weighted square lattice for different sizes, and then label each edge with its associated weight. It's similar to this thread "How to load a weighed shapefile in networkX" ...
0
votes
2answers
30 views

Using dictionary of file names and DD coordinates to create points in shapefile using shapely?

I'm working on a Python script that strips the GPS info from images and uses that info to create a shapefile from that info. Right now I have all the file names as keys to tuples of decimal degrees ...
0
votes
0answers
25 views

Coordinate System shows up incorrect after converting a shapely object to a shapefile [duplicate]

I am trying to convert a simple point object created using shapely to a shapefile using fiona as instructed in this post. I pretty much followed line by line except that I changed the crs as I need it ...
2
votes
0answers
50 views

Intersecting shapefile/GeoDataFrame using Geopandas, shapely etc?

I'm currently transferring from ESRI to open source GIS by recreating basic ArcGIS tasks in Python, mainly using Geopandas since I have some experience with Pandas. Now I'm trying to intersect a ...
0
votes
0answers
13 views

Getting zip code from string geom using shapely?

I have a list of geoms each in string form. I can convert them either to our or python shapely geom but does any have a function to find a zipcode from that geom? I was unable to find one. I can use ...
0
votes
2answers
75 views

Converting list of polygons to multipolygon using shapely?

I have a list of polygons where each polygon is a wkt form as follows: list_polygons = ['POLYGON ((-88.131229288 41.900200029,-88.12973798 41.900104202,-88.129785999 41.894907769,-88.131352409 41....
4
votes
1answer
57 views

Making Shapely box larger using GeoPandas?

I'm creating a box that covers the the area of a GeoPandas GeoDataFrame, so that I can use it as an inverted map to later cover up unwanted spill-over data. import geopandas as gpd import geoplot as ...
1
vote
1answer
29 views

How to reverse the MultiLineString command to a list of arrays

Let's you have a list of coordinates that you can convert to a line string: coords = [((0.0, 0.0), (0.0, 20.0)), ((20.0, 0.0), (20.0, 20.0)), ((1.0569687968009744, 14.934839039628798), (5....
2
votes
0answers
36 views

Dissolve Line Strings to one string - “No Shapely geometry can be created from null value”

I have a layer with 7000 LineStrings, all represent bus routes: It seems that all the bus routes are contiguous, but I'm not sure of it. I'm trying to use python shapely to dissolve all those ...
3
votes
1answer
72 views

Using libraries other than PyQGIS to develop plugin for QGIS?

I develop a plugin for QGIS. Before to integreted it in the QGIS I developped it with GIS library (Fiona, shapely, geopandas, ...) and it work well. Now I try to build it with plugin_builder of QGIS. ...
2
votes
1answer
27 views

I have the following multilinestring, and I am looking for finding the intersection between each pair

I have a pair of lines, which I like to find the intersect of each of one them with each other. I know for two lines I can do the following: from shapely.geometry import LineString line1 = ...
1
vote
0answers
23 views

Cut line at intersection using Shapely

I'm trying to cut a line at the intersection, if a line crosses another line within a single multilinestring then and the end of the line is below a maximum distance threshold then it swaps the end of ...
1
vote
2answers
62 views

How to extract biggest Polygon from MultiPolygon in GeoPandas?

Given a Shapely MultiPolygon, how can I extract the biggest Polygon? For example, given a MultiPolygon as follows: from shapely.geometry import Polygon, MultiPolygon multipolygon = MultiPolygon([...
0
votes
1answer
43 views

Quickly find all polygons that overlap with two or more polygons in Shapely

I have a set of Polygons (in Shapely) that I wish to find all intersections that are comprised of overlaps of two or more polygons. I have been working based off the code found in this answer. I have ...
1
vote
1answer
44 views

Intersection function returns multiple coordinates

I am trying to find intersection vertices of two polygons defined below PG = Polygon([(0.0,0.0), (0.0,4.0), (2.0, 0.0)]) QG = shapely.affinity.rotate(PG, 10.0, origin="centroid") print(PG....
0
votes
1answer
46 views

Clip shapefile based on another shapefile [closed]

I have two shapefiles with me, one big and one small. I want to clip part of big shapefile where the small shapefile is located. I tried QGIS vector intersect by geometry, but that is returning me ...
0
votes
1answer
28 views

Find intersection vertices of two polygons

I have defined two polygons and I can find whether they intersect or not. I need to find the intersection vertices if they intersect or not ? How can I do that ? p1 = Polygon([(0,0), (1,1), (1,0)]) ...
0
votes
0answers
25 views

ST_Polygonize/Shapely cannot polygonize when overlapping with shared node/point

I'm trying to use both polygonize_full (Shapely, python) and ST_Polygonize (postgis) to get all polygons from a set of line strings. There is one case where it fails: when there is an "overlapping ...
0
votes
0answers
94 views

Smoothing shapefiles using Python

The purple is the original polygon to be smoothed and I would like to smooth the polygons as the red line using Python. I tried simplify but looks like I need a buffer and simplify the buffer. But I ...
1
vote
0answers
53 views

How to segment polygon in to line segment?

I want to segment a Polygon or PolyLine in segment of line and remove some segments. I have an polygon that i convert in polyline by the code below and it work well: from shapely.geometry import ...
0
votes
0answers
41 views

Writing only one of the input vector fields to output vector using Fiona/ Python?

I'm working on a function to perform operations on folders of vector files. These files might have differing attribute fields but there will be a common field between them. I'm using fiona in python ...
0
votes
1answer
136 views

Python geopandas dataframe of polygons — determine nearest neighbor polygon?

I am trying to figure out how to dynamically create expanded regions of interest based on polygon geometries in geopandas until some threshold is satisfied (essentially custom regions across the ...
0
votes
0answers
18 views

How can I group the geodataframe on the basis of the column

I have a geodataframe that has a ununique column(text) and polygon geometry for each row. How can I group the gdf on the basis of the column? gathering and converting polygons to multipolygon I think ...
1
vote
1answer
82 views

Delaunay triangulation algorithm in shapely producing erratic result

I would like to triangulate the following polygon: The wkt for the geometry is given as follows: POLYGON ((3 0, 2 0, 2 0.75, 2.5 0.75, 2.5 0.6, 2.25 0.6, 2.25 0.2, 3 0.2, 3 0)) I ran this code to ...
1
vote
0answers
187 views

Calculating distance between point and MultiPolygon Geoseries object in Python [closed]

I want to calculate the distance of a point from the Multiploygon geoseries object created using cascaded_union function of GeoPandas. Following is my code: import numpy as np import pandas as pd ...
1
vote
0answers
19 views

Check point in line segment not accurate in Shapely

I use Shapely and I've run into an issue where I can find the intersection of two lines. However once I have the intersection point, I don't seem to be able and cross-reference that it belongs in both ...
0
votes
0answers
26 views

Would like to randomly sample points from within a polygon using Python [duplicate]

I would like to achieve something similar to the ArcGIS Create Random Points tool using geopandas, shapely, or rasterio. I aim to have a polygon with some holes in it (removed by subtracting buffered ...
0
votes
1answer
107 views

Dissolving polygons to single part features with Python (shapely and fiona)?

I used the code from Dissolving polygons based on multiple attributes with Python (shapely and fiona)? to dissolve a shapefile using shapely and fiona. However the output creates multi-part geometries....
0
votes
0answers
51 views

Issue with GeoPandas method 'contains' for two GeoDataFrames

I want to verify that a GeoDataFrame called mask2 COMPLETELY CONTAINS all the linestrings in another GeoDataFrame called transect_file2. In the image is clearly visible that transect number 16 (TR_ID=...
0
votes
0answers
51 views

Broadcast Shapely Point on numpy array

I have some code that looks something like this: def get_objs(all_objs, line, my_distance): """ Gets all objs within my_distance of line. all_objs is a numpy array of shape (x, 4) ...
0
votes
0answers
41 views

Creating a grid of modifiable hexagonal tiles as overlay in geopandas

I have geo-tagged car sharing dataset which I am analyzing using geopandas. For analysis purposes I would like to create my own polygon overlay of hexagonal tiles. I have managed to find a ...
0
votes
1answer
85 views

Getting geohash of LINESTRING in PostGIS?

I have some LINESTRING in PostGIS. LINESTRING(104.011 30.637,104.014 30.638,104.022 30.640,104.026 30.645) LINESTRING(104.022 30.666,104.031 30.659) LINESTRING(104.044 30.655,104.056 30.655) I ...
2
votes
1answer
670 views

Fast intersection of a list of polygons with a bounding polygon using Shapely

I have a list of Shapely polygons which I need to find the intersection of each with a bounding Shapely polygon. Not all the polygons in the list cross the boundary of the bounding polygon so I only ...
0
votes
1answer
46 views

shapely wrong output — when snapping points to line shapefile

I have a series of nodes to be connected to a road network, so as to calculate the cost of transportation. I used shapely to snap the nodes to the road network polylines. Most of the connections ...
0
votes
0answers
21 views

Closest point between two outer edges/ polygons

I have been trying to find two closest points between two polygons. Initially I used the "nearest_points" shapely function. However this does not always return a point on each of the polygon edges. e....
2
votes
1answer
249 views

Split polygon by MultiLineString - shapely

I'm working on splitting a polygon given a set of linestrings using the shapely python library. The problem I'm facing is that a polygon cannot be split by a MultiLineString usingshapely.ops.split(...
1
vote
0answers
109 views

Shapely : cascaded_union seems to return too many polygons

I'm trying to get the union of around 4,000 polygons using Shapely's cascaded_union function. The output of this function is a multipolygon in my case, which is normal since many input polygons do not ...
0
votes
1answer
185 views

How to find overlapping polygons of two shapefiles - Python [closed]

I have a mkl file A and a shapefile B containing polygons, each one of them having a single feature: the name associated to the polygon. I am looking for the polygons of A which are overlapped by ...
1
vote
2answers
438 views

Create Polygon with Length, Width, and a center coordinate

Using Shapely or like library, How can I create a rectangular polygon with known Length, Width (in meters)(Drawing over EPSG: 3857), and center coordinates (EPSG: 4326)? The output needs to be in ...
0
votes
1answer
46 views

Merging multi-polygons gives me error in shapely

I am trying to merge a bunch of either polygons or multipolygons by the merge_multi_polygons function in shapely, I am using my below code inside Spark elems=row['_c0'] ...
1
vote
1answer
49 views

Role of boundaries when using shapely within function

According to the shapely documentation: object.within(other) Returns True if the object’s boundary and interior intersect only with the interior of the other (not its boundary or exterior) ...
1
vote
0answers
195 views

How to prevent “Type error: unhashable type” while writing properties with Fiona?

Using shapely's dissolve method I created new geometries from two existing shapefiles. Now I would like to save those new geometries and their properties with Fiona. I have tried to write the ...
3
votes
0answers
63 views

Shapefile polygon operation efficiency

I would like to make a graph from a shapefile, where edges would express spatial relations between polygons according to DE-9IM For that, I use fiona + shapely My code is working but it is extremely ...
1
vote
0answers
31 views

Can Polygon cross other Polygon on the surface?

I'm using Shapely (https://shapely.readthedocs.io/en/latest/manual.html) I'm trying to get 'True' value for crosses method (https://shapely.readthedocs.io/en/stable/manual.html#object.crosses) with ...
0
votes
0answers
12 views

Efficienctly determine which of a set of coordinates which are contained within a set of closed polygons via python [duplicate]

I'm trying to determine which of about 300,000 points fall within any of 215 closed polygons. My code right now loops through each point and then through each shape to see if it the point is ...
2
votes
0answers
93 views

Shapely .project() function not working on horizontal or vertical sections of line

I have a function called intersect_point_to_line that includes the following relevant code snippet: for i in range(len(segment.coords[:])): if i < len(segment.coords)-1: seg = ...
1
vote
1answer
75 views

Trajectory Similarity Measurement with Shapely or other Python libraries

Are any of the famous trajectory similarity measurement methods such as Dynamic Time Warping(DTW), Edit Distance based methods or Longest Common Subsequence based Measures implemented in shapely or ...
2
votes
2answers
405 views

Generating Steiner tree using Network X in Python?

I'm trying to generate a Steiner tree in Python using NetworkX. I have a range of geolocated nodes saved in the GeoJSON format, allowing me to visually validate the outputs in QGIS. A radially ...