Questions tagged [geodataframe]
is a pandas.DataFrame that has a column with geometry
83
questions
-1
votes
0
answers
16
views
I m computing queens contiguity PySal weigth but i have problem that w.n!=dataframe dimension [closed]
Im computing the spatial weights in GeoDataFrame but i have a different dimensions between the weights dim and the rows dim... because I want these two dim to be equal!!!
w_queen = weights.contiguity....
1
vote
1
answer
33
views
Encoding issue while making GeoDataFrame from shapefile using URL
The dataset I want to use have some special characters like ü, õ, ö, ä. which cause encoding issue.
The below example runs totally fine and doesnt mess up those characters.
gdf_local = gpd.read_file(r'...
2
votes
2
answers
71
views
Using Shapely methods (explain_validity and make_valid) on shapefile
I'm trying to find and repair invalidity in my polygons. I have already found out that 10 polygons have self-intersection problems in QGIS, trying the same thing with shapely.
This is my code:
import ...
0
votes
0
answers
30
views
Applying functools.reduce to make Geopandas geometries valid for unary_union
I want to calculate the total area of a GeoDataFrame, year_df, where the geometries overlap so I need to take the union. I was running into an issue with unary_union (some TopologyException that the ...
1
vote
0
answers
39
views
A faster way to extract geometry xy of geodataframe
I need a faster way to extract geometry xy of a large dataset which is in a geodataframe format.
I have developed a lambda function as below to do that but I need a faster way.
The following is a ...
0
votes
2
answers
61
views
Check if geometry field in GeoPandas geodataframe have any row with specific type
This question is related to: Filtering by geometry type in GeoPandas
I need to check if my geodataframe contains 'MultiPolygon' type.
Below is my attempt, but it doesn't work. According to ...
2
votes
1
answer
107
views
Fill NaN geometries records with other geometric column
I have a GeoDataFrame with two geometry columns.
I want to fill missing values of the one with the other.
Both columns contain polygons or multipolygons.
I have tried:
geo_df['geom_2'].fillna(geo_df['...
3
votes
1
answer
233
views
Using multiple predicate parameters on sjoin in GeoPandas
Looking for a way to run GeoDataFrame.sjoin() with more than one predicate.
For example, on QGIS' "Join by location" tool, there is a check box of predicates to mark as needed.
When trying ...
0
votes
1
answer
163
views
Convert JSON to GeoDataFrame and append both geometry and filename
I am currently running an experiment on automating a task by merging information from various file types and doing a number of operations to achieve this.
Currently, I am reading a list of GeoJSONs ...
1
vote
1
answer
156
views
Getting the percentage of how much areas intersects with another using GeoPandas
I have two GeoPandas dataframes, namely:
grid - the base map that contains a grid of 100x100 meter squares.
land - the land use of an area (e.g. farmland, meadow, etc.).
How do I, upon spatially ...
1
vote
1
answer
84
views
Can GeoPandas accept lists as property values?
Properties in GeoJSON features can be lists (or "arrays" in Javascript). For example, the following GeoJSON feature is formatted correctly, and includes a values property that is a list:
{
...
0
votes
1
answer
96
views
Create a function that will return geodataframe
I have created the following function to take Origin = str, Destination = str, line = shapely.geometry.linestring.LineString, node = GeoDataFrame
def create_lines_df(Origin, Destination, line_, nodes_)...
2
votes
1
answer
252
views
Creating a geodataframe from a list of LineStrings or routes
I have created a separate LineString for each origin-destination couples
of subdivisions and I did it manually cause when I use a for loop it creates a dataframe with 1 LineString from all lines...
...
3
votes
1
answer
164
views
Displaying polygon on top of DEM with GeoPandas and Rasterio
I have a DEM and a polygon, both in the NAD83 Datum. I need to plot both at the same time.
Plotting the polygon
import os
import rasterio
import geopandas as gpd
import contextily as cx
import ...
1
vote
0
answers
93
views
Buffer not working in GeoPandas
This seems pretty simple but I can't seem to create a buffer around a GeoDataFrame. I'm making this buffer so that it will be the extent of the axes instead of the original layer. This is to make the ...
1
vote
1
answer
129
views
Get the sum of an attribute within a set radius for each row using GeoPandas
I have grid map that contains cells. Each cell is represented as a row in the dataframe, and each row contains the average population "pop" attribute.
What I need is that for each of these ...
2
votes
2
answers
749
views
Filtering GeoDataFrame rows with list of strings in GeoPandas
I want to filter GeoPandas GeoDataFrame rows by a list containing 4 'matches';
list_of_names = ['BE36_1000_1349', 'BE36_1000_1350', 'BE36_1000_1449', 'BE36_1000_1450'].
I want to return four complete ...
0
votes
0
answers
32
views
Iterating over two very large dataframes: finding the closest LineString (1/150k) to a Point (1/1.2m)
I have a dataset of calls (1.2m rows), each with a 'Point' geometry. Likewise I have a street dataset (150k rows), each with a LineString geometry. My goal is to identify, for each call, the closest ...
-1
votes
1
answer
602
views
Finding if point is in polygon then taking attribute from polygon dataframe and inserting it as a column in the point dataframe
I'm doing some GIS analysis in Python for COVID work. I've geocoded our entire membership (gdf_schoolAgedChildren) base and captured their locations in a shapely point data type (for each member). I'...
1
vote
1
answer
76
views
Getting median value of attribute for duplicate polygons and dropping duplicates using GeoPandas
I have a DataFrame that resulted from spatially joining a digital elevation map with a square grid map.
This unexpectedly resulted in duplicate rows where two rows will have the same "geometry&...
2
votes
0
answers
1k
views
AttributeError when setting coordinate system with set_crs() in GeoPandas [closed]
I'm trying to set the coordinate reference system for a GeoDataFrame using the following code:
import geopandas
from shapely.geometry import shape
from shapely.geometry import Point
d = {'col1': ['...
3
votes
2
answers
94
views
Getting polygon with max attribute within polygons with same geometry using GeoPandas
I have a GeoDataframe containing the spatially joined result of a square grid map and flood hazard data. However, there are instances of rows with the same "geometry" but differing "...
3
votes
1
answer
949
views
Pandas DataFrame to GeoDataFrame with Polygon geometry using groupby and lambda
I have a pandas DataFrame like this
name loc_x loc_y grp_name
a1 1.0 2.0 set1
a2 2.0 3.0 set1
a3 3.2 4.1 set2
a4 7.9 4.2 ...
4
votes
1
answer
361
views
How does GeoPandas' representative_point() work?
I need to compute points that, unlike centroids, are assured to be within a geometry. GeoPandas offers the method geopandas.GeoDataFrame.representative_point(), but I cannot find how it works. ...
0
votes
0
answers
233
views
Adding a new point to a graph in NetworkX
I am working with some points between which I need to find the shortest paths along a graph in NetworkX. I'm trying to take a point that is currently not on the graph and connect it to the graph, i.e.,...
0
votes
1
answer
48
views
Error when creating geodataframe from lists [geographic coordinates and GRIB CRS]
I'm working with meteorological data and I want to insert the grid points and also their polygon in a GeoDataFrame.
They are generated by ERA5 and in a GRIB format.
When I try to create the ...
1
vote
1
answer
1k
views
How to get lat and lon from a GeoPandas geodataframe polygon
I am looking to get the lat and lon coordinates for a number of different polygons in a geodataframe. The following code was suggested on another answer but this returns non lat and lon numbers (lon = ...
1
vote
0
answers
35
views
Rasterize multiple polygons and calculate average
I have a vector layer that contains many overlapping polygons, each containing a "Value" in the attribute table. I am trying to rasterize each polygon as an individual raster layer, and then ...
1
vote
1
answer
244
views
How to make necessary changes to Geodataframe to export as geopackage or shapefile
I am trying to export a geodatabase I created via the OMSNX package. ()
When I attempt to convert the file from a geodatabase to shapefile I get an error "ValueError: Invalid field type <class ...
2
votes
1
answer
848
views
Plotting multiple maps using GeoPandas
I have two GeoDataFrames. The first one have the administrative boundaries of the 25 regions of a country. The second one, the urban fabric of the same country.
regions.head()
COD NAMEREG ...
0
votes
1
answer
161
views
Python convert GeoDataFrame to shapefile using ogr2ogr, unable to open error
I have a GeoDataFrame that I am trying to save as a shapefile using ogr2ogr. Based on the Q&A for Use GeoDataFrame as a osgeo.ogr DataSource and Using geopandas GeoDataFrame in gdal.Grid for ...
0
votes
0
answers
274
views
ValueError: 'ITEM' is both an index level and a column label, which is ambiguous
I'm trying to process some data, with geopandas0.9.
Here is my code:
locations = select_polygons.groupby(class_col).apply(lambda x: \
sample_locations_from_polygon(x, sample_on_boundary='...
3
votes
1
answer
432
views
Exporting multiple GeoPandas GeoDataFrames to one KMZ file
I have two GeoPandas GeoDataFrames, and I want to export them to a KMZ file with a nested folder structure. Below is a stand-alone code to create the GeoDataFrames, and a screenshot of how I would ...
3
votes
1
answer
1k
views
Creating LINESTRING from two POINT(s) and finding mid-POINT
I would like to create a LINESTRING from two POINT geometries and then determine the mid-POINT. So, from my original Pandas' DataFrame, with "x" and "y" columns, I created the ...
0
votes
1
answer
351
views
Attempting to get index value of Geopandas dataframes in list produces ValueError
When looping through a list of Geopandas geodataframes and attempting to get the index value of the current dataframe in the loop, I'm getting ValueError: Can only compare identically-labeled ...
4
votes
1
answer
66
views
Defining coordinate system for every GeoDataFrame (shapefile) in list
I am looking to set a coordinate system for every GeoDataFrame in a list of them. So I need this:
gdfs[0].crs = "EPSG:6668"
gdfs[1].crs = "EPSG:6668"
And so on but iteratively. I ...
9
votes
1
answer
3k
views
Shapely coordinate sequence to GeoDataFrame
Using the shapely bounding box function box, and a GeoDataFrameof points, I have extracted a bounding box and created a buffer around it (below gdf is a GeoDataFrameof points):
bbox=shapely.geometry....
3
votes
1
answer
121
views
Save geodataframes from list to separate shapefiles
I have a list of geodataframes which I imported from a folder full of shapefiles:
import glob
import geopandas as gpd
shapefiles = glob.iglob('E:/folder/shapefiles/*.shp')
gdfs = [gpd.read_file(file) ...
-2
votes
1
answer
58
views
How to change column value by matching row value in data frame?
Say I do have the following table
| longitude | latitude | temperature | label |
|-----------|----------|-------------|-------|
| x | y | z | 1 |
| p | q | ...
0
votes
1
answer
910
views
Error saving geodaframe to shp: AttributeError: 'Series' object has no attribute 'to_file'
I have been struggling with a problem related to Getting AttributeError: 'DataFrame' object has no attribute 'to_file' from GeoPandas even though file converted into GeoDataframe ...
4
votes
1
answer
2k
views
Converting DataFrame to GeoDataFrame with Polygon [closed]
I would like to convert my DataFrame to GeoDataFrame, but every post is about points. I need to convert polygons. Coordinates are in df['geometry']. How can I do that?
My DataFrame is below:
I was ...
4
votes
2
answers
61
views
Build land classes from GIS data
I have combined geo-referenced terrain, climate, and soil data with the requirements of the different agricultural food crops in order to build land classes that tell you where which crop can be grown....
3
votes
1
answer
2k
views
geopandas GeoDataFrame.to_postgis is showing AttributeError: 'GeoDataFrame' object has no attribute 'to_postgis'
I have this geopandas geodataframe which I want to write in the postgis/postgreSQL database.
I have followed the steps as shown here by the geopandas docs
https://geopandas.readthedocs.io/en/latest/...
2
votes
1
answer
242
views
geopandas to_postgis: ValueError: geom (geometry(MULTILINESTRING,4326)) not a string
I have a GeoPandas GeoDataFrame with a column named geom having MultiLineString values as such:
print(gdf.to_markdown()) # using package 'tabulate' to display a markdown table
| | uid | key | ...
9
votes
2
answers
4k
views
Quick way to get WKT from a GeoDataFrame's geometries in GeoPandas?
Is there a quick way to produce a column/series containing the WKTs of all the geometries in a GeoPandas GeoDataFrame?
I got around this using the apply function (see example below), but I just ...
0
votes
0
answers
45
views
How to translate from GeoJSON to GeoDataFrame [duplicate]
I want to convert GeoJSON into a GeoDataFrame, but it doesn't work.
GeoJSON is stored in a dictionary variable.
If you know of a solution, I would like to know how to solve this problem.
This is my ...
5
votes
0
answers
200
views
Finding union of many geodataframes using GeoPandas
I have a series of many GeoPandas Polygon objects, each with an associated exposure time. My goal is to find the union of all the Polygons in order to create an exposure time map.
For each Polygon in ...
3
votes
1
answer
1k
views
Converting DataFrame with geometry column into GeoDataFrame in Pandas
I have this DataFrame:
In [120]: a
Out[120]:
a b c
0 111 333 [POINT (0 0)]
1 222 444 [POINT (0 0)]
I am trying to convert with the next line, but it fails:
In [125]: b = ...
4
votes
2
answers
169
views
Applying geometric operation on multiple GeoDataFrames
I have a collection of geodataframes in my Python environment. How can I apply for each GeoDataFrame the same spatial operation using following manner and create a new variable with the reference that ...
1
vote
1
answer
940
views
Getting maximum length inside polygon using GeoPandas [closed]
I'm having a a GeoDataFrame of polygons. I want to find the maximum length of a straight line that can fit inside each polygon. You could call this the characteristic length of the polygon. The length ...