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.

1
vote
1answer
25 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
25 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
45 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
41 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
14 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
69 views

Is PostGIS faster than Shapely

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
17 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
30 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
17 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
33 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
52 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
57 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
33 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
22 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
29 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
42 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
24 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
16 views

get z-axis of a 3D shapely Polygon

Using python 2.7, shapely library import numpy as np import shapely.geometry from shapely.wkt import loads as shp_load wkt = "POLYGON ((-0.0391 -0.1857 0.1000,22.8031 14.7072 0.1000,5.1794 41.7378 0....
0
votes
0answers
49 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....
3
votes
1answer
75 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, ...
0
votes
1answer
84 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
36 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
160 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
36 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
48 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
51 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
52 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
209 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
96 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
48 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
41 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
80 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
39 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
65 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
122 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
46 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
160 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
48 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
58 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
35 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
47 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
327 views

Access vertices of a line in Python

Given a shapely.geometry.linestring: How do you access single vertices using Python?
2
votes
1answer
67 views

Extracting GPS points inside the region boundary

I have large set of GPS coordinates of human mobility in different parts of China, but I am only interested in points in Beijing City. These points are in excel csv file that I read into pandas ...
1
vote
0answers
33 views

Why does my Fiona output look different from my image

I'm trying to export my houghlines as a shapefile, which works. But the output the lines in my shapefile are very different then the generated hough lines that are shown on the image. Example: The ...
0
votes
1answer
73 views

Dissolving polygons based on multiple attributes with Python (shapely and fiona)?

I would like to dissolve a polygon shapefile based on two different fields, using Python and open source libraries. I'm just able to dissolve the shapefile using one single field, with Gene's answer ...
1
vote
1answer
52 views

Error creating buffers in shapefile

I have a function to create buffers from everything in a shapefile, but I'm getting an error on some files: Record's geometry type does not match collection schema's geometry type: 'Polygon' != '...
0
votes
1answer
25 views

Print just coordinates

I am relatively new to coding, but I am using fiona within python and would like to print the coordinates that make up the points of the polygon to later add to a separate list. However I am having a ...
3
votes
4answers
178 views

Interchange y, x to x, y with geopandas (python) or QGIS

I realized that the order of my geopandas dataframe is wrong, it has y, x instead of x, y. This makes it difficult to use with other modules that needs exactly x, y type of coordinates. Is there any ...
0
votes
1answer
45 views

Strange behavior when writing coordinates to an ESRI shapefile

I am using python code straight out of the GDAL/OGR Cookbook to write lat/lon coordinates (stored in a numpy array of tuples) to an ESRI shapefile like this: #using almost entirely GDAL cookbook code ...