xarray.Dataset.xvec.set_geom_indexes#

Dataset.xvec.set_geom_indexes(coord_names, crs=None, allow_override=False, **kwargs)#

Set a new GeometryIndex for one or more existing coordinate(s). One GeometryIndex is set per coordinate. Only 1-dimensional coordinates are supported.

Parameters:
coord_namesstr or list

Name(s) of the coordinate(s) used to build the index.

crsAny, optional

CRS in any format accepted by pyproj.CRS.from_user_input() such as an authority string (e.g. "EPSG:4326"), EPSG code (e.g. 4326) or a WKT string.

allow_overridebool, default False

If the coordinate(s) already have a GeometryIndex, allow to replace the existing CRS, even when both are not equal.

Returns:
assignedsame type as caller

A new object with the same data and new index(es)

Examples

>>> da = (
...     xr.DataArray(
...         np.random.rand(2),
...         coords={"geom": [shapely.Point(1, 2), shapely.Point(3, 4)]},
...         dims="geom",
...     )
... )
>>> da
<xarray.DataArray (geom: 2)>
array([0.06610343, 0.03144603])
Coordinates:
  * geom     (geom) object POINT (1 2) POINT (3 4)
>>> da.xvec.set_geom_indexes("geom", crs=4326)
<xarray.DataArray (geom: 2)>
array([0.06610343, 0.03144603])
Coordinates:
  * geom     (geom) object POINT (1 2) POINT (3 4)
Indexes:
    geom     GeometryIndex (crs=EPSG:4326)