Questions tagged [shapely]

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

Filter by
Sorted by
Tagged with
5
votes
2answers
65 views
+50

Self split geopandas Linestring geodataframe in a fast way without loosing all attributes

I have geodataframe of many LineStrings. The LineStrings intersect but are not split at those intersections. My current solution to achieve this is from here: network = gp.read_file(filenameNetwork) ...
3
votes
3answers
84 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....
2
votes
2answers
619 views

Flipping coordinates with Shapely

I have Shapely geometries where latitude and longitude where mapped to X and Y the wrong way around. Latitude is mapped as X, longitude as Y. How can I fix the coordinates so that the current X and Y ...
4
votes
1answer
58 views

What exactly are cap_style and join_style in shapely buffer function?

I was trying to make a function that modifies polygons removing narrow spaces inside (setting a minimum distance between a vertex and a segment that is not adjacent) and at the same time remove sharp ...
2
votes
1answer
673 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 ...
1
vote
0answers
16 views

How to create a raster delineating all drainage basins using pysheds python

I am going through the tutorial of "Pysheds" available in the following website https://www.hatarilabs.com/ih-en/elevation-model-conditioning-and-stream-network-delimitation-with-python-and-...
0
votes
1answer
30 views

Merge overlapping polygons based on attribute

My objective is very similar to these questions: here and here. The only real difference is I want to merge overlapping polygons if they are of the same class (an attribute). For example, if polygons ...
2
votes
1answer
24 views

Affine Tranformation Matrix; shapely asks 6 coefficients, but rasterio delivers 9; how to translate

Some lines have been extracted via scikit-image, now tho goal is to vectorize them within the origin coordinate reference system #some geotif opened with rasterio src = rasterio.open(raster_path) ...
1
vote
0answers
45 views

Buffer around Point is elliptical, not circular

I'm trying to create a circle around a point using the code from this answer here. Adding below for better visibility as well from functools import partial import pyproj from shapely.ops import ...
5
votes
1answer
3k 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 ...
0
votes
1answer
30 views

Problem with intersection between two Geopandas Dataframes

I have 2 shape files one "country.shp" (containing the tiles geometry covering the whole country) & other "district.shp"(containing one particular district). Now I want to get the tiles ...
0
votes
0answers
7 views

Drop Linestring geometry from a GeoDataFrame

I try to create a shapefile of the FAO/GAUL/2015/leve1 country regions of the LMIC's countries. For that I decided to use Python as it gave me access to the earthengine API and the geopandas librairy. ...
1
vote
1answer
1k views

Getting CRS to export shapely polygon to shapefile

I am trying to export a shapely polygon to a shapefile. I have tried this, but the CRS is missing, when I try to import it in to QGIS. The shapely polygon is from this OSMNX example but edited to work ...
0
votes
1answer
53 views

Calculating distance between two Linestring using Python

I have two linestring, each linestring represents a rail road. I am trying to calculate minimum distance between these two linestrings. Which function is efficient to do this? I have only come across ...
0
votes
1answer
43 views

How to create a GeoPandas GeoDataFrame from rasterio features?

I try to create a GeoDataFrame of paches of same values in a binary raster using rasterio and GeoPandas. data_file is a binary TIFF raster with 0 where there is no deforestation and 1 if there is a ...
1
vote
2answers
40 views

Masking a NetCDF file using a shapefile of points with rioxarray

I took the proposed solution from this question (How to mask NetCDF time series data from a shapefile in Python?) and tried to implement it. However, whenever I apply this solution it seems to set all ...
0
votes
1answer
27 views

Computing linestring between two different point shapefiles

I have two point shapefile representing towns within a state and I want find the distance between them. Since the points are in different shapefiles, should I merge them so they would be in the same ...
2
votes
1answer
57 views

What is the algorithm that Shapely used to check if two polygons intersect?

What is the algorithm that Shapely used to check if two polygons intersect? from shapely.geometry import Polygon p1 = Polygon([(0,0), (3,0), (3,1), (1,1), (1,2), (3,2), (3,3), (0,3)]) p2 = Polygon([(4,...
0
votes
1answer
29 views

GeoPandas setting geometry for a row with .loc and Multipolygons

Given the following example: def merge_with_largest(input_gdf,poly): # select the polygons bordering polygon close_by_gdf = input_gdf[input_gdf.geometry.intersects(poly)] # selects ...
0
votes
1answer
154 views

How to drop rows from a GeoPandas dataframe that are raising errors, in this case: TopologyException, Ring Self-intersection

I am trying to find the points from a geopandas frame that are inside the polygons from another geopandas frame. The code that I am using is the following: points[points.geometry.within(polygons....
0
votes
2answers
610 views

including SRID in WKBWriter in Shapely doesn't work

I want to encode coordinates of LineString in WKB with the SRID included wkbwriter = shapely.geos.WKBWriter(shapely.geos.lgeos, big_endian=False, include_srid=True) geo = wkbwriter.write_hex(...
0
votes
0answers
69 views

Removing duplicate points in GeoPandas using distance and time

I have a list of of coordinates that have areas mapped out on a map user_id id latitude longitude requested_at 84 106 13.0472367 77.5022635 12-10-2020 14:59 84 107 13.0472789 77.5024498 ...
3
votes
2answers
54 views

“Multi-part geometries do not provide a coordinate sequence” error when extracting the long and lat of start and end points in GeoPandas

I am trying to extract the start and endpoint coordinates in GeoPandas. Following this link, I am using this code to extract the start and endpoints for GeoJSON files. def add_start_end_nodes_to_gdf(...
2
votes
2answers
330 views

How do you validate longitude and latitude coordinates in Python?

I am working on a bunch of shapefile data, and I need to process it and after some kind of processing, I need to feed the data to an indexer (in this case ElasticSearch). The problem is I just ...
6
votes
1answer
71 views

Creating polygon from two not connected linestrings using shapely

I'd like to know if there is a way to create a polygon in shapely from two not connected linestrings. I've been struggling with this question from some hours now and I can't find a way to deal with it....
0
votes
0answers
30 views

Symmetrical Difference using fiona and shapely

I have a polygon that I want to merge into an existing polygon. To do this I first need to run symmetrical difference between the two overlapping polygons, and then merge them. Before symmetrical ...
1
vote
1answer
334 views

Calculate area of polygons in square meters when CRS is EPSG:25833

I have EPSG:28533 coordinates and would like to calculate its area in square meters and then transform these coordinates to EPSG:3857. I have taken the code from here to calculate the area but it does ...
2
votes
1answer
188 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/...
1
vote
1answer
1k 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'] ...
0
votes
0answers
19 views

Iteratively polygonize MultiLineString

I have an implementation of alpha-shape below. My goal is to compute the polygons for a list of alphas but do it as fast as possible. LineProfiler showed that almost all of the time is spent in list(...
0
votes
1answer
2k views

Determining if point on boundary using shapely? [closed]

I'm new to Python, and I want to test if a certain point lies ON the (boundary) of a polygon - not inside, not outside, just if it's on the boundary. The points and polygon already defined polygon = ...
33
votes
5answers
50k views

How to write Shapely geometries to shapefiles?

Can someone demonstrate a simple way to write geometry data-structures from shapely into shapefiles? I am particularly interested in polygons with holes and linestrings. It would also be beneficial to ...
15
votes
3answers
55k views

Check if a point falls within a multipolygon with Python

I have tried several examples of code using libraries such as shapefile, fiona, and ogr to attempt to check whether a point (x, y) falls within the boundaries of a multipolygon created with ArcMap (...
2
votes
1answer
68 views

Difference in geometries of shapefiles

I have the geometry of the outline region as part of one shapefile (which is only one feature and there are other features in it apart from this). Other polygon regions' boundaries which are colored ...
20
votes
2answers
19k views

How to polygonize raster to shapely polygons

I am seeking an open-source python solution to convert raster to polygon (no ArcPy). I did know the GDAL function to convert raster to polygon, and here is the manual: http://pcjericks.github.io/py-...
3
votes
1answer
83 views

Shapely flips lat/long coordinate

I have a pandas dataframe containing a Shapely geometry object. The shapely object (circle) was computed from the following SO https://stackoverflow.com/questions/27431528/find-the-intersection-...
0
votes
1answer
294 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
0answers
31 views

Converting SQLite BLOB geo to Polygon in Python using SQLite3

I am trying to convert a geo column into Polygons in Python with SQLite3. I imported the file into Python and geo rows look like following first row: geo[0] = b'\x00\x01$i\x00\x00@\xd9\x94\x8b\xd6<\...
2
votes
1answer
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 ...
1
vote
1answer
752 views

Shapely Polygon to numpy boolean mask [closed]

How can I convert my Shapely polygon to a numpy pixel array representing a boolean mask, with True for where the polygon is?
0
votes
0answers
672 views

Geopandas geodataframe copy with where clause causes geometry issues

Question up front: What is likely happening here, where when I take copy of the dataframe with a where clause present that there is an apparent break in the geometry, as implied by the linestring ...
0
votes
0answers
29 views

Shapely adds more vertices to a polygon for smother snapping

I'm using shapely to snap together some polygons. The problem is that snapping in shapley only supports vertices to vertices snapping (i.e. a vertices from a polygon can only ever snapped to the ...
0
votes
0answers
28 views

Find vertices of LineStrings within Polygon - Shapely

I would like to use Shapely to find the vertices that are located within the boundaries of a Shapely Polygon. So far, I could only manage to get it running by converting the LineString and the Polygon ...
1
vote
1answer
32 views

Determining driver, spatial reference and other props from an open GDAL layer

I have a very large network share full of data (raster, vector, sometimes mixed inside of geopackage and/or file geodatabase containers). I have a set of classes that crawl through it all and use ...
31
votes
3answers
23k views

Transforming Shapely Polygon and MultiPolygon objects

Is there an easy way of transforming Shapely objects (namely, Polygons and MultiPolygons) from one projection to another without having to dig around and extract coordinates by hand? In fact, I don'...
5
votes
2answers
5k views

Auto-select suitable UTM Zone based on Grid Intersection

I was wondering if the following approach a) would be considered valid and b) someone already did this in python. I have a python script where users can choose an area of analysis (anywhere on the ...
1
vote
0answers
20 views

Why does dropping a single point dramatically affect location of polygon centroid?

I'm a relative novice working with some coordinate data using shapely and have found a weird behavior when trying to identify outlier points. The approach I am using is to iterate over a series of ...
3
votes
1answer
1k views

How best to use shapely to write a dict to a shapefile

I have created a shapely object (i.e. the_pt) for my Points & Multipoints to do a buffer analysis against another shapely object (i.e. city_pt) using: return_shapes = [] for pt in points: ...
1
vote
1answer
122 views

Create LineString from lat/lon coords form CSV. with beginning and ending lat/lon?

I am iterating through a CSV file of tornadoes, and for each row getting the beginning lat, beginning long, ending lat, and ending long. and trying to plot their line geometry on a map. I got the ...
17
votes
5answers
17k views

Area in KM from Polygon of coordinates

I have polygons from coordinates in (python shapely) that looks like this POLYGON ((24.8085317 46.8512821, 24.7986952 46.8574619, 24.8088238 46.8664741, 24.8155239 46.8576335, 24.8085317 46.8512821)) ...

1
2 3 4 5
13