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
|
Version
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
v. 1.0.0
|
v. 1.1.0
|
||||||
|
|
||||||
Description
|
Description
|
||||||
-----------
|
-----------
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
<ReleaseNotes>
|
<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"
|
<Changeset component="org.gcube.spatial-data.geo-utility.1-0-0"
|
||||||
date="2016-01-26">
|
date="2016-01-26">
|
||||||
<Change>[Feature #2054] First Release</Change>
|
<Change>[Feature #2054] First Release</Change>
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
||||||
<groupId>org.gcube.spatial.data</groupId>
|
<groupId>org.gcube.spatial.data</groupId>
|
||||||
<artifactId>geo-utility</artifactId>
|
<artifactId>geo-utility</artifactId>
|
||||||
<packaging>jar</packaging>
|
<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>
|
<name>A library with several utility classes to work with geo-spatial data: WmsUrlValidator, GeoGetStyles, etc..</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -6,6 +6,8 @@ package org.gcube.spatial.data.geoutility.bean;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.spatial.data.geoutility.wms.ZAxis;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class NcWmsLayerMetadata.
|
* The Class NcWmsLayerMetadata.
|
||||||
|
@ -24,18 +26,22 @@ public class NcWmsLayerMetadata implements Serializable {
|
||||||
public static final String SUPPORTEDSTYLES = "supportedStyles";
|
public static final String SUPPORTEDSTYLES = "supportedStyles";
|
||||||
public static final String PALETTES = "palettes";
|
public static final String PALETTES = "palettes";
|
||||||
public static final String DEFAULTPALETTE = "defaultPalette";
|
public static final String DEFAULTPALETTE = "defaultPalette";
|
||||||
|
public static final String Z_AXIS = "zaxis";
|
||||||
|
|
||||||
private String defaultPalette;
|
private String defaultPalette;
|
||||||
private List<String> supportedStyles;
|
private List<String> supportedStyles;
|
||||||
private List<String> palettes;
|
private List<String> palettes;
|
||||||
private int responseCode;
|
private int responseCode;
|
||||||
|
private ZAxis zAxis;
|
||||||
|
private String rawJson;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new nc wms layer metadata.
|
* Instantiates a new nc wms layer metadata.
|
||||||
*/
|
*/
|
||||||
public NcWmsLayerMetadata() {
|
public NcWmsLayerMetadata() {
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new nc wms layer metadata.
|
* Instantiates a new nc wms layer metadata.
|
||||||
*
|
*
|
||||||
|
@ -43,12 +49,34 @@ public class NcWmsLayerMetadata implements Serializable {
|
||||||
* @param defaultPalette the default palette
|
* @param defaultPalette the default palette
|
||||||
* @param supportedStyles the supported styles
|
* @param supportedStyles the supported styles
|
||||||
* @param palettes the palettes
|
* @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.responseCode = responseCode;
|
||||||
this.defaultPalette = defaultPalette;
|
this.defaultPalette = defaultPalette;
|
||||||
this.supportedStyles = supportedStyles;
|
this.supportedStyles = supportedStyles;
|
||||||
this.palettes = palettes;
|
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;
|
return defaultPalette;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the supported styles.
|
* 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.
|
* Sets the default palette.
|
||||||
*
|
*
|
||||||
|
@ -102,6 +150,8 @@ public class NcWmsLayerMetadata implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the response code.
|
||||||
|
*
|
||||||
* @return the responseCode
|
* @return the responseCode
|
||||||
*/
|
*/
|
||||||
public int getResponseCode() {
|
public int getResponseCode() {
|
||||||
|
@ -109,6 +159,8 @@ public class NcWmsLayerMetadata implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Sets the response code.
|
||||||
|
*
|
||||||
* @param responseCode the responseCode to set
|
* @param responseCode the responseCode to set
|
||||||
*/
|
*/
|
||||||
public void setResponseCode(int responseCode) {
|
public void setResponseCode(int responseCode) {
|
||||||
|
@ -116,7 +168,6 @@ public class NcWmsLayerMetadata implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the palettes.
|
* Sets the palettes.
|
||||||
*
|
*
|
||||||
|
@ -125,11 +176,14 @@ public class NcWmsLayerMetadata implements Serializable {
|
||||||
public void setPalettes(List<String> palettes) {
|
public void setPalettes(List<String> palettes) {
|
||||||
this.palettes = palettes;
|
this.palettes = palettes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("NcWmsLayerMetadata [defaultPalette=");
|
builder.append("NcWmsLayerMetadata [defaultPalette=");
|
||||||
builder.append(defaultPalette);
|
builder.append(defaultPalette);
|
||||||
|
@ -137,6 +191,10 @@ public class NcWmsLayerMetadata implements Serializable {
|
||||||
builder.append(supportedStyles);
|
builder.append(supportedStyles);
|
||||||
builder.append(", palettes=");
|
builder.append(", palettes=");
|
||||||
builder.append(palettes);
|
builder.append(palettes);
|
||||||
|
builder.append(", responseCode=");
|
||||||
|
builder.append(responseCode);
|
||||||
|
builder.append(", zAxis=");
|
||||||
|
builder.append(zAxis);
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,10 +158,11 @@ public class NcWmsGetMetadata {
|
||||||
try{
|
try{
|
||||||
source = httpConnection.getInputStream();
|
source = httpConnection.getInputStream();
|
||||||
String jsonTxt = IOUtils.toString(source);
|
String jsonTxt = IOUtils.toString(source);
|
||||||
|
metadata.setRawJson(jsonTxt);
|
||||||
|
|
||||||
JSONObject json = new JSONObject(jsonTxt);
|
JSONObject json = new JSONObject(jsonTxt);
|
||||||
|
|
||||||
JSONArray supportedStyles = json.getJSONArray("supportedStyles");
|
JSONArray supportedStyles = json.getJSONArray(NcWmsLayerMetadata.SUPPORTEDSTYLES);
|
||||||
|
|
||||||
if(supportedStyles!=null){
|
if(supportedStyles!=null){
|
||||||
List<String> s = new ArrayList<String>(supportedStyles.length());
|
List<String> s = new ArrayList<String>(supportedStyles.length());
|
||||||
for (int i=0; i<supportedStyles.length(); i++) {
|
for (int i=0; i<supportedStyles.length(); i++) {
|
||||||
|
@ -170,8 +171,7 @@ public class NcWmsGetMetadata {
|
||||||
metadata.setSupportedStyles(s);
|
metadata.setSupportedStyles(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray palettes = json.getJSONArray("palettes");
|
JSONArray palettes = json.getJSONArray(NcWmsLayerMetadata.PALETTES);
|
||||||
|
|
||||||
if(palettes!=null){
|
if(palettes!=null){
|
||||||
List<String> s = new ArrayList<String>(palettes.length());
|
List<String> s = new ArrayList<String>(palettes.length());
|
||||||
for (int i=0; i<palettes.length(); i++) {
|
for (int i=0; i<palettes.length(); i++) {
|
||||||
|
@ -180,7 +180,25 @@ public class NcWmsGetMetadata {
|
||||||
metadata.setPalettes(s);
|
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());
|
logger.trace("returning: "+metadata.toString());
|
||||||
}catch (JSONException e){
|
}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
|
// 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 {
|
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) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
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