# Questions tagged [shapely]

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

151 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
718 views

### Shapely with Rtree versus STRtree

I have a huge interrogation regarding the performance difference between Rtree and STRtree included in Shapely. Below is a short code where we create randomly 250 000 triangles (defined by 4 vertice) ...
107 views

### “Merging” 2 layers of LineString with splits at intersections

I would like to "merge" 2 networks of lines and these lines need to be split when they intersect. With pictures it should be clearer : What to do: if a black line intersects a red line, they should ...
387 views

### Making polygon for every point in set using voronois?

I'm trying to make polygons from points, were each point will be represented by one polygon. I tried using voronois, but the results are incomplete. While I more or less understand where this ...
50 views

### Convert the geometry column of a GeoDataFrame with mixed geometry types to a unique multi-type

I have a GeoDataFrame where I have a mix of geometry types in its geometry column, some are multi-geometry types, some are single geometry types, some are empty geometry types, and others are None (...
55 views

### Obtaining a transform for Affine transformation (Cartesian to geodetic coordinate system)

I have a Line, defined as 2 points in a Cartesian coordinate system. Shapely allows projecting this line with an affine transformation if a transform is specified. from shapely.geometry import ...
134 views

### Performance improvement methods in a shapely environment

I am trying to use the Shapely and Fiona libraries to eliminate polygons from one layer (some triangles) from another layer (which represents the world's oceans). I am looking for suggestions to ...
4k views

### Point in Polygon using Rtree and Shapely

I am wondering what the correct syntax is for doing a point in polygon search using Shapely and RTree. I'm really interested in speeding the process up using the RTree index but am not having any luck ...
1k 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, ...
22 views

### Calculating population within a circle excluding intersects with shapely

I have a data of a centroid and a count: centroid population id 0 POINT(38.9081 77.0349) 9004.0 0 1 POINT(38.8521,77.0377) 517.0 1 2 POINT(38.9081 77.0377) 10369.0 ...
126 views

### Finding all possible adjacent/closest geometrical points from a given point

So, I have a dataframe like this, import numpy as np import pandas as pd import descartes from shapely.geometry import Point, Polygon import geopandas as gpd import matplotlib.pyplot as plt df = pd....
128 views

I'm trying to run a program that uses shapely on a GCE Virtual Machine (Ubuntu 18.04). I'm getting an error on the geos.py file, here is the relevant trace I'm getting: [geos:73] - [DEBUG]: Found ...
86 views

### Assign area of polygon to raster cell. Effective way in Python

I have quite interesting task to resolve, but my solution is not effective, so I am looking for some advice to improve my code. I have raster dataset covering Europe, in crs WGS 1984 (4326). The cells ...
492 views

### Multi-part geometries do not themselves provide the array interface

So initially I had multiple perpendicular lines along a coastline. Next I clipped these lines based on polygons along the coastline,such as the follwing. I am trying to use this resulting shapefile ...
294 views

### Find the closest line to a polygon Python Rtree

I have a series of fields and roads I am trying to find the nearest road to each field. I want to add field to each of my polygons with the index/name/etc of the closest road. Would this be the ...
76 views

### Split line at regular intervals in shapely

I have been trying to use Shapely to split a shapefile with multiple features at regular intervals. I have used the split function to do this. I can easily create the points at which the lines should ...
219 views

### Find a centerline of an intersection between two irregular shaped polygons

I have two irregular shaped polygons that overlap each other at least in at two points. I want to first find the intersection area between all of them, then for the polygon pair that intersects I want ...
75 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 ...
152 views

### Merge linestrings between two nodes based on condition

I am working with dense openstreetmap road networks and I am trying to simplify the network. To simplify it, I would like to merge all the linestrings that only intersect with one other line, as shown ...
435 views

### Alpha hull with island

I need the 'concave hull' or alphashape of a set of points. Also, I'd like to have it with holes/donuts/islands in the middle. See my attached image. The outer hull is being calculated fine. But the ...
830 views

### Install shapely for QGIS on Mac

I know there are a number of similar questions, but none of them have answers that allow me to use shapely in QGIS. In particular I am trying to install the Contour plugin, but this fails with the ...
893 views

### Importing matplotlib basemap and shapely

I'm not sure if this is the right place to ask this, but here we go. I have a python script that uses matplotlib's basemap and another part that uses shapely to do an intersection of 2 polygons. If ...
268 views

### Find nearest polygon (from GeoSeries) to point (from GeoSeries)

I have two GeoSeries, consisting of points and polygons. I want to find the polygon in dataframe B that is closest to each point in dataframe A. The polygons are rooftops from https://github.com/...
241 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), (...
40 views

### How to cluster interconnected lines in Python without PostGIS?

I'm working with a subset of data from OpenStreetMap, where I have these island-like groups of line features. The groups are not connected to one another, but the lines are all interconnected within ...
77 views

### Geopandas shows points outside of buffer geometry even though inside

I have some ship trajectories and I want to know which point of the trajectory is inside the port(=buffer) and which points are outside. The following picture shows my Geopandas Dataframe with the ...
51 views

### Polygonize every single pixel of a raster

How can I get every pixel separated? When I calc unique values, if two pixels have the same value, it converts in one row in the final shape. I need every single pixel converted into one unique ...
151 views

### More stable spatial sort using Shapely's within?

I was trying to use a modified version of the spatial sorting method illustrated in shapely's documentation, using only polygons exteriors (so that I can detect if a polygon lies inside another ...
64 views

### Problem when trying to cut linestring at multiple points after conversion from Multi-linestring

This is my script: def cut_line_at_points(line, points): ''' line is gdf format points are series of points in gdf format ''' # union all geometries - convert the gdf to shpely (...
55 views

### ESRI Geometry Union slower than Built in dissolve which is slower than Shapely

I work with point datasets a lot. We try to keep a running layer of points and update the dataset with new points while removing the old points. So, we do a lot of checking the extents of the new ...
468 views

### CRS of Shapely Object

I've imported a row from a Postgres DB using sqlalchemy. One of the column types is GEOMETRY from postgis and upon import >>>> type(row[0].geom) returns class 'geoalchemy2.elements....
43 views

### Creating Swath View from Point data using Python?

My situation Input: point data from planting file Feature Attribute: [('DeletionFlag', 'C', 1, 0), ['Field', 'C', 254, 0], ['Dataset', 'C', 254, 0], ['Product', 'C', 254, 0], ['Obj__Id', 'N', 15,...
714 views

### Finding shortest distance from point(s) to number of polygons at varying angles using shapely?

My aim is to calculate the distance a point is from land in Python, trying to replicate the functionality of fetchR. Given an origin and distance, I create shapely LineStrings which radiate out from ...
2k views

### Geopandas simplify results in gaps between polygons

The goal is to simplify the geometries of a shapefile containing multipolygons. However, when I use Shapely's simplify in geopandas, the result contains gaps between the polygons. I was hoping that ...
467 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 ...
210 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 ...
97 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 ...
3k 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 ...
275 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 = ...
848 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 ...
579 views

### No handlers could be found for logger “shapely.geos”

I have the following code to get area of polygon using shapely and pycrs. I was able to run this code successfully in a jupyter notebook but when I incorporate it into my main code, I had an error ...
218 views

### Classify / section line or group of points according to shape (with shapely objects)

Is there any python module/function that classifies/sections a shapely line according to the shape the line forms? If not, I could do it with the positions of the points that form the line. I would ...
433 views

### Storing Shapely polygons in MySQL

I have to store some polygons in a MySQL database. The polygons are in Plate Carrée (ESPG 32662) projection, but I also tried to first converting them to the usual latitude-longitude projection (ESPG ...
480 views

### When does Shapely's “polygonize_full” detect a dangle?

Shapely's polygonize_full operation, which merges line segments into polygons, returns four geometry collections: polygons, dangles, cuts and invalid ring lines. Dangles are defined in the ...
756 views

### Find Properties of Nearest Line Segments to Point in Python

I have been trying to find a workable Python approach to finding nearest line segments to one (or more) points, and came accross @gene's solution to @RustyMagoo's problem here: from shapely.geometry ...
588 views

### How do I create a raster file from a geopandas dataframe storing lats, longs, values, and geometries

From a text file with time, lat, long, and cf values, I create a pandas dataframe (cf_df). Then I use the lat, long values to create a geoseries and create a geopandas dataframe from the original ...
1k views

### Interpolating every X distance along line in shapely

If I have a shapely multiline object that contains many lines whose total length each is 50km (when traced from the origin), and I want to interpolate along the multiline every X meters (let's say ...
569 views

### Projecting GeoJSON polygon object in python to calculate area

I have a script, written in python, that does many calculations - but one set of calculations hinges on determining the area of a polygon that I read in, in GeoJSON format. I can convert this object ...
106 views

### Where is my Polygon?

I created this script to merge all of the polygons in a shapefile into a single polygon. I am using Python 2.7.5, Shapely 1.3.0, and Fiona 1.1.5. def merge(path_in, path_out): #Import Libraries ...