I need to perform some geometric operations with geometries from another source on a netCDF-file. Therefore I store the geometries (shapely.geometry.Polygon
) from the other source in a geopandas.GeoDataFrame
.
Next is to read a netCDF
file into a GeoDataFrame
. The recipe seems clear: read the netCDF
with xarray
, store it into a pandas.DataFrame
, perform a shapely.geometry.Point
operation on the extracted lat/lon data and convert it into a GeoDataFrame
.
Afterwards, I will do some statistics with geometry-operators.
When I read the netCDF
file with xarray
(see here)
import xarray as xr
dnc = xr.open_dataset(ff)
df = dnc.to_dataframe()
I get
>>>> dnc
<xarray.Dataset>
Dimensions: (lat: 16801, lon: 19201)
Coordinates:
* lat (lat) float32 -32.0 -31.9992 -31.9983 -31.9975 -31.9967 ...
* lon (lon) float32 -73.0 -72.9992 -72.9983 -72.9975 -72.9967 ...
Data variables:
hgt (lat, lon) int16 0 0 0 4 0 5 0 9 9 8 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
>>> dnc.hgt.size
322596001
>>> dnc.lat.size
16801
>>> dnc.lon.size
19201
and
>>> df.head()
hgt
lat lon
-32.0 -73.000000 0
-72.999168 0
-72.998337 0
-72.997498 4
-72.996666 0
In df
there is no access on lat
and lon
. I also have problems to understand the partially empty column lat
. So I think that the shapely.geometry.Point((lon, lat))
must be performed on dnc
for every combination of lon
and lat
. Is that right? Any ideas how to code it?