Questions tagged [shapely]
PostGIS-ish operations outside a database context for Pythoneers and Pythonistas.
1,128
questions
0
votes
0
answers
28
views
How to do tiling within a boundingbox?
I have a segmentation results as can be seen here
and the bounding box of the segmentation mask:
the bounding box has the following coordinates
tensor([201.7975, 2.4227, 401.5916, 476.8693])
I ...
0
votes
1
answer
25
views
Shapely area of self-intersecting polygon
I am trying to calculate area between two curves. One is diagonal straight line and the other is arbitrary curve. The curves intersect so I cannot just take an area under one curve and subtract the ...
-1
votes
1
answer
56
views
Use of a single LineString to display two data fields
I have a recurring problem for which I cannot find an easy solution, whereas I guess there is one.
I have a dataset representing road traffic data at a street level. This dataset is associated with a ...
-1
votes
0
answers
20
views
How to build a polygon based on the void(s) inside a set of spatial data? [closed]
I have a set of spatial data in simple (x,y) format. The points are distanced irregularly but close to each other, except where there are voids. There are no data for the void regions.
I'm trying to ...
0
votes
0
answers
25
views
DataFrame print raises Shapely Deprecation Warning (Iteration over multi-part geometries...) when MultiPolygon in DataFrame cell
Create a dataframe with 1 col and 1 row
Input:
data = [[[12.9883, 52.7281],
[12.9883, 52.2658],
[13.8967, 52.2658],
[13.8967, 52.7281],
[12.9883, 52.7281]]]
df = ...
0
votes
0
answers
43
views
Subclassing Polygon in Shapely
I'm working with Shapely in Python and trying to subclass the Polygon class. However, I'm encountering an error when trying to add a custom attribute during object creation. Could you please provide ...
0
votes
1
answer
53
views
How to make sure generated random boundingboxes within another boundingbox are not overlapping?
I have a boundingbox
a = [233.9259, 16.3902, 356.8651, 426.9131]
import shapely.geometry
bbox = (233.9259, 16.3902, 356.8651, 426.9131)
polygon = shapely.geometry.box(*bbox, ccw=True)
polygon....
0
votes
1
answer
48
views
Python shapely, incorrectly showing point inside/outside polygon
I am reading polygons from an ESRI Shapefile and I want to test if certain points (coordinates) are inside those polygons. I am using Pyshp to read the shapefiles and Shapely to check if the points ...
0
votes
2
answers
58
views
Finding to which polygon a point belongs - In python
I have a SHP file with polygons (representing neighborhoods) and a CSV file of murders in my city with coordenates of where it happened. I need to find to which neigborhood each murder belongs and ...
0
votes
1
answer
78
views
How to overlay shapely.Polygon on tiff image
I have an oblique image of a building, saved in a TIFF. That image is georeferenced using GCPs (using ESPG:32617). Additionally, I have a shapely.Polygon that's coordinates of the same building in ...
0
votes
0
answers
41
views
Define Latitude Longitude Grid from center point
i would like to create a regular squared grid from a particular point. I have a polygon, i take the center of this polygon and i would like to create a grid that contains this polygon using python.
...
0
votes
0
answers
22
views
How to turn a PNG into a shapefile without black lines
I have a PNG image where each color is a type of landcoverage. I go and check all of these colours and extract it's contours with cv2.
for color in target_colors:
mask = cv2.inRange(...
0
votes
2
answers
45
views
How to check lon/lat polygon pixels over land or ocean quickly?
I have 2d lon/lat arrays and am trying to check the land type like this:
import numpy as np
from shapely.geometry import Polygon
import cartopy.io.shapereader as shpreader
from shapely.ops import ...
0
votes
0
answers
32
views
Is there a way to form reliably a Shapely Linestring from unordered list of points?
I have a list of points (1 list for x values 1 list for y values) from which I want to form a shapely Linestring, to later form a polygon out of, with Linestring.buffer. In 99% of the cases my ...
0
votes
0
answers
38
views
Complex constraints in SciPy minimize
I am trying to set up a few constraints for my minimization problem which looks as below:
result = minimize(objective_func, initial_guess, constraints=all_constraints)
where the initial_guess = [0, 0, ...
0
votes
1
answer
29
views
Plot Shapely LineStrings overlayed by Points in Jupyter
I'm trying to display points over line strings to debug whether there are multiple points on the same line:
def to_shapely(points: list[point]):
return shapely.ops.unary_union([
shapely....
1
vote
1
answer
54
views
Get buffer around line string with varying distance
Given a linestring and an equally long list of distances (scalars), how can I get a new polyline that is left (or right) to the original one with an offset as specified at the respective position in ...
0
votes
0
answers
36
views
Error exporting geodataframe (with linestring geometry) to shapefile
I'm using python in a Jupyter notebook to read data from multiple shapefiles into a geodataframe to process and combine the data, then attempting to export it back out in a single shapefile, but am ...
1
vote
1
answer
52
views
Checking if shapely point is in given route from networkx
I want to check if a shapely Point is part of a route obtained by the shortest_path() function of networkx for the city of Aachen, Germany.
I want to go from Node 7192074686 to node 32885719. In 2022, ...
0
votes
1
answer
55
views
Distance between two points of MULTILINESTRING using Python?
I have a .gdb file on river network and need to calculate distance between points that belong to the same river. So I need to calculate distance for every section of the river.
I read .gdb file with ...
0
votes
0
answers
45
views
How to find the polyline between two points of a contour using OpenCV?
For my Python project with OpenCV.
How can I find the polygon drawn in red knowing the coordinates of points A, B, C and having the information on the image such as width and height?
At this moment I ...
0
votes
1
answer
29
views
How to convert pyproj1 to pyproj2 when calculate circle?
I used code as below to calculate circle coordinates for give center point:
from shapely import ops
from shapely.geometry import Point
from pyproj import Proj, transform
from functools import partial
...
0
votes
0
answers
37
views
Trouble Installing Shapely Library on OpenWRT Linux Without Pip Support
I'm facing difficulties while trying to install the Shapely library on an OpenWRT Linux x86 version where I cannot use pip due to lack of support. The Python version available is 3.9. My objective is ...
0
votes
1
answer
65
views
Find nearest point between Point and list of LineStrings without for-loop
Assume a list of Linestrings and a single point
line1 = LineString([(0, 0), (1, 1)])
line2 = LineString([(0, 1), (1, 0)])
line3 = LineString([(1, 0), (1, 1)])
line_list = [line1, line2, line3]
point ...
0
votes
0
answers
35
views
Heat map with time for LineString s
I have data on the traffic in some roads. I would like to plot it as a "heatmap", showing how busy different roads are over time with a map in the background (e.g. an OpenStreetMap). If ...
0
votes
1
answer
41
views
Shapely for pixel geometry
I'm using the shapely library to handle my geometry-based computation. However, I'm working with integer geometry (such as pixels), which unfortunately means the shapely computations are off-by-one. ...
0
votes
1
answer
27
views
Python shapely difference between polygon and a collection of circles not working properly
I am trying to measure the vacancies within a cluster of circles.
A vacancy is a empty area whose surface area is bigger than a target area
The algorithm I am targeting should work like this:
I first ...
0
votes
0
answers
40
views
Spatially dissolve lines that intersect, after attending tabular conditions
I need to dissolve all Linestrings from a geodataframe that intersect each other after attending some tabular conditions: 1)have the same ID and 2) have the same opening year. The data represent a ...
0
votes
0
answers
49
views
How can I convert 2D POLYGON data to 3D polygon data? and plotting?
I have a 2D POLYGON vector. For example, when I run print(map['geometry'][0]), the result is:
POLYGON ((127.032790006694 37.4744929935236, 127.032814864098 37.4751960230234, 127.034762251212 37....
0
votes
1
answer
50
views
WKT moving polygon to center
I have a WKT object and want to move its center to the origin (0,0).
Here is an example and what I tried:
from shapely import wkt
poly_str = 'POLYGON ((14.217343909259455 -2.9030822376560224, 16....
0
votes
0
answers
42
views
Matching correctly two polygons that come from different shapefiles
I am trying to match 2 polygons that come from two different shapefiles,
The one with the borders (black line) and the one with blue color in the picture.
.
My main point is how I can match them ...
0
votes
0
answers
50
views
Seg Fault raised by Shapely Concave Hull
When I attempt to create a concave hull using the below 8 points I get a seg fault. Excluding the second last point allows it to work however, and that point works by itself. It seems to be some kind ...
0
votes
0
answers
36
views
Shapely (or Geos) parallel_offset bug when updating from Shapely 1.7.1 to 1.8
I have a big project depending on Shapely. When updating shapely from 1.7.1 to 1.8, I have an issue with parallel_offset . For some geometries, when expecting a LineString to be offset as a LineString,...
1
vote
1
answer
126
views
How to create a bounding box given in distance, projection, and point to select points given in coordinates?
Given a a point (lat, lng) and a projection crs create
a bounding box square given by miles to select rows
in a geopandas GeoDataFrame where the geometry is made up
of other points.
Seems like ...
0
votes
0
answers
81
views
How to connect points to create a polygon
I want to connect a set of points to create a polygon. I tried connecting points clockwise, but did not receive the expected results.
Could anyone suggest how to improve the code so that I could get ...
1
vote
0
answers
55
views
Stop two polygons from overlapping by removing equal area from both
I need to create a hitbox for two lines, the lines never cross. To do so, I use shapely buffer, which gives me polygon around the line that serves as a hitbox (shown on image below).
The problem is ...
1
vote
0
answers
49
views
how to project a epsg:4326 shapely geometry to epsg:3857?
I'm working with a geodataset of fields. I want to compute the surface of each parcel on the fly when they are displayed on the map (the rational for that is not relevant here).
When I was able to ...
0
votes
1
answer
90
views
Measure distance between two points on a LineString in Python
I have the following problem: I have a route (as a LineString, from A to B). The route passes close to a point C1. I want to know how long the path is from point A along the route to point C1 (see ...
2
votes
1
answer
70
views
Method shapely.intersection returns a wrong answer
I try to find intersection of two edges in 2D using method shapely.intersection and get a wrong answer
Shapely module v.2.0.1
from shapely.geometry import LineString
a = LineString([[30.0,0.0],[36.0,...
0
votes
0
answers
13
views
How to prevent shapely.wkt.loads from changing precision of coordinates in Polygon
I am having an issue using shapely.wkt.loads to load geometry, validate it, and check if the loaded wkt string is the same as the one I will get by exporting after load. I am doing this to fix issues ...
0
votes
0
answers
18
views
Find id of polygon in which points lie
I am working on a python function. As input I have a dictionary with a set of polygons that cover the entire globe. Each polygon can be accessed by their id, such that plate_polygon[301] gives the ...
0
votes
2
answers
111
views
How to interpolate between lat, lon coordinates in rasterio
I have a satellite image that I load into python with Rasterio, which gives the BoundingBox coordinates of the rectangular image, essentially (X1,Y1), (X2,Y2), (X3,Y3), (X4,Y4) in Decimal Degrees ...
-1
votes
1
answer
78
views
Render Shapely polygon intersecting with the date border correctly
I have got a shapely polygon given in WGS84 coordinates formed like shown in the picture. As you can see, it intersects the date border.
When I get the polygon into a shapely polygon the coordinates ...
0
votes
1
answer
24
views
which algorithm use pyhton shaply library to detect points in polygon?
Which algorithm does Shapely use to detect whether points are inside a polygon? I checked the documentation but couldn't find any specific algorithm mentioned.
1
vote
1
answer
46
views
Does updating the resolution of a raster modify its bounds?
I'm new with geo data and rasters ...
I am using a library rasterio with Python to work with rasters. Currently, I have a raster with a certain resolution and corresponding bounds defined by its ...
0
votes
0
answers
60
views
transform ESRI:102008 polygon shapefile to EPSG:4326 via shapely
I'm having trouble transforming a multipolygon shapefile with CRS of ESRI:102008 to EPSG:4326. The shapefile looks like this (data1)
As I have difficulty merging ESRI shapefile with my other shape ...
1
vote
0
answers
89
views
"Invalid value encountered in intersects" when comparing polygons with shapely
I've seen "invalid value encountered in intersection" before, and it seemed like adding a check for if a.intersects(b) was the fix for that. Now I'm getting a warning from intersects() ...
1
vote
0
answers
31
views
How can I change a list of lat,lon to a shapely polygon object? [closed]
I have a list of coordinates for a bounding box and a circle on one side of the bounding box. How can I create a polygon object in shapely from these?
I have the coordinates of the bounding box as ...
0
votes
1
answer
62
views
Trying to understand the max_distance parameter in Spatial Join sjoin_nearest() GeoPandas Python
I have two geopandas dataframe having Point and LineString Geometries.
I want to use spatial joins to combine these dataframes on the basis of the distance between them.
Following are the two ...
1
vote
1
answer
82
views
Shapely finding a non-existent intersection point
I'm trying to find an intersection point between two lines but Shapely occasionally detects intersection point that don't exist on either line. This is significant because I'm calculating surface ...