Questions tagged [shapely]
PostGIS-ish operations outside a database context for Pythoneers and Pythonistas.
920
questions
0
votes
0
answers
26
views
How to scale polygon using shapely?
Im trying to scale one shape to a larger one, like this:
I have an example here
poly_context = {'type': 'MULTIPOLYGON',
'coordinates': [[[[1, 2], [2, 1], [4, 3], [3, 4]]]]}
poly_shape = shapely....
0
votes
0
answers
23
views
Irregular Polygon Sub-division?
I have a problem in which I have an irregular polygon shaped container which needs to be sub-divided such that it contains certain smaller rectangles of specific dimensions. I have previously tried ...
0
votes
0
answers
10
views
Python scale GeoJSON by absolute value in meters
I am trying to generate a python code that takes geojson containing polygon as input an then outputs a polygon that is scaled by exact value in meters. For example lets say that my polygon is a square ...
-1
votes
0
answers
27
views
Plot a centreline in rectangle using shapely [closed]
I have a shapely polygon as rectangle. Need to plot centrelines for each rectangle and store all those lines in one variable, so that can be coverted to kml.
My approach is this way.
using poly....
0
votes
0
answers
25
views
Image segmentatino: Convert GeoJSON to COCO JSON, pycocotools return empty mask
I am labeling my maps (in TIF format) in Azavea GroundWork. The files I downloaded are organized in STAC catalog. The labeled segmentation is in .geojson. Labeled segmentations are polygons. The ...
0
votes
0
answers
33
views
Could not find module (or one of its dependencies). Try using the full path with constructor syntax?
I am trying to install greppo and this error is popping up.
Here is detail:
Collecting Shapely==1.7.1
Using cached Shapely-1.7.1.tar.gz (383 kB)
Preparing metadata (setup.py) ... error
error: ...
0
votes
1
answer
15
views
Find polygon centroid with Shapely given vertices with lat, lon
Trying to find the centroid of Polygon with Shapely but I do not understand how to tell the library that the vertices are (lon, lat). Perhaps I need to set a projection?
Here is my code:
from shapely....
0
votes
0
answers
25
views
Split lines in GeoPandas
I can find how to split 1 line using geopandas/shapely
def split_line_by_point(line, point, tolerance: float=1.0e-12):
return split(snap(line, point, tolerance), point)
However I can't figure out ...
0
votes
1
answer
34
views
Make Polygon objects from geojson
I have geojson files that can have x amount of polygons so I have a for loop that goes through the file and adds the coords of each polygon to an array. Now i'm trying to index the array when making ...
-2
votes
0
answers
76
views
Select elements inside the boundary of a shape in a numpy matrix
Let's say I have a big numpy matrix of shape (3000, 3000). I want to select/extract elements lying inside a polygonal boundary inside the matrix. For example in the image below, I want to color points ...
0
votes
0
answers
19
views
How to create a uniform continuous grid (i.e., a geopandas.GeoSeries) composed solely of uniform shapely.geometry.BBox in parallel?
I have a script that generates a continuous regular grid (i.e., a geopandas.GeoSeries) that is composed solely of shapely.geometry.BBox instances. This script runs correctly in a single-core. Given ...
0
votes
1
answer
52
views
Polygon Shapely package python issues with airflow, giving false even though point is inside polygon
I'm facing an issue when running a portion of my code that involves the use of Shapely package (for polygon and points) in python on Airflow.
What the code does:
It converts a url to point (using a ...
0
votes
0
answers
17
views
Memory leak logs indicate shapely.wkt.loads
I have a code like below.
shapes_list = [shapely.wkt.loads(entry['shape'] if type(entry) is dict else entry) for entry in entries]
The problem is that tracemalloc points to this place as the memory ...
1
vote
2
answers
38
views
Vectorized creation of shapely Polygons from GeoPandas DataFrame
I have a GeoDataFrame with a point geometry.
From the point geometry, I want to define a square polygon geometry in a quite straightforward manner.
Given a point, the point should be the left bottom ...
0
votes
1
answer
34
views
How may I calculate the centroid of a multipolygon in shapely (not a polygon)
I understand that the centroid of a polygon may be calculated from
from shapely.geometry import Polygon
coordinate_list = [[1,2], [2,3], [5,5]]
output = Polygon(coordinate_list).centroid
However, my ...
0
votes
1
answer
40
views
Finding points in radius of each point in same GeoDataFrame
I have geoDataFrame:
df = gpd.GeoDataFrame([[0, 'A', Point(10,12)],
[1, 'B', Point(14,8)],
[2, 'C', Point(100,2)],
[3, 'D' ,Point(...
2
votes
1
answer
136
views
Add node between existing edge in Networkx Graph generated by OSMnx
I have gotten sensor location data from Highway England. I want to add these sensor locations to OSM multidigraph. How to do that?
import numpy as np
import pandas as pd
import networkx as nx
from ...
0
votes
1
answer
23
views
polygon.contains() returns false value
I have constructed a shapely polygon with the following shape
POLYGON ((28 0, 28 68, 44 68, 44 58, 46 0, 38 45, 46 0, 41 34, 46 0, 42 24, 46 0, 46 7, 46 0, 28 0))
I wrote a code that checks if a ...
1
vote
1
answer
51
views
Splitting Polyline by Polygon and Calculating resultant line lengths in Python
I have a Google Encoded Polyline that I am getting from a call to the Google Maps Directions API.
"apflIffec@lFgKdAfq@jQvo@f[||AzzAdmBx`@hsAfy@p\\hwAkEv`Bhl@toA|s@ni@|sAnvAffDtOphAfvBdxAtd@...
2
votes
0
answers
141
views
Python - georeference png image to geojson of polygons
I have a folder of multiple png images of the same map. The map is on country level and consists of administrative polygons. I have the geojson for this and I want to georeference programmatically, ...
0
votes
0
answers
35
views
Python: Help troubleshooting code for generating a cross section of an object
The aim of my code is to take a 3D object with known internal structure, and generate a 2D cross section based on coordinates in a CSV. It will then draw the cross section with matplotlib. The CSV is ...
0
votes
1
answer
40
views
How to add Point to the LineString?
I am working on vessel tracking. I have setup route path, and vessel current position. Now my aim is to add that current position point to the path and update it. and calculate the length of ...
0
votes
0
answers
27
views
Clip lower value polygons with larger value polygons in shapefile
I have a dataset of circular polygons that correspond to tree crowns.
Many polygons overlap with each other, and some are even completely covered by larger polygons (or larger polygons covered by many ...
1
vote
1
answer
65
views
convert polygon recorded as object to shapely polygon gives 'str' object has no attribute '__array_interface__'
Initially, I have 2 datasets. One is dataset with 45 polygons defined in Excel and another one is geometric coordinates of points. I need to know for each geometric point in which of 45 polygons it ...
1
vote
1
answer
26
views
How to find index of nearest geometry using Geopandas
this is an extension of the question at How to find index of nearest geometry. I need to find the closest point in the Geopandas DF target_df to each point in the Geopandas DF source_df. I can do ...
0
votes
1
answer
57
views
How to convert the following coordinates to 'shapely' polygon?
I have the coordinates from a list in the following format :
[572.71063 453.9848 622.2049 472.86023]
where the four numbers correspond to X1, Y1, X2, Y2 coordinates of a rectangle. (X1,Y1 top left ...
1
vote
0
answers
56
views
why does the result of shapely difference still result in overlaps?
I have a simple case of two overlapping polygons. I want to remove the overlap between them using shapely difference. However, when I do that, the resulting differenced polygon, still overlaps other ...
0
votes
0
answers
38
views
Convert MultiLineString Geometry to LineString in Pandas dataframe
I have a dataframe in which geormtry column is MultiLineString. I need to convert it to LineString to use it in networkx. I used the following code from this question to work with shapefile. But I do ...
3
votes
2
answers
61
views
How to speed up calculating geometry area of 2D boundary arrays?
Background
I have four 2D arrays: lon_centers, lat_centers, lon_bnds, and lat_bnds. bnds means the boundary of each pixel and centers stands for the center of pixels.
Data overview
import numpy as np
...
2
votes
2
answers
174
views
Resample points in a Geodataframe so they stay equally spaced but inside area
I have a geopandas dataframe that contains a complex area and some Point objects representing latitude and longitue inside that same area, both reading from .kml and .xlsx files, not defined by me. ...
1
vote
1
answer
52
views
Improve performance of LineString creation, that currently is created by a lambda function
I have a dataframe like this (this example has only four rows, but in practice it has O(10^6) rows):
DF:
nodeid lon lat wayid
0 1 1.70 42.10 52
1 2 1.80 42.30 ...
0
votes
1
answer
74
views
Creating polygons using rasterio and shapely based on a lon, lat and an array of 0's and 1's
I have an numpy array with 0 and 1's. I am trying to convert the 1's into polygons. I have managed to do so using rasterio and shapely as seen in the code below:
im = np.array([[0, 0, 0, 0, 0],
[0, ...
0
votes
0
answers
63
views
Rasterio mask image fill pixels
I am programmatically processing satellite images and using Rasterio to clip my Area of Interests. All my rasterio masks are currently in the 1:1 aspect ratio (square). I have a specific case where in ...
0
votes
0
answers
31
views
Optimizing the area covered by a fixed set of polygons
I'm trying to use the python package shapely to tackle the following problem. I have a fixed rectangle(say R), which is a "boundary" and inside it, there is a fixed collection of sub-...
0
votes
0
answers
32
views
Using shapely with Pyspark: worker cannot find geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']
I am working in a docker environment where I have a spark cluster set up and I want to use shapely with pyspark.
I installed shapely with conda. In the spark-master I see:
MyEnv/lib/libgeos_c.so
MyEnv/...
0
votes
0
answers
91
views
Splitting Polyline based on starting point using Shapely
I have a network of polylines and point data that I am trying to split out into individual line segments based on a given starting point of the network. I know that this can be done using the ArcGIS ...
1
vote
2
answers
109
views
how to find the coordinates of the intersection point of a line ( parallel to a given line) and other line
I have 3 point A, B, C in the link. The points generate a triangle ABC.2 red lines parallel to AB and distance between them is 30. the green line passes through B and is perpendicular to AC. here is ...
0
votes
0
answers
229
views
Convert the '.coords' to a numpy array instead
I am having hard times to figure out how to solve this warning:
"_len_ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the geoms property instead ...
0
votes
1
answer
91
views
Geopandas way of removing child geometries
I have huge list shapely polygon objects, which has lots of possible geometries, which might fall between each other.
I am trying to find most efficient way of keeping only parent/containing shapes ...
0
votes
0
answers
170
views
Find the smallest enclosing shape in python with a given amount of corners
Say you have two polygons (yellow and orange) representing two observations of the same building. It is likely the building has been modified between the observations.
How can I generate the smallest ...
0
votes
0
answers
46
views
How to perform more complex spatial joins with GeoDataFrames?
Given two GeoDataFrames, g1, g2, I want to get all the rows from g1 which do not intersect any rows from g2, or only touch them.
For this there are some operations which I am missing in the interface:
...
1
vote
2
answers
26
views
geopandas: match accident point to nearest road
I have the following GeoDataFrames:
accidents_c = collection of all accidents in austria as points,
streets = roads in austria as a linestrings (open street map data)
Both have the crs type epsg:3310
...
1
vote
2
answers
116
views
"ConvexHull", "alpha_shape" in python generate different area values why?
I am trying to compute the area of an irregular polygon.
I used "ConvexHull" and "alpha_shape" but the output of the surface(area) is not the same.
any suggestions please?
you ...
0
votes
0
answers
186
views
snap points to polygons/lines at nearest point in shapely
I have a point layer (point) and a line layer (subgrid) which is polygon boundaries converted to lines. I want the points to snap to the nearest point on the line (if within 100m) so I can fetch ...
0
votes
0
answers
23
views
First intersection of a line with multiple shapes on plane
I want to find the first intersection of a line with multiple polygons.
Let's say I have a line going from bottom left to top right in this Image
How can I get the coordinates of the point where the ...
0
votes
1
answer
33
views
Polygon Intersection with LineString (closed curve)
I have a polygon as such
polygon_coords = [(-13585557.004033158, 4498795.070440721), (-13585215.14187693, 4500515.198409752), (-13581108.78850055, 4497863.34704348), (-13581192.612077117, 4497554....
0
votes
0
answers
42
views
Clipping a LineString with Another LineString in Shapely
I have two multi-segment LineString objects: base and clipper.
I know the clipper partially overlaps base.
However, they are not necessarily axis aligned and have floating point coordinates so any ...
0
votes
0
answers
171
views
Can't use shapely when generating .exe from python file with pyinstaller
I'm trying to create a .exe file from a python code; in a part of my code, I use shapely to create a polygon and check if points are in or out of this polygon.
When I create a .exe from my python code ...
0
votes
1
answer
45
views
Shapely Difference on multiple MultiLineStrings
I have written a function blade that returns a Shapely MultiLineString. I would like to be able to run blade n-times, and have each subsequent call only be the difference of all the previous calls.
...
1
vote
2
answers
193
views
Calculate length of LineString in meters using Python
I know this question has been asked before, but I just cannot figure it out. I'm just trying to find the length in meters from a LineString that I've made from two points ('EPSG:4326'). In R I get ...