Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 negatively impact the performance.
  for feature in features_lst:

Here's the code sample I used:

crime_gdf = gpd.read_file('datasets/crimes.geojson', bbox=bbox)

crimes.geojson is a file containing a large number of points, each with a 'Crime type'

bbox defines the boundaries

The code runs as expected, but I don't understand that warning.

EDIT

I converted the geojson to feather, and I get the same warning.

like image 935
leosole Avatar asked Nov 24 '20 21:11

leosole


People also ask

What file formats are supported by geopandas?

GeoPandas supports writing and reading the Apache Parquet and Feather file formats. Apache Parquet is an efficient, columnar storage format (originating from the Hadoop ecosystem). It is a widely used binary file format for tabular data.

How many code examples of geopandas are there?

The following are 30 code examples of geopandas.read_file () . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module geopandas , or try the search function .

Does geopandas support pre-filtering when loading large datasets?

Since geopandas is powered by Fiona, which is powered by GDAL, you can take advantage of pre-filtering when loading in larger datasets. This can be done geospatially with a geometry or bounding box.

How does geopandas work with Fiona?

This is possible because geopandas makes use of the great fiona library, which in turn makes use of a massive open-source program called GDAL/OGR designed to facilitate spatial data transformations. Any arguments passed to geopandas.read_file () after the file name will be passed directly to fiona.open (), which does the actual data importation.


2 Answers

While it could cause problems ignoring warnings in some contexts, I am finding this one particularly annoying repeated in my code output.

I found the warning can be ignored using

import warnings
# filter out RuntimeWarnings, due to geopandas/fiona read file spam
# https://stackoverflow.com/questions/64995369/geopandas-warning-on-read-file
warnings.filterwarnings("ignore",category=RuntimeWarning)

I added in the comments referencing this post to explain why I am filtering out these warnings. When this warning is suppressed in a future geopandas / fiona release then this code snippet should probably be removed, as it may also suppress meaningful warnings and could be problematic in some contexts.

like image 114
Carl Higgs Avatar answered Oct 07 '22 09:10

Carl Higgs


See my comment in Fiona's issue tracker: https://github.com/Toblerity/Fiona/issues/986

GDAL (the library Fiona uses to access the geodata) maintains an iterator over the features that are currently read. There a some operations that, for some drivers, can influence this iterator. Thus, after such operations we have to ensure that the iterator is set to the correct position that a continuous read of the data is ensured. Such operations include counting all features in a dataset, respectively calculating its extent.

There are different types of drivers in GDAL. Some drivers support random access, while some do not. For the drivers that do not support random access, the resetting of the iterator involves reading all features again up to the iterator position. As this is a possible costly operation, this RuntimeWarning is emitted, so that users are aware of this behavior.

like image 25
rbuffat Avatar answered Oct 07 '22 10:10

rbuffat