/webportal/src/main/java/au/org/emii/portal/menu/MapLayerMetadata.java

http://alageospatialportal.googlecode.com/ · Java · 394 lines · 289 code · 67 blank · 38 comment · 16 complexity · 9c4c584efae2db289af5ea0121741ced MD5 · raw file

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