Questions tagged [geodataframe]

is a pandas.DataFrame that has a column with geometry

Filter by
Sorted by
Tagged with
0 votes
1 answer
14 views

Add raster pixel information to existing geodataframe, one column per band

I have a land cover dataset (a geopandas.GeoDataFrame) with a series of "buffers" over a territory. The dataset has roughly this format: unit_id , ..., geometry, 30 ...
  • 101
0 votes
1 answer
29 views

Geodataframe to SHP in loop and name of the GDF

I am trying to export multiple gdf to shp and name these shp by the gdf name. I have found this solution here is my list: maloobchod_list = [maloobchod2006_geom, maloobchod2011_geom, ...
0 votes
2 answers
57 views

Clip data using GeoPandas or PostGIS [closed]

I have two geodataframes - points. First gdf contains smaller number of points. I am trying to clip my second gdf (with higher number of points and therefore bigger area) to the extent of first gdf. ...
1 vote
0 answers
63 views

Why will Geopandas not read geopackage into dataframe? [closed]

I am trying to read in a geopackage as a dataframe using Geopandas. I am using Python 3.8, Geopandas 0.10.2, and Fiona 1.8.20. The geopackage I was using to test this is publicly available in any of ...
  • 1,729
0 votes
0 answers
57 views

Clipping NetCDF files with a geodataframe in Python

I have monthly estimates of PM 2.5 for 20 consecutive years stored in NetCDF files with a precision of 0.01°x0.01° (i.e. for each 0.01°x0.01° square on the world map, there is an estimate of PM 2.5). [...
3 votes
1 answer
62 views

Preserving None values in GeoPandas when dissolving (by="id", aggfunc="first", as_index=False)

If I dissolve two geometries with the same id and tell to aggregate the other attributes from the first geometry, I get the attributes values from the second geometry because the first is None. ...
1 vote
2 answers
317 views

Writing empty GeoDataFrame to shapefile using Python

I don't know why this is so hard to find or to do, but how does one create an empty .shp with geopandas? I essentially want to duplicate the processes of creating a type: polygon shapefile from QGIS, ...
  • 1,057
6 votes
3 answers
558 views

Extracting latitude and longitude pairs as list from LineString in GeoPandas

I have a GeoPandas GeoDataFrame that looks like this: shape_id geometry 1000252 LINESTRING (4.91790 52.34725, 4.91797 52.34715... 1000254 LINESTRING (4.80382 52.34495, 4.80413 52.34500... ...
2 votes
1 answer
66 views

Converting QGIS feature selection into dataframe to allow plotting

I have a layer containing thousands of points of X,Y,Z data (sample below). fid field_1 field_2 field_3 1 525146 675224 -342.1 2 525148 675224 -342.2 3 525150 675224 -342.1 4 525152 ...
  • 323
4 votes
1 answer
65 views

Unable to execute spatial join after CRS transformation in GeoPandas

I'm trying to join a points GeoPandas GeoDataFrame with a polygon GeoDataFrame, but I'm getting an empty results (inner join). The points GeoDataFrame I'm loading it by using latitude and longitude. ...
4 votes
2 answers
327 views

Reading Inspire XML with GeoPandas

I am trying to plot the German Railway net from here, using GeoPandas. It downloads an Inspire XML file. gpd.read_file only seems to read the header. Importing it as a Pandas Dataframe with pd....
1 vote
1 answer
115 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'...
3 votes
2 answers
1k 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 ...
  • 43
0 votes
0 answers
76 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 ...
0 votes
0 answers
137 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 ...
2 votes
2 answers
578 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
253 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['...
  • 592
3 votes
1 answer
785 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 ...
  • 592
0 votes
1 answer
409 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 ...
  • 65
2 votes
1 answer
510 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 ...
  • 79
1 vote
1 answer
219 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: { ...
  • 113
0 votes
1 answer
177 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
683 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
272 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,169
1 vote
0 answers
193 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,169
1 vote
1 answer
324 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 ...
  • 79
3 votes
2 answers
1k 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 ...
  • 315
0 votes
0 answers
58 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 ...
0 votes
1 answer
1k 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'...
  • 11
1 vote
1 answer
120 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&...
  • 79
2 votes
0 answers
2k 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': ['...
  • 31
3 votes
2 answers
255 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 "...
  • 79
3 votes
1 answer
2k 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 ...
  • 95
4 votes
1 answer
623 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
409 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
89 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 ...
2 votes
1 answer
3k 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 = ...
  • 31
1 vote
0 answers
70 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
548 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 ...
  • 31
2 votes
1 answer
1k 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
224 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 ...
  • 911
0 votes
0 answers
865 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
640 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 ...
  • 911
4 votes
1 answer
2k 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
622 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 ...
  • 1,060
4 votes
1 answer
80 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 ...
  • 412
10 votes
1 answer
5k 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....
  • 1,545
3 votes
1 answer
183 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) ...
  • 412
-2 votes
1 answer
186 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 | ...
  • 11
0 votes
1 answer
1k 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 ...