Questions tagged [geopandas]
GeoPandas is an open source project to make working with geospatial data in python easier. GeoPandas extends the datatypes used by pandas to allow spatial operations on geometric types.
2,744
questions
113
votes
17
answers
145k
views
Error installing geopandas:" A GDAL API version must be specified " in Anaconda
This error raised while installing geopandas. I've looking for its solution on the web, but none of them really explain what happened and how to solve it..
This is the full error:
Collecting ...
80
votes
3
answers
98k
views
Make a union of polygons in GeoPandas, or Shapely (into a single geometry)
I am trying to find the union of two polygons in GeoPandas and output a single geometry that encompasses points from both polygons as its vertices. The geopandas.overlay function gives me polygons ...
54
votes
2
answers
43k
views
GeoPandas Label Polygons
Given the shape file available here: I'd like to label each polygon (county) in the map. Is this possible with GeoPandas?
import geopandas as gpd
import matplotlib.pyplot as plt
%matplotlib inline
...
44
votes
1
answer
51k
views
Converting a geopandas geodataframe into a pandas dataframe
What is the most efficient way to convert a geopandas geodataframe into a pandas dataframe? Below is the method I use, is there another method which is more efficient or better in general at not ...
39
votes
17
answers
106k
views
how to successfully install pyproj and geopandas?
I have tried to install geopandas via I python by running !pip install geopandas, but this fails with "python setup.py egg_info" failed with error code 1 and then Path to long directory. I read online ...
36
votes
3
answers
61k
views
GeoPandas Set CRS on Points
Given the following GeoDataFrame:
h=pd.DataFrame({'zip':[19152,19047],
'Lat':[40.058841,40.202162],
'Lon':[-75.042164,-74.924594]})
crs='none'
geometry = [Point(xy) for ...
34
votes
8
answers
69k
views
Convert geopandas shapely polygon to geojson
I created a circle using geopandas and it returned a shapely polygon:
POLYGON: ((...))
I want this same polygon as a geojson object. I ran across this:
shapely.geometry.mapping(shapelyObject)
...
34
votes
1
answer
39k
views
geopandas point in polygon
I have a GeoDataFrame of polygons (~30) and a GeoDataFrame of Points (~10k)
I'm looking to create 30 new columns (with appropriate polygon names) in my GeoDataFrame of Points with a simple boolean ...
34
votes
1
answer
49k
views
Which geopandas datasets (maps) are available?
I just created a very simple geopandas example (see below). It works, but I noticed that it is important for me to be able to have a custom part of the world. Sometimes Germany and sometimes only ...
33
votes
4
answers
55k
views
Geopandas: how to read a csv and convert to a geopandas dataframe with polygons?
I read a .csv file as a dataframe that looks like the following:
import pandas as pd
df = pd.read_csv('myFile.csv')
df.head()
BoroName geometry
0 Brooklyn MULTIPOLYGON (((-73....
31
votes
3
answers
64k
views
Shapely point geometry in geopandas df to lat/lon columns
I have a geopandas df with a column of shapely point objects. I want to extract the coordinate (lat/lon) from the shapely point objects to generate latitude and longitude columns. There must be an ...
28
votes
4
answers
33k
views
Loading JSON into a GeoDataFrame
I'm having difficulty loading the following JSON containing GIS data (https://data.cityofnewyork.us/resource/5rqd-h5ci.json) into a GeoDataFrame.
The following code fails when I try to set the ...
28
votes
1
answer
30k
views
Converting a column of Polygons from string to GeoPandas geometry
I have a dataframe stored as csv file, one column of which is Polygon object. However, this column is stored as strings instead of GeoPandas geometry object. How can I convert this column to Geopandas ...
23
votes
4
answers
9k
views
why can't I import geopandas?
My only line of code is
import geopandas
and it gives me the error
OSError: Could not find libspatialindex_c library file
has anyone encountered this before? my script was working just fine ...
22
votes
1
answer
36k
views
Colorbar on Geopandas
I am trying to create a Matplotlib colorbar on GeoPandas.
import geopandas as gp
import pandas as pd
import matplotlib.pyplot as plt
#Import csv data
df = df.from_csv('data.csv')
#Convert Pandas ...
20
votes
3
answers
18k
views
Relocating legend from GeoPandas plot
I'm plotting a map with legends using the GeoPandas plotting function. When I plot, my legends appear in the upper right corner of the figure. Here is how it looks like:
I wanted to move the ...
20
votes
2
answers
19k
views
Plotting a geopandas dataframe using plotly
I have a geopandas dataframe, which consists of the region name(District), the geometry column, and the amount column. My goal is to plot a choropleth map using the method mentioned below
https://...
19
votes
2
answers
16k
views
DataFrame with WKT Column to GeoPandas Geometry
I wrote a script to query a PostGIS database, returning a Pandas dataframe like this:
ID ... WKT
0 1 ... LINESTRING(1.5047434 42.6319022,1.5053385 42.6...
1 2 ... ...
18
votes
8
answers
21k
views
RuntimeError: b'no arguments in initialization list'
I'm trying to solve my issue in my own but I couldn't, I'm trying to run this code in every format you can imagine and in ArcGIS pro software it's the same I can't find this error message in any other ...
18
votes
1
answer
36k
views
Get Distance Between Two Points in GeoPandas
I have two points as below. I need to get the distance between them in meters.
POINT (80.99456 7.86795)
POINT (80.97454 7.872174)
How can this be done via GeoPandas?
18
votes
2
answers
19k
views
Geopandas ImportError: The descartes package is required for plotting polygons in geopandas
I'am trying to run a simple geopandas code using ANACONDA spyder. However, I'am encountering an error.
I have included the code and the error as below:
--
here is the code:
import geopandas as ...
17
votes
2
answers
14k
views
Geopandas PostGIS connection
I recently started using Geopandas in python for some of my spatial work and am very pleased with it - I'm currently trying to read in PostGIS features and don't quite understand how to parameterize ...
17
votes
5
answers
41k
views
How to find which points intersect with a polygon in geopandas?
I've been trying to use the "intersects" feature on a geodataframe, looking to see which points lie inside a polygon. However, only the first feature in the frame will return as true. What am I ...
17
votes
1
answer
13k
views
Create a GeoDataFrame from a GeoJSON object
I have a Feature Collection of polygons and I have to first write it in a temporary file to then load it with geopandas.GeoDataFrame.from_file(tmp_json_file), is there any way to not write the ...
17
votes
3
answers
31k
views
Calculate Distance to Nearest Feature with Geopandas
I'm looking to do the equivalent of the ArcPy Generate Near Table using Geopandas / Shapely. I'm very new to Geopandas and Shapely and have developed a methodology that works, but I'm wondering if ...
17
votes
4
answers
18k
views
ImportError: Spatial indexes require either `rtree` or `pygeos` in geopanda but rtree is installed
I am trying to clip spatial data in python but when I run my code...
europe = gpd.clip(worldmap, europe_bound_gdf)
... I get the error:
(ImportError: Spatial indexes require either rtreeorpygeos`.)
...
16
votes
1
answer
15k
views
Multi-Layer .gdb files in Python?
I'm trying to read in some .gdb files(folders?) from here: .
I use GeoPandas and do the following:
# file from local path
mallard = gpd.read_file('./bird-species/E00039600_mallard.gdb/')
# geopandas ...
16
votes
1
answer
10k
views
Using Geopandas, how do I select all points not within a polygon?
I have a DataFrame containing Chicago addresses which I've geocoded into latitude and longitude values, and then into Point objects (making the DataFrame a GeoDataFrame). A small fraction have been ...
16
votes
1
answer
30k
views
Convert Points to Lines Geopandas
Hello I am trying to convert a list of X and Y coordinates to lines. I want to mapped this data by groupby the IDs and also by time. My code executes successfully as long as I grouby one column, but ...
16
votes
1
answer
7k
views
Intersection of Two LineStrings Geopandas
Let's say I have the following to GeoDataFrames of linestrings, one of which represents roads and one of which represents contour lines.
>>> import geopandas as gpd
>>> import ...
16
votes
1
answer
18k
views
GeoPandas: How to obtain bounding boxes for every geometry in a geodataframe
I am using GeoPandas in python and have a valid GeoDataframe of polygons.
0 POLYGON Z ((68.70999999999999 623.1 0, 35.71 6...
1 POLYGON Z ((221.33 645.02 0, 185.7 640.33 0, 1...
2 ...
15
votes
1
answer
18k
views
Convert Geopandas Multipolygon to Polygon
I have a geodataframe with a Multipolygon geometry:
I would like to convert them to Polygons i.e. fill in the holes of multipolygon and make it a single polygon.
I have tried the code from this ...
15
votes
3
answers
25k
views
Conda install some-package hangs with (Solving environment: failed)
I have tried multiple ways but can't conda install packages (in my case, geopandas). I tried geopandas install guide, but get output that the solver runs forever. I tried without creating an ...
15
votes
6
answers
22k
views
Can't install geopandas in Anaconda environment
I am trying to install the geopandas package with Anaconda Prompt, but after I use conda install geopandas an unexpected thing happened:
Collecting package metadata (current_repodata.json): done
...
14
votes
3
answers
16k
views
Concat multiple shapefiles via geopandas
I'm trying to combine multiple shapefiles by implementing the follwing:
import geopandas as gpd
import pandas as pd
for i in range(10,56):
interesting_files = "/Users/m3105/Downloads/area/...
14
votes
2
answers
12k
views
Geopandas reduce legend size (and remove white space below map)
I would like to know how to change the legend automatically generated by Geopandas. Mostly I would like to reduce its size because it's quite big on the generated image. The legend seems to take all ...
14
votes
3
answers
3k
views
Get the nearest distance with two geodataframe in pandas
Here is my first geodatframe :
!pip install geopandas
import pandas as pd
import geopandas
city1 = [{'City':"Buenos Aires","Country":"Argentina","Latitude":-34.58,"Longitude":-58.66},
{'...
13
votes
1
answer
18k
views
Geopandas add labels to points on plot
I have a geodataframe 'all_locations' with a geometry column and a column with the name of the point. Plotting the points on a map works just fine but I want to annotate the points with location name.
...
13
votes
1
answer
11k
views
Plot the Geometry of one row of a GeoDataFrame
I would like to plot the geometry contained in a single row of a geopandas dataframe, but I am having problems. Here an example
import geopandas as gpd
import numpy as np
from shapely.geometry import ...
13
votes
1
answer
10k
views
Can geopandas get a geopackage's (or other vector file) all layers?
I want to use geopandas read a geopackage file, It can read the first layer or specific layer with layer='' parameter. But how can it read all layers? May be like:
all_layers = gp.read_xxxx('xxx.gpkg'...
12
votes
4
answers
16k
views
Write GeoDataFrame into SQL Database
I hope that my question is not ridiculous since, surprisingly, this question has apparently not really been asked yet (to the best of my knowledge) on the popular websites.
The situation is that I ...
12
votes
2
answers
13k
views
Overly Function from GeoPandas Not Working
I simply want to use geopandas to get a union and intersection of two polygonal areas. I define:
import geopandas as gpd
from shapely.geometry import Polygon
polys1 = gpd.GeoSeries([Polygon([(0,0), (...
12
votes
3
answers
14k
views
Change background map for contextily
I have this code:
import pandas as pd
import numpy as np
from geopandas import GeoDataFrame
import geopandas
from shapely.geometry import LineString, Point
import matplotlib.pyplot as plt
import ...
12
votes
1
answer
9k
views
Plotly: How to set choropleth map color for a discrete categorical variable?
I am trying to plot a world map with all the countries having different risk levels (low, moderate and high). I would like to make each risk level a different color but am not sure how to change the ...
12
votes
3
answers
13k
views
What is the most efficient way to convert numpy arrays to Shapely Points?
I have a function that outputs a grid of points as x and y numpy arrays for interpolation, but before I interpolate, I want to use Geopandas to perform an intersection with my research boundary (...
11
votes
2
answers
12k
views
Shapely polygon to binary mask
I have seen this question asked but have not really been able to find a full response. I have a simple shapely polygon, called polygon. I would like to extract this polygon as a binary mask (ideally a ...
11
votes
1
answer
11k
views
GEOPANDAS .sjoin 'index_left' and 'index_right' cannot be names in the frames being joined
I am trying to make a spatial join of 2 geo data frames.
Both the indexes are of this kind:
RangeIndex(start=0, stop=312, step=1)
I get the following error:
-----------------------------------------...
11
votes
2
answers
12k
views
How to use geopanda or shapely to find nearest point in same geodataframe
I have a geodataframe showing ~25 locations represented as point geometry. I am trying to come up with a script that goes through each point, identifies the nearest location and returns the name of ...
11
votes
1
answer
10k
views
How do I test if Point is in Polygon/Multipolygon with geopandas in Python?
I have the Polygon data from the States from the USA from the website
arcgis
and I also have an excel file with coordinates of citys. I have converted the coordinates to geometry data (Points).
Now ...
10
votes
3
answers
3k
views
Geopandas warning on read_file()
I'm getting the following warning reading a geojson with geopanda's read_file():
...geodataframe.py:422: RuntimeWarning: Sequential read of iterator was interrupted. Resetting iterator. This can ...