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
1
vote
1answer
35 views

Dump multiple geometry columns of a GeoDataFrame to Features in a FeatureCollection (GeoJSON) instead of properties?

I have a GeoDataFrame with some of its attributes that are geometries (only the position is the one which was interpreted as the active geometry when loading the data from PostGIS): import psycopg2 ...
0
votes
0answers
25 views

Calculate Distance between 2 Shapely Points in Meters

I am trying to calculate the distance (in meters) between 2 lon/lng points of type shapely.geometry.point.Point using Python and Shapely. These 2 points are returned from PostGIS by SQLAlchemy/...
1
vote
1answer
20 views

Create square grid on raster file

I have tried to create a fishnet(10 by 10) using the below code. But the output is as shown below. What is that I'm missing in the below code? import geopandas as gpd from shapely.geometry import ...
4
votes
0answers
53 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 (...
1
vote
1answer
44 views

Negate the shapely intersection predicate

I have two Shapely geometries: 1 MultiPoint instance named multipoints 1 Polygon instance named polygon I can compute their intersection by: multipoints.intersection(polyon) which results in all ...
4
votes
1answer
81 views

Excluding self-intersections when performing a linestring difference in shapely

I have a (complex) LineString (with 1 self-intersection): ls_self_intersection = LineString([(1, 2), (4, 2), (4, 3), (3, 3), (3, 1)]) and I have a (simple) LineString (with no self-intersection): ls =...
0
votes
1answer
35 views

Interpolating LineString by adding new Point in middle between each two points [closed]

I want to add interpolated points in a LineString using shapely. The interpolated points should be in the middle of every two Points present in the LineString. The shapely interpolate function adds ...
2
votes
1answer
30 views

Error when calculating final polygon after subtracting all intersecting polygons using shapely

This question is a follow-on question from Calculating final polygon after subtracting all intersecting polygons using shapely which was answered. I have a list of centroids that I buffer to 5000 ...
4
votes
1answer
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 ...
2
votes
1answer
44 views

Calculating final polygon after subtracting all intersecting polygons using shapely [closed]

I have a list of centroids that I buffer to 5000 meters radius. I need to take each resulting circle and run it against the remaining centroids(also buffered to 5000 m) and find the final shape after ...
2
votes
1answer
16 views

Can't Form DataFrame from Parallel Offset Output

I've been developing code to take a .csv with lat-long coords and convert them to LineStrings before creating parallel offsets for them. This has been working so far, but yesterday after clearing my ...
5
votes
1answer
53 views

Finding the closest point to a polygon in a shapefile using GeoPandas

I have the following map of statistical regions of Belgium: The blue dots correspond to coordinates for which I have temperature data. Surrounded by the red circle is Brussels. As it can be seen, ...
1
vote
1answer
45 views

Shapely command error: from shapely.geometry import LineString

I am trying to run a program but getting the following error when I am using the command: from shapely.geometry import LineString Error: FileNotFoundError: Could not find module 'C:\Users\SWWB\...
3
votes
1answer
76 views

python rioxarray.clip masking netcdf data with a polygon returns all nan

My question is similar to what others have already asked but the posted solutions haven't worked for me. The similar posts are masking a netcdf file using a shapefile of points with rioxarray and how ...
1
vote
0answers
32 views

Geopandas .difference between two different shapes produces empty difference

I have been puzzled by this, and I feel like it's a geopandas bug. base = gpd.GeoSeries(dist_to_remove).plot(edgecolor='black', color='yellow') gpd.GeoSeries(prec_shape).plot(ax = base, color='red', ...
3
votes
0answers
23 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 ...
1
vote
0answers
17 views

Create Polygons in Python that use the max extents to make a box

I have field collected data that is usually collected with 6 points to create a form of polygon. I can subset those 6 points and create the polygon no problem, with this code: eastList = channelFilter[...
0
votes
1answer
45 views

Finding duplicate shapely polygons (same polygons with different points) [closed]

I am interested in finding out duplicate shapely polygons having different points but covering the same area. For example, let assume I have 2 polygons: poly1 = POLYGON((4 1, 30 1, 45 1, 45 6, 12 6, 4 ...
6
votes
3answers
159 views

Multipolygon supposed to be contained by another but returned False with Shapely

There are two multi-polygons a and A where a is supposed to be contained inside A. Using shapely, the following difference operator b = a.difference(A) print(b) gives POLYGON EMPTY However testing A....
0
votes
1answer
120 views

GEOSGeom_createLinearRing_r returned a NULL pointer

I want to import cartopy on Python3, but it keeps showing me File "shapely\speedups\_speedups.pyx", line 408, in shapely.speedups._speedups.geos_linearring_from_py ...
1
vote
0answers
15 views

Attribute network features (lines) with data from their endpoint

Goal To prioritize water lines in a network based on the building they service Detail I have a shapefile of water lines in a region. The lines are split at their vertices and form a network (more or ...
4
votes
1answer
108 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 ...
1
vote
1answer
75 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-...
2
votes
1answer
36 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) ...
3
votes
1answer
114 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 ...
6
votes
2answers
126 views

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) ...
0
votes
1answer
15 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. ...
0
votes
1answer
79 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
65 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 ...
2
votes
1answer
113 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
0answers
118 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
163 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(...
6
votes
1answer
88 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
50 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 ...
0
votes
0answers
22 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
37 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 ...
0
votes
1answer
100 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 ...
3
votes
1answer
143 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-...
1
vote
0answers
52 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<\...
0
votes
1answer
54 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
0answers
34 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
1answer
36 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
34 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 ...
1
vote
0answers
21 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 ...
2
votes
0answers
13 views

Generating equidistant Points inside box which also contains MultiPolygon [duplicate]

I have a box bounded by min_x, min_y, max_x, max_y, I also have a multipolygon = poly contained in that box. I'm trying to equidistantly scatter points throughout that box, outside of that ...
1
vote
0answers
38 views

Using shapely to scatter points in an equidistant manner around a MultiPolygon in a Box?

I have a box bounded by min_x, min_y, max_x, max_y, I also have a multipolygon = poly contained in that box. I'm trying to equidistantly scatter points throughout that box, outside of that ...
2
votes
1answer
266 views

Creating a square buffer around a shapely polygon

I have a list of polygons in a shapefile that I transform into a geopandas dataframe: polygons = gdp.read_file(polygon_file) then I would like to create the smallest possible square buffer (in lat-...
3
votes
1answer
71 views

Directional Buffer increasing radius of geometry

I have a bunch of polygons in the shape of a pie in a geopandas df under geometry as seen below and I am looking at increasing the radius from x to y of the polygons. Can this be done using geopandas ...
1
vote
0answers
27 views

Creating a linestring from points using shapely

I am creating a linestring from points using shapely, but I could not generate the linestring using the points on my local system. This code is running fine on Google Colab. Is there any package ...
3
votes
1answer
55 views

Shapely parallel_offset returning an empty list

I have a LineString and when I try to create a right parallel line with parallel_offset I get an empty list. What am I doing wrong? The code is as follow: Line_ = LineString([Point(-131241, 5700864), ...

1
2 3 4 5
14