Skip to content

Commit

Permalink
fixed wcs versions to properly work on irsic and geoeuskadi
Browse files Browse the repository at this point in the history
  • Loading branch information
moovida committed Nov 2, 2024
1 parent 8c2c2ec commit 318bb09
Show file tree
Hide file tree
Showing 23 changed files with 103 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static IWebCoverageService getServiceForVersion(String url, String versio
if (version.equals("1.0.0")) {
return new org.hortonmachine.gears.io.wcs.wcs100.WebCoverageService100(url, version, xml, cookies, timeout,
auth, headers);
} else if (version.equals("1.1.1") || version.equals("1.1.0")) {
} else if (version.equals("1.1.2") || version.equals("1.1.1") || version.equals("1.1.0")) {
return new org.hortonmachine.gears.io.wcs.wcs111.WebCoverageService111(url, version, xml, cookies, timeout,
auth, headers);
} else if (version.equals("2.0.1")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ public class TestGeoeuskadi {

public static void main(String[] args) throws Exception {

String outFolder = "/Users/hydrologis/TMP/KLAB/WCS/DUMPS/";
String outFolder = "C:\\Users\\hydrologis\\Dropbox\\G-ANT\\lavori\\2024_10_30_bilbao_aries\\WCS\\";

// String SERVICE_URL = "https://geo.hazi.eus/ows";
String SERVICE_URL = "https://geo.hazi.eus/S2GEOEUSKADI_RGB/wcs";
String coverageId = "S2GEOEUSKADI_RGB__S2A_20160703T110602307Z_RGB"; //S2GEOEUSKADI_RGB:S2A_20150818T110635806Z_RGB";
String SERVICE_URL = "https://geo.hazi.eus/ows";
// String SERVICE_URL = "https://geo.hazi.eus/S2GEOEUSKADI_RGB/wcs";
// String SERVICE_URL = "https://www.geo.euskadi.eus/geoeuskadi/services/U11/WCS_KARTOGRAFIA/MapServer/WCSServer";
String coverageId = "0"; //S2GEOEUSKADI_RGB:S2A_20150818T110635806Z_RGB";
String version = null;

IWebCoverageService service = IWebCoverageService.getServiceForVersion(SERVICE_URL, version);
Expand Down Expand Up @@ -66,11 +67,11 @@ public static void main(String[] args) throws Exception {
}

// describe coverage
String describeCoverageUrl = service.getDescribeCoverageUrl(coverageId);
System.out.println(describeCoverageUrl);

IDescribeCoverage describeCoverage = service.getDescribeCoverage(coverageId);
System.out.println(describeCoverage);
// String describeCoverageUrl = service.getDescribeCoverageUrl(coverageId);
// System.out.println(describeCoverageUrl);
//
// IDescribeCoverage describeCoverage = service.getDescribeCoverage(coverageId);
// System.out.println(describeCoverage);

// get coverage
CoverageReaderParameters parameters = new CoverageReaderParameters(service, coverageId);
Expand Down
7 changes: 6 additions & 1 deletion gears/src/main/java/org/hortonmachine/gears/io/wcs/Wcs.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ public String describeUrl(String coverageId) throws Exception {
}

public IDescribeCoverage describe(String coverageId) throws Exception {
return service.getDescribeCoverage(coverageId);
try {
return service.getDescribeCoverage(coverageId);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

public List<String> formats() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public static void main(String[] args) throws Exception {
// &subset=Lat(34.54889,37.31744)
// &subset=Long(26.51071,29.45505)

String outFolder = "/Users/hydrologis/TMP/KLAB/WCS/DUMPS/";
String outFolder = "C:\\Users\\hydrologis\\Dropbox\\G-ANT\\lavori\\2024_10_30_bilbao_aries\\WCS\\";

String SERVICE_URL = "https://geoservices9.civis.bz.it/geoserver/ows"; // ?service=WCS&version=2.0.1&request=GetCapabilities";
String SERVICE_URL = "https://www.geo.euskadi.eus/WCS_KARTOGRAFIA"; // "https://geoservices9.civis.bz.it/geoserver/ows"; // ?service=WCS&version=2.0.1&request=GetCapabilities";
// String coverageId = "p_bz-Elevation__DigitalTerrainModel-2.5m";
String coverageId = "p_bz-Elevation:DigitalElevationModel-2.5m";

Expand All @@ -65,7 +65,7 @@ public static void main(String[] args) throws Exception {
// String coverageId = "OneGDev:AegeanLevantineSeas-MCol";
// Envelope env = new Envelope(26.51071, 29.45505, 35.5, 36.0);

String version = "1.0.0";
String version = null;// "1.1.1";

IWebCoverageService service = IWebCoverageService.getServiceForVersion(SERVICE_URL, version);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hortonmachine.gears.io.wcs;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -167,6 +168,11 @@ public static XmlHelper getXmlHelperForRequest(String urlString) throws Exceptio
HttpRequest request = uriBuilder.GET().build();
// Send the request and retrieve the response
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
int status = response.statusCode();
if (status >= 400) {
String error = "Unable to get data form: " + urlString;
throw new IOException(error);
}
xmlHelper = XmlHelper.fromStream(response.body());

} catch (SSLHandshakeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void printTree() {
* @param level The level of indentation
* @param visitor The visitor to use
*/
public void printTree(Node node, int level) {
public static void printTree(Node node, int level) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
System.out.println(getIndentation(level) + "Element: " + node.getNodeName());
if (node.hasAttributes()) {
Expand Down Expand Up @@ -261,7 +261,7 @@ private Map<String, Object> getSubElements(Node node) {
return subElements;
}

public String getIndentation(int level) {
public static String getIndentation(int level) {
StringBuilder indentation = new StringBuilder();
for (int i = 0; i < level; i++) {
indentation.append(" "); // Use two spaces for each level of indentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public String toUrl(HashMap<String, String> additionalParams) throws Exception {
url += "&request=GetCoverage";
if (this.wcsVersion.equals("2.0.1")) {
url = build201Url(url);
} else if (this.wcsVersion.equals("1.1.1") || this.wcsVersion.equals("1.1.0")) {
} else if (this.wcsVersion.equals("1.1.2") || this.wcsVersion.equals("1.1.1") || this.wcsVersion.equals("1.1.0")) {
url = build111(url);
} else if (this.wcsVersion.equals("1.0.0")) {
url = build100(url);
Expand All @@ -200,25 +200,31 @@ private String build100(String url)
url += "&format=" + this.format;

Envelope finalRequestEnvelope = requestedEnvelope;
Integer finalRequestEnvelopeSrid = requestedEnvelopeSrid;
ICoverageSummary coverageSummary = wcs.getCoverageSummary(this.identifier);
ReferencedEnvelope dataEnvelope = coverageSummary.getWgs84BoundingBox();
ReferencedEnvelope dataEnvelopeWgs84 = coverageSummary.getWgs84BoundingBox();
if (this.requestedEnvelope != null) {
ReferencedEnvelope requestEnvelopeWgs84 = null;
// TODO check this next, should not be necessary
ReferencedEnvelope requestedReferenceEnvelope = new ReferencedEnvelope(requestedEnvelope,
CRS.decode("EPSG:" + requestedEnvelopeSrid));
if (requestedEnvelopeSrid != 4326) {
ReferencedEnvelope requestedReferenceEnvelope = new ReferencedEnvelope(requestedEnvelope,
CRS.decode("EPSG:" + requestedEnvelopeSrid));
finalRequestEnvelope = requestedReferenceEnvelope.transform(DefaultGeographicCRS.WGS84, true);
requestEnvelopeWgs84 = requestedReferenceEnvelope.transform(DefaultGeographicCRS.WGS84, true);
// finalRequestEnvelopeSrid = 4326;
} else {
requestEnvelopeWgs84 = requestedReferenceEnvelope;
}
// if the requested envelope is partially outside the data envelope, we need to
// clip it
if (!dataEnvelope.contains(finalRequestEnvelope)) {
if (!dataEnvelopeWgs84.contains((Envelope) requestEnvelopeWgs84)) {
Logger.INSTANCE.w(
"Requested envelope is partially outside the data envelope. Clipping requested envelope to data envelope.");
finalRequestEnvelope = finalRequestEnvelope.intersection(dataEnvelope);
finalRequestEnvelope = finalRequestEnvelope.intersection(dataEnvelopeWgs84);
}
} else {
// since bbox is mandatory, we use the data envelope
finalRequestEnvelope = dataEnvelope;
requestedEnvelopeSrid = 4326;
finalRequestEnvelope = dataEnvelopeWgs84;
finalRequestEnvelopeSrid = 4326;
}

double minx = finalRequestEnvelope.getMinX();
Expand All @@ -227,8 +233,8 @@ private String build100(String url)
double maxy = finalRequestEnvelope.getMaxY();
url += "&BBOX=" + minx + "," + miny + "," + maxx + "," + maxy;

if (this.requestedEnvelopeSrid != null)
url += "&CRS=EPSG:" + requestedEnvelopeSrid; // TODO use the supplied srid + this.requestedEnvelopeSrid;
if (finalRequestEnvelopeSrid != null)
url += "&CRS=EPSG:" + finalRequestEnvelopeSrid;

if (this.rowsCols != null) {
url += "&WIDTH=" + this.rowsCols[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public String descCov_url(String service_url) {
if (!params.contains("CoverageID")) {
qs.add(new String[] { "CoverageID", identifier });
}
} else if (version.equals("1.1.0") || version.equals("1.1.1")) {
} else if (version.equals("1.1.2") || version.equals("1.1.0") || version.equals("1.1.1")) {
// # NOTE: WCS 1.1.0 is ambigous about whether it should be identifier
// # or identifiers (see tables 9, 10 of specification)
if (!params.contains("identifiers")) {
Expand Down Expand Up @@ -112,7 +112,7 @@ public IDescribeCoverage read(String service_url, int timeout) throws Exception{
describeCoverage = new org.hortonmachine.gears.io.wcs.wcs100.models.DescribeCoverage();
} else if (version.equals("2.0.0") || version.equals("2.0.1")) {
describeCoverage = new org.hortonmachine.gears.io.wcs.wcs201.models.DescribeCoverage();
} else if (version.equals("1.1.0") || version.equals("1.1.1")) {
} else if (version.equals("1.1.2") || version.equals("1.1.0") || version.equals("1.1.1")) {
describeCoverage = new org.hortonmachine.gears.io.wcs.wcs111.models.DescribeCoverage();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public IWcsCapabilities read(String service_url, int timeout) throws Exception {
if (version.equals("2.0.1")) {
wcsCapabilities = new org.hortonmachine.gears.io.wcs.wcs201.models.WcsCapabilities();
XmlHelper.apply(xmlHelper.getRootNode(), wcsCapabilities);
} else if (version.equals("1.1.1") || version.equals("1.1.0")) {
} else if (version.equals("1.1.2") || version.equals("1.1.1") || version.equals("1.1.0")) {
wcsCapabilities = new org.hortonmachine.gears.io.wcs.wcs111.models.WcsCapabilities();
XmlHelper.apply(xmlHelper.getRootNode(), wcsCapabilities);
} else if (version.equals("1.0.0")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CoverageSummary(List<ICoverageSummary> coverageSummaries) {
}

public boolean checkElementName(String name) {
if (name.equals("wcs:CoverageOfferingBrief") || name.endsWith(":CoverageOfferingBrief"))
if (name.equals("wcs:CoverageOfferingBrief") || name.endsWith("CoverageOfferingBrief"))
return true;
return false;
}
Expand All @@ -40,7 +40,9 @@ public void visit(Node node) throws Exception {
cs.abstract_ = XmlHelper.findFirstTextInChildren(node, "description");

Node keywordsNode = XmlHelper.findNode(node, "keywords");
cs.keywords = XmlHelper.findAllTextsInChildren(keywordsNode, "keyword");
if (keywordsNode!=null) {
cs.keywords = XmlHelper.findAllTextsInChildren(keywordsNode, "keyword");
}
cs.coverageId = XmlHelper.findFirstTextInChildren(node, "name");

Node bboxNode = XmlHelper.findNode(node, "lonLatEnvelope");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DescribeCoverage implements IDescribeCoverage {

@Override
public boolean checkElementName(String name) {
if (name.equals("wcs:CoverageDescription") || name.endsWith(":CoverageDescription"))
if (name.equals("wcs:CoverageDescription") || name.endsWith("CoverageDescription"))
return true;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Identification implements XmlHelper.XmlVisitor {

@Override
public boolean checkElementName(String name) {
if (name.equals("wcs:Service") || name.endsWith(":Service"))
if (name.equals("wcs:Service") || name.endsWith("Service"))
return true;
return false;
}
Expand All @@ -30,7 +30,9 @@ public void visit(Node node) {
abstract_ = XmlHelper.findFirstTextInChildren(node, "description");

Node keywordsNode = XmlHelper.findNode(node, "keywords");
keywords = XmlHelper.findAllTextsInChildren(keywordsNode, "keyword");
if(keywordsNode!=null) {
keywords = XmlHelper.findAllTextsInChildren(keywordsNode, "keyword");
}

// serviceType = XmlHelper.findFirstTextInChildren(node, "servicetype");
// supportedVersions = XmlHelper.findAllTextsInChildren(node, "servicetypeversion");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class OperationsMetadata implements XmlHelper.XmlVisitor {

@Override
public boolean checkElementName(String name) {
if (name.equals("wcs:Capability") || name.endsWith(":Capability"))
if (name.equals("wcs:Capability") || name.endsWith("Capability"))
return true;
return false;
}
Expand All @@ -26,7 +26,7 @@ public void visit(Node node) {
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
String name = childNode.getNodeName().toLowerCase();
if (name.endsWith(":getcapabilities")) {
if (name.endsWith("getcapabilities")) {
Node getNode = XmlHelper.findNode(childNode, "Get");
if (getNode != null) {
Node onlineResNode = XmlHelper.findNode(getNode, "OnlineResource");
Expand All @@ -35,7 +35,7 @@ public void visit(Node node) {
getCapabilitiesUrl = getCapabilitiesUrl.substring(0, getCapabilitiesUrl.length() - 1);
}
}
} else if (name.endsWith(":describecoverage")) {
} else if (name.endsWith("describecoverage")) {
Node getNode = XmlHelper.findNode(childNode, "Get");
if (getNode != null) {
Node onlineResNode = XmlHelper.findNode(getNode, "OnlineResource");
Expand All @@ -44,7 +44,7 @@ public void visit(Node node) {
describeCoverageUrl = describeCoverageUrl.substring(0, describeCoverageUrl.length() - 1);
}
}
} else if (name.endsWith(":getcoverage")) {
} else if (name.endsWith("getcoverage")) {
Node getNode = XmlHelper.findNode(childNode, "Get");
if (getNode != null) {
Node onlineResNode = XmlHelper.findNode(getNode, "OnlineResource");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public class WcsCapabilities implements IWcsCapabilities {

@Override
public boolean checkElementName(String name) {
if (name.equals("wcs:WCS_Capabilities") || name.endsWith(":WCS_Capabilities"))
if (name.equals("wcs:WCS_Capabilities") || name.endsWith("WCS_Capabilities"))
return true;
return false;
}

@Override
public void visit(Node node) throws Exception {
version = XmlHelper.findAttribute(node, "version");

identification = new Identification();
XmlHelper.apply(node, identification);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,29 @@ public CoverageSummary(List<ICoverageSummary> coverageSummaries) {
}

public boolean checkElementName(String name) {
if (name.equals("wcs:CoverageSummary") || name.endsWith(":CoverageSummary"))
if (name.equals("wcs:CoverageSummary") || name.endsWith("CoverageSummary"))
return true;
return false;
}

public void visit(Node node) {
CoverageSummary cs = new CoverageSummary(null);
cs.title = XmlHelper.findFirstTextInChildren(node, "label");
String title = XmlHelper.findFirstTextInChildren(node, "label");
if(title == null) {
title = XmlHelper.findFirstTextInChildren(node, "title");
}
cs.title = title;
cs.abstract_ = XmlHelper.findFirstTextInChildren(node, "description");

Node keywordsNode = XmlHelper.findNode(node, "keywords");
cs.keywords = XmlHelper.findAllTextsInChildren(keywordsNode, "keyword");
cs.coverageId = XmlHelper.findFirstTextInChildren(node, "name");
if(keywordsNode != null) {
cs.keywords = XmlHelper.findAllTextsInChildren(keywordsNode, "keyword");
}
cs.coverageId = XmlHelper.findFirstTextInChildren(node, "Identifier");
if (cs.coverageId == null) {
cs.coverageId = XmlHelper.findFirstTextInChildren(node, "name");
}


Node bboxNode = XmlHelper.findNode(node, "WGS84BoundingBox");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class DescribeCoverage implements IDescribeCoverage {

@Override
public boolean checkElementName(String name) {
if (name.equals("wcs:CoverageDescription") || name.endsWith(":CoverageDescription"))
System.out.println(name);
if (name.equals("wcs:CoverageDescription") || name.endsWith("CoverageDescription"))
return true;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public void visit(Node node) {
abstract_ = XmlHelper.findFirstTextInChildren(node, "abstract");

Node keywordsNode = XmlHelper.findNode(node, "keywords");
keywords = XmlHelper.findAllTextsInChildren(keywordsNode, "keyword");
if(keywordsNode != null) {
keywords = XmlHelper.findAllTextsInChildren(keywordsNode, "keyword");
}

serviceType = XmlHelper.findFirstTextInChildren(node, "servicetype");
supportedVersions = XmlHelper.findAllTextsInChildren(node, "servicetypeversion");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class WcsCapabilities implements IWcsCapabilities {

@Override
public boolean checkElementName(String name) {
if (name.equals("wcs:Capabilities") || name.endsWith(":Capabilities"))
if (name.equals("wcs:Capabilities") || name.endsWith("Capabilities"))
return true;
return false;
}
Expand Down
Loading

0 comments on commit 318bb09

Please sign in to comment.