Updated library to be more general
git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/spatial-data/geo-utility@124013 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8ab2bab5c8
commit
9596e53349
|
@ -19,14 +19,14 @@ import org.gcube.spatial.data.geoutility.wms.ZAxis;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class GeoGetStylesUtility.
|
* The Class GeoNcWMSMetadataUtility.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
* Jan 25, 2016
|
* Feb 9, 2016
|
||||||
*/
|
*/
|
||||||
public class GeoGetStylesUtility {
|
public class GeoNcWMSMetadataUtility {
|
||||||
|
|
||||||
public static Logger logger = Logger.getLogger(GeoGetStylesUtility.class);
|
public static Logger logger = Logger.getLogger(GeoNcWMSMetadataUtility.class);
|
||||||
public static final String COLORSCALERANGE = "COLORSCALERANGE";
|
public static final String COLORSCALERANGE = "COLORSCALERANGE";
|
||||||
public static final String COLORSCALERANGE_DEFAULT_VALUE = "auto";
|
public static final String COLORSCALERANGE_DEFAULT_VALUE = "auto";
|
||||||
boolean isNcWms = false;
|
boolean isNcWms = false;
|
||||||
|
@ -34,8 +34,11 @@ public class GeoGetStylesUtility {
|
||||||
private List<String> geoStyles;
|
private List<String> geoStyles;
|
||||||
private Map<String, String> mapNcWmsStyles;
|
private Map<String, String> mapNcWmsStyles;
|
||||||
private WmsUrlValidator validator;
|
private WmsUrlValidator validator;
|
||||||
|
private int connectionTimeout;
|
||||||
|
private NcWmsLayerMetadata ncMetadata;
|
||||||
|
private ZAxis zAxis = null;
|
||||||
/** The Constant CONNECTION_TIMEOUT. */
|
/** The Constant CONNECTION_TIMEOUT. */
|
||||||
public static final int CONNECTION_TIMEOUT = 1000; //DEFAULT CONNECTION TIMEOUT
|
public static final int DEFAULT_CONNECTION_TIMEOUT = 1000; //DEFAULT CONNECTION TIMEOUT
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,8 +47,8 @@ public class GeoGetStylesUtility {
|
||||||
* @param wmsRequest the wms request
|
* @param wmsRequest the wms request
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public GeoGetStylesUtility(String wmsRequest) throws Exception{
|
public GeoNcWMSMetadataUtility(String wmsRequest) throws Exception{
|
||||||
this(wmsRequest, CONNECTION_TIMEOUT);
|
this(wmsRequest, DEFAULT_CONNECTION_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,22 +59,23 @@ public class GeoGetStylesUtility {
|
||||||
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
|
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public GeoGetStylesUtility(String wmsRequest, int connectionTimeout) throws Exception{
|
public GeoNcWMSMetadataUtility(String wmsRequest, int connectionTimeout) throws Exception{
|
||||||
this.wmsRequest = wmsRequest;
|
this.wmsRequest = wmsRequest;
|
||||||
|
this.connectionTimeout = connectionTimeout;
|
||||||
this.validator = new WmsUrlValidator(wmsRequest);
|
this.validator = new WmsUrlValidator(wmsRequest);
|
||||||
validator.parseWmsRequest(true, false);
|
validator.parseWmsRequest(true, false);
|
||||||
loadStyles(connectionTimeout);
|
validateConnectionTimeout();
|
||||||
|
loadMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new geo get styles utility.
|
* Instantiates a new geo get styles utility.
|
||||||
*
|
*
|
||||||
* @param validator the validator
|
* @param validator the validator
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public GeoGetStylesUtility(WmsUrlValidator validator) throws Exception{
|
public GeoNcWMSMetadataUtility(WmsUrlValidator validator) throws Exception{
|
||||||
this(validator, CONNECTION_TIMEOUT);
|
this(validator, DEFAULT_CONNECTION_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,17 +86,40 @@ public class GeoGetStylesUtility {
|
||||||
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
|
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public GeoGetStylesUtility(WmsUrlValidator validator, int connectionTimeout) throws Exception{
|
public GeoNcWMSMetadataUtility(WmsUrlValidator validator, int connectionTimeout) throws Exception{
|
||||||
this.wmsRequest = validator.getWmsRequest();
|
this.wmsRequest = validator.getWmsRequest();
|
||||||
this.validator = validator;
|
this.validator = validator;
|
||||||
loadStyles(connectionTimeout);
|
this.connectionTimeout = connectionTimeout;
|
||||||
|
validateConnectionTimeout();
|
||||||
|
loadMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load styles.
|
* Validate connection timeout.
|
||||||
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
|
|
||||||
*/
|
*/
|
||||||
private void loadStyles(int connectionTimeout){
|
private void validateConnectionTimeout(){
|
||||||
|
if(this.connectionTimeout<=0)
|
||||||
|
this.connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load metadata.
|
||||||
|
*
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
private void loadMetadata() throws Exception{
|
||||||
|
String uriWMSService = validator.getBaseWmsServiceUrl();
|
||||||
|
String layerName = validator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
|
||||||
|
this.ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout, METADATA.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load styles. This method retrieve WMS styles into List {@link #getGeoStyles()}
|
||||||
|
* and ncWMS styles into Map {@link #getMapNcWmsStyles()}
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public void loadStyles(){
|
||||||
|
|
||||||
String uriWMSService = validator.getBaseWmsServiceUrl();
|
String uriWMSService = validator.getBaseWmsServiceUrl();
|
||||||
String layerName = validator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
|
String layerName = validator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
|
||||||
|
@ -176,12 +203,13 @@ public class GeoGetStylesUtility {
|
||||||
isNcWms = true;
|
isNcWms = true;
|
||||||
try{
|
try{
|
||||||
|
|
||||||
METADATA[] meta = new METADATA[3];
|
if(ncMetadata==null){
|
||||||
meta[0] = METADATA.SUPPORTEDSTYLES;
|
METADATA[] meta = new METADATA[3];
|
||||||
meta[1] = METADATA.DEFAULTPALETTE;
|
meta[0] = METADATA.SUPPORTEDSTYLES;
|
||||||
meta[2] = METADATA.PALETTES;
|
meta[1] = METADATA.DEFAULTPALETTE;
|
||||||
|
meta[2] = METADATA.PALETTES;
|
||||||
NcWmsLayerMetadata ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout, meta);
|
this.ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout, meta);
|
||||||
|
}
|
||||||
|
|
||||||
if(ncMetadata!=null && ncMetadata.getResponseCode()==200){
|
if(ncMetadata!=null && ncMetadata.getResponseCode()==200){
|
||||||
//STYLES
|
//STYLES
|
||||||
|
@ -199,10 +227,6 @@ public class GeoGetStylesUtility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Z-AXIS
|
|
||||||
if(ncMetadata.getZAxis()!=null){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
|
@ -216,30 +240,39 @@ public class GeoGetStylesUtility {
|
||||||
this.geoStyles = styles;
|
this.geoStyles = styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load z axis values for a ncWMS layer
|
* Load z axis values for a ncWMS layer.
|
||||||
*
|
*
|
||||||
* @param connectionTimeout the connection timeout
|
|
||||||
* @return the z axis
|
* @return the z axis
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public ZAxis loadZAxis(int connectionTimeout){
|
public void loadZAxis() throws Exception{
|
||||||
|
|
||||||
String uriWMSService = validator.getBaseWmsServiceUrl();
|
if(ncMetadata==null){
|
||||||
String layerName = validator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
|
String uriWMSService = validator.getBaseWmsServiceUrl();
|
||||||
|
String layerName = validator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
|
||||||
METADATA[] meta = new METADATA[1];
|
METADATA[] meta = new METADATA[1];
|
||||||
meta[0] = METADATA.Z_AXIS;
|
meta[0] = METADATA.Z_AXIS;
|
||||||
|
this.ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout, meta);
|
||||||
try {
|
|
||||||
NcWmsLayerMetadata ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout, meta);
|
|
||||||
return ncMetadata.getZAxis();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
logger.error("Exception during ncWMS get zAxis: "+e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.ncMetadata==null)
|
||||||
|
this.zAxis = null;
|
||||||
|
|
||||||
|
this.zAxis = this.ncMetadata.getZAxis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the zAxis
|
||||||
|
*/
|
||||||
|
public ZAxis getzAxis() {
|
||||||
|
|
||||||
|
return zAxis;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the geo styles.
|
* Gets the geo styles.
|
||||||
*
|
*
|
||||||
|
@ -296,7 +329,7 @@ public class GeoGetStylesUtility {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("GeoGetStylesUtility [isNcWms=");
|
builder.append("GeoNcWMSMetadataUtility [isNcWms=");
|
||||||
builder.append(isNcWms);
|
builder.append(isNcWms);
|
||||||
builder.append(", wmsRequest=");
|
builder.append(", wmsRequest=");
|
||||||
builder.append(wmsRequest);
|
builder.append(wmsRequest);
|
||||||
|
@ -306,6 +339,12 @@ public class GeoGetStylesUtility {
|
||||||
builder.append(mapNcWmsStyles);
|
builder.append(mapNcWmsStyles);
|
||||||
builder.append(", validator=");
|
builder.append(", validator=");
|
||||||
builder.append(validator);
|
builder.append(validator);
|
||||||
|
builder.append(", connectionTimeout=");
|
||||||
|
builder.append(connectionTimeout);
|
||||||
|
builder.append(", ncMetadata=");
|
||||||
|
builder.append(ncMetadata);
|
||||||
|
builder.append(", zAxis=");
|
||||||
|
builder.append(zAxis);
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
|
@ -22,12 +22,6 @@ public class NcWmsLayerMetadata implements Serializable {
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 5111586382138532571L;
|
private static final long serialVersionUID = 5111586382138532571L;
|
||||||
|
|
||||||
//GET PARAMETERS
|
|
||||||
// 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";
|
|
||||||
|
|
||||||
public static enum METADATA {
|
public static enum METADATA {
|
||||||
SUPPORTEDSTYLES("supportedStyles"),
|
SUPPORTEDSTYLES("supportedStyles"),
|
||||||
PALETTES("palettes"),
|
PALETTES("palettes"),
|
||||||
|
@ -40,9 +34,6 @@ public class NcWmsLayerMetadata implements Serializable {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the key
|
|
||||||
*/
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
|
|
|
@ -24,9 +24,9 @@ public class GeoJUnitTest {
|
||||||
// String wmsRequest = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows?service=wms&version=1.1.0&request=GetMap&layers==IGG:area_temp_1000&width=676&height=330&srs=EPSG:4326&crs=EPSG:4326&format=application/openlayers&bbox=-85.5,-180.0,90.0,180.0";
|
// String wmsRequest = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows?service=wms&version=1.1.0&request=GetMap&layers==IGG:area_temp_1000&width=676&height=330&srs=EPSG:4326&crs=EPSG:4326&format=application/openlayers&bbox=-85.5,-180.0,90.0,180.0";
|
||||||
String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
|
String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
|
||||||
// String wmsRequest = "http://www.fao.org/figis/geoserver/species?SERVICE=WMS&BBOX=-176.0,-90.0,180.0,90&styles=&layers=layerName&FORMAT=image/gif";
|
// String wmsRequest = "http://www.fao.org/figis/geoserver/species?SERVICE=WMS&BBOX=-176.0,-90.0,180.0,90&styles=&layers=layerName&FORMAT=image/gif";
|
||||||
GeoGetStylesUtility geo;
|
GeoNcWMSMetadataUtility geo;
|
||||||
try {
|
try {
|
||||||
geo = new GeoGetStylesUtility(wmsRequest);
|
geo = new GeoNcWMSMetadataUtility(wmsRequest);
|
||||||
System.out.println("Returned styles: "+geo.getGeoStyles().toString());
|
System.out.println("Returned styles: "+geo.getGeoStyles().toString());
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue