comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java @ 1107:005c2964f9af

Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles. flys-artifacts/trunk@2610 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 30 Aug 2011 14:13:06 +0000
parents e9f66d63bdd0
children 5b1198c27d43
comparison
equal deleted inserted replaced
1106:e9f66d63bdd0 1107:005c2964f9af
5 import java.net.MalformedURLException; 5 import java.net.MalformedURLException;
6 import java.util.List; 6 import java.util.List;
7 7
8 import javax.xml.xpath.XPathConstants; 8 import javax.xml.xpath.XPathConstants;
9 9
10 import com.vividsolutions.jts.geom.Geometry;
10 import com.vividsolutions.jts.geom.LineString; 11 import com.vividsolutions.jts.geom.LineString;
11 import com.vividsolutions.jts.geom.Polygon; 12 import com.vividsolutions.jts.geom.Polygon;
12 13
13 import org.apache.log4j.Logger; 14 import org.apache.log4j.Logger;
14 15
15 import org.opengis.feature.simple.SimpleFeature; 16 import org.opengis.feature.simple.SimpleFeature;
16 import org.opengis.feature.simple.SimpleFeatureType; 17 import org.opengis.feature.simple.SimpleFeatureType;
18 import org.opengis.referencing.FactoryException;
19 import org.opengis.referencing.NoSuchAuthorityCodeException;
17 20
18 import org.geotools.feature.FeatureCollection; 21 import org.geotools.feature.FeatureCollection;
19 import org.geotools.feature.FeatureCollections; 22 import org.geotools.feature.FeatureCollections;
20 import org.geotools.feature.SchemaException; 23 import org.geotools.feature.SchemaException;
24 import org.geotools.referencing.CRS;
21 25
22 import de.intevation.artifacts.Artifact; 26 import de.intevation.artifacts.Artifact;
23 import de.intevation.artifacts.CallContext; 27 import de.intevation.artifacts.CallContext;
24 28
25 import de.intevation.artifacts.common.utils.Config; 29 import de.intevation.artifacts.common.utils.Config;
39 extends DefaultState 43 extends DefaultState
40 implements FacetTypes 44 implements FacetTypes
41 { 45 {
42 /** The logger that is used in this state.*/ 46 /** The logger that is used in this state.*/
43 private static Logger logger = Logger.getLogger(FloodMapState.class); 47 private static Logger logger = Logger.getLogger(FloodMapState.class);
48
49
50 public static final String KEEP_ARTIFACT_DIR =
51 System.getProperty("flys.uesk.keep.artifactsdir", "false");
44 52
45 53
46 public static final String XPATH_SHAPEFILE_DIR = 54 public static final String XPATH_SHAPEFILE_DIR =
47 "/artifact-database/floodmap/shapefile-path/@value"; 55 "/artifact-database/floodmap/shapefile-path/@value";
48 56
72 } 80 }
73 81
74 WSPLGENJob job = prepareWSPLGENJob(artifact, artifactDir); 82 WSPLGENJob job = prepareWSPLGENJob(artifact, artifactDir);
75 83
76 if (job == null) { 84 if (job == null) {
77 removeDirectory(artifact); 85 if (KEEP_ARTIFACT_DIR.equals("false")) {
86 removeDirectory(artifact);
87 }
78 88
79 logger.error("No WSPLGEN processing has been started!"); 89 logger.error("No WSPLGEN processing has been started!");
80 90
81 return null; 91 return null;
82 } 92 }
258 protected void setLine(FLYSArtifact artifact, File dir, WSPLGENJob job) { 268 protected void setLine(FLYSArtifact artifact, File dir, WSPLGENJob job) {
259 String geoJSON = artifact.getDataAsString("uesk.barriers"); 269 String geoJSON = artifact.getDataAsString("uesk.barriers");
260 String srid = FLYSUtils.getRiverSrid(artifact); 270 String srid = FLYSUtils.getRiverSrid(artifact);
261 String srs = "EPSG:" + srid; 271 String srs = "EPSG:" + srid;
262 272
263 SimpleFeatureType ft = GeometryUtils.buildBarriersFeatureType(srs); 273 List<SimpleFeature> features = getBarriersFeatures(geoJSON, srs);
264 List<SimpleFeature> features = GeometryUtils.parseGeoJSON(geoJSON, ft); 274 if (features == null || features.size() == 0) {
275 logger.debug("No barrier features extracted.");
276 return;
277 }
265 278
266 FeatureCollection[] fcs = splitLinesAndPolygons(features); 279 FeatureCollection[] fcs = splitLinesAndPolygons(features);
267 280
268 File shapeLines = new File(dir, WSPLGEN_BARRIERS_LINES); 281 File shapeLines = new File(dir, WSPLGEN_BARRIERS_LINES);
269 File shapePolys = new File(dir, WSPLGEN_BARRIERS_POLY); 282 File shapePolys = new File(dir, WSPLGEN_BARRIERS_POLY);
270 283
271 try { 284 try {
272 GeometryUtils.writeShapefile( 285 GeometryUtils.writeShapefile(
273 shapeLines, 286 shapeLines,
274 GeometryUtils.buildFeatureType("lines", srid, "LineString"), 287 GeometryUtils.buildFeatureType(
288 "lines", srs, LineString.class, CRS.decode(srs)),
275 fcs[0]); 289 fcs[0]);
276 job.addLin(shapeLines.getAbsolutePath()); 290 job.addLin(shapeLines.getAbsolutePath());
277 291
278 GeometryUtils.writeShapefile( 292 GeometryUtils.writeShapefile(
279 shapePolys, 293 shapePolys,
280 GeometryUtils.buildFeatureType("polygons", srid, "Polygon"), 294 GeometryUtils.buildFeatureType(
295 "polygons", srs, Polygon.class, CRS.decode(srs)),
281 fcs[1]); 296 fcs[1]);
282 job.addLin(shapePolys.getAbsolutePath()); 297 job.addLin(shapePolys.getAbsolutePath());
283 } 298 }
284 catch (MalformedURLException mue) { 299 catch (MalformedURLException mue) {
285 logger.error("Error while writing shapefile: " + mue.getMessage()); 300 logger.error("Error while writing shapefile: " + mue.getMessage());
288 logger.error("Error while writing shapefile: " + ioe.getMessage()); 303 logger.error("Error while writing shapefile: " + ioe.getMessage());
289 } 304 }
290 catch (SchemaException se) { 305 catch (SchemaException se) {
291 logger.error("Error while writing shapefile: " + se.getMessage()); 306 logger.error("Error while writing shapefile: " + se.getMessage());
292 } 307 }
308 catch (NoSuchAuthorityCodeException nsae) {
309 logger.error("Error while writing shapefile: " + nsae.getMessage());
310 }
311 catch (FactoryException fe) {
312 logger.error("Error while writing shapefile: " + fe.getMessage());
313 }
314 }
315
316
317 protected List<SimpleFeature> getBarriersFeatures(String json, String srs) {
318 SimpleFeatureType ft = null;
319 List<SimpleFeature> features = null;
320
321 try {
322 ft = GeometryUtils.buildFeatureType(
323 "barriers", srs, Geometry.class, CRS.decode(srs));
324
325 features = GeometryUtils.parseGeoJSON(json, ft);
326 }
327 catch (SchemaException se) {
328 logger.warn("Error while reading GeoJSON: " + se.getMessage());
329 }
330 catch (NoSuchAuthorityCodeException nsae) {
331 logger.warn("Error while reading GeoJSON: " + nsae.getMessage());
332 }
333 catch (FactoryException fe) {
334 logger.warn("Error while reading GeoJSON: " + fe.getMessage());
335 }
336
337 return features;
293 } 338 }
294 339
295 340
296 protected FeatureCollection[] splitLinesAndPolygons(List<SimpleFeature> f) { 341 protected FeatureCollection[] splitLinesAndPolygons(List<SimpleFeature> f) {
297 FeatureCollection lines = FeatureCollections.newCollection(); 342 FeatureCollection lines = FeatureCollections.newCollection();

http://dive4elements.wald.intevation.org