shapely

Remove Sliver Polygons Using Shapely, Matplotlib in Python

Remove Sliver Polygons Using Shapely, Matplotlib in Python Question: I have code that starts with points, buffers them into polygons, and finds overlapping regions and makes them into their own polygons. I ran into problems trying to color each polygon individually, because there are 7 very, very small polygons near the center of the overlapping …

Total answers: 1

Draw and Color Overlapping Circles with Shapely in Python

Draw and Color Overlapping Circles with Shapely in Python Question: I am trying to draw and color overlapping circles using Shapely in Python. I’ve looked at several similar examples but keep running into problems with depreciated functions (like cascaded_union) Here’s my code so far: import matplotlib.pyplot as plt from shapely.geometry import Point, Polygon, MultiPoint, MultiPolygon …

Total answers: 1

Vectorized creation of shapely Polygons from GeoPandas DataFrame

Vectorized creation of shapely Polygons from GeoPandas DataFrame Question: 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 corner in a square with sides 250 units of length. I.e, …

Total answers: 3

Generate points which lie on linestring in geopandas

Generate points which lie on linestring in geopandas Question: Lets say that I have the following geodataframe: import geopandas as gpd from shapely.geometry import LineString line = LineString([(2.2, 4.2), (7.2, -25.1), (9.26, -2.456)]) gdf = gpd.GeoDataFrame(index=[0], crs=’epsg:4326′, geometry=[line]) Now what I want to achieve is to generate, lets say, 100 points that randomly lie on …

Total answers: 1

how to convert geojson to shapely polygon?

how to convert geojson to shapely polygon? Question: i have a geoJSON geo = {‘type’: ‘Polygon’, ‘coordinates’: [[[23.08437310100004, 53.15448536100007], [23.08459767900007, 53.15448536100007], [23.08594514600003, 53.153587050000056], (…) [23.08437310100004, 53.15448536100007]]]} and i want to use these coordinates as an input to shapely.geometry.Polygon. The problem is that Polygon only accepts tuple values, meaning i have to convert this geojson to …

Total answers: 3

Syntax for creating a new, empty GeoDataFrame

Syntax for creating a new, empty GeoDataFrame Question: I have a GeoDataFrame (let’s call it Destinations) that was made from a point shapefile using GeoPandas. For every feature (correct me if the terminology is wrong) in Destinations, I need to find the nearest node on a graph and save that node to another GeoDataFrame (let’s …

Total answers: 2

How to get the endpoint of a LineString in Shapely

How to get the endpoint of a LineString in Shapely Question: Linestring1 = LINESTRING (51.2176008 4.4177154, 51.21758 4.4178548, **51.2175729 4.4179023**, *51.21745162000732 4.41871738126533*) Linestring2 = LINESTRING (*51.21745162000732 4.41871738126533*, **51.2174025 4.4190475**, 51.217338 4.4194807, 51.2172511 4.4200562, 51.2172411 4.4201077, 51.2172246 4.4201654, 51.2172067 4.420205, 51.2171806 4.4202355, 51.2171074 4.4202929, 51.2170063 4.4203409, 51.2169564 4.4203641, 51.2168076 4.4204243, 51.2166588 4.4204833, 51.2159018 4.420431, 51.2154117 4.4203843) …

Total answers: 4

Draw perpendicular line of fixed length at a point of another line

Draw perpendicular line of fixed length at a point of another line Question: I have two points A (10,20) and B (15,30). The points generate a line AB. I need to draw a perpendicular line, CD, on point B with a length of 6 (each direction 3 units) in Python. I already have some properties …

Total answers: 4

How to use geopanda or shapely to find nearest point in same geodataframe

How to use geopanda or shapely to find nearest point in same geodataframe Question: I have a geodataframe showing ~25 locations represented as point geometry. I am trying to come up with a script that goes through each point, identifies the nearest location and returns the name of the nearest location and the distance. I …

Total answers: 2

How to calculate the center of gravity with shapely in python?

How to calculate the center of gravity with shapely in python? Question: I discovered shapely but I did not find how to calculated the center of gravity of a polygon! Does someone have the solution? Asked By: Vianney Bailleux || Source Answers: If your polygon has a uniform density, its center of mass coincides with …

Total answers: 3