15 votes
Accepted

Calculating area of lat/lon polygons without transformation using GeoPandas

Overview Since version 0.7.0 geopandas has embedded the pyproj library as the crs object. pyproj, since version 2.3.0, has the ability to calculate the area of arbitrary polygons on a sphere. (see ...
user avatar
  • 884
10 votes
Accepted

GeoPandas Warnings unless wrong EPSG is used

You get that warning because EPSG:4326 (WGS84) is geographic CRS and its unit is degree. The key message here is "Geometry is in a geographic CRS". You don't get a warning when using EPSG:...
user avatar
9 votes
Accepted

Converting polygon to list of coordinates with shapely

Here is another solution using the mapping(): returns a new, independent geometry with coordinates copied from the context. import json from shapely.geometry import Polygon, mapping poly = Polygon([...
user avatar
  • 24k
8 votes

Filtering by geometry type in GeoPandas

Using geometry.type=="MULTIPOLYGON" is (15 times in my computer) faster. at_geometries[at_geometries.geometry.type=="MULTIPOLYGON"]`
user avatar
8 votes
Accepted

Filtering by geometry type in GeoPandas

There are many solutions (see How to filter a geodataframe by geometry type? for example) With .loc as you but with geometry.type or geom_type gdf0 = gdf.loc[gdf.geometry.geometry.type=='MultiPolygon']...
user avatar
  • 51k
8 votes
Accepted

Calculating polygon area within other polygon using GeoPandas

Use GeoPandas Overlay polygons = gpd.read_file("Polygons.shp") small_polygon = gpd.read_file("Small_polygon.shp") Intersection of the two GeoDataFrames: result = gpd.overlay(...
user avatar
  • 51k
7 votes
Accepted

Pandas DataFrame to GeoDataFrame with Polygon geometry using groupby and lambda

Instead of using apply this can be done using the agg method with named aggregations. The only thing is that agg cannot yet operate on multiple columns, so the points must be condensed to a single ...
user avatar
  • 884
7 votes

Fastest way to extract the neighbours of a GPS point among millions of other points?

There are many clustering algorithms you can use, for example DBSCAN: Very large n_samples, medium n_clusters import geopandas as gpd import pandas as pd from sklearn.cluster import DBSCAN import ...
user avatar
  • 52.2k
7 votes
Accepted

GeometryCollection causing RuntimeError in Python

intersection process must have returned different geometries. In this case, it is usual to get GeometryCollection. For layers in the image, intersection may return all geometry types (point, line, ...
user avatar
7 votes
Accepted

How to get all records if WFS output limited to 1000?

Check the service capabilities https://geoservices.noord-holland.nl/ags/services/oi_dataservice_alg/MapServer/WFSServer?request=GetCapabilities&service=WFS&version=2.0.0 <ows:Constraint ...
user avatar
  • 52.4k
6 votes

GeoPandas write esri-shape file failure: AttributeError: 'DataFrame' object has no attribute 'to_file'

The error clearly states that grid_up2geo is not a GeoDataFrame, but DataFrame. You need to create a GeoDataFrame to be able to use to_file method. You can easily create a GeoDataFrame from a ...
user avatar
6 votes

Converting polygon to list of coordinates with shapely

Input data you have is probably a string(?) and it is almost in WKT (Well-known Text) format. Therefore, shapely.wkt.loads method helps you. But first, you have to have closed coordinates. That's, the ...
user avatar
6 votes

Converting polygon to list of coordinates with shapely

Easier with simple list comprehension: poly = Polygon([[14.471329,46.037286],[14.467378,46.036733],[14.468441,46.034822]]) poly.wkt POLYGON ((14.471329 46.037286, 14.467378 46.036733, 14.468441 46....
user avatar
  • 51k
6 votes
Accepted

Creating minimal enveloping polygon to set of geometries in GeoPandas

What you need is a concave hull. Create a list of all polygons coordinates and concave hull them. This takes about 30 s for two polygon groups so try it on a subset if you have a very large dataset. ...
user avatar
  • 52.2k
5 votes
Accepted

How to create a simple polygon from coordinates in GeoPandas with Python?

This simple code is working for Python 3.9 and geopandas 0.9.0, and it works for older versions too: import geopandas as gpd from shapely.geometry import Polygon lat_point_list = [50.854457, 52....
user avatar
  • 524
5 votes

Plotting multiple maps using GeoPandas

I usually plot multiple maps as following. import pandas as pd import geopandas as gpd import matplotlib.pyplot as plt fig, axs = plt.subplots(5, 5, figsize=(25, 25)) axs = axs.flatten() for idx in ...
user avatar
  • 374
5 votes
Accepted

Geopandas spatial join giving empty result

You need to specify the how parameter which is "inner" by default (see docu here). "inner" keeps only the left geometries once the condition ("within") is True for both ...
user avatar
5 votes
Accepted

How does GeoPandas' representative_point() work?

Geopandas uses shapely for geometry manipulations. In shapely representative_point is a call to the GEOSPointOnSurface method in the GEOS C library. The GEOS library is also used by PostGIS, so I'm ...
user avatar
  • 884
5 votes

Calculating polygon area within other polygon using GeoPandas

I don't use geopandas but in any GIS system what you are describing is a Union or Intersect style operation. This you can apply at the dataset level and I suspect would be far more efficient than ...
user avatar
  • 38.8k
5 votes

Get the right SRID (AUTHORITY) of the .shp

EPSG codes don't just define CRS, which is I think what you are seeking here. In your example none of the EPSG authority codes using in the WKT describe the CRS and GIS applications that parse the ...
user avatar
  • 11.9k
5 votes
Accepted

Extracting the space between polygons

Try unary_union to dissolve all obstacles to a big multipolygon. Then create a rectangle around the multipolygon and difference: import geopandas as gpd df = gpd.read_file(r'C:\GIS\data\tempdata\my....
user avatar
  • 52.2k
5 votes

Converting multiple x,y coordinates to new coordinate system using GeoPandas

Just convert to GeoSeries (geometry) and reproject them one at a time: import geopandas as gpd import numpy as np EPSG_ITM = 2157 EPSG_Irish = 29902 # load csv file gdf = gpd.read_file(r"file....
user avatar
  • 52.7k
5 votes

Converting multiple x,y coordinates to new coordinate system using GeoPandas

You can make a multipoint-typed GeoDataFrame using the following script. Sample CSV: M1_EASTING,M1_NORTHING,M2_EASTING,M2_NORTHING,M3_EASTING,M3_NORTHING -361065,7600889,-361310,7600913,-361205,...
user avatar
5 votes
Accepted

Reading Inspire XML with GeoPandas

This is a GML file with layers. To read a layer, pass the layer name: In [6]: db = gpd.read_file("DB-Netz_INSPIRE_20200217.xml",layer="RailwayLine") /home/rowlings/.local/lib/...
user avatar
  • 52k
5 votes

Reading Inspire XML with GeoPandas

You can list all the layers using fiona.listlayers(datasource): import fiona as fio import geopandas as gpd gml = "/vsizip/DB_Inspire_XML_2019.zip" for layer in fio.listlayers(gml): ...
user avatar
  • 52.7k
4 votes

Count overlapping features using Geopandas

It took quite a bit of head scratching, but I finally got there! Here is how you can do it in GeoPandas. def count_overlapping_features(in_gdf): # Get the name of the column containing the ...
user avatar
  • 1,737
4 votes

Geopandas simplify results in gaps between polygons

As mentioned, you need a topology aware simplification algorithm. For this I use the topojson package: gdf = <geopandas dataframe> import topojson as tp topo = tp.Topology(gdf.to_crs({'init':'...
user avatar
4 votes

Grouping GeoDataFrame by column while comparing feature area and adding values to new column with GeoPandas

With such a question you will probably find more luck on the Stack Overflow. However, I may try to resolve it. There are several hints regarding your code: there are more columns than just "...
user avatar
  • 24k
4 votes

Finding nearest point in other GeoDataFrame using GeoPandas

As of v0.10.0 geopandas supports sjoin_nearest natively - see here
user avatar
  • 153
4 votes

Strange warning/error when working with polygons

This is not an error on user side. It is the result of a recent change in Numpy 1.21 coupled with a way shapely implements (rather not implements) __array_interface__. There is nothing the user should ...
user avatar
  • 2,139

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