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 Change (NPCC). Data includes the 10th, 25th, 50th, 75th and 90th percentile projections for the years 2020, 2050, 2080 and 2100.
I can read this into a GeoDataFrame
using:
import geopandas as gpd
# Download from https://data.cityofnewyork.us/City-Government/Projected-Sea-Level-Rise/6an6-9htp directly...
data = gpd.read_file("NYCFutureHighTideWithSLR.gdb", driver='FileGDB', layer=0)
Here I am reading the 0th (first) layer in the database.
But what does that actually mean? I'm not sure what order the percentile-year layers were provided in by the city, so I'd like to, if possible, also read the names of the various layers.
However, I am unsure how to do so, or even if layer names is a feature of this data format at all. Does anyone know how to do this in Python, preferably by using new-school tools like fiona
or geopandas
?
Answer
The fiona.listlayers()
function returns a list of names of layers in a dataset.
import fiona
fiona.listlayers('NYCFutureHighTideWithSLR.gdb')
Any of the elements of the list can be used as a value of the layer
keyword argument for gpd.read_file()
.
The integer index of a list element may also be used. If the layers of your dataset are ['layer_a', 'layer_b']
, then gpd.read_file("NYCFutureHighTideWithSLR.gdb", driver='FileGDB', layer='layer_b')
and gpd.read_file("NYCFutureHighTideWithSLR.gdb", driver='FileGDB', layer=1)
are equivalent.
No comments:
Post a Comment