Questions tagged [geopandas]

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

Filter by
Sorted by
Tagged with
49
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','...
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 ...
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 ...
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?
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 ...
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 ...
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?
15
votes
7answers
11k 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 io import pandas as pd import requests data = requests.get("https:/...
14
votes
3answers
12k 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 ...
14
votes
2answers
16k 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)....
14
votes
1answer
1k 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
6answers
25k 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 ...
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 ...
13
votes
1answer
1k 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
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).
12
votes
1answer
8k 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)...
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 ...
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 ...
11
votes
1answer
750 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
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 ...
10
votes
1answer
5k 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 ...
10
votes
1answer
8k 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 ...
10
votes
4answers
9k 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 ...
10
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 ...
9
votes
2answers
14k 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 ...
9
votes
1answer
3k 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 ...
9
votes
1answer
26k views

Create a polygon from coordinates in GeoPandas with Python

I was trying to create a simple Polygon from a list of coordinates and export it to multiple formats (including shapefile and GeoJSON) and wanted to automate it using Python. There were some good ...
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 ...
8
votes
1answer
10k 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 ...
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 ...
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.
8
votes
1answer
4k 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
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
2answers
7k views

List all polygon vertices coordinates using geopandas

I'm trying to list all polygon vertices coordinates of a rectangle with four corners and a hole with four corners. I drew the vertices in this order: import geopandas as gpd #import matplotlib.pyplot ...
7
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 ...
7
votes
1answer
5k views

Shapely polygon union results in strange artifacts of tiny, non-overlapping areas

I am not sure if this is a shapely bug or a problem with my polygons. I have a bunch of polygons that look like this: They are level-12 watersheds provided by HydroBasins, and are presumably non-...
7
votes
1answer
25k 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 ...
7
votes
1answer
7k 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 ...
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 ...
7
votes
1answer
2k 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,...
7
votes
2answers
5k 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 ...
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 ...
7
votes
2answers
2k views

Buffering line with flat cap style using GeoPandas?

I'm interested in buffering a linestring geometry using a flat cap style rather than the default round cap style using GeoPandas. I see shapely, which geopandas is based off, has the option to do that:...
6
votes
2answers
3k views

geopandas error “minimums more than maximums”

I posted this question on stackoverflow here, but it seems that gis.stackexchange is the more appropriate platform. I am trying to merge two geodataframes in geopandas (want to see which polygon each ...
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
2answers
20k views

Filter a GeoPandas dataframe for points within a specific country

I have a dataframe of health survey data which is geotagged, called momdata. I have converted the dataframe to a GeoPandas dataframe, and used the geotags as the geometry column within the dataframe, ...
6
votes
3answers
2k views

Randomly sample from geopandas DataFrame in Python

I am reading a shapefile as geopandas DataFrame and them using pandas subset method to select a region. geodata = gpd.read_file(bayshp) geodata.dtypes geodata.head(10) OBJECTID FIPSSTCO ...
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) ...
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 ...

1
2 3 4 5
14