Compare commits
7 Commits
task_22747
...
master
Author | SHA1 | Date |
---|---|---|
Francesco Mangiacrapa | 528b6a4131 | |
Francesco Mangiacrapa | 4b34eefa49 | |
Francesco Mangiacrapa | dfc8dbb2c8 | |
Roberto Cirillo | c51d61ab7b | |
Francesco Mangiacrapa | 019fc40121 | |
Francesco Mangiacrapa | f1b6cc9b40 | |
Francesco Mangiacrapa | d8518b664b |
|
@ -1,10 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
|
||||
|
||||
<wb-module deploy-name="geo-utility">
|
||||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
|
||||
|
||||
<property name="context-root" value="geo-utility"/>
|
||||
|
||||
|
||||
<property name="java-output-path" value="/geo-utility/target/geo-utility-1.0.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
|
||||
|
||||
</wb-module>
|
||||
|
||||
|
||||
</project-modules>
|
||||
|
|
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -4,27 +4,30 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v1-3-0]
|
||||
|
||||
## [v1-2-0-SNAPSHOT] - 2022-02-01
|
||||
- Improved WFS builder [#26026]
|
||||
|
||||
## [v1.2.0] - 2022-02-01
|
||||
|
||||
- [#22747] Added WFS utilities
|
||||
|
||||
## [v1-1-2] - 2019-10-24
|
||||
## [v1.1.2] - 2019-10-24
|
||||
|
||||
- [#17831#change-92733] Bug fixed
|
||||
|
||||
|
||||
## [v1-1-1] - 2016-04-27
|
||||
## [v1.1.1] - 2016-04-27
|
||||
|
||||
- Updated comment in WMSGetStyles class
|
||||
- Bug fixing for method getValueOfParameter
|
||||
|
||||
|
||||
## [v1-1-0] - 2016-02-09
|
||||
## [v1.1.0] - 2016-02-09
|
||||
|
||||
- [Feature #2191] Updated NcWmsGetMetadata to retrieve z-axis
|
||||
|
||||
|
||||
## [v1-0-0] - 2016-01-26
|
||||
## [v1.0.0] - 2016-01-26
|
||||
|
||||
- [#2054] First release
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -5,13 +5,13 @@
|
|||
<parent>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.2.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.gcube.spatial.data</groupId>
|
||||
<artifactId>geo-utility</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.3.0</version>
|
||||
<name>geo-utility</name>
|
||||
<description>A library with utility classes to interact with geo-spatial data: WmsUrlValidator, GeoGetStyles, etc..</description>
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@ public enum WmsParameters {
|
|||
SRS("SRS","EPSG:4326"),
|
||||
CRS("CRS","EPSG:4326"), //WMS 1.3.0 COMPLIANT
|
||||
FORMAT("FORMAT","image/png"),
|
||||
TRANSPARENT("TRANSPARENT","true");
|
||||
TRANSPARENT("TRANSPARENT","true"),
|
||||
CQL_FILTER("CQL_FILTER","");
|
||||
|
||||
private String parameter;
|
||||
private String value;
|
||||
|
|
|
@ -0,0 +1,220 @@
|
|||
package org.gcube.spatial.data.geoutility.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BBOX implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -8703212808072493411L;
|
||||
|
||||
/** The lower left X. */
|
||||
private double lowerLeftX = 0.0;
|
||||
|
||||
/** The lower left Y. */
|
||||
private double lowerLeftY = 0.0;
|
||||
|
||||
/** The upper right X. */
|
||||
private double upperRightX = 0.0;
|
||||
|
||||
/** The upper right Y. */
|
||||
private double upperRightY = 0.0;
|
||||
|
||||
/** The crs. */
|
||||
private String crs = "";
|
||||
|
||||
public static enum COORDINATE_FORMAT {
|
||||
XY, YX
|
||||
}
|
||||
|
||||
public static final String BBOX_Separator = ",";
|
||||
|
||||
public BBOX() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new bbox.
|
||||
*
|
||||
* @param bbox the bbox as [minX,minY,maxX,maxY] XY (e.g. when service
|
||||
* version is 1.1.0). The bbox as [minY,minX,maxY,maxX] YZ
|
||||
* (e.g. when service version is 1.3.0)
|
||||
* @param serviceVersion the service version
|
||||
*/
|
||||
public BBOX(String bbox, COORDINATE_FORMAT format) {
|
||||
|
||||
if (format == null)
|
||||
format = COORDINATE_FORMAT.XY;
|
||||
|
||||
String[] theBBOX = bbox.replace("\\[", "").replace("\\]", "").split(",");
|
||||
switch (format) {
|
||||
case XY:
|
||||
this.lowerLeftX = Double.parseDouble(theBBOX[0]);
|
||||
this.lowerLeftY = Double.parseDouble(theBBOX[1]);
|
||||
this.upperRightX = Double.parseDouble(theBBOX[2]);
|
||||
this.upperRightY = Double.parseDouble(theBBOX[3]);
|
||||
break;
|
||||
case YX:
|
||||
this.lowerLeftX = Double.parseDouble(theBBOX[1]);
|
||||
this.lowerLeftY = Double.parseDouble(theBBOX[0]);
|
||||
this.upperRightX = Double.parseDouble(theBBOX[2]);
|
||||
this.upperRightY = Double.parseDouble(theBBOX[3]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public BBOX(double lowerLeftX, double lowerLeftY, double upperRightX, double upperRightY, String crs) {
|
||||
super();
|
||||
this.lowerLeftX = lowerLeftX;
|
||||
this.lowerLeftY = lowerLeftY;
|
||||
this.upperRightX = upperRightX;
|
||||
this.upperRightY = upperRightY;
|
||||
this.crs = crs;
|
||||
}
|
||||
|
||||
public String toBBOXString(COORDINATE_FORMAT format) {
|
||||
|
||||
if (format == null)
|
||||
format = COORDINATE_FORMAT.XY;
|
||||
|
||||
switch (format) {
|
||||
case XY:
|
||||
return String.format("%s%s%s%s%s%s%s", String.valueOf(lowerLeftX), BBOX_Separator,
|
||||
String.valueOf(lowerLeftY), BBOX_Separator, String.valueOf(upperRightX), BBOX_Separator,
|
||||
String.valueOf(upperRightY));
|
||||
case YX:
|
||||
return String.format("%s%s%s%s%s%s%s", String.valueOf(lowerLeftY), BBOX_Separator,
|
||||
String.valueOf(lowerLeftX), BBOX_Separator, String.valueOf(upperRightY), BBOX_Separator,
|
||||
String.valueOf(upperRightX));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String toBBOXString(BBOX extBBOX, COORDINATE_FORMAT format) {
|
||||
|
||||
if (format == null)
|
||||
format = COORDINATE_FORMAT.XY;
|
||||
|
||||
switch (format) {
|
||||
case XY:
|
||||
return String.format("%s%s%s%s%s%s%s", String.valueOf(extBBOX.getLowerLeftX()), BBOX_Separator,
|
||||
String.valueOf(extBBOX.getLowerLeftY()), BBOX_Separator, String.valueOf(extBBOX.getUpperRightX()),
|
||||
BBOX_Separator, String.valueOf(extBBOX.getUpperRightY()));
|
||||
case YX:
|
||||
return String.format("%s%s%s%s%s%s%s", String.valueOf(extBBOX.getLowerLeftY()), BBOX_Separator,
|
||||
String.valueOf(extBBOX.getLowerLeftX()), BBOX_Separator, String.valueOf(extBBOX.getUpperRightY()),
|
||||
BBOX_Separator, String.valueOf(extBBOX.getUpperRightX()));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the lower left X.
|
||||
*
|
||||
* @return the lower left X
|
||||
*/
|
||||
public double getLowerLeftX() {
|
||||
return lowerLeftX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lower left X.
|
||||
*
|
||||
* @param lowerLeftX the new lower left X
|
||||
*/
|
||||
public void setLowerLeftX(double lowerLeftX) {
|
||||
this.lowerLeftX = lowerLeftX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the lower left Y.
|
||||
*
|
||||
* @return the lower left Y
|
||||
*/
|
||||
public double getLowerLeftY() {
|
||||
return lowerLeftY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lower left Y.
|
||||
*
|
||||
* @param lowerLeftY the new lower left Y
|
||||
*/
|
||||
public void setLowerLeftY(double lowerLeftY) {
|
||||
this.lowerLeftY = lowerLeftY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the upper right X.
|
||||
*
|
||||
* @return the upper right X
|
||||
*/
|
||||
public double getUpperRightX() {
|
||||
return upperRightX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the upper right X.
|
||||
*
|
||||
* @param upperRightX the new upper right X
|
||||
*/
|
||||
public void setUpperRightX(double upperRightX) {
|
||||
this.upperRightX = upperRightX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the upper right Y.
|
||||
*
|
||||
* @return the upper right Y
|
||||
*/
|
||||
public double getUpperRightY() {
|
||||
return upperRightY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the upper right Y.
|
||||
*
|
||||
* @param upperRightY the new upper right Y
|
||||
*/
|
||||
public void setUpperRightY(double upperRightY) {
|
||||
this.upperRightY = upperRightY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the crs.
|
||||
*
|
||||
* @return the crs
|
||||
*/
|
||||
public String getCrs() {
|
||||
return crs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the crs.
|
||||
*
|
||||
* @param crs the new crs
|
||||
*/
|
||||
public void setCrs(String crs) {
|
||||
this.crs = crs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("BBOX [lowerLeftX=");
|
||||
builder.append(lowerLeftX);
|
||||
builder.append(", lowerLeftY=");
|
||||
builder.append(lowerLeftY);
|
||||
builder.append(", upperRightX=");
|
||||
builder.append(upperRightX);
|
||||
builder.append(", upperRightY=");
|
||||
builder.append(upperRightY);
|
||||
builder.append(", crs=");
|
||||
builder.append(crs);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -16,12 +16,10 @@ public enum WFSParameter {
|
|||
TYPENAME("TYPENAME", ""),
|
||||
STYLES("STYLES", ""),
|
||||
BBOX("BBOX", "-180,-90,180,90"),
|
||||
WIDTH("WIDTH", "676"),
|
||||
HEIGHT("HEIGHT", "230"),
|
||||
SRSNAME("srsName", "EPSG:4326"),
|
||||
CRS("CRS","EPSG:4326"), //WMS 1.3.0 COMPLIANT
|
||||
CRS("CRS",""), //WMS 1.3.0 COMPLIANT
|
||||
OUTPUTFORMAT("OUTPUTFORMAT", "application/json"),
|
||||
MAXFEATURES("MAXFEATURES", "10"),
|
||||
MAXFEATURES("MAXFEATURES", ""),
|
||||
PROPERTYNAME("PROPERTYNAME",""),
|
||||
CQL_FILTER("CQL_FILTER","");
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package org.gcube.spatial.data.geoutility.wfs;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.spatial.data.geoutility.shared.wfs.WFSParameter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class WFSQueryBuilder.
|
||||
|
@ -13,8 +16,14 @@ import org.gcube.spatial.data.geoutility.shared.wfs.WFSParameter;
|
|||
*/
|
||||
public class WFSQueryBuilder {
|
||||
|
||||
private static Logger LOG = LoggerFactory.getLogger(WFSQueryBuilder.class);
|
||||
|
||||
private String query = "";
|
||||
|
||||
private static HashMap<WFSParameter, String> wfsGetFeatureRequest = new HashMap<WFSParameter, String>();
|
||||
|
||||
public static final String GEOM_NAME_BOUNDED = "geom";
|
||||
|
||||
/**
|
||||
* Instantiates a new WFS query builder.
|
||||
*/
|
||||
|
@ -22,6 +31,22 @@ public class WFSQueryBuilder {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default WFS get feature request.
|
||||
*
|
||||
* @return the default WFS get feature request
|
||||
*/
|
||||
public HashMap<WFSParameter, String> getDefaultWFSGetFeatureRequest() {
|
||||
|
||||
wfsGetFeatureRequest.clear();
|
||||
|
||||
for (WFSParameter key : WFSParameter.values()) {
|
||||
wfsGetFeatureRequest.put(key, key.getValue());
|
||||
}
|
||||
|
||||
return wfsGetFeatureRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the parameter.
|
||||
*
|
||||
|
@ -67,4 +92,86 @@ public class WFSQueryBuilder {
|
|||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the WFS feature query.
|
||||
*
|
||||
* @param endpoint the endpoint
|
||||
* @param wfsGetFeatureRequest the wfs get feature request
|
||||
* @return the string
|
||||
*/
|
||||
public String buildWFSFeatureQuery(String endpoint, HashMap<WFSParameter, String> wfsGetFeatureRequest) {
|
||||
|
||||
LOG.debug("Map server endpoint: " + endpoint);
|
||||
LOG.debug("wfsGetFeatureRequest is: " + wfsGetFeatureRequest);
|
||||
|
||||
for (WFSParameter param : wfsGetFeatureRequest.keySet()) {
|
||||
if (param != null) {
|
||||
String value = wfsGetFeatureRequest.get(param);
|
||||
if (value != null) {
|
||||
switch (param) {
|
||||
case CQL_FILTER: {
|
||||
if (!value.isEmpty()) {
|
||||
if (value.contains("BBOX(" + GEOM_NAME_BOUNDED + "")) {
|
||||
// THE BBOX IS ALREADY USED INTO CQL FILTERING, SO USING IT DIRECTLY
|
||||
addParameter(WFSParameter.CQL_FILTER, value);
|
||||
} else {
|
||||
// I NEED TO ENCODE THE BBOX INTO CQL FILTERING,
|
||||
String boundingBox = wfsGetFeatureRequest.get(WFSParameter.BBOX);
|
||||
String cqlFilterValue = "BBOX(" + GEOM_NAME_BOUNDED + "," + boundingBox + ")" + " AND "
|
||||
+ value;
|
||||
addParameter(WFSParameter.CQL_FILTER, cqlFilterValue);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BBOX:
|
||||
// skipping
|
||||
break;
|
||||
|
||||
case SRSNAME: {
|
||||
// skipping
|
||||
break;
|
||||
}
|
||||
|
||||
case MAXFEATURES: {
|
||||
// Adding MAXFEATURES only if is not empty and it is an integer
|
||||
try {
|
||||
if (!value.isEmpty()) {
|
||||
Integer.parseInt(value);
|
||||
addParameter(param, value);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (!value.isEmpty())
|
||||
addParameter(param, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the query does not contain the CRS adding the SRSNAME
|
||||
if (!query.contains(WFSParameter.CRS.getParameter())) {
|
||||
String srsName = wfsGetFeatureRequest.get(WFSParameter.SRSNAME);
|
||||
if (srsName != null)
|
||||
addParameter(WFSParameter.SRSNAME, srsName);
|
||||
}
|
||||
|
||||
// If the query does not contain the CQL_FILTER adding the BBOX
|
||||
if (!query.contains(WFSParameter.CQL_FILTER.getParameter())) {
|
||||
String boundingBox = wfsGetFeatureRequest.get(WFSParameter.BBOX);
|
||||
if (boundingBox != null)
|
||||
addParameter(WFSParameter.BBOX, boundingBox);
|
||||
}
|
||||
|
||||
String wfsQuery = endpoint + "?" + query;
|
||||
|
||||
LOG.info("WFS: " + wfsQuery);
|
||||
return wfsQuery;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,8 @@ public enum WmsParameters {
|
|||
SRS("SRS","EPSG:4326"),
|
||||
CRS("CRS","EPSG:4326"), //WMS 1.3.0 COMPLIANT
|
||||
FORMAT("FORMAT","image/png"),
|
||||
TRANSPARENT("TRANSPARENT","true");
|
||||
TRANSPARENT("TRANSPARENT","true"),
|
||||
CQL_FILTER("CQL_FILTER","");
|
||||
|
||||
private String parameter;
|
||||
private String value;
|
||||
|
|
Loading…
Reference in New Issue