3 votes
Accepted

Creating a dummy to identify if a point lies within a polygon using Python

Use spatial join import geopandas as gpd import numpy as np poly = gpd.read_file(r'D:\temp_diverse\polygons.shp') point = gpd.read_file(r'D:\temp_diverse\points.shp') df = gpd.sjoin(poly, point[['...
  • 55.4k
3 votes

How to add buffer in to a geo location

Your coordinates are lat long, you need to set the geometry to epsg 4326, then reproject to a crs with meters as units, then buffer: import geopandas as gpd import pandas as pd locations = pd....
  • 55.4k
3 votes
Accepted

Loading a ogr data object into a geodataframe

You can export your selection to an in-memory geojson (or geopackage or some other format inc. shapefile if you must) and read that with GeoPandas. Note use of newer (gdal 2+) gdal.OpenEx syntax ...
  • 54.2k
2 votes

Draw polygons around a set of points and create clusters in Python

This does not guarantee they dont overlap, you will have to manually adjust the parameters until they dont. import matplotlib.pyplot as plt import geopandas as gpd from sklearn.cluster import DBSCAN ...
  • 55.4k
2 votes
Accepted

Implementing polygon self-intersection in Python

You can cross join the df to itself, then check for intersections and intersect. This can be slow, or wont work with large dataframes. For example 1000 rows will become 1 million with the cross join. ...
  • 55.4k
2 votes
Accepted

Convert local file (shp/CSV) into Earth Engine (EE) object

You can convert your dataframe to GeoJSON (https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_json.html). The GeoJSON can then be used to generate an ee.FeatureCollection, ...
  • 10.3k
1 vote
Accepted

Creating point grid over polygon boundary in Python / geopandas

Find the total bounds (xmin, ymin, xmax, ymax), create two lists of x and y coordinates within them. List all combinations of the x and y coordinates, create points. import geopandas as gpd import ...
  • 55.4k
1 vote
Accepted

Computing zonal statistics with Rasterstats in Python

The most common issue with this is your shapefile and raster do not have the same CRS. You can try fixing this with geopandas, converting the shapefile CRS to the raster CRS. default_crs = 'EPSG:4326' ...
  • 1,015
1 vote

Loading a ogr data object into a geodataframe

This works with the pyogrio engine (https://pyogrio.readthedocs.io/en/latest/api.html#pyogrio.read_dataframe) and the current version of geopandas. It can also work with fiona 1.9+ (https://github.com/...
  • 6,206
1 vote
Accepted

Convert GeoPandas linestring from lat long to UTM

You should be able to use to_crs: https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.to_crs.html geometry.to_crs("EPSG:32650") # or geometry.to_crs("+proj=utm +zone=...
  • 6,206
1 vote
Accepted

How to loop through shapefile and identify polygon overlap regions in Python

I am no expert on GeoPandas, not having used it all that much, so my adaptation of the code in your question may not be the cleanest or most efficient but, testing on a made-up data set, this seems to ...
  • 15.8k
1 vote

Create a shapefile of concentric circles in Python by buffering a point at different levels

Create a column with lists of buffered geometries and explode: import pandas as pd import geopandas as gpd pd.options.mode.chained_assignment = None d = pd.DataFrame({'x': [572311], 'y': [6450763 ]}) ...
  • 55.4k
1 vote

Converting geometry from bounds to Polygon using GeoPandas

Use shapely box import geopandas as gpd from shapely.geometry import box lines = gpd.read_file("lines.shp") # total bounds of the shapefile xmin,ymin,xmax,ymax = lines.total_bounds ...
  • 51.8k

Only top scored, non community-wiki answers of a minimum length are eligible