Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 484:823e4f808418
Generate JTS geometries (multi polygons and multi linestrings) from
interpolation with external palette indices.
gnv-artifacts/trunk@559 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 18 Jan 2010 11:25:52 +0000 |
parents | 64e65daa65e9 |
children | 6e8364e766fa |
comparison
equal
deleted
inserted
replaced
483:c8089cd7d777 | 484:823e4f808418 |
---|---|
1 package de.intevation.gnv.state.profile.horizontalcrosssection; | 1 package de.intevation.gnv.state.profile.horizontalcrosssection; |
2 | 2 |
3 import com.vividsolutions.jts.geom.Coordinate; | 3 import com.vividsolutions.jts.geom.Coordinate; |
4 import com.vividsolutions.jts.geom.Envelope; | 4 import com.vividsolutions.jts.geom.Envelope; |
5 import com.vividsolutions.jts.geom.MultiLineString; | |
6 import com.vividsolutions.jts.geom.MultiPolygon; | |
5 import com.vividsolutions.jts.geom.Polygon; | 7 import com.vividsolutions.jts.geom.Polygon; |
6 | 8 |
7 import de.intevation.artifactdatabase.Config; | 9 import de.intevation.artifactdatabase.Config; |
8 import de.intevation.artifactdatabase.XMLUtils; | 10 import de.intevation.artifactdatabase.XMLUtils; |
9 | 11 |
27 import de.intevation.gnv.math.AreaInterpolation; | 29 import de.intevation.gnv.math.AreaInterpolation; |
28 import de.intevation.gnv.math.AttributedPoint2ds; | 30 import de.intevation.gnv.math.AttributedPoint2ds; |
29 import de.intevation.gnv.math.Point2d; | 31 import de.intevation.gnv.math.Point2d; |
30 import de.intevation.gnv.math.QueriedXYDepth; | 32 import de.intevation.gnv.math.QueriedXYDepth; |
31 | 33 |
34 import de.intevation.gnv.raster.ExternalIndexConverter; | |
35 import de.intevation.gnv.raster.IsoAttributeGenerator; | |
36 import de.intevation.gnv.raster.JTSMultiLineStringProducer; | |
37 import de.intevation.gnv.raster.JTSMultiPolygonProducer; | |
38 import de.intevation.gnv.raster.Palette; | |
39 import de.intevation.gnv.raster.PaletteManager; | |
40 import de.intevation.gnv.raster.Raster; | |
41 import de.intevation.gnv.raster.Vectorizer; | |
42 | |
32 import de.intevation.gnv.state.InputData; | 43 import de.intevation.gnv.state.InputData; |
33 import de.intevation.gnv.state.OutputStateBase; | 44 import de.intevation.gnv.state.OutputStateBase; |
34 | 45 |
35 import de.intevation.gnv.state.exception.StateException; | 46 import de.intevation.gnv.state.exception.StateException; |
36 | 47 |
37 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; | 48 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; |
38 | 49 |
39 import de.intevation.gnv.utils.FileUtils; | 50 import de.intevation.gnv.utils.FileUtils; |
51 import de.intevation.gnv.utils.Pair; | |
40 import de.intevation.gnv.utils.StringUtils; | 52 import de.intevation.gnv.utils.StringUtils; |
41 import de.intevation.gnv.utils.WKTUtils; | 53 import de.intevation.gnv.utils.WKTUtils; |
42 | 54 |
43 import java.awt.Dimension; | 55 import java.awt.Dimension; |
44 | 56 |
46 import java.io.IOException; | 58 import java.io.IOException; |
47 import java.io.OutputStream; | 59 import java.io.OutputStream; |
48 | 60 |
49 import java.util.ArrayList; | 61 import java.util.ArrayList; |
50 import java.util.Collection; | 62 import java.util.Collection; |
63 import java.util.HashMap; | |
51 import java.util.List; | 64 import java.util.List; |
65 import java.util.Map; | |
52 | 66 |
53 import org.apache.log4j.Logger; | 67 import org.apache.log4j.Logger; |
54 | 68 |
55 import org.w3c.dom.Document; | 69 import org.w3c.dom.Document; |
56 import org.w3c.dom.Element; | 70 import org.w3c.dom.Element; |
325 .getQueryExecutor(); | 339 .getQueryExecutor(); |
326 | 340 |
327 return process( | 341 return process( |
328 env, | 342 env, |
329 p, | 343 p, |
330 numSamples(callContext), | 344 callContext, |
331 preprocess( | 345 preProcess( |
332 queryExecutor.executeQuery( | 346 queryExecutor.executeQuery( |
333 queryID, | 347 queryID, |
334 addedFilterValues)), | 348 addedFilterValues))); |
335 getGroundInterpolation(callContext)); | |
336 } | 349 } |
337 catch (QueryException e) { | 350 catch (QueryException e) { |
338 log.error(e,e); | 351 log.error(e,e); |
339 } | 352 } |
340 | 353 |
341 throw new StateException("no result produced"); | 354 throw new StateException("no result produced"); |
342 } | 355 } |
343 | 356 |
344 public AttributedPoint2ds preprocess(Collection<Result> results) { | 357 public AttributedPoint2ds preProcess(Collection<Result> results) { |
345 | 358 |
346 boolean debug = log.isDebugEnabled(); | 359 boolean debug = log.isDebugEnabled(); |
347 | 360 |
348 if (debug) { | 361 if (debug) { |
349 log.debug("--- preprocess: " + results.size() + " results"); | 362 log.debug("--- preProcess: " + results.size() + " results"); |
350 } | 363 } |
351 | 364 |
352 AttributedPoint2ds ap2ds = new AttributedPoint2ds(); | 365 AttributedPoint2ds ap2ds = new AttributedPoint2ds(); |
353 | 366 |
354 ArrayList<Point2d> points = new ArrayList<Point2d>(results.size()); | 367 ArrayList<Point2d> points = new ArrayList<Point2d>(results.size()); |
407 } | 420 } |
408 | 421 |
409 public AttributedPoint2ds process( | 422 public AttributedPoint2ds process( |
410 Envelope boundingBox, | 423 Envelope boundingBox, |
411 Polygon polygon, | 424 Polygon polygon, |
412 int numSamples, | 425 CallContext callContext, |
413 AttributedPoint2ds input, | 426 AttributedPoint2ds input |
414 int groundInterpolation | |
415 ) { | 427 ) { |
416 if (input == null) { | 428 if (input == null) { |
417 log.error("no data to interpolate"); | 429 log.error("no data to interpolate"); |
418 return null; | 430 return null; |
419 } | 431 } |
420 | 432 |
433 Integer parameterId = | |
434 (Integer)input.getAttribute("PARAMETERID"); // XXX: hardcoded | |
435 | |
436 if (parameterId == null) { | |
437 log.error("missing parameter id"); | |
438 return null; | |
439 } | |
440 | |
441 Map<Integer, PaletteManager> paletteManagers = | |
442 getPalettes(callContext); | |
443 | |
444 PaletteManager paletteManager = paletteManagers.get(parameterId); | |
445 | |
446 if (paletteManager == null) { | |
447 log.error("no palette found for parameter id " + parameterId); | |
448 return null; | |
449 } | |
450 | |
421 boolean debug = log.isDebugEnabled(); | 451 boolean debug = log.isDebugEnabled(); |
422 | 452 |
423 if (debug) { | 453 if (debug) { |
424 log.debug("before interpolation"); | 454 log.debug("interpolation"); |
425 } | 455 } |
426 | 456 |
427 AreaInterpolation interpolation = | 457 AreaInterpolation interpolation = |
428 new AreaInterpolation(); | 458 new AreaInterpolation(); |
429 | 459 |
430 List<? extends Point2d> points = input.getPoints(); | 460 int numSamples = numSamples(callContext); |
461 int groundInterpolation = getGroundInterpolation(callContext); | |
431 | 462 |
432 if (!interpolation.interpolate( | 463 if (!interpolation.interpolate( |
433 points, | 464 input.getPoints(), |
434 boundingBox, | 465 boundingBox, |
435 new Dimension(numSamples, numSamples), | 466 new Dimension(numSamples, numSamples), |
436 new QueriedXYDepth(groundInterpolation) | 467 new QueriedXYDepth(groundInterpolation) |
437 )) { | 468 )) { |
438 log.error("interpolation failed"); | 469 log.error("interpolation failed"); |
439 return null; | 470 return null; |
440 } | 471 } |
441 | 472 |
473 // Do the post processing | |
474 Raster raster = new Raster( | |
475 interpolation.getRaster(), | |
476 numSamples); | |
477 | |
478 // TODO: Filter operations. | |
479 | |
442 if (debug) { | 480 if (debug) { |
443 log.debug("after interpolation"); | 481 log.debug("to indexed raster"); |
444 } | 482 } |
445 | 483 |
446 return null; | 484 // scan for regions with base palette |
485 Palette basePalette = paletteManager.getBase(); | |
486 | |
487 int [] intRaster = raster.toIndexed(basePalette); | |
488 | |
489 // produce JFreeChart compatible polygons | |
490 | |
491 if (debug) { | |
492 log.debug("vectorize indexed raster"); | |
493 } | |
494 | |
495 // produce JTS compatible polygons | |
496 | |
497 JTSMultiPolygonProducer jtsmpp = new JTSMultiPolygonProducer( | |
498 boundingBox.getMinX(), boundingBox.getMinY(), | |
499 boundingBox.getMaxX(), boundingBox.getMaxY()); | |
500 | |
501 int numRegions = new Vectorizer(intRaster, numSamples) | |
502 .process(jtsmpp); | |
503 | |
504 Map<Integer, MultiPolygon> polygons = jtsmpp.getMultiPolygons( | |
505 new ExternalIndexConverter(basePalette)); | |
506 | |
507 jtsmpp.clear(); jtsmpp = null; // help gc | |
508 | |
509 int numColors = polygons.size(); | |
510 | |
511 if (debug) { | |
512 log.debug("number of regions: " + numRegions); | |
513 log.debug("number of colors: " + numColors); | |
514 } | |
515 // generate iso lines | |
516 | |
517 int numIso; | |
518 | |
519 if (numColors < 5) { numIso = 5; } | |
520 else if (numColors < 10) { numIso = 2; } | |
521 else { numIso = 0; } | |
522 | |
523 Palette isoPalette; | |
524 | |
525 if (numIso == 0) { // same palette | |
526 isoPalette = basePalette; | |
527 /* intRaster = intRaster; */ | |
528 } | |
529 else { | |
530 isoPalette = paletteManager.getLevel(numIso); | |
531 intRaster = raster.toIndexed(isoPalette); | |
532 } | |
533 | |
534 JTSMultiLineStringProducer jtslsp = new JTSMultiLineStringProducer( | |
535 boundingBox.getMinX(), boundingBox.getMinY(), | |
536 boundingBox.getMaxX(), boundingBox.getMaxY()); | |
537 | |
538 numRegions = new Vectorizer(false, intRaster, numSamples) | |
539 .process(jtslsp); | |
540 | |
541 IsoAttributeGenerator iag = new IsoAttributeGenerator(isoPalette); | |
542 | |
543 List<Pair<Object, MultiLineString>> lineStrings = | |
544 jtslsp.getMultiLineStrings(iag); | |
545 | |
546 jtslsp.clear(); jtslsp = null; // help gc | |
547 | |
548 input.setInterpolation(interpolation); | |
549 | |
550 input.setPolygons(polygons); | |
551 input.setLineStrings(lineStrings); | |
552 | |
553 return input; | |
447 } | 554 } |
448 | 555 |
449 | 556 |
450 /** | |
451 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#setup(org.w3c.dom.Node) | |
452 */ | |
453 @Override | 557 @Override |
454 public void setup(Node configuration) { | 558 public void setup(Node configuration) { |
455 super.setup(configuration); | 559 super.setup(configuration); |
456 this.ijkQueryID = Config.getStringXPath(configuration,"queryID-ijk"); | 560 this.ijkQueryID = Config.getStringXPath(configuration,"queryID-ijk"); |
457 | 561 |
484 String interpolation = (String)context.get( | 588 String interpolation = (String)context.get( |
485 GNVArtifactContext.HORIZONTAL_CROSS_SECTION_GROUND_INTERPOLATION_KEY); | 589 GNVArtifactContext.HORIZONTAL_CROSS_SECTION_GROUND_INTERPOLATION_KEY); |
486 | 590 |
487 return RasterObject.getInterpolationType(interpolation); | 591 return RasterObject.getInterpolationType(interpolation); |
488 } | 592 } |
593 | |
594 private static Map<Integer, PaletteManager> getPalettes( | |
595 CallContext callContext | |
596 ) { | |
597 GNVArtifactContext context = | |
598 (GNVArtifactContext)callContext.globalContext(); | |
599 Map<Integer, PaletteManager> palettes = | |
600 (Map<Integer, PaletteManager>)context.get( | |
601 GNVArtifactContext.PALETTES_KEY); | |
602 return palettes != null | |
603 ? palettes | |
604 : new HashMap<Integer, PaletteManager>(); | |
605 } | |
489 } | 606 } |
490 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 607 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |