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

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

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. Always present for Lines and Polygons. For Points: only present if there are multipart geometries.

  • ‘part_node_count’ : The number of nodes per individual geometry. Only for Lines with multipart geometries and for Polygons with multipart geometries or holes.

  • ‘interior_ring’ : Integer boolean indicating whether rings are interior or exterior. Only for Polygons with holes.

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


Please refer to the CF conventions document: