Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 622:89aca25642d6
Implemented method stubs of MapfileGenerator. Mapfiles are successfully created corresponding meta.xml files.
gnv-artifacts/trunk@693 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 19 Feb 2010 13:28:34 +0000 |
parents | 567216b56983 |
children | 65f09139e9b3 |
comparison
equal
deleted
inserted
replaced
621:567216b56983 | 622:89aca25642d6 |
---|---|
50 import de.intevation.gnv.utils.Pair; | 50 import de.intevation.gnv.utils.Pair; |
51 import de.intevation.gnv.utils.ShapeFileWriter; | 51 import de.intevation.gnv.utils.ShapeFileWriter; |
52 import de.intevation.gnv.utils.StringUtils; | 52 import de.intevation.gnv.utils.StringUtils; |
53 import de.intevation.gnv.utils.WKTUtils; | 53 import de.intevation.gnv.utils.WKTUtils; |
54 | 54 |
55 import de.intevation.gnv.wms.LayerInfo; | |
56 | |
55 import java.awt.Dimension; | 57 import java.awt.Dimension; |
56 | 58 |
57 import java.io.File; | 59 import java.io.File; |
60 import java.io.FileNotFoundException; | |
61 import java.io.FileOutputStream; | |
58 import java.io.IOException; | 62 import java.io.IOException; |
59 import java.io.OutputStream; | 63 import java.io.OutputStream; |
60 | 64 |
61 import java.util.ArrayList; | 65 import java.util.ArrayList; |
62 import java.util.Collection; | 66 import java.util.Collection; |
72 import org.w3c.dom.Node; | 76 import org.w3c.dom.Node; |
73 | 77 |
74 /** | 78 /** |
75 * @author Tim Englich (tim.englich@intevation.de) | 79 * @author Tim Englich (tim.englich@intevation.de) |
76 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) | 80 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
81 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) | |
77 */ | 82 */ |
78 public class HorizontalCrossSectionMeshOutputState | 83 public class HorizontalCrossSectionMeshOutputState |
79 extends OutputStateBase | 84 extends OutputStateBase |
80 { | 85 { |
81 private static Logger log = Logger | 86 private static Logger log = Logger |
82 .getLogger(HorizontalCrossSectionMeshOutputState.class); | 87 .getLogger(HorizontalCrossSectionMeshOutputState.class); |
83 | 88 |
84 /** | 89 /** |
85 * The UID of this Class | 90 * The UID of this Class |
86 */ | 91 */ |
87 private static final long serialVersionUID = 3233620652465061860L; | 92 private static final long serialVersionUID = 3233620652465061860L; |
88 | 93 |
89 public static final boolean USE_INDEX_BUFFER = | 94 public static final boolean USE_INDEX_BUFFER = |
90 Boolean.getBoolean("gnv.horizontal.cross.section.mesh.index.buffer"); | 95 Boolean.getBoolean("gnv.horizontal.cross.section.mesh.index.buffer"); |
96 | |
97 public static final String META_FILE_NAME = "meta.xml"; | |
98 public static final String ISOLINES_NAME = "isolines.shp"; | |
99 public static final String POLYGON_NAME = "polygons.shp"; | |
100 public static final String LAYER_MODEL = "horizontalcrosssection"; | |
91 | 101 |
92 private String ijkQueryID; | 102 private String ijkQueryID; |
93 | 103 |
94 private Boolean shapeFileLock = new Boolean(true); | 104 private Boolean shapeFileLock = new Boolean(true); |
95 | 105 |
248 } | 258 } |
249 else { | 259 else { |
250 AttributedPoint2ds result = getResult(uuid, callContext); | 260 AttributedPoint2ds result = getResult(uuid, callContext); |
251 if (result != null | 261 if (result != null |
252 && (path = writeToShapeFile(uuid, result, callContext)) != null) { | 262 && (path = writeToShapeFile(uuid, result, callContext)) != null) { |
263 | |
264 Document meta = null; | |
265 if ((meta = writeMeta(callContext, uuid, path)) != null) { | |
266 MapfileGenerator.getInstance().update(); | |
267 return meta; | |
268 } | |
269 | |
253 pathElement.setTextContent(path); | 270 pathElement.setTextContent(path); |
254 } | 271 } |
255 } | 272 } |
256 | 273 |
257 return document; | 274 return document; |
288 Map<Integer, MultiPolygon> polygons = result.getPolygons(); | 305 Map<Integer, MultiPolygon> polygons = result.getPolygons(); |
289 | 306 |
290 List<Pair<Object, MultiLineString>> isolines = | 307 List<Pair<Object, MultiLineString>> isolines = |
291 result.getLineStrings(); | 308 result.getLineStrings(); |
292 | 309 |
293 File polygonsFile = new File(shapeDir, "polygons.shp"); | 310 File polygonsFile = new File(shapeDir, POLYGON_NAME); |
294 File isolinesFile = new File(shapeDir, "isolines.shp"); | 311 File isolinesFile = new File(shapeDir, ISOLINES_NAME); |
295 | 312 |
296 if (!ShapeFileWriter.writeMultiPolygonsToFile( | 313 if (!ShapeFileWriter.writeMultiPolygonsToFile( |
297 polygonsFile, | 314 polygonsFile, |
298 (Integer)result.getAttribute("parameter"), | 315 (Integer)result.getAttribute("parameter"), |
299 (Integer)result.getAttribute("layer"), | 316 (Integer)result.getAttribute("layer"), |
318 shapeFilePath = shapeDir.getAbsolutePath(); | 335 shapeFilePath = shapeDir.getAbsolutePath(); |
319 success = true; | 336 success = true; |
320 | 337 |
321 callContext.afterCall(CallContext.STORE); | 338 callContext.afterCall(CallContext.STORE); |
322 | 339 |
323 MapfileGenerator.getInstance().update(); | |
324 | |
325 return shapeFilePath; | 340 return shapeFilePath; |
326 } | 341 } |
327 finally { | 342 finally { |
328 if (!success && createdDir) { | 343 if (!success && createdDir) { |
329 FileUtils.deleteRecursive(shapeDir); | 344 FileUtils.deleteRecursive(shapeDir); |
330 } | 345 } |
331 } | 346 } |
332 } | 347 } |
348 | |
349 protected Document writeMeta(CallContext context, String uuid, String path){ | |
350 InputData inputParam = inputData.get("parameterid"); | |
351 Map<Integer, PaletteManager> paletteManagers = getPalettes(context); | |
352 String paramType = null; | |
353 | |
354 if (inputParam == null || paletteManagers == null) { | |
355 log.warn("Parameter-id not found."); | |
356 paramType = LAYER_MODEL; | |
357 } | |
358 else { | |
359 Integer parameterId = Integer.parseInt(inputParam.getValue()); | |
360 PaletteManager paletteManager = paletteManagers.get(parameterId); | |
361 | |
362 paramType = LAYER_MODEL + "_" + paletteManager.getName(); | |
363 } | |
364 | |
365 | |
366 Document meta = XMLUtils.newDocument(); | |
367 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | |
368 meta, | |
369 ArtifactNamespaceContext.NAMESPACE_URI, | |
370 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
371 | |
372 Element root = creator.create("meta"); | |
373 meta.appendChild(root); | |
374 | |
375 writePolygonMeta(context, meta, root, uuid, path, paramType); | |
376 writeIsolineMeta(context, meta, root, uuid, path, paramType); | |
377 | |
378 try { | |
379 File metaFile = new File(path, META_FILE_NAME); | |
380 | |
381 if (!metaFile.createNewFile() || !metaFile.canWrite()) { | |
382 log.error("Error while writing meta file: "+metaFile.toString()); | |
383 return null; | |
384 } | |
385 | |
386 OutputStream out = new FileOutputStream(metaFile); | |
387 XMLUtils.toStream(meta, out); | |
388 | |
389 return meta; | |
390 } | |
391 catch (FileNotFoundException fnfe) { | |
392 log.error(fnfe); | |
393 } | |
394 catch (IOException ioe) { | |
395 log.error(ioe, ioe); | |
396 } | |
397 | |
398 return meta; | |
399 } | |
400 | |
401 | |
402 protected void writePolygonMeta( | |
403 CallContext context, | |
404 Document document, | |
405 Element meta, | |
406 String uuid, | |
407 String path, | |
408 String paramType | |
409 ) { | |
410 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | |
411 document, | |
412 ArtifactNamespaceContext.NAMESPACE_URI, | |
413 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
414 | |
415 Element layer = creator.create(LayerInfo.LAYER); | |
416 Element model = creator.create(LayerInfo.LAYER_MODEL); | |
417 Element name = creator.create(LayerInfo.LAYER_NAME); | |
418 Element type = creator.create(LayerInfo.LAYER_TYPE); | |
419 Element status = creator.create(LayerInfo.LAYER_STATUS); | |
420 Element data = creator.create(LayerInfo.LAYER_DATA); | |
421 | |
422 model.setTextContent(paramType); | |
423 name.setTextContent(uuid); | |
424 type.setTextContent("POLYGON"); | |
425 status.setTextContent("DEFAULT"); | |
426 data.setTextContent(POLYGON_NAME); | |
427 | |
428 layer.appendChild(model); | |
429 layer.appendChild(name); | |
430 layer.appendChild(type); | |
431 layer.appendChild(status); | |
432 layer.appendChild(data); | |
433 | |
434 meta.appendChild(layer); | |
435 } | |
436 | |
437 | |
438 protected void writeIsolineMeta( | |
439 CallContext context, | |
440 Document document, | |
441 Element meta, | |
442 String uuid, | |
443 String path, | |
444 String paramType | |
445 ) { | |
446 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | |
447 document, | |
448 ArtifactNamespaceContext.NAMESPACE_URI, | |
449 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
450 | |
451 Element layer = creator.create(LayerInfo.LAYER); | |
452 Element model = creator.create(LayerInfo.LAYER_MODEL); | |
453 Element name = creator.create(LayerInfo.LAYER_NAME); | |
454 Element type = creator.create(LayerInfo.LAYER_TYPE); | |
455 Element status = creator.create(LayerInfo.LAYER_STATUS); | |
456 Element data = creator.create(LayerInfo.LAYER_DATA); | |
457 | |
458 model.setTextContent(paramType+"_isolines"); | |
459 name.setTextContent(uuid); | |
460 type.setTextContent("LINE"); | |
461 status.setTextContent("DEFAULT"); | |
462 data.setTextContent(ISOLINES_NAME); | |
463 | |
464 layer.appendChild(model); | |
465 layer.appendChild(name); | |
466 layer.appendChild(type); | |
467 layer.appendChild(status); | |
468 layer.appendChild(data); | |
469 | |
470 meta.appendChild(layer); | |
471 } | |
472 | |
333 | 473 |
334 protected AttributedPoint2ds getResult(String uuid, CallContext callContext) | 474 protected AttributedPoint2ds getResult(String uuid, CallContext callContext) |
335 throws StateException | 475 throws StateException |
336 { | 476 { |
337 CacheFactory cf = CacheFactory.getInstance(); | 477 CacheFactory cf = CacheFactory.getInstance(); |
484 } | 624 } |
485 ap2ds.setPoints(points); | 625 ap2ds.setPoints(points); |
486 | 626 |
487 return ap2ds; | 627 return ap2ds; |
488 } | 628 } |
489 | 629 |
490 public AttributedPoint2ds process( | 630 public AttributedPoint2ds process( |
491 Envelope boundingBox, | 631 Envelope boundingBox, |
492 Polygon polygon, | 632 Polygon polygon, |
493 CallContext callContext, | 633 CallContext callContext, |
494 AttributedPoint2ds input | 634 AttributedPoint2ds input |