Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ default Force getForceAxisOrder() {
return Force.NONE;
}

/**
* Optional CRS identifier (URI) used to reference this CRS, e.g., the alias
* "http://www.opengis.net/def/crs/OGC/0/CRS84" for CRS84. If present, {@code toUriString()}
* returns this value so that responses echo the identifier used in the request. Auxiliary, i.e.,
* excluded from {@code equals()}/{@code hashCode()}: instances differing only in this attribute
* represent the same CRS.
*/
@JsonIgnore
@Value.Auxiliary
Optional<String> getUriOverride();

@JsonIgnore
@Value.Lazy
default boolean isCompoundCrs() {
Expand Down Expand Up @@ -130,6 +141,9 @@ default List<String> toUrnStrings() {
@JsonIgnore
@Value.Lazy
default String toUriString() {
if (getUriOverride().isPresent()) {
return getUriOverride().get();
}
if (Objects.equals(this, OgcCrs.CRS84)) {
return OgcCrs.CRS84_URI;
}
Expand All @@ -139,12 +153,18 @@ default String toUriString() {
return String.format("http://www.opengis.net/def/crs/EPSG/0/%d", getCode());
}

/**
* Returns all registered URIs of this CRS: the canonical URI plus, in the case of CRS84, the
* "OGC/0/CRS84" alias URI. Unlike {@code toUriStrings()}, the list does not decompose a compound
* CRS into its components, it lists the identifiers of this CRS.
*/
@JsonIgnore
@Value.Lazy
default Optional<String> toAlternativeUriString() {
return Objects.equals(this, OgcCrs.CRS84)
? Optional.of(OgcCrs.CRS84_URI_NEW)
: Optional.empty();
default List<String> allUris() {
if (Objects.equals(this, OgcCrs.CRS84)) {
return List.of(OgcCrs.CRS84_URI, OgcCrs.CRS84_URI_NEW);
}
return List.of(toUriString());
}

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ public interface OgcCrs {
String CRS84_URI_NEW = "http://www.opengis.net/def/crs/OGC/0/CRS84";
String CRS84_CURIE = "OGC:CRS84";

/**
* The same CRS as {@link #CRS84} ({@code equals()} is {@code true}), but {@code toUriString()}
* returns the "OGC/0/CRS84" alias URI instead of the "OGC/1.3/CRS84" URI.
*/
EpsgCrs CRS84_OGC0 =
new ImmutableEpsgCrs.Builder().from(CRS84).uriOverride(CRS84_URI_NEW).build();

EpsgCrs CRS84h = EpsgCrs.of(4979, Force.LON_LAT);

String CRS84h_URI = "http://www.opengis.net/def/crs/OGC/0/CRS84h";
String CRS84h_CURIE = "OGC:CRS84h";

static Optional<EpsgCrs> fromString(String prefixedCode) {
if (Objects.equals(prefixedCode, CRS84_URI_NEW)) {
return Optional.of(CRS84);
return Optional.of(CRS84_OGC0);
}
if (Objects.equals(prefixedCode, CRS84_URI)) {
return Optional.of(CRS84);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ class EpsgCrsSpec extends Specification {

}

def 'fromString - crs84 alias'() {
when:
def crs = EpsgCrs.fromString(OgcCrs.CRS84_URI_NEW)

then:
crs.code == 4326
crs.forceAxisOrder == EpsgCrs.Force.LON_LAT
crs == OgcCrs.CRS84
crs.hashCode() == OgcCrs.CRS84.hashCode()
crs.toUriString() == OgcCrs.CRS84_URI_NEW
crs.toUrnString() == "urn:ogc:def:crs:OGC::4326"
crs.toSafeCurie() == OgcCrs.CRS84_CURIE

}

def 'fromString - crs84h'() {
when:
def crs = EpsgCrs.fromString(OgcCrs.CRS84h_URI)
Expand Down Expand Up @@ -93,10 +108,23 @@ class EpsgCrsSpec extends Specification {
crs.toUriString() == uri

where:
crs | uri
EpsgCrs.of(25832) | "http://www.opengis.net/def/crs/EPSG/0/25832"
OgcCrs.CRS84 | OgcCrs.CRS84_URI
OgcCrs.CRS84h | OgcCrs.CRS84h_URI
crs | uri
EpsgCrs.of(25832) | "http://www.opengis.net/def/crs/EPSG/0/25832"
OgcCrs.CRS84 | OgcCrs.CRS84_URI
OgcCrs.CRS84_OGC0 | OgcCrs.CRS84_URI_NEW
OgcCrs.CRS84h | OgcCrs.CRS84h_URI
}

def 'allUris'() {
expect:
crs.allUris() == uris

where:
crs | uris
EpsgCrs.of(25832) | ["http://www.opengis.net/def/crs/EPSG/0/25832"]
OgcCrs.CRS84 | [OgcCrs.CRS84_URI, OgcCrs.CRS84_URI_NEW]
OgcCrs.CRS84_OGC0 | [OgcCrs.CRS84_URI, OgcCrs.CRS84_URI_NEW]
OgcCrs.CRS84h | [OgcCrs.CRS84h_URI]
}

def 'CoordinateTupleWithPrecision - uri'() {
Expand Down
Loading