From 26ca68c213372e13c267509a0bbcc5b82ceabc8c Mon Sep 17 00:00:00 2001 From: Alba Vilanova Cortezon Date: Wed, 31 Aug 2022 16:22:22 +0200 Subject: [PATCH] Create points shapefiles --- nes/nc_projections/points_nes.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nes/nc_projections/points_nes.py b/nes/nc_projections/points_nes.py index 8d5ccff..1847fde 100644 --- a/nes/nc_projections/points_nes.py +++ b/nes/nc_projections/points_nes.py @@ -3,7 +3,9 @@ import sys import warnings import numpy as np +import pandas as pd from copy import deepcopy +import geopandas as gpd from netCDF4 import date2num, stringtochar from numpy.ma.core import MaskError from .default_nes import Nes @@ -645,4 +647,11 @@ class PointsNes(Nes): Create spatial geodataframe (shapefile). """ - raise NotImplementedError("Shapefile format cannot be written with point data.") + # Create dataframe cointaining all points + geometry = gpd.points_from_xy(self.lon['data'], self.lat['data']) + fids = np.arange(len(self._lon['data'])) + fids = fids[self.read_axis_limits['x_min']:self.read_axis_limits['x_max']] + gdf = gpd.GeoDataFrame(index=pd.Index(name='FID', data=fids.ravel()), geometry=geometry, crs="EPSG:4326") + self.shapefile = gdf + + return gdf -- GitLab