Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/MapGenerator.java @ 9619:63bbd5e45839
#21 WMS Legend
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Thu, 10 Oct 2019 16:08:47 +0200 |
parents | 5e38e2924c07 |
children |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/MapGenerator.java Thu Oct 10 16:02:31 2019 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/MapGenerator.java Thu Oct 10 16:08:47 2019 +0200 @@ -8,6 +8,14 @@ package org.dive4elements.river.exports; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; import org.dive4elements.artifactdatabase.data.StateData; import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifactdatabase.state.Facet; @@ -27,21 +35,11 @@ import org.dive4elements.river.themes.ThemeDocument; import org.dive4elements.river.utils.ArtifactMapfileGenerator; import org.dive4elements.river.utils.GeometryUtils; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; import com.vividsolutions.jts.geom.Envelope; - public class MapGenerator implements OutGenerator, FacetTypes { private static Logger log = Logger.getLogger(MapGenerator.class); @@ -67,62 +65,53 @@ protected String outName; + private String legend; + @Override - public void setup(Object config) { + public void setup(final Object config) { log.debug("MapGenerator.setup"); } @Override - public void init( - String outName, - Document request, - OutputStream out, - CallContext context - ) { + public void init(final String outName, final Document request, final OutputStream out, final CallContext context) { log.debug("MapGenerator.init"); - this.outName = outName; - this.request = request; - this.out = out; - this.context = context; + this.outName = outName; + this.request = request; + this.out = out; + this.context = context; - this.layers = new ArrayList<WMSLayerFacet>(); + this.layers = new ArrayList<>(); this.maxExtent = null; this.initialExtent = null; } - @Override - public void setMasterArtifact(Artifact master) { + public void setMasterArtifact(final Artifact master) { log.debug("MapGenerator.setMasterArtifact"); this.master = master; } @Override - public void setCollection(D4EArtifactCollection collection) { + public void setCollection(final D4EArtifactCollection collection) { this.collection = collection; } @Override - public void doOut( - ArtifactAndFacet artifactFacet, - ThemeDocument attr, - boolean visible) - { - String name = artifactFacet.getFacetName(); + public void doOut(final ArtifactAndFacet artifactFacet, final ThemeDocument attr, final boolean visible) { + final String name = artifactFacet.getFacetName(); - log.debug("MapGenerator.doOut: " + - artifactFacet.getArtifact().identifier() + " | " + name); - D4EArtifact flys = (D4EArtifact) artifactFacet.getArtifact(); + log.debug("MapGenerator.doOut: " + artifactFacet.getArtifact().identifier() + " | " + name); + final D4EArtifact flys = (D4EArtifact) artifactFacet.getArtifact(); - Facet nativeFacet = artifactFacet.getFacet(); + final Facet nativeFacet = artifactFacet.getFacet(); if (nativeFacet instanceof WMSLayerFacet) { - WMSLayerFacet wms = (WMSLayerFacet) nativeFacet; - Envelope extent = wms.getOriginalExtent(); + final WMSLayerFacet wms = (WMSLayerFacet) nativeFacet; + final Envelope extent = wms.getOriginalExtent(); - layers.add(wms); + this.layers.add(wms); setMaxExtent(extent); setSrid(wms.getSrid()); @@ -133,95 +122,67 @@ } // FIXME: Already generated by HWSBarrierState // wms has a wrong SRID which would break that layer - //else if (FLOODMAP_USERSHAPE.equals(name)) { - // createUserShapeLayer(flys, wms); - //} + // else if (FLOODMAP_USERSHAPE.equals(name)) { + // createUserShapeLayer(flys, wms); + // } else { log.debug("doOut: createDatabaseLayer for facet name: " + name); createDatabaseLayer(flys, wms, attr); } - } - else { + } else { log.warn("Facet not supported: " + nativeFacet.getClass()); } } - - protected void createWSPLGENLayer( - D4EArtifact flys, - WMSLayerFacet wms, - ThemeDocument attr - ) { + protected void createWSPLGENLayer(final D4EArtifact flys, final WMSLayerFacet wms, final ThemeDocument attr) { try { - if(wms instanceof WSPLGENLayerFacet) { + if (wms instanceof WSPLGENLayerFacet) { // Retrieve waterlevel ground differences from artifact - StateData dFrom = - flys.getData(WaterlevelGroundDifferences.LOWER_FIELD); - StateData dTo = - flys.getData(WaterlevelGroundDifferences.UPPER_FIELD); - StateData dStep = - flys.getData(WaterlevelGroundDifferences.DIFF_FIELD); + final StateData dFrom = flys.getData(WaterlevelGroundDifferences.LOWER_FIELD); + final StateData dTo = flys.getData(WaterlevelGroundDifferences.UPPER_FIELD); + final StateData dStep = flys.getData(WaterlevelGroundDifferences.DIFF_FIELD); - String fromStr = dFrom != null - ? (String) dFrom.getValue() - : null; - String toStr = dTo != null - ? (String) dTo.getValue() - : null; - String stepStr = dStep != null - ? (String) dStep.getValue() - : null; + final String fromStr = dFrom != null ? (String) dFrom.getValue() : null; + final String toStr = dTo != null ? (String) dTo.getValue() : null; + final String stepStr = dStep != null ? (String) dStep.getValue() : null; - float from = Float.parseFloat(fromStr); - float to = Float.parseFloat(toStr); - float step = Float.parseFloat(stepStr); + final float from = Float.parseFloat(fromStr); + final float to = Float.parseFloat(toStr); + final float step = Float.parseFloat(stepStr); - ArtifactMapfileGenerator mfg = new ArtifactMapfileGenerator(); - mfg.createUeskLayer( - flys, - (WSPLGENLayerFacet) wms, - attr.createDynamicMapserverStyle( - from, to, step, context.getMeta()), - context); - } - else { - log.warn("Cannot create WSPLGEN layer from: " + - wms.getClass()); + final ArtifactMapfileGenerator mfg = new ArtifactMapfileGenerator(); + mfg.createUeskLayer(flys, (WSPLGENLayerFacet) wms, attr.createDynamicMapserverStyle(from, to, step, this.context.getMeta()), this.context); + } else { + log.warn("Cannot create WSPLGEN layer from: " + wms.getClass()); } } - catch (IOException ioe) { + catch (final IOException ioe) { log.error(ioe, ioe); } } - - protected void createUserShapeLayer(D4EArtifact flys, WMSLayerFacet wms) { - ArtifactMapfileGenerator mfg = new ArtifactMapfileGenerator(); + protected void createUserShapeLayer(final D4EArtifact flys, final WMSLayerFacet wms) { + final ArtifactMapfileGenerator mfg = new ArtifactMapfileGenerator(); try { mfg.createUserShapeLayer(flys, wms); } - catch (FileNotFoundException fnfe) { + catch (final FileNotFoundException fnfe) { log.error(fnfe, fnfe); } - catch (IOException ioe) { + catch (final IOException ioe) { log.error(ioe, ioe); } } - - protected void createDatabaseLayer( - D4EArtifact flys, - WMSLayerFacet wms, - ThemeDocument attr - ) { + protected void createDatabaseLayer(final D4EArtifact flys, final WMSLayerFacet wms, final ThemeDocument attr) { log.debug("createDatabaseLayer for facet: " + wms.getName()); - ArtifactMapfileGenerator mfg = new ArtifactMapfileGenerator(); + final ArtifactMapfileGenerator mfg = new ArtifactMapfileGenerator(); try { - File baseDir = mfg.getShapefileBaseDir(); - File artDir = new File(baseDir, flys.identifier()); + final File baseDir = mfg.getShapefileBaseDir(); + final File artDir = new File(baseDir, flys.identifier()); if (artDir != null && !artDir.exists()) { log.debug("Create new directory: " + artDir.getPath()); @@ -229,41 +190,31 @@ } if (wms instanceof WMSDBLayerFacet) { - mfg.createDatabaseLayer( - flys, - (WMSDBLayerFacet) wms, - attr.createMapserverStyle()); - } - else { + mfg.createDatabaseLayer(flys, (WMSDBLayerFacet) wms, attr.createMapserverStyle()); + } else { log.warn("Cannot create DB layer from: " + wms.getClass()); } } - catch (FileNotFoundException fnfe) { + catch (final FileNotFoundException fnfe) { log.error(fnfe, fnfe); } - catch (IOException ioe) { + catch (final IOException ioe) { log.error(ioe, ioe); } } - @Override - public void generate() - throws IOException - { + public void generate() throws IOException { log.debug("MapGenerator.generate"); - ArtifactMapfileGenerator mfg = new ArtifactMapfileGenerator(); + final ArtifactMapfileGenerator mfg = new ArtifactMapfileGenerator(); mfg.generate(); - Document response = XMLUtils.newDocument(); - ElementCreator c = new ElementCreator( - response, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); + final Document response = XMLUtils.newDocument(); + final ElementCreator c = new ElementCreator(response, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX); - Element root = c.create("floodmap"); - Element layers = c.create("layers"); + final Element root = c.create("floodmap"); + final Element layers = c.create("layers"); response.appendChild(root); root.appendChild(layers); @@ -271,18 +222,16 @@ appendLayers(layers); appendMapInformation(root, c); - XMLUtils.toStream(response, out); + XMLUtils.toStream(response, this.out); } - - protected void appendLayers(Element parent) { - for (WMSLayerFacet facet: layers) { + protected void appendLayers(final Element parent) { + for (final WMSLayerFacet facet : this.layers) { parent.appendChild(facet.toXML(parent.getOwnerDocument())); } } - - protected void setMaxExtent(Envelope maxExtent) { + protected void setMaxExtent(final Envelope maxExtent) { if (maxExtent == null) { return; } @@ -296,16 +245,14 @@ this.maxExtent.expandToInclude(maxExtent); } - - protected void setInitialExtent(Envelope initialExtent) { + protected void setInitialExtent(final Envelope initialExtent) { if (this.initialExtent == null && initialExtent != null) { log.debug("Set initial extent to: " + initialExtent); this.initialExtent = new Envelope(initialExtent); } } - - protected void setSrid(String srid) { + protected void setSrid(final String srid) { if (srid == null || srid.length() == 0) { return; } @@ -313,8 +260,7 @@ this.srid = srid; } - - protected void appendMapInformation(Element parent, ElementCreator c) { + protected void appendMapInformation(final Element parent, final ElementCreator c) { String mE; if (this.maxExtent != null) { mE = GeometryUtils.jtsBoundsToOLBounds(this.maxExtent); @@ -323,17 +269,17 @@ mE = "0 0 1 1"; } - Element maxExtent = c.create("maxExtent"); + final Element maxExtent = c.create("maxExtent"); maxExtent.setTextContent(mE); - if(this.initialExtent != null) { - String iE = GeometryUtils.jtsBoundsToOLBounds(this.initialExtent); - Element initExtent = c.create("initialExtent"); + if (this.initialExtent != null) { + final String iE = GeometryUtils.jtsBoundsToOLBounds(this.initialExtent); + final Element initExtent = c.create("initialExtent"); initExtent.setTextContent(iE); parent.appendChild(initExtent); } - Element srid = c.create("srid"); + final Element srid = c.create("srid"); srid.setTextContent(this.srid); // TODO zoom levels @@ -343,7 +289,6 @@ parent.appendChild(srid); } - /** * Returns an instance of <i>EmptySettings</i> currently! * @@ -354,9 +299,8 @@ return new EmptySettings(); } - @Override - public void setSettings(Settings settings) { + public void setSettings(final Settings settings) { this.settings = settings; } }