Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/HWSBarriersState.java @ 5688:7b6cca32f940
Added tag 2.9.19 for changeset c4162d8378a1
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 12 Apr 2013 19:18:02 +0200 |
parents | 9207142726b3 |
children |
rev | line source |
---|---|
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.states; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
2 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
3 import java.io.File; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
4 import java.io.FileNotFoundException; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
5 import java.io.IOException; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
6 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
7 import java.util.ArrayList; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
8 import java.util.Arrays; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
9 import java.util.List; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
10 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
11 import org.apache.log4j.Logger; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
12 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
13 import org.apache.velocity.Template; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
14 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
15 import org.geotools.data.shapefile.ShapefileDataStore; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
16 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
17 import org.geotools.feature.FeatureCollection; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
18 import org.geotools.feature.FeatureCollections; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
19 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
20 import org.opengis.feature.simple.SimpleFeatureType; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
21 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
22 import org.opengis.feature.type.GeometryDescriptor; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
23 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
24 import org.w3c.dom.Element; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
25 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
26 import de.intevation.artifactdatabase.state.Facet; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
27 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
28 import de.intevation.artifacts.Artifact; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
29 import de.intevation.artifacts.CallContext; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
30 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
31 import de.intevation.artifacts.common.utils.FileTools; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
32 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
33 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
34 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
35 import de.intevation.flys.artifacts.FLYSArtifact; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
36 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
37 import de.intevation.flys.artifacts.access.MapAccess; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
38 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
39 import de.intevation.flys.artifacts.model.LayerInfo; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
40 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
41 import de.intevation.flys.artifacts.model.map.HWS; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
42 import de.intevation.flys.artifacts.model.map.HWSContainer; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
43 import de.intevation.flys.artifacts.model.map.HWSFactory; |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
44 |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
45 import de.intevation.flys.utils.ArtifactMapfileGenerator; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
46 import de.intevation.flys.utils.FLYSUtils; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 import de.intevation.flys.utils.GeometryUtils; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
48 import de.intevation.flys.utils.MapfileGenerator; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
50 public class HWSBarriersState |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
51 extends DefaultState |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
52 { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
53 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 /** The logger that is used in this class.*/ |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
55 private static Logger logger = Logger.getLogger(HWSBarriersState.class); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
56 private static final String HWS_SHAPEFILE_LINES = "hws-lines.shp"; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
57 private static final String HWS_SHAPEFILE_POINTS = "hws-points.shp"; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
58 private static final String USER_RGD_SHAPE = "user-rgd.shp"; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
59 private static final String USER_RGD_ZIP = "user-rgd.zip"; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
60 private static final String USER_RGD_FILENAME = "user-rgd"; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
61 @Override |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
62 protected String getUIProvider() { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
63 return "map_digitize"; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
64 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
65 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
66 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
67 @Override |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
68 protected Element createStaticData( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
69 FLYSArtifact flys, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
70 ElementCreator creator, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
71 CallContext cc, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
72 String name, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
73 String value, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
74 String type |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
75 ) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
76 Element dataElement = creator.create("data"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
77 creator.addAttr(dataElement, "name", name, true); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
78 creator.addAttr(dataElement, "type", type, true); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
79 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
80 Element itemElement = creator.create("item"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
81 creator.addAttr(itemElement, "value", value, true); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
82 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
83 creator.addAttr(itemElement, "label", "", true); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
84 dataElement.appendChild(itemElement); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
85 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
86 return dataElement; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
87 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
88 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
89 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
90 @Override |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
91 public Object computeAdvance( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
92 FLYSArtifact artifact, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
93 String hash, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
94 CallContext context, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
95 List<Facet> facets, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
96 Object old |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
97 ) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
98 File artifactDir = getDirectory(artifact); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
99 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
100 if (artifactDir == null) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
101 logger.error("Could not create directory for HWS shapefile!"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
102 return null; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
103 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
104 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
105 MapAccess access = new MapAccess(artifact, context); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
106 String river = access.getRiver(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
107 HWSContainer hwsLines = HWSFactory.getHWSLines(river); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
108 HWSContainer hwsPoints = HWSFactory.getHWSPoints(river); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
109 List<String> selected = access.getHWS(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
110 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
111 List<HWS> selectedLines = hwsLines.getHws(selected); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
112 List<HWS> selectedPoints = hwsPoints.getHws(selected); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
113 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
114 FeatureCollection collectionLines = FeatureCollections.newCollection(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
115 SimpleFeatureType lineType = null; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
116 for (HWS h : selectedLines) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
117 lineType = h.getFeatureType(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
118 collectionLines.add(h.getFeature()); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
119 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
120 boolean successLines = false; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
121 if (lineType != null && collectionLines.size() > 0) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
122 File shapeLines = new File(artifactDir, HWS_SHAPEFILE_LINES); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
123 successLines = GeometryUtils.writeShapefile( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
124 shapeLines, lineType, collectionLines); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
125 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
126 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
127 FeatureCollection collectionPoints = FeatureCollections.newCollection(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
128 SimpleFeatureType pointType = null; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
129 for (HWS h : selectedPoints) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
130 pointType = h.getFeatureType(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
131 collectionPoints.add(h.getFeature()); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
132 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
133 boolean successPoints = false; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
134 if (pointType != null && collectionPoints.size() > 0) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
135 File shapePoints = new File(artifactDir, HWS_SHAPEFILE_POINTS); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
136 successPoints =GeometryUtils.writeShapefile( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
137 shapePoints, pointType, collectionPoints); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
138 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
139 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
140 if (successLines) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
141 createMapfile( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
142 artifact, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
143 artifactDir, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
144 MapfileGenerator.MS_LAYER_PREFIX + "hws-lines", |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
145 HWS_SHAPEFILE_LINES, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
146 "LINE", |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
147 "31467", |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
148 "hws"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
149 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
150 if (successPoints) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
151 createMapfile( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
152 artifact, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
153 artifactDir, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
154 MapfileGenerator.MS_LAYER_PREFIX + "hws-points", |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
155 HWS_SHAPEFILE_POINTS, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
156 "POINT", |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
157 "31467", |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
158 "hws"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
159 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
160 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
161 String userRgd = artifact.getDataAsString("uesk.user-rgd"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
162 if (!userRgd.equals("none")) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
163 if (extractUserShp(artifactDir)) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
164 try { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
165 ShapefileDataStore store = new ShapefileDataStore( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
166 new File(artifactDir.getCanonicalPath() + |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
167 "/" + USER_RGD_SHAPE) |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
168 .toURI().toURL()); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
169 GeometryDescriptor desc = |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
170 store.getSchema().getGeometryDescriptor(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
171 String type = desc.getType().getName().toString(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
172 String proj = |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
173 desc.getCoordinateReferenceSystem(). |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
174 getCoordinateSystem().toString(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
175 int pos1 = proj.indexOf("EPSG\",\""); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
176 int pos2 = proj.indexOf("\"]]"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
177 String epsg = ""; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
178 if (pos1 >= 0 && pos2 >= 0) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
179 epsg = |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
180 proj.substring(proj.indexOf("EPSG\",\"") + 7, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
181 proj.indexOf("\"]]")); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
182 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
183 else { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
184 logger.warn("Could not read EPSG code from shapefile."); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
185 return null; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
186 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
187 if (type.contains("Line")) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
188 type = "LINE"; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
189 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
190 else if (type.contains("Poly")) { |
5394
9207142726b3
Fix typo in HWSBarriersState that caused mapfile corruption
Andre Heinecke <aheinecke@intevation.de>
parents:
5313
diff
changeset
|
191 type = "POLYGON"; |
5310
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
192 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
193 else { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
194 type = "POINT"; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
195 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
196 createMapfile( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
197 artifact, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
198 artifactDir, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
199 MapfileGenerator.MS_LAYER_PREFIX + USER_RGD_FILENAME, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
200 USER_RGD_SHAPE, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
201 type, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
202 epsg, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
203 "user-rgd"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
204 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
205 catch (IOException e) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
206 logger.warn("No mapfile for user-rgd created!"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
207 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
208 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
209 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
210 return null; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
211 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
212 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
213 private boolean extractUserShp(File dir) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
214 // TODO Auto-generated method stub |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
215 File archive = new File(dir, USER_RGD_ZIP); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
216 boolean exists = archive.exists(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
217 logger.debug("Zip file exists: " + exists); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
218 if (exists) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
219 try { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
220 File tmpDir = new File(dir, "usr_tmp"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
221 FileTools.extractArchive(archive, tmpDir); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
222 moveFiles(tmpDir, dir); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
223 return true; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
224 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
225 catch (IOException ioe) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
226 logger.warn("Zip archive " + dir + "/" |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
227 + USER_RGD_ZIP + " could not be extracted."); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
228 return false; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
229 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
230 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
231 return false; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
232 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
233 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
234 private void moveFiles(File source, final File target) |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
235 throws IOException |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
236 { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
237 if (!source.exists()) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
238 return; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
239 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
240 if (!target.exists()) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
241 target.mkdir(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
242 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
243 FileTools.walkTree(source, new FileTools.FileVisitor() { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
244 @Override |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
245 public boolean visit(File file) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
246 if (!file.isDirectory()) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
247 String name = file.getName(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
248 String suffix = ""; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
249 int pos = name.lastIndexOf('.'); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
250 if (pos > 0 && pos < name.length() - 1) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
251 suffix = name.substring(pos + 1); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
252 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
253 else { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
254 return true; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
255 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
256 try { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
257 FileTools.copyFile(file, new File(target, USER_RGD_FILENAME + "." + suffix)); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
258 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
259 catch (IOException ioe) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
260 logger.warn ("Error while copying file " + file.getName()); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
261 return true; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
262 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
263 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
264 return true; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
265 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
266 }); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
267 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
268 FileTools.deleteRecursive(source); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
269 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
270 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
271 private void createMapfile( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
272 FLYSArtifact artifact, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
273 File artifactDir, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
274 String name, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
275 String hwsShapefile, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
276 String type, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
277 String srid, |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
278 String group |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
279 ) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
280 LayerInfo info = new LayerInfo(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
281 info.setName(name + artifact.identifier()); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
282 info.setType(type); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
283 info.setDirectory(artifact.identifier()); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
284 info.setTitle(name); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
285 info.setData(hwsShapefile); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
286 info.setSrid(srid); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
287 info.setGroupTitle(group); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
288 MapfileGenerator generator = new ArtifactMapfileGenerator(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
289 Template tpl = generator.getTemplateByName(MapfileGenerator.SHP_LAYER_TEMPLATE); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
290 try { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
291 File layer = new File(artifactDir.getCanonicalPath() + "/" + name); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
292 generator.writeLayer(info, layer, tpl); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
293 List<String> layers = new ArrayList<String>(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
294 layers.add(layer.getAbsolutePath()); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
295 generator.generate(); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
296 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
297 catch(FileNotFoundException fnfe) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
298 logger.warn("Could not find mapfile for hws layer"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
299 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
300 catch (Exception ioe) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
301 logger.warn("Could not create mapfile for hws layer"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
302 logger.warn(Arrays.toString(ioe.getStackTrace())); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
303 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
304 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
305 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
306 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
307 @Override |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
308 public void endOfLife(Artifact artifact, Object callContext) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
309 super.endOfLife(artifact, callContext); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
310 logger.info("ScenarioSelect.endOfLife: " + artifact.identifier()); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
311 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
312 FLYSArtifact flys = (FLYSArtifact) artifact; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
313 removeDirectory(flys); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
314 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
315 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
316 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
317 /** |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
318 * Removes the directory and all its content where the required data and the |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
319 * results of WSPLGEN are stored. Should be called in endOfLife(). |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
320 */ |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
321 // FIXME: I've seen this code somewhere else... |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
322 protected void removeDirectory(FLYSArtifact artifact) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
323 String shapePath = FLYSUtils.getXPathString( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
324 FLYSUtils.XPATH_FLOODMAP_SHAPEFILE_DIR); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
325 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
326 File artifactDir = new File(shapePath, artifact.identifier()); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
327 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
328 if (artifactDir.exists()) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
329 logger.debug("Delete directory: " + artifactDir.getAbsolutePath()); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
330 boolean success = FileTools.deleteRecursive(artifactDir); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
331 if (!success) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
332 logger.warn("could not remove dir '" + artifactDir + "'"); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
333 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
334 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
335 else { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
336 logger.debug("There is no directory to remove."); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
337 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
338 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
339 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
340 /** |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
341 * Returns (and creates if not existing) the directory for storing WSPLEN |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
342 * data for the owner artifact. |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
343 * |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
344 * @param artifact The owner Artifact. |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
345 * |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
346 * @return the directory for WSPLEN data. |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
347 */ |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
348 protected File getDirectory(FLYSArtifact artifact) { |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
349 String shapePath = FLYSUtils.getXPathString( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
350 FLYSUtils.XPATH_FLOODMAP_SHAPEFILE_DIR); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
351 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
352 File artifactDir = FileTools.getDirectory( |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
353 shapePath, artifact.identifier()); |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
354 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
355 return artifactDir; |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
356 } |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
357 |
11c853b0854a
Added new states for HWS, user shapefile and barriers.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
358 } |
5313
a1cb9a734cc5
Cleaned up imports.#
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5310
diff
changeset
|
359 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |