Skip to content

Commit

Permalink
Merge pull request #90 from wetransform-os/pr/storage-crs-code
Browse files Browse the repository at this point in the history
Fixes the use of storage CRS code from list of supported CRS
  • Loading branch information
copierrj authored Apr 5, 2023
2 parents 4c305da + 7f485e0 commit a42d248
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private FeatureTypeMetadata createFeatureTypeMetadata( FeatureStore featureStore
List<MetadataUrl> metadataUrls = datasetMetadata != null && !datasetMetadata.getMetadataUrls().isEmpty() ?
datasetMetadata.getMetadataUrls() :
Collections.emptyList();
String storageCrs = featureStore.getStorageCrs() != null ? featureStore.getStorageCrs().getName() : null;
String[] storageCrsCodes = featureStore.getStorageCrs() != null ? featureStore.getStorageCrs().getOrignalCodeStrings() : null;
return new FeatureTypeMetadata( name )
.dateTimeProperty( dateTimeProperty )
.extent( extent )
Expand All @@ -285,7 +285,7 @@ private FeatureTypeMetadata createFeatureTypeMetadata( FeatureStore featureStore
.metadataUrls( metadataUrls )
.filterProperties( filterProperties )
.featureType( featureType )
.storageCrs( storageCrs );
.storageCrsCodes( storageCrsCodes != null ? Arrays.asList( storageCrsCodes ) : null );
}

private List<FilterProperty> parseFilterProperties( FeatureType featureType ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,45 @@ private Collection createCollection( OafDatasetConfiguration oafConfiguration, S
String title = featureType.getTitle();
String description = featureType.getDescription();
List<String> suppportedCrs = oafConfiguration.getSuppportedCrs();

/*
* From the codes known for the storage CRS we try to use one that is part of the
* supported CRS.
*
* For reference from "OGC API Features Part 2: Coordinate Reference Systems":
*
* Requirement 4:
* The value of the storageCrs property SHALL be one of the CRS identifiers from the list
* of supported CRS identifiers found in the collection object using the crs property.
*/
String selectedCode = selectCrsCode( featureType.getStorageCrsCodes(), suppportedCrs );

return new Collection( featureTypeId, title, description, links, featureType.getExtent(), suppportedCrs,
featureType.getStorageCrs() );
selectedCode );
}

private Map<String, String> getFeatureTypeNsPrefixes( FeatureStore featureStore ) {
/**
* Select a CRS code from the given codes, preferring codes from the given list of supported codes.
* If there is no match the first code is used as fall-back.
*
* @param crsCodes codes to select from
* @param suppportedCodes the supported/preferred codes
* @return the selected code
*/
public static String selectCrsCode(List<String> crsCodes, List<String> suppportedCodes) {
if (crsCodes == null || crsCodes.isEmpty()) {
return null;
}

for (String candidate : crsCodes) {
if (suppportedCodes.contains(candidate)) {
return candidate;
}
}
return crsCodes.get(0);
}

private Map<String, String> getFeatureTypeNsPrefixes( FeatureStore featureStore ) {
Map<String, String> prefixToNs = new HashMap<String, String>();
FeatureType[] featureTypes = featureStore.getSchema().getFeatureTypes();
for ( FeatureType ft : featureTypes ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class FeatureTypeMetadata {

private FeatureType featureType;

private String storageCrs;
private List<String> storageCrsCodes;

public FeatureTypeMetadata( QName featureTypeName ) {
this.name = featureTypeName;
Expand Down Expand Up @@ -91,8 +91,8 @@ public FeatureTypeMetadata featureType( FeatureType featureType ) {
return this;
}

public FeatureTypeMetadata storageCrs( String storageCrs ) {
this.storageCrs = storageCrs;
public FeatureTypeMetadata storageCrsCodes( List<String> storageCrsCodes ) {
this.storageCrsCodes = storageCrsCodes;
return this;
}

Expand Down Expand Up @@ -128,7 +128,7 @@ public FeatureType getFeatureType() {
return featureType;
}

public String getStorageCrs() {
return storageCrs;
public List<String> getStorageCrsCodes() {
return storageCrsCodes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*-
* #%L
* deegree-ogcapi-features - OGC API Features (OAF) implementation - Querying and modifying of geospatial data objects
* %%
* Copyright (C) 2019 - 2020 lat/lon GmbH, info@lat-lon.de, www.lat-lon.de
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package org.deegree.services.oaf.workspace;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Arrays;
import java.util.List;

import org.deegree.cs.coordinatesystems.ICRS;
import org.deegree.cs.exceptions.UnknownCRSException;
import org.deegree.cs.persistence.CRSManager;
import org.junit.Test;

public class DeegreeDataAccessTest {

@Test
public void test_selectCrsCode_ETRS89() throws UnknownCRSException {
String lookupCode = "http://www.opengis.net/def/crs/EPSG/0/4258";
String code = selectCode( lookupCode, Arrays.asList( lookupCode ) );
assertThat( code, is( lookupCode ));
}

@Test
public void test_selectCrsCode_WGS84() throws UnknownCRSException {
String lookupCode = "http://www.opengis.net/def/crs/EPSG/0/4326";
String code = selectCode( lookupCode, Arrays.asList( lookupCode ) );
assertThat( code, is( lookupCode ) );
}

@Test
public void test_selectCrsCode_ETRS89_AlternateCode() throws UnknownCRSException {
String lookupCode = "urn:ogc:def:crs:EPSG::4258";
String allowedCode = "http://www.opengis.net/def/crs/EPSG/0/4258";
String code = selectCode( lookupCode, Arrays.asList( allowedCode ) );
assertThat( code, is( allowedCode ) );
}

@Test
public void test_selectCrsCode_NoMatch() throws UnknownCRSException {
String lookupCode = "http://www.opengis.net/def/crs/EPSG/0/4326";
ICRS crs = CRSManager.lookup( lookupCode );
String code = selectCode( lookupCode, Arrays.asList( "EPSG:12345" ) );
assertThat( code, is( crs.getCode().getOriginal() ));
}

private String selectCode( String crsCode, List<String> supportedCodes ) throws UnknownCRSException {
ICRS crs = CRSManager.lookup( crsCode );
return DeegreeDataAccess.selectCrsCode( Arrays.asList( crs.getOrignalCodeStrings() ), supportedCodes );
}

}

0 comments on commit a42d248

Please sign in to comment.