Skip to content

Commit

Permalink
Merge pull request #4521 from rouault/zarr_crs_rename
Browse files Browse the repository at this point in the history
Zarr: rename 'crs' attribute to '_CRS' to avoid potential conflict with a regular attribute
  • Loading branch information
rouault authored Sep 22, 2021
2 parents 84d6e0f + 281c6de commit 8da1095
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
8 changes: 4 additions & 4 deletions autotest/gdrivers/zarr_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def test_zarr_read_crs(crs_member):
}

zattrs_all = {
"crs": {
"_CRS": {
"projjson": {
"$schema": "https://proj.org/schemas/v0.2/projjson.schema.json",
"type": "GeographicCRS",
Expand Down Expand Up @@ -687,7 +687,7 @@ def test_zarr_read_crs(crs_member):
}
}

zattrs = {"crs": {crs_member: zattrs_all["crs"][crs_member]}}
zattrs = {"_CRS": {crs_member: zattrs_all["_CRS"][crs_member]}}

try:
gdal.Mkdir('/vsimem/test.zarr', 0)
Expand Down Expand Up @@ -1576,8 +1576,8 @@ def create():
data = gdal.VSIFReadL(1, 10000, f)
gdal.VSIFCloseL(f)
j = json.loads(data)
assert 'crs' in j
crs = j['crs']
assert '_CRS' in j
crs = j['_CRS']
assert 'wkt' in crs
assert 'url' in crs
if 'projjson' in crs:
Expand Down
4 changes: 2 additions & 2 deletions gdal/doc/source/drivers/raster/zarr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ SRS encoding
------------

The Zarr specification has no provision for spatial reference system encoding.
GDAL uses a ``crs`` attribute that is a dictionnary that may contain one or
GDAL uses a ``_CRS`` attribute that is a dictionnary that may contain one or
several of the following keys: ``url`` (using a OGC CRS URL), ``wkt`` (WKT:2019
used by default on writing, WKT1 also supported on reading.), ``projjson``.
On reading, it will use ``url`` by default, if not found will fallback to ``wkt``
Expand All @@ -99,7 +99,7 @@ and then ``projjson``.
.. code-block:: json
{
"crs":{
"_CRS":{
"wkt":"PROJCRS[\"NAD27 \/ UTM zone 11N\",BASEGEOGCRS[\"NAD27\",DATUM[\"North American Datum 1927\",ELLIPSOID[\"Clarke 1866\",6378206.4,294.978698213898,LENGTHUNIT[\"metre\",1]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433]],ID[\"EPSG\",4267]],CONVERSION[\"UTM zone 11N\",METHOD[\"Transverse Mercator\",ID[\"EPSG\",9807]],PARAMETER[\"Latitude of natural origin\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8801]],PARAMETER[\"Longitude of natural origin\",-117,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8802]],PARAMETER[\"Scale factor at natural origin\",0.9996,SCALEUNIT[\"unity\",1],ID[\"EPSG\",8805]],PARAMETER[\"False easting\",500000,LENGTHUNIT[\"metre\",1],ID[\"EPSG\",8806]],PARAMETER[\"False northing\",0,LENGTHUNIT[\"metre\",1],ID[\"EPSG\",8807]]],CS[Cartesian,2],AXIS[\"easting\",east,ORDER[1],LENGTHUNIT[\"metre\",1]],AXIS[\"northing\",north,ORDER[2],LENGTHUNIT[\"metre\",1]],ID[\"EPSG\",26711]]",
"projjson":{
Expand Down
8 changes: 5 additions & 3 deletions gdal/frmts/zarr/zarr_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

#define ZARR_DEBUG_KEY "ZARR"

#define CRS_ATTRIBUTE_NAME "_CRS"

/************************************************************************/
/* ZarrArray::ZarrArray() */
/************************************************************************/
Expand Down Expand Up @@ -232,7 +234,7 @@ void ZarrArray::Flush()
pszAuthorityCode);
}

oAttrs.Add("crs", oCRS);
oAttrs.Add(CRS_ATTRIBUTE_NAME, oCRS);
}

if( m_osUnit.empty() )
Expand Down Expand Up @@ -3084,7 +3086,7 @@ std::shared_ptr<ZarrArray> ZarrGroupBase::LoadArray(const std::string& osArrayNa
oAttributes = oTmpDoc.GetRoot();
}

const auto crs = oAttributes["crs"];
const auto crs = oAttributes[CRS_ATTRIBUTE_NAME];
std::shared_ptr<OGRSpatialReference> poSRS;
if( crs.GetType() == CPLJSONObject::Type::Object )
{
Expand All @@ -3097,7 +3099,7 @@ std::shared_ptr<ZarrArray> ZarrGroupBase::LoadArray(const std::string& osArrayNa
poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
if( poSRS->SetFromUserInput(item.ToString().c_str(), OGRSpatialReference::SET_FROM_USER_INPUT_LIMITATIONS) == OGRERR_NONE )
{
oAttributes.Delete("crs");
oAttributes.Delete(CRS_ATTRIBUTE_NAME);
break;
}
poSRS.reset();
Expand Down

0 comments on commit 8da1095

Please sign in to comment.