/webportal/src/main/java/au/org/emii/portal/menu/MapLayerMetadata.java
Java | 394 lines | 289 code | 67 blank | 38 comment | 16 complexity | 9c4c584efae2db289af5ea0121741ced MD5 | raw file
1package au.org.emii.portal.menu; 2 3import java.io.Serializable; 4import java.util.ArrayList; 5import java.util.Collection; 6import java.util.Collections; 7import java.util.List; 8import net.sf.json.JSONObject; 9import org.apache.commons.lang.StringEscapeUtils; 10 11public class MapLayerMetadata implements Serializable { 12 13 private static final long serialVersionUID = 1L; 14 public final static int EARLIEST_CONCATENATED = 0; 15 public final static int EARLIEST_ISO = 1; 16 public final static int LATEST_CONCATENATED = 2; 17 public final static int LATEST_ISO = 3; 18 private String units = null; 19 private List<Double> bbox = null; 20 private List<Double> scaleRange; 21 private List<String> supportedStyles; 22 private List<String> datesWithData = new ArrayList<String>(); 23 /** 24 * 25 */ 26 private String nearestTimeIso; 27 private String copyright; 28 private List<String> palettes; 29 private String defaultPalette; 30 private boolean logScaling; 31 private String moreInfo; 32 // necessary? 33 private int timeSteps; 34 private String zAxisUnits = null; 35 private boolean zAxisPositive; 36 private List<Double> zAxisValues = new ArrayList<Double>(); 37 private long id; 38 private long maplayerid; 39 private boolean isSpeciesLayer = false; 40 //private String speciesLsid; 41 private String speciesRank; 42 private String speciesDisplayName; 43 private String speciesDisplayLsid; 44 private double[] layerExtent; 45 private int occurrencesCount; 46 47 public boolean isIsSpeciesLayer() { 48 return isSpeciesLayer; 49 } 50 51 public void setIsSpeciesLayer(boolean isSpeciesLayer) { 52 this.isSpeciesLayer = isSpeciesLayer; 53 } 54 55// public String getSpeciesLsid() { 56// return speciesLsid; 57// } 58// 59// public void setSpeciesLsid(String speciesLsid) { 60// this.speciesLsid = speciesLsid; 61// } 62 63 public String getSpeciesDisplayName() { 64 return speciesDisplayName; 65 } 66 67 public void setSpeciesDisplayName(String speciesDisplayName) { 68 this.speciesDisplayName = speciesDisplayName; 69 } 70 71 public String getSpeciesDisplayLsid() { 72 return speciesDisplayLsid; 73 } 74 75 public void setSpeciesDisplayLsid(String speciesDisplayLsid) { 76 this.speciesDisplayLsid = speciesDisplayLsid; 77 } 78 79 public String getSpeciesRank() { 80 return speciesRank; 81 } 82 83 public void setSpeciesRank(String speciesRank) { 84 this.speciesRank = speciesRank; 85 } 86 87 public double[] getLayerExtent() { 88 return layerExtent; 89 } 90 91 public void setLayerExtent(double[] layerExtent) { 92 this.layerExtent = layerExtent; 93 } 94 95 /** 96 * Set the layer extent after expanding the polygon by the 97 * given percent in all directions. 98 * 99 * min longitude -= factor*Width 100 * min latitude -= factor*Height 101 * max longitude += factor*Width 102 * max latitude += factor*Height 103 * 104 * @param polygon WKT for a rectangular polygon. 105 * @param expandFactor 106 */ 107 public void setLayerExtent(String polygon, double expandFactor) { 108 layerExtent = polygonToExtents(polygon); 109 double fw = expandFactor * (layerExtent[2] - layerExtent[0]); 110 double fh = expandFactor * (layerExtent[3] - layerExtent[1]); 111 layerExtent[0] -= fw; 112 layerExtent[1] -= fh; 113 layerExtent[2] += fw; 114 layerExtent[3] += fh; 115 } 116 117 /** 118 * WKT bounding box as POLYGON. 119 * 120 * @return 121 */ 122 public String getLayerExtentString() { 123 if (layerExtent != null) { 124 return "POLYGON((" + layerExtent[0] + " " + layerExtent[1] + "," 125 + layerExtent[2] + " " + layerExtent[1] + "," 126 + layerExtent[2] + " " + layerExtent[3] + "," 127 + layerExtent[0] + " " + layerExtent[3] + "," 128 + layerExtent[0] + " " + layerExtent[1] + "))"; 129 } 130 return null; 131 } 132 133 public long getMaplayerid() { 134 return maplayerid; 135 } 136 137 public void setMaplayerid(long maplayerid) { 138 this.maplayerid = maplayerid; 139 } 140 141 public String getzAxisUnits() { 142 return zAxisUnits; 143 } 144 145 public void setzAxisUnits(String zAxisUnits) { 146 this.zAxisUnits = zAxisUnits; 147 } 148 149 public boolean iszAxisPositive() { 150 return zAxisPositive; 151 } 152 153 public void setzAxisPositive(boolean zAxisPositive) { 154 this.zAxisPositive = zAxisPositive; 155 } 156 157 public List<Double> getzAxisValues() { 158 return zAxisValues; 159 } 160 161 public void setzAxisValues(List<Double> zAxisValues) { 162 this.zAxisValues = zAxisValues; 163 } 164 165 public long getId() { 166 return id; 167 } 168 169 public void setId(long id) { 170 this.id = id; 171 } 172 173 public void setDatesWithData(List<String> datesWithData) { 174 this.datesWithData = datesWithData; 175 } 176 177 public void addDateWithData(String date) { 178 datesWithData.add(date); 179 } 180 181 public String getUnits() { 182 return units; 183 } 184 185 public void setUnits(String units) { 186 this.units = units; 187 } 188 189 public int getTimeSteps() { 190 return timeSteps; 191 } 192 193 public void setTimeSteps(int timeSteps) { 194 this.timeSteps = timeSteps; 195 } 196 197 public String getZAxisUnits() { 198 return zAxisUnits; 199 } 200 201 public void setZAxisUnits(String axisUnits) { 202 zAxisUnits = axisUnits; 203 } 204 205 public boolean isZAxisPositive() { 206 return zAxisPositive; 207 } 208 209 public void setZAxisPositive(boolean axisPositive) { 210 zAxisPositive = axisPositive; 211 } 212 213 public String getNearestTimeIso() { 214 return nearestTimeIso; 215 } 216 217 public void setNearestTimeIso(String nearestTimeIso) { 218 this.nearestTimeIso = nearestTimeIso; 219 } 220 221 public String getCopyright() { 222 return copyright; 223 } 224 225 public void setCopyright(String copyright) { 226 this.copyright = copyright; 227 } 228 229 public String getDefaultPalette() { 230 return defaultPalette; 231 } 232 233 public void setDefaultPalette(String defaultPalette) { 234 this.defaultPalette = defaultPalette; 235 } 236 237 public boolean isLogScaling() { 238 return logScaling; 239 } 240 241 public void setLogScaling(boolean logScaling) { 242 this.logScaling = logScaling; 243 } 244 245 public List<Double> getBbox() { 246 return bbox; 247 } 248 249 public String getBboxString() { 250 if (bbox == null) { 251 return null; 252 } 253 if (bbox.size() == 0) { 254 return null; 255 } 256 return bbox.get(0) + "," 257 + bbox.get(1) + "," 258 + bbox.get(2) + "," 259 + bbox.get(3); 260 } 261 262 public void setBbox(List<Double> bbox) { 263 bbox.set(0,Math.max(-180.0,bbox.get(0))); 264 bbox.set(1,Math.max(-85.0,bbox.get(1))); 265 bbox.set(2,Math.min(180.0,bbox.get(2))); 266 bbox.set(3,Math.min(85.0,bbox.get(3))); 267 this.bbox = bbox; 268 } 269 270 public List<Double> getScaleRange() { 271 return scaleRange; 272 } 273 274 public void setScaleRange(List<Double> scaleRange) { 275 this.scaleRange = scaleRange; 276 } 277 278 public List<String> getPalettes() { 279 return palettes; 280 } 281 282 public void setPalettes(List<String> palettes) { 283 this.palettes = palettes; 284 } 285 286 public List<String> getSupportedStyles() { 287 return supportedStyles; 288 } 289 290 public void setSupportedStyles(List<String> supportedStyles) { 291 this.supportedStyles = supportedStyles; 292 } 293 294 public String getMoreInfo() { 295 return moreInfo; 296 } 297 298 public void setMoreInfo(String moreInfo) { 299 this.moreInfo = moreInfo; 300 } 301 302 public List<Double> getZAxisValues() { 303 return zAxisValues; 304 } 305 306 public void setZAxisValues(List<Double> axisValues) { 307 zAxisValues = axisValues; 308 } 309 310 @SuppressWarnings("unchecked") 311 public void setZAxisValues(Collection collection) { 312 zAxisValues.addAll(collection); 313 } 314 315 public List<String> getDatesWithData() { 316 return datesWithData; 317 } 318 319 public void sortDatesWithData() { 320 Collections.sort(datesWithData); 321 } 322 323 /** 324 * A layer supports animation if it has more than 325 * one date listed in it's datesWithData list 326 * @return 327 */ 328 public boolean isSupportsAnimation() { 329 return (datesWithData.size() > 1); 330 331 } 332 333 /** 334 * wrapper for getUnits() to escape any javascript chars 335 * @return 336 */ 337 public String getUnitsJS() { 338 return StringEscapeUtils.escapeJavaScript(getUnits()); 339 } 340 341 public boolean isOutside(String viewArea) { 342 double[] vArea = polygonToExtents(viewArea); 343 if(vArea == null) { 344 return false; 345 } 346 return !(vArea[0] >= layerExtent[0] && vArea[2] <= layerExtent[2] 347 && vArea[1] >= layerExtent[1] && vArea[3] <= layerExtent[3]); 348 } 349 350 double[] polygonToExtents(String polygon) { 351 try { 352 double[] extents = new double[4]; 353 String s = polygon.replace("POLYGON((", "").replace("))", "").replace(",", " ").replace("MULTI(", "").replace(")", "").replace("(", ""); 354 String[] sa = s.split(" "); 355 double long1 = Double.parseDouble(sa[0]); 356 double lat1 = Double.parseDouble(sa[1]); 357 double long2 = Double.parseDouble(sa[0]); 358 double lat2 = Double.parseDouble(sa[1]); 359 for (int i = 0; i < sa.length; i += 2) { 360 double lng = Double.parseDouble(sa[i]); 361 double lat = Double.parseDouble(sa[i + 1]); 362 if (lng < long1) { 363 long1 = lng; 364 } 365 if (lng > long2) { 366 long2 = lng; 367 } 368 if (lat < lat1) { 369 lat1 = lat; 370 } 371 if (lat > lat2) { 372 lat2 = lat; 373 } 374 } 375 extents[0] = Math.min(long1, long2); 376 extents[2] = Math.max(long1, long2); 377 extents[1] = Math.min(lat1, lat2); 378 extents[3] = Math.max(lat1, lat2); 379 return extents; 380 } catch (Exception e) { 381 System.out.println("polygonToExtents: " + polygon); 382 e.printStackTrace(); 383 } 384 return null; 385 } 386 387 public int getOccurrencesCount() { 388 return occurrencesCount; 389 } 390 391 public void setOccurrencesCount(int count) { 392 occurrencesCount = count; 393 } 394}