2191: Geo Utility enhancements: update json parser to retrieve z-axis property
Task-Url: https://support.d4science.org/issues/2191 pom version updated at 1.1.0 updated to retrieve z-axis property updated distro git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/spatial-data/geo-utility@124009 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
47bbef21fb
commit
c6df35cdc8
|
@ -14,7 +14,7 @@ Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo".
|
|||
Version
|
||||
------------------------
|
||||
|
||||
v. 1.0.0
|
||||
v. 1.1.0
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.spatial-data.geo-utility.1-1-0"
|
||||
date="2016-02-09">
|
||||
<Change>[Feature #2191] Update NcWmsGetMetadata to retrieve z-axis property</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.spatial-data.geo-utility.1-0-0"
|
||||
date="2016-01-26">
|
||||
<Change>[Feature #2054] First Release</Change>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
|||
<groupId>org.gcube.spatial.data</groupId>
|
||||
<artifactId>geo-utility</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<name>A library with several utility classes to work with geo-spatial data: WmsUrlValidator, GeoGetStyles, etc..</name>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -6,6 +6,8 @@ package org.gcube.spatial.data.geoutility.bean;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.spatial.data.geoutility.wms.ZAxis;
|
||||
|
||||
|
||||
/**
|
||||
* The Class NcWmsLayerMetadata.
|
||||
|
@ -24,18 +26,22 @@ public class NcWmsLayerMetadata implements Serializable {
|
|||
public static final String SUPPORTEDSTYLES = "supportedStyles";
|
||||
public static final String PALETTES = "palettes";
|
||||
public static final String DEFAULTPALETTE = "defaultPalette";
|
||||
public static final String Z_AXIS = "zaxis";
|
||||
|
||||
private String defaultPalette;
|
||||
private List<String> supportedStyles;
|
||||
private List<String> palettes;
|
||||
private int responseCode;
|
||||
private ZAxis zAxis;
|
||||
private String rawJson;
|
||||
|
||||
/**
|
||||
* Instantiates a new nc wms layer metadata.
|
||||
*/
|
||||
public NcWmsLayerMetadata() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new nc wms layer metadata.
|
||||
*
|
||||
|
@ -43,12 +49,34 @@ public class NcWmsLayerMetadata implements Serializable {
|
|||
* @param defaultPalette the default palette
|
||||
* @param supportedStyles the supported styles
|
||||
* @param palettes the palettes
|
||||
* @param zAxis the z axis
|
||||
* @param json the json
|
||||
*/
|
||||
public NcWmsLayerMetadata(int responseCode, String defaultPalette, List<String> supportedStyles, List<String> palettes) {
|
||||
public NcWmsLayerMetadata(int responseCode, String defaultPalette, List<String> supportedStyles, List<String> palettes, ZAxis zAxis, String json) {
|
||||
this.responseCode = responseCode;
|
||||
this.defaultPalette = defaultPalette;
|
||||
this.supportedStyles = supportedStyles;
|
||||
this.palettes = palettes;
|
||||
this.zAxis = zAxis;
|
||||
this.rawJson = json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the raw json.
|
||||
*
|
||||
* @param jsonTxt the new raw json
|
||||
*/
|
||||
public void setRawJson(String jsonTxt) {
|
||||
this.rawJson =jsonTxt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the raw json.
|
||||
*
|
||||
* @return the rawJson
|
||||
*/
|
||||
public String getRawJson() {
|
||||
return rawJson;
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,7 +89,6 @@ public class NcWmsLayerMetadata implements Serializable {
|
|||
return defaultPalette;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the supported styles.
|
||||
*
|
||||
|
@ -82,6 +109,27 @@ public class NcWmsLayerMetadata implements Serializable {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the z axis.
|
||||
*
|
||||
* @return the zAxis
|
||||
*/
|
||||
public ZAxis getZAxis() {
|
||||
|
||||
return zAxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the z axis.
|
||||
*
|
||||
* @param zAxis the zAxis to set
|
||||
*/
|
||||
public void setZAxis(ZAxis zAxis) {
|
||||
|
||||
this.zAxis = zAxis;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the default palette.
|
||||
*
|
||||
|
@ -102,6 +150,8 @@ public class NcWmsLayerMetadata implements Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the response code.
|
||||
*
|
||||
* @return the responseCode
|
||||
*/
|
||||
public int getResponseCode() {
|
||||
|
@ -109,6 +159,8 @@ public class NcWmsLayerMetadata implements Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the response code.
|
||||
*
|
||||
* @param responseCode the responseCode to set
|
||||
*/
|
||||
public void setResponseCode(int responseCode) {
|
||||
|
@ -116,7 +168,6 @@ public class NcWmsLayerMetadata implements Serializable {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the palettes.
|
||||
*
|
||||
|
@ -125,11 +176,14 @@ public class NcWmsLayerMetadata implements Serializable {
|
|||
public void setPalettes(List<String> palettes) {
|
||||
this.palettes = palettes;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("NcWmsLayerMetadata [defaultPalette=");
|
||||
builder.append(defaultPalette);
|
||||
|
@ -137,6 +191,10 @@ public class NcWmsLayerMetadata implements Serializable {
|
|||
builder.append(supportedStyles);
|
||||
builder.append(", palettes=");
|
||||
builder.append(palettes);
|
||||
builder.append(", responseCode=");
|
||||
builder.append(responseCode);
|
||||
builder.append(", zAxis=");
|
||||
builder.append(zAxis);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
|
|
@ -158,10 +158,11 @@ public class NcWmsGetMetadata {
|
|||
try{
|
||||
source = httpConnection.getInputStream();
|
||||
String jsonTxt = IOUtils.toString(source);
|
||||
metadata.setRawJson(jsonTxt);
|
||||
|
||||
JSONObject json = new JSONObject(jsonTxt);
|
||||
|
||||
JSONArray supportedStyles = json.getJSONArray("supportedStyles");
|
||||
|
||||
JSONArray supportedStyles = json.getJSONArray(NcWmsLayerMetadata.SUPPORTEDSTYLES);
|
||||
if(supportedStyles!=null){
|
||||
List<String> s = new ArrayList<String>(supportedStyles.length());
|
||||
for (int i=0; i<supportedStyles.length(); i++) {
|
||||
|
@ -170,8 +171,7 @@ public class NcWmsGetMetadata {
|
|||
metadata.setSupportedStyles(s);
|
||||
}
|
||||
|
||||
JSONArray palettes = json.getJSONArray("palettes");
|
||||
|
||||
JSONArray palettes = json.getJSONArray(NcWmsLayerMetadata.PALETTES);
|
||||
if(palettes!=null){
|
||||
List<String> s = new ArrayList<String>(palettes.length());
|
||||
for (int i=0; i<palettes.length(); i++) {
|
||||
|
@ -180,7 +180,25 @@ public class NcWmsGetMetadata {
|
|||
metadata.setPalettes(s);
|
||||
}
|
||||
|
||||
metadata.setDefaultPalette(json.getString("defaultPalette"));
|
||||
metadata.setDefaultPalette(json.getString(NcWmsLayerMetadata.DEFAULTPALETTE));
|
||||
|
||||
JSONObject zaxis = json.getJSONObject(NcWmsLayerMetadata.Z_AXIS);
|
||||
if(zaxis!=null){
|
||||
System.out.println(zaxis);
|
||||
ZAxis zAxis = new ZAxis();
|
||||
zAxis.setUnits(zaxis.getString(ZAxis.UNITS));
|
||||
zAxis.setPositive(zaxis.getBoolean(ZAxis.POSITIVE));
|
||||
JSONArray values = zaxis.getJSONArray(ZAxis.VALUES);
|
||||
System.out.println(values);
|
||||
if(values!=null){
|
||||
List<Integer> s = new ArrayList<Integer>(values.length());
|
||||
for (int i=0; i<values.length(); i++) {
|
||||
s.add(values.getInt(i));
|
||||
}
|
||||
zAxis.setValues(s);
|
||||
}
|
||||
metadata.setZAxis(zAxis);
|
||||
}
|
||||
|
||||
logger.trace("returning: "+metadata.toString());
|
||||
}catch (JSONException e){
|
||||
|
@ -203,7 +221,7 @@ public class NcWmsGetMetadata {
|
|||
// http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?item=minmax&layers=analyzed_field&bbox=-180.0,-85.0,180.0,85.0&crs=EPSG%3A4326&request=GetMetadata&width=640&height=480
|
||||
|
||||
try {
|
||||
System.out.println(NcWmsGetMetadata.getMetadata("http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc", "analyzed_field"));
|
||||
System.out.println(NcWmsGetMetadata.getMetadata("http://thredds.research-infrastructures.eu/thredds/wms/public/netcdf/WOA2005TemperatureAnnual_CLIMATOLOGY_METEOROLOGY_ATMOSPHERE_.nc", "t00an1"));
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.spatial.data.geoutility.wms;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Feb 9, 2016
|
||||
*/
|
||||
public class ZAxis implements Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 7559936591822228182L;
|
||||
public static final String UNITS = "units";
|
||||
public static final String POSITIVE = "positive";
|
||||
public static final String VALUES = "values";
|
||||
|
||||
private String units;
|
||||
private boolean positive;
|
||||
private List<Integer> values;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ZAxis() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param units
|
||||
* @param positive
|
||||
* @param values
|
||||
*/
|
||||
public ZAxis(String units, boolean positive, List<Integer> values) {
|
||||
this.units = units;
|
||||
this.positive = positive;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the units
|
||||
*/
|
||||
public String getUnits() {
|
||||
|
||||
return units;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the positive
|
||||
*/
|
||||
public boolean isPositive() {
|
||||
|
||||
return positive;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the values
|
||||
*/
|
||||
public List<Integer> getValues() {
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param units the units to set
|
||||
*/
|
||||
public void setUnits(String units) {
|
||||
|
||||
this.units = units;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param positive the positive to set
|
||||
*/
|
||||
public void setPositive(boolean positive) {
|
||||
|
||||
this.positive = positive;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param values the values to set
|
||||
*/
|
||||
public void setValues(List<Integer> values) {
|
||||
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ZAxis [units=");
|
||||
builder.append(units);
|
||||
builder.append(", positive=");
|
||||
builder.append(positive);
|
||||
builder.append(", values=");
|
||||
builder.append(values);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue