Stack Exchange Network

Stack Exchange network consists of 174 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
0answers
10 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
26 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
25 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 ...
1
vote
2answers
68 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
71 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
25 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
27 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
18 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
52 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
57 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
51 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
52 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
35 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
82 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
51 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
61 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
30 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
56 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
78 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
92 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
35 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 ...
-1
votes
0answers
27 views

Generating co-ordinates of intersection (if any) in a MultiLineString using Shapely

I'm trying to generate coordinates of intersection in one MultiLineString which generates random lengths of lines. This is my code: def gen_streets(length, coordRange): new_street = [] i = 0 ...
1
vote
0answers
39 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
64 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
46 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
27 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 = ...
0
votes
0answers
59 views

How to query all points within 2000 meters through spatial index in python?

As you can see, I have some data and the projection epsg:4326. For example geometry id 0 POINT (120.681175 27.989723) 1 1 POINT (120.70615 27.97382) 2 2 POINT (120....
4
votes
1answer
111 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
116 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
42 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
180 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
39 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 ...
1
vote
0answers
49 views

Is this a bug in Shapely's ops.snap?

I have two polylines whose endpoints are near to each other, but do not overlap. I've put them into this shapefile. I want to use shapely's ops.snap() to snap their endpoints, but it's not working as ...
1
vote
0answers
62 views

Polygonizing raster cells in rasterio regardless of value?

I would like to polygonize every single cell of a raster dataset using rasterio. I have been experimenting with the following function based on this question: def polygonize_raster(dataset): # ...
2
votes
1answer
70 views

British National Grid and WGS84 conversion doesn't match in reverse in GeoPandas/PyProj

When I try to convert Google Map's lat/long into EPSG:27700 and then add a 50-meter buffer, I'm getting unexpected results. I noticed that conversions in pyproj between WGS84 and BNG are not ...
0
votes
2answers
298 views

Points into Multipoint with Shapely

I have a list of x,y,z points named simply "A". I'm trying to convert them to a multipoint with Shapely. from shapely.geometry import Point, MultiPoint orig = Point(1.9,2.5,3.1) destinations = ...
0
votes
2answers
127 views

shapely within and contain methods don't work the way I think they should

I am using Python 3.6 with the latest version of shapely from Anaconda. from shapely.geometry import Point,LineString g = LineString(coordinates=[(0, 0), (6.656423206909781, 4.437570291332059)]) p =...
1
vote
0answers
59 views

Overlay two linestring objects in geopandas, accounting for the attributes

This is a follow up to Intersecting MultiLinestring based geodataframes with geopandas? in which I was trying to intersect polyline layers and carry the attributes over to a resulting overlay/...
1
vote
1answer
55 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 ...
2
votes
1answer
114 views

rasterio mask method

I am using a simple ASCII raster file to test the rasterio.mask module ncols 4 nrows 4 xllcorner 0 yllcorner 0 cellsize 0.5 nodata_value -9999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 I generated the ...
0
votes
0answers
46 views

Split method not working in shapely?

The following two scripts are very similar in that they both make use of the interpolate method to create a point along the line, and then attempt to split the line based on that point. The variable r ...
1
vote
0answers
84 views

Polygonizing OpenStreetMap MultiPolygon with Shapely?

I'm trying to import a very basic OpenStreetMap multipolygon made out of two outer lines into Shapely: import json from shapely.ops import transform from shapely.geometry import mapping,shape from ...
1
vote
1answer
178 views

Getting polygon breadth in Shapely

Is it possible to get polygon breadth in Shapely, similar to how it provides polygon length? http://toblerity.org/shapely/shapely.geometry.html I am also ok with a solution that uses fiona or any non-...
1
vote
0answers
53 views

Dealing with a hole (or inner ring) at the intersection of two MultiPolygon polygons in Python Shapely

I have a problem with Shapely geometry object MultiPolygon (the exact data is shown below) in Python. I need to find a way to merge the small grid cell polygon with the larger polygon but after ...
1
vote
0answers
195 views

Generating a single geohash for a bounding box in python

the following code generates bounding box for the coordinates that are given in the input but currently it generates geohashes for all the 4 coordinates of the polygon. i want to be able to generate a ...
0
votes
0answers
66 views

Geopandas fails to transform coordinates from OSGB36 to WGS84

Strangely, geopandas gives the wrong output when trying to transform a geodataframe from the OSGB36 projection (epsg=27700) to WGS84 (epsg=4326): import geopandas as gpd from pyproj import Proj, ...
0
votes
1answer
60 views

Join points to a line with minimal distance

I have a point cloud (x,y) in a random order. Say sorted([(1, 1), (2, 2), (0, 0), (4, 4), (3, 3)]). Is there an easy way to connect them to a simple line like ((0,0),(1,1),(2,2),(3,3),(4,4)) doing ...
1
vote
0answers
40 views

Split geopandas DataFrame evenly by distance

Is it possible to split a geopandas DataFrame that contains LineStrings in evenly spaced segments? I have a DataFrame loaded from a shapefile that contains the track of a railway. I want to project ...
0
votes
0answers
61 views

Spatial join in Geopandas is only finding itself

I ran my code successfully last week, cleared the kernel and now it does not work. It must be something simple I'm missing, but I cannot seem to puzzle it out. The purpose of the code is to find all ...
2
votes
1answer
355 views

Access vertices of a line in Python

Given a shapely.geometry.linestring: How do you access single vertices using Python?