cf_xarray.shapely_to_cf(geometries, grid_mapping=None)[source]#

Convert a DataArray with shapely geometry objects into a CF-compliant dataset.


Only point geometries are currently implemented.

geometriessequence of shapely geometries or xarray.DataArray

A sequence of geometry objects or a Dataset with a “geometry” variable storing such geometries. All geometries must be of the same base type : Point, Line or Polygon, but multipart geometries are accepted.

grid_mappingstr, optional

A CF grid mapping name. When given, coordinates and attributes are named and set accordingly. Defaults to None, in which case the coordinates are simply names “crd_x” and “crd_y”.


Only the longitude_latitude grid mapping is currently implemented.

A dataset with shapely geometry objects translated into CF-compliant variables :
  • ‘x’, ‘y’ : the node coordinates

  • ‘crd_x’, ‘crd_y’ : the feature coordinates (might have different names if grid_mapping is available).

  • ‘node_count’ : The number of nodes per feature. Absent if all instances are Points.

  • ‘geometry_container’ : Empty variable with attributes describing the geometry type.

  • Other variables are not implemented as only Points are currently understood.


Please refer to the CF conventions document: