Questions tagged [geopandas]

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

Filter by
Sorted by
Tagged with
40
votes
2answers
36k 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(): ...
18
votes
4answers
15k 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','...
14
votes
1answer
786 views

Why is Shapely's snapping (GEO snaps) not working as expected?

I'm trying to snap two lines to each other using Shapely/Geopandas but the result of the snapping is very odd. I tried : import geopandas as gpd from shapely.geometry import * from shapely.ops ...
13
votes
2answers
6k 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 ...
13
votes
1answer
943 views

Counting features into intersections of Shapely Polygons

I have a geopandas GeoDataFrame containing hundreds of shapely Polygon and MultiPolygon geometries. The polygons overlap in lots of places. I'd like to make a new geometry that contains a count of how ...
12
votes
3answers
10k 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 ...
12
votes
3answers
6k 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 ...
12
votes
2answers
11k 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 ...
11
votes
3answers
8k 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?
11
votes
1answer
601 views

Python: Break linestring based on condition

I have a geopandas dataframe of a bunch of linestrings that have some data associated with each vertex/point: Point_x = (Lat, Lon, Time, ID, Data1, Data2, Data3) The points are converted to ...
10
votes
2answers
9k 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?
10
votes
2answers
6k views

Filter by bounding box in geopandas?

I have a geopandas dataframe in EPSG:4326 and I'd make a new dataframe consisting of all the rows that fall within a certain bounding box. First I get the bounding box that I care about (which is ...
10
votes
4answers
7k views

Reading raw data into geopandas

Is it possible to read raw data into a geopandas GeoDataFrame, a la a pandas DataFrame? For example, the following works: import pandas as pd import requests data = requests.get("https://data....
10
votes
1answer
8k 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 ...
10
votes
1answer
4k views

Geopandas Line Polygon Intersection

I'm trying to find where multiple lines intersect a polygon for two different geodataframes: from shapely.geometry import Polygon, LineString import geopandas as gpd polygon = Polygon([(0, 0), (1, 0)...
9
votes
1answer
4k views

Change marker size in plot with GeoPandas

I have a geodataframe with points and some associated data. I want to plot it on a map using geopandas and have the size of the points correspond to one of the columns in the geodataframe. So far I ...
8
votes
1answer
10k 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 ...
8
votes
1answer
8k 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 ...
8
votes
2answers
4k 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.
8
votes
2answers
10k views

Geopandas Polygon to matplotlib patches Polygon conversion

Unfortunately geopandas plotting is extremely slow and takes a lot of resources, hence I would like to use instead matplotlib for plotting. When I use pure Fiona to open and read the shapefile I ...
8
votes
1answer
3k views

Crop a raster using rasterio and geopandas

I am cropping a set of historic aerial photographs. These photographs have large black areas in the edges (0 value). However there is also valid data with a 0 value. The workflow I am using is: Load ...
8
votes
1answer
3k views

Sharing a Folium Interactive Map w/ Embedded Markers

I have been experimenting with a few Python packages that have great potential for my dissertation research. Since I use pandas for pretty much everything, geopandas was a natural choice for working ...
7
votes
4answers
14k views

GeoPandas: return lat and long of a centroid point

I would like to return the lat and lon or x and y from the point object in the following series as I plan to link them with an API I built that links OSM and NetworkX. The centroids will be added as ...
7
votes
3answers
10k 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 ...
7
votes
1answer
7k 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 ...
7
votes
1answer
4k 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 ...
7
votes
1answer
2k views

How do I return the percentage of an area of a polygon intersecting another polygon?

Using shapely or geopandas: Suppose I have a shp file V and another shp file Z. For each polygon v in V, and for each polygon z in Z, I would like to know what percentage of the area of z falls ...
7
votes
1answer
655 views

Remove empty geometries from geodataframe

Since geopandas can't perform overlay/intersection with lines, I found a workaround: import geopandas as gpd import fiona from shapely.geometry import shape, MultiPolygon, LineString, MultiLineString ...
6
votes
1answer
7k views

Cannot get plot() in geopandas to produce a map of the GeoDataFrame

I have installed all the necessary and optional modules for geopandas (with the exception of rtree) as listed at http://geopandas.org/install.html I am following the tutorials from this site and also ...
6
votes
2answers
2k 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).
6
votes
1answer
2k views

Trouble when Dissolving Geopandas Polygons

I have dissolved polygons with geopandas. However, the head of attribute table became values of this table. How can I fix this trouble? See:
6
votes
1answer
497 views

Iterating features and buffering using GeoPandas?

I have a shapefile with many large polygons and would like to process each polygon individually because spatial operations on the entire dataset are too big for memory. For instance, iterate shapefile,...
6
votes
1answer
1k views

GeoPandas GeoDataFrame plot statistics - how?

The plot method of a GeoPandas GeoDataFrame overrides the DataFrame parent method to plot the geometries of the associated GeoSeries. This is very convenient, but I'd also like to use the easy ways ...
6
votes
1answer
6k views

geopandas: can't save geojson

My task is to upload geojson, add data from corresponding csv, drop some columns, then save it back to geojson. However, after I did everything, added csv data (gj.join(df) ), etc, I can't save it ...
6
votes
2answers
7k views

GDAL ImportError: DLL load failed: The specified module could not be found

I'm running Python 3.5.4 on Anaconda and i'm trying to install geopandas. I've followed the instructions to install geopandas here - http://geoffboeing.com/2014/09/using-geopandas-windows/ - but ...
5
votes
2answers
2k views

geopandas dissolve overlapping polygons

Goal is to group polygon (1,2,4) and polygon (3) based on overlap. All polygons are part of the same shapefile layer. In ArcMap I can simply do dissolve and uncheck Create multipart features. ...
5
votes
2answers
6k views

How do I write a GeoPandas dataframe into a single file (preferably JSON or GeoPackage)?

I'm new to GIS and having a basic beginner problem. I've got data in the form of a geopackage .gpkg from GADM.org. I can read in and use the data without problem using Geopandas (via built-in Fiona)....
5
votes
1answer
17k views

Geopanda write GeoDataFrame into shapefile or spatialite

I trying to save file from GeoDataFrame to shapefile or spatialite. But for some reason i got error: My GeoDataFrame appear correctly without any issuesi look's like there is something wrong with my ...
5
votes
1answer
6k 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
2answers
2k views

GeoPandas spatial join and count

I have following two GeoDataFrames. One with the crime count per polygon per year. Polygon Year total_crime shape_area geometry 0 0 2009 1 3.266388e+06 ...
5
votes
1answer
7k 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. ...
5
votes
2answers
3k views

Geopandas: counting the number of raster pixels within a shapefile polygon

I have a shapefile that I have loaded as a geopandas dataframe, and it has a geometry column containing polygons and multipolygons. My end goal is to do some zonal computations on a GeoTiff raster, ...
5
votes
1answer
3k 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 ...
5
votes
1answer
6k 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
2k views

Calculating length of polygon in geopandas?

For example to calculate the area is like this: df['area']=df['geometry'].area How do we find the length of the perimiter?
5
votes
1answer
844 views

Dissolve causes 'No Shapely geometry can be created from null value' in geopandas

When I do dissolve: With this specific shapefile happens with other similar it is working fine. Also I checked for null values in the geometry and there weren't any. data2 = pst[pst['PROP_TYPE'].str....
5
votes
2answers
3k views

How to merge polygons using GeoDataFrame?

I would like to merge polygons (parcels) which are inside the white road (which is a hole) -- see the picture. The way I'm doing this is certainly a bad way because later, in my script, I have this ...
5
votes
1answer
312 views

How to do snapping in Geopandas?

I want to perform snapping in all the lines of a shapefile that don't connect to the nearest other lines. It would be okay to have a tolerance of 0.5 meters. So between 0.5 it should connect to the ...
5
votes
1answer
816 views

Difference between lines and polygons using geopandas

I wanted to geopandas.overlay() on lines and polygons : get the geometries from the lines that are not in the polygons. I tried using geopandas for this : result = gpd.overlay(my_lines, my_polygons, ...
5
votes
2answers
3k views

Geopandas: Write layer back into GeoDataBase

I use geopandas (which uses fiona) to read a GeoDataBase layer (using driver="OpenFileGDB") into a geodataframe for easy manipulation. read_shp = gpd.read_file(GDB_file, layer=layer_choice) That ...