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.

1
vote
0answers
17 views

Calculating distance between point and MultiPolygon Geoseries object in Python

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
15 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
18 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
43 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
23 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
31 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
19 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
47 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
78 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
31 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
14 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
56 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
50 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
59 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
115 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
29 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
46 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
51 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
59 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
11 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
53 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
49 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
213 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 ...
1
vote
1answer
226 views

Snap points shapefile to line shapefile using shapely

I have 2 datasets: 1) a road network shapefile which has many polylines and 2) a bus stop shapefile which has many points representing bus stops. My points shapefile has CRS of EPSG 4326 and my line ...
1
vote
0answers
34 views

How is intersection implemented in Shapely?

I have gone over code and manuals and questions and I can not still find out how exactly the intersection function is implemented in Shapely. Can anyone point me to the right place? Details: Does ...
1
vote
1answer
44 views

Why does shapely intersection of two lines change behaviour when fiona module is imported?

I am having issues with calculating an intersection of two LineStrings using Shapely. Such an intersection should return a point, yet my code returns a LineString. I found a simple example of an ...
1
vote
0answers
24 views

How to output file with all overlaps between two Shapefiles - Neighborhood/Zip Codes [closed]

I have a pretty specific problem I would like help with. I have two shapefiles: neighborhoods from https://www.zillow.com/howto/api/neighborhood-boundaries.htm zip codes from the census bureau: ...
1
vote
1answer
133 views

Installing shapely on Linux?

I am beginner in Linux. I have a problem to use Shapely 1.6.4 post2... I installed shapely by this command: $ pip install shapely and it worked good Collecting shapely Using cached https://files....
1
vote
2answers
259 views

Python shapely intersection with buffer in meter

Having a line and a polygon, I use shapely to determine the intersection between the two with a defined buffer. Both the line and the polygon are in WGS84 coordinates, while the buffer is in meter. ...
1
vote
1answer
65 views

No output of simple intersection in QGIS / Shapely

I have three simple geometries (download): 1) Province boundaries of a province in Egypt (Al Wadi Al Jadid). 2) A 10 x 10 degree polygon (index = 417). 3) another 10 x 10 degree polygon (index = 416)....
0
votes
1answer
68 views

How to know if a coordinate is within a polygon in shapefile not working?

I have coordinates (lat and lng) in an Excel document a shapefile which contains all the different Canada provinces shapes. I would like to be able to generate a new field in Excel in order to ...
0
votes
0answers
105 views

Python/shapely: unary_union raises AttributeError: 'map' object has no attribute '_geom'

I am updating from Python 2.7 to Python 3.6. I have code that worked before and now raises an error where it uses shapely.ops.unary_union(). The argument used with that call is a GeoJSON object {'...
1
vote
0answers
103 views

Is PostGIS faster than Shapely [closed]

I've recently tried using Shapely to dissolve and intersect large sets of 100'000+ geometries, some of them quite complex. This would take me at least one hour, at which point I would usually shut the ...
0
votes
1answer
165 views

Create Shapely linestring from string of coordinates in text format

I have a DataFrame where one column consists of lines stored like so: '[[-7.61, 42.15],[-6.62, 43.16],[-8.9, 41.0],[-9.2, 40.5]]' Is there an easy way to read these lines directly into shapely ...
0
votes
0answers
188 views

Get the nearest distance between two points in a road network using GDAL/Shapely/NetworkX

I want to measure the distance between two points in a road network like this: I have the road WKT and also the points WKT. I know that I can measure this using QGIS (road graph plugin) or PyQGIS, ...
1
vote
1answer
96 views

Creating LineString and length of LineString from multiple latlon points for each row in a Pandas Dataframe

So I want to create a LineString and get the length of the LineString from two sets of LatLon coordinates (points) in each row in a Pandas Dataframe, and store in a new column How can I do this?
0
votes
1answer
111 views

Using GeoPandas, Shapely and Fiona to “select” state from shapefile, save it and display it? [closed]

I have the usual US census states shapefile for the 48 contiguous states. I am trying to select a state of interest from that shapefile then save that shapefile and display. I want to use GeoPandas, ...
2
votes
1answer
170 views

Finding if latitude and longitude in shapefile region

I referenced this very helpful question, but still cannot crack the issue. I downloaded Zillow's neighborhood shapefile for Connecticut and have a latitude and longitude: 41.344602, -73.071443 which ...
2
votes
1answer
258 views

Extracting Longitude and Latitude from shapefile?

I am working with a shapefile which can be found here. I am doing some data visualisation and want to see if certain longitude and latitudes are within a certain polygon in the shapefile. This is the ...
0
votes
1answer
47 views

Convert the polygon format with lat lon?

I am a newbie working on GIS data. I am working on the problem of finding overlapping regions using polygon shapefiles. Most of my shapefiles contain information with latlongs. For example the ...
0
votes
0answers
43 views

Convert GeoTIFF image to Python Shapely polygon geometries representing 3 dimensional triangles [duplicate]

I am working on implementing the example at Quantized-Mesh-Tile on my own data sets which are in .Tif (Digital Elevation Models) format. According to the module, it accept input data in one of this ...
0
votes
1answer
122 views

How to create shape in Shapely from an SVG <path> element?

AFAIK, you need to provide a list of coordinates to Shapely in order to create a shape but that's not how SVG <path> element works. Is there a way to create a Shapely shape using an SVG <path&...
1
vote
0answers
59 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 ...
0
votes
0answers
37 views

Shapely intersection operation gives non-intersecting results

I generated two lines by calculating the intersection of each of two overlapping Polygon objects with an overlapping LineString object that goes through both. In pictures: Here is the code: src = ...
4
votes
1answer
209 views

Using shapely.affinity and affine_transform?

I have shapely.geometry Point: from shapely.geometry import Point point1 = Point(0, 100, 200) and I want to swap coordinates Y and Z: from shapely.affinity import affine_transform matrix = [1,0,0, ...
1
vote
1answer
257 views

Perform sjoin in geopandas leads to:'AttributeError: 'GeoSeries' object has no attribute 'columns''

I try to find all the polygons in a dataframe thant intersect an other dataframe (made by buffering my polygons) usign sjoin. First I did the buffers gdf['geom_buf'] = gdf.geom.buffer(100) Then I ...
0
votes
1answer
49 views

Generating a raster layer with intersecting line lengths as cell values

I have a polyline vector layer and a template raster dataset. For this polyline vector layer I would like to generate a new raster dataset based on the template raster dataset, but in which each cell ...
1
vote
2answers
265 views

Invalid multipolygon of valid individual polygons

Could anyone please explain this to me? The polygons all have valid geometry but the resulting multipolygon somehow doesn't. The following script: from shapely.geometry import Polygon, MultiPolygon ...
1
vote
0answers
50 views

Spatial join of building footprints with Shapely and Fiona

I would like to do a spatial merge of the address nodes of Baton Rouge into their surrounding building footprints. Every building (polygon) should get the properties of the address (point). Here is ...