Questions tagged [geopandas]

an open source project to make working with geospatial data in Python easier.

Filter by
Sorted by
Tagged with
16
votes
3answers
12k views

Dissolving polygons based on attributes with Python (shapely, fiona)?

I have been trying to create a function that does basically the same thing that the QGIS "dissolve" function. I thought it would be super easy but well apparently not. So from what I have gathered ...
48
votes
2answers
53k views

Convert a pandas DataFrame to a GeoDataFrame

This seems like a simple enough question, but I can't figure out how to convert a pandas DataFrame to a GeoDataFrame for a spatial join. Here is an example of what my data looks like using df.head(): ...
31
votes
5answers
26k views

GeoPandas: Find nearest point in other dataframe

I've got 2 geodataframes: import geopandas as gpd from shapely.geometry import Point gpd1 = gpd.GeoDataFrame([['John',1,Point(1,1)],['Smith',1,Point(2,2)],['Soap',1,Point(0,2)]],columns=['Name','ID','...
11
votes
2answers
12k views

Creating polygon grid using Geopandas

I'm working with a geodataframe of points and I need to create a grid of rectangular polygons. I know how to have bounds of the geodataframe with gdf.geometry.bounds. Now using this information and ...
19
votes
2answers
18k views

Getting polygon areas using geopandas?

Given a geopandas GeoDataFrame containing a series of polygons, I would like to get the area in km sq of each feature in my list. This is a pretty common problem, and the usual suggested solution in ...
19
votes
3answers
10k views

Adding GeoPandas Dataframe to PostGIS table?

I have a simple GeoPandas Dataframe: I would like to upload this GeoDataframe to a PostGIS table. I have a Database setup with the PostGIS extension already but can't seem to add this Dataframe as a ...
16
votes
3answers
12k views

What units are used by GeoPandas/Shapely area and distance functions?

it looks like a silly question, yet I can't find clear answer on that: what units geopandas/shapely use calculating distance/area between objects?
13
votes
1answer
10k views

GeoPandas to_file() saves GeoDataFrame without coordinate system

I have GeoPandas 0.2.1 py27_0 fiona 1.7.0 np110py27_1 Python 2.7.10 installed in Anaconda 2-4.1.1-Windows-x86 environment. I am able to construct GeoDataFrame by reading input datasets and ...
5
votes
1answer
10k views

Split lines at points using Shapely

I'm trying to split a shapefile of geometry type 'line' at a shapefile of geometry type 'point. These points are snapped to the lines and are the start points/end points of other line shapefiles. ...
1
vote
1answer
75 views

How to obtain mean, maximum, and mininum of all points located within polygons using spatial joint in python?

I am trying to estimate summary statistics of points located inside a polygon. Each points in the point layer is associated with N attributes. My target is to summarize (say mean, min,..) the ...
16
votes
3answers
8k views

geopandas spatial join extremely slow

I am using the code below to find a country (and sometimes state) for millions of GPS points. The code currently takes about one second per point, which is incredibly slow. The shapefile is 6 MB. I ...
11
votes
2answers
12k views

Rasterize a shapefile with Geopandas or fiona - python

I need to rasterize a really simple shapefile a bit like this http://tinyurl.com/odfbanu. Which is just a shapefile coutaining counties in the US.I have seen this previous answer : GDAL RasterizeLayer ...
7
votes
1answer
6k views

Plot shapefile on top of raster using plot and imshow from matplotlib

I need to plot a shapefile on top of a raster. I would like to use the python package rasterio and some combination of fiona or geopandas to load the shapefile. I found an example in the rasterio ...
8
votes
1answer
13k views

Turning GeoDataFrame of x,y coordinates into Linestrings using GROUPBY?

I have a dataframe of X,Y coordinates that represent points along the paths taken by several different entities. Pseudo-data here, but it is roughly of the form: entity_id lat lon time 1001 ...
5
votes
1answer
10k views

Intersecting two shape problem using geopandas

I'm trying to intersect two polygons based on the following link, intersecting two shapefiles from Python or command line But problem occured that shows a "ValueError: Geometry column cannot contain ...
10
votes
1answer
12k views

Geopandas buffer using geodataframe while maintaining the dataframe

The objective is to create a geoDataFrame with buffered geometries AND with all the "attributes" of the original geodataframe. I am able to perform a buffer on my geoDataFrame using: gdfHybasBuffer ...
6
votes
1answer
4k views

How can I superimpose a geopandas dataframe on a raster plot?

I have a geopandas dataframe countries with country polygons, and a raster dataset raster (read with rasterio). I've already aligned the two as follows: countries = countries.to_crs(raster.crs.data) ...
2
votes
1answer
4k views

Geopandas/folium map not displaying?

I'm trying to use a combination of geopandas, pandas and folium to create a polygon map that I can embed incorporate into a web page. For some reason, it's not displaying and wonder if anyone can ...
1
vote
1answer
2k views

Casting geometry to MULTI using GeoPandas?

Shapefiles can mix simple POLYGONs and MULTIPOLYGONs in the same data source. Spatial databases like PostGIS and SpatiaLite are strict, and will not put a POLYGON in a MULTIPOLYGON geometry column. I'...
3
votes
1answer
1k views

geopandas.intersects() over each row

In trying to answer Writing selected features to shapefile using OGR and Python? I ran into problems with geopandas.GeoSeries intersects methods. I have the following line and polygon: import pandas ...
1
vote
3answers
10k views

Only read specific attribute columns of a shapefile with Geopandas / Fiona

Having geopandas installed in my Python environment, I can read a shapefile into a geodataframe with In: import geopandas as gpd myShapefile = gpd.read_file(path_to_my_shapefile) print(myShapefile) ...
1
vote
0answers
207 views

Why is Union in ArcMap much faster than other approaches? [closed]

Taking the union* of these two large shapefiles file1 file2 locally using ArcMap takes appr. 10 min. Over the last few weeks, I've tried to obtain the same results using other, open-source ...
8
votes
2answers
6k views

Merging overlapping features using Geopandas?

I have a Shapefile with overlapping features. Is there an easy way to merge them with geopandas? I found a way with shapely, but I would like to do it with geopandas directly.
12
votes
3answers
5k views

Find all neighbors using geopandas

I am wondering whether it is possible to identify all neighbors to each polygon using only python (with, e.g., geopandas) in the same way that can be done with python in QGIS (Find neighbors polygon).
18
votes
2answers
15k views

Joining (concat) list of similar dataframes in geopandas?

I have a list of dataframes, all of the same structure and all are polygons. How can I add them all together using geopandas?
5
votes
1answer
4k views

How do I convert Eastings and Northings projection to WSG84 in geopandas?

I'm very new to projections and struggling to convert a map dataset from OSGB36 (Eastings and Northings) to WGS84 (lat/longs). I've used geopandas to import a shapefile. Now I want to export it as ...
8
votes
4answers
13k views

Handling KML/CSV with geopandas - DriverError: unsupported driver: u'CSV'

I'm trying to import a dataset of UK postcode districts UK postcode districts from Google Fusion tables into geopandas with the aim of splicing it to a dataset of house prices. The problem is that ...
3
votes
1answer
1k views

Reading data to geopandas using WFS?

I'm new to GIS. Trying to use Finnish population data on 1km tiles available here: http://www.stat.fi/org/avoindata/paikkatietoaineistot_en.html The WFS service is here: http://geo.stat.fi/geoserver/...
6
votes
1answer
6k views

Reading the names of geodatabase file layers in Python

I'm looking at New York City's Projected Sea Level Rise dataset. This dataset states that it is: Geodatabase of projected sea level rise based on models released by New York City Panel on Climate ...
1
vote
3answers
4k views

python mask netcdf data using shapefile (xarray & geopandas) [duplicate]

I am using the following packages: import pandas as pd import numpy as np import xarray as xr import geopandas as gpd I have the following objects storing data: print(precip_da) Out[]: <...
8
votes
1answer
15k views

How to extract long and lat from geometry column in GeoPandas?

I read a shapefile with GeoPandas and I get a nice table with a column "geometry". This column contains shapely.geometry.polygon.Polygon or shapely.geometry.multipolygon.MultiPolygon object. import ...
5
votes
1answer
9k views

Changing colours in GeoPandas?

I have a very simple map (http://www.nyc.gov/html/dcp/download/bytes/nybb_15b.zip) and I have never before worked with shapefiles in any way. Can someone tell me what I need to do in order to change ...
5
votes
1answer
3k views

Insert Geopandas GeoDataFrame into Spatialite database

Is it possible to insert a Geopandas GeoDataFrame directly into a Spatialite database with Python so that the geometry column of the GeoDataFrame becomes a proper geometry table in the database which ...
5
votes
1answer
2k views

Speed up row-wise point in polygon with Geopandas

I have a geopandas GeoDataframe which contains some attributes and a geometry column which is filled with shapely Point(lon, lat) objects. Moreover, there is a GeoSeries which is equally indexed as ...
4
votes
1answer
2k views

TypeError: Input geometry column must contain valid geometry objects

I'm working in a urban biodiversity project and I have a csv file for a birds inventory with a column index called 'geom' composed by multypolygons as this: name geom ...
4
votes
1answer
1k views

Writing GeoPandas data frame to PostGIS?

Similar question has to this has been asked before Adding GeoPandas Dataframe to PostGIS table? I have followed the example but I am running into an issue I cannot solve. There is some geometry ...
3
votes
0answers
1k views

Overlay Union Geopandas improve performance

How to speed up the "union" of two shapefiles using geopandas? I have two large shapefiles: geodataframe_left.shape = (3610, 12) (500 MB) (link) geodataframe_right.shape = (16396, 3) (200 MB) (link)...
2
votes
3answers
325 views

Mask xarray dataset using a shapefile [closed]

I have an xarray dataset of some satellite data and I'd like to mask it using a shapefile. I have previously been doing this using a combination of PIL, numpy and gdal but it would be cleaner to do ...
2
votes
1answer
5k views

How to select features where column matches a regex and save them in a new shapefile?

I want to select features from a shapefile where the value of column matches a regex then save only the selected features in a new shapefile.(I used regex101.com to write the regex and check if it's ...
7
votes
4answers
13k views

How to use GeoSeries.distance to get the right answer

When I want the distance between two points [(117.454361,38.8459879),(117.459880 ,38.846255)] (longitude,latitude) on the earth, I take the GeoSeries.distance method, but the method does not give me ...
7
votes
1answer
10k views

Add CRS to a shapefile in Geopandas?

I am trying to add CRS to a shapefile that I am exporting: shp1= gpd.read_file(i[1],encoding='iso8859_7',crs_wkt='2100') shp1.to_file(out,encoding='iso8859_7',crs_wkt='2100') When I import it to a ...
5
votes
2answers
8k views

Calculate distance between a coordinate and a county in GeoPandas

I have a single coordinate and a GeoPandas Dataframe representing US counties whose geometry is polygons that form the boundary of counties. Each of these polygons is also given through lat/lon pairs. ...
5
votes
1answer
2k views

Buffer GeoPandas dataframe based on a column value

I have a GeoPandas dataframe with a series of polygons in the geometry column. I also have a bufferdist column for each row containing an integer. The dataframe looks like bufferdist geometry 0 ...
5
votes
1answer
2k views

Dissolve not based on attribute in GeoPandas?

I would like to dissolve a shapefile regardless of attribute content using geopandas. The regular dissolve can be accomplished with something like this: import geopandas all = geopandas.read_file(...
4
votes
1answer
2k views

Find csv lat and long points in a shapefile polygon with geopandas spatial index

I have a csv with two sets of latitude and longitude points, and a shapefile with espg 4326. I want to find which points are inside the shapefile. I've been following the guide here which uses a ...
3
votes
1answer
3k views

Python Shapely - filling small gaps between multi polygons

I have a set of rectangular polygons, which currently form a directional path. The library I am using is Python Shapely / GeoPandas. The issue I am having is as the path changes direction, there are ...
3
votes
2answers
4k views

How do I extract points from a LineString or Polygon data frame and make a dictionary of point data frames?

I am building some pre-processing routines for 3D visualization of GIS data and I have several line and polygon shapefiles with multiple features. I want to extract the points for each of the features ...
3
votes
2answers
676 views

Building GeoDataFrame row by row

I am trying to build GeoDataFrame row by row, from an empty one. The equivalent using only pandas would be something like this : df = pandas.DataFrame(columns=['a','b','c','d']) df.loc['y'] = ...
3
votes
1answer
2k views

Inserting LiDAR points (from laspy) in GeoDataFrame without using a numpy array?

Working with Python 3.6 (Anaconda) under Windows using a laspy fork that works with Python 3 (https://github.com/sethrh/laspy). I am loading a LAS file to a GeoPandas GeoDataFrame to eventually ...
3
votes
1answer
961 views

Intersecting MultiLinestring based geodataframes with geopandas?

I would like to perform the following operation using geopandas. The segments are delimited by red points and the blue items are attribute information. My inputs are the first and second line ...