# HG changeset patch # User Ingo Weinzierl # Date 1319781265 0 # Node ID 092e1e5020bc63d14d93c240f4fc8000036a5e46 # Parent 9be01e2e6897a74d558275e94870ea8ec6159203 Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress). flys-artifacts/trunk@3095 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 9be01e2e6897 -r 092e1e5020bc flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Oct 27 14:04:04 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Oct 28 05:54:25 2011 +0000 @@ -1,3 +1,27 @@ +2011-10-28 Ingo Weinzierl + + * src/main/java/de/intevation/flys/utils/GeometryUtils.java: Added new + method gerRiverBoundary() which returns an Envelope object (which + represents the bounding box of a Geometry) of a riveraxis specified by its + rivername. + + * src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java: Use + Geometry.getRiverBoundary() to determine the max extent of a river. + + * src/main/java/de/intevation/flys/wsplgen/FacetCreator.java, + src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java: Use + JTS Envelope to save the bounding boxes of WMS layers. + + * src/main/java/de/intevation/flys/artifacts/services/MapInfoService.java: + Adapted the code to apply the changes in GeometryUtils (use Envelope to + determine the max extent of the river axis). + + * src/main/java/de/intevation/flys/exports/MapGenerator.java: New (work in + progress). This Generator will currently return a map configuration in XML + which consists of parameters required by OpenLayers to create a map. + + * doc/conf/conf.xml: Registered the new MapGenerator. + 2011-10-27 Felix Wolfsteller * doc/conf/meta-data.xml: Do not recommend historical data to load diff -r 9be01e2e6897 -r 092e1e5020bc flys-artifacts/doc/conf/conf.xml --- a/flys-artifacts/doc/conf/conf.xml Thu Oct 27 14:04:04 2011 +0000 +++ b/flys-artifacts/doc/conf/conf.xml Fri Oct 28 05:54:25 2011 +0000 @@ -115,6 +115,7 @@ de.intevation.flys.exports.WDifferencesCurveGenerator de.intevation.flys.exports.WDifferencesCurveInfoGenerator de.intevation.flys.exports.WDifferencesExporter + de.intevation.flys.exports.MapGenerator de.intevation.flys.exports.ReportGenerator de.intevation.flys.exports.ReportGenerator diff -r 9be01e2e6897 -r 092e1e5020bc flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java Thu Oct 27 14:04:04 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java Fri Oct 28 05:54:25 2011 +0000 @@ -9,6 +9,8 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; +import com.vividsolutions.jts.geom.Envelope; + import de.intevation.artifacts.Artifact; import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.CallContext; @@ -20,6 +22,7 @@ import de.intevation.artifactdatabase.state.Facet; import de.intevation.flys.artifacts.states.DefaultState.ComputeType; +import de.intevation.flys.utils.GeometryUtils; public class WMSLayerFacet @@ -30,7 +33,7 @@ protected String stateId; protected String hash; protected String url; - protected String extent; + protected Envelope extent; protected String srid; @@ -83,13 +86,18 @@ } - public void setExtent(String extent) { + public void setExtent(Envelope extent) { if (extent != null) { this.extent = extent; } } + public Envelope getExtent() { + return extent; + } + + public void setSrid(String srid) { if (srid != null) { this.srid = srid; @@ -97,6 +105,11 @@ } + public String getSrid() { + return srid; + } + + public Object getData(Artifact artifact, CallContext context) { return null; } @@ -115,8 +128,10 @@ ec.addAttr(facet, "name", name, true); ec.addAttr(facet, "url", url, true); ec.addAttr(facet, "layers", layers.get(0), true); - ec.addAttr(facet, "extent", extent != null ? extent : "", true); ec.addAttr(facet, "srid", srid != null ? srid : "", true); + ec.addAttr(facet, "extent", extent != null + ? GeometryUtils.jtsBoundsToOLBounds(extent) + : "", true); return facet; } diff -r 9be01e2e6897 -r 092e1e5020bc flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MapInfoService.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MapInfoService.java Thu Oct 27 14:04:04 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MapInfoService.java Fri Oct 28 05:54:25 2011 +0000 @@ -5,7 +5,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; -import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.Envelope; import de.intevation.artifacts.CallMeta; import de.intevation.artifacts.GlobalContext; @@ -79,8 +79,8 @@ RiverAxis axis = RiverAxis.getRiverAxis(river); if (axis != null) { - Geometry geom = axis.getGeom().getBoundary(); - String bounds = GeometryUtils.jtsBoundsToOLBounds(geom); + Envelope env = axis.getGeom().getEnvelopeInternal(); + String bounds = GeometryUtils.jtsBoundsToOLBounds(env); logger.debug("River '" + river + "' bounds: " + bounds); Element bbox = cr.create("bbox"); diff -r 9be01e2e6897 -r 092e1e5020bc flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java Thu Oct 27 14:04:04 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverAxisState.java Fri Oct 28 05:54:25 2011 +0000 @@ -71,7 +71,7 @@ url); facet.addLayer(WMS_LAYER_NAME); - facet.setExtent(GeometryUtils.getRiverBounds(river)); + facet.setExtent(GeometryUtils.getRiverBoundary(river)); facet.setSrid(FLYSUtils.getRiverSrid(artifact)); facets.add(facet); diff -r 9be01e2e6897 -r 092e1e5020bc flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java Fri Oct 28 05:54:25 2011 +0000 @@ -0,0 +1,208 @@ +package de.intevation.flys.exports; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +import com.vividsolutions.jts.geom.Envelope; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; + +import de.intevation.artifactdatabase.state.Facet; + +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.WMSLayerFacet; +import de.intevation.flys.utils.GeometryUtils; + + +public class MapGenerator implements OutGenerator, FacetTypes { + + private static Logger logger = Logger.getLogger(MapGenerator.class); + + + protected Artifact master; + + protected Document request; + + protected OutputStream out; + + protected CallContext context; + + protected List layers; + + protected Envelope maxExtent; + protected Envelope initialExtent; + + protected String srid; + + + + @Override + public void init(Document request, OutputStream out, CallContext context) { + logger.debug("MapGenerator.init"); + + this.request = request; + this.out = out; + this.context = context; + + this.layers = new ArrayList(); + + this.maxExtent = null; + this.initialExtent = null; + } + + + @Override + public void setMasterArtifact(Artifact master) { + logger.debug("MapGenerator.setMasterArtifact"); + this.master = master; + } + + + @Override + public void doOut( + Artifact artifact, + Facet facet, + Document attr, + boolean visible) + { + String name = facet.getName(); + + logger.debug("MapGenerator.doOut: " +artifact.identifier()+" | "+name); + FLYSArtifact flys = (FLYSArtifact) artifact; + + Facet nativeFacet = flys.getNativeFacet(facet); + + if (nativeFacet instanceof WMSLayerFacet) { + WMSLayerFacet wms = (WMSLayerFacet) nativeFacet; + Envelope extent = wms.getExtent(); + + layers.add(wms); + + setMaxExtent(extent); + setSrid(wms.getSrid()); + + if (FLOODMAP_WSPLGEN.equals(name) && initialExtent == null) { + setInitialExtent(extent); + } + } + else { + logger.warn("Facet not supported: " + nativeFacet.getClass()); + } + + } + + + @Override + public void generate() + throws IOException + { + logger.debug("MapGenerator.generate"); + + Document response = XMLUtils.newDocument(); + ElementCreator c = new ElementCreator( + response, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element root = c.create("floodmap"); + Element layers = c.create("layers"); + + response.appendChild(root); + root.appendChild(layers); + + appendLayers(layers); + appendMapInformation(root, c); + + XMLUtils.toStream(response, out); + } + + + protected void appendLayers(Element parent) { + for (WMSLayerFacet facet: layers) { + parent.appendChild(facet.toXML(parent.getOwnerDocument())); + } + } + + + protected void setMaxExtent(Envelope maxExtent) { + if (maxExtent == null) { + return; + } + + if (this.maxExtent == null) { + logger.debug("Set max extent to: " + maxExtent); + this.maxExtent = maxExtent; + return; + } + + logger.debug("Expand max extent by: " + maxExtent); + logger.debug("Max extent before expanding: " + this.maxExtent); + this.maxExtent.expandToInclude(maxExtent); + logger.debug("Max extent after expanding: " + this.maxExtent); + } + + + protected void setInitialExtent(Envelope initialExtent) { + if (initialExtent == null) { + return; + } + + if (this.initialExtent == null) { + logger.debug("Set initial extent to: " + initialExtent); + this.initialExtent = initialExtent; + return; + } + + logger.debug("Set initial extent to: " + initialExtent); + this.initialExtent = initialExtent; + } + + + protected void setSrid(String srid) { + if (srid == null || srid.length() == 0) { + return; + } + + this.srid = srid; + } + + + protected void appendMapInformation(Element parent, ElementCreator c) { + String mE = GeometryUtils.jtsBoundsToOLBounds(this.maxExtent); + logger.debug("BUILD MAX EXTENT OF:" + this.maxExtent); + logger.debug("BUILD MAX EXTENT:" + mE); + + Element maxExtent = c.create("maxExtent"); + maxExtent.setTextContent(mE); + + String iE = GeometryUtils.jtsBoundsToOLBounds(this.initialExtent); + logger.debug("BUILD INITIAL EXTENT OF: " + this.initialExtent); + logger.debug("BUILD INITIAL EXTENT: " + iE); + Element initExtent = c.create("initialExtent"); + initExtent.setTextContent(iE); + + Element srid = c.create("srid"); + srid.setTextContent(this.srid); + + // TODO zoom levels + // TODO resolutation + + parent.appendChild(maxExtent); + parent.appendChild(initExtent); + parent.appendChild(srid); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 9be01e2e6897 -r 092e1e5020bc flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java --- a/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java Thu Oct 27 14:04:04 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java Fri Oct 28 05:54:25 2011 +0000 @@ -12,6 +12,7 @@ import org.apache.log4j.Logger; import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Geometry; import org.opengis.feature.simple.SimpleFeature; @@ -44,13 +45,23 @@ } - public static String getRiverBounds(String rivername) { + public static Envelope getRiverBoundary(String rivername) { RiverAxis axis = RiverAxis.getRiverAxis(rivername); if (axis != null) { // TODO Take the correct EPSG into account. Maybe, we need to // reproject the geometry. - Geometry geom = axis.getGeom().getBoundary(); - return jtsBoundsToOLBounds(geom); + return axis.getGeom().getEnvelopeInternal(); + } + + return null; + } + + + public static String getRiverBounds(String rivername) { + Envelope env = getRiverBoundary(rivername); + + if (env == null) { + return jtsBoundsToOLBounds(env); } return null; @@ -58,21 +69,19 @@ /** - * Returns the boundary of Geometry geom in OpenLayers + * Returns the boundary of Envelope env in OpenLayers * representation. * - * @param geom The geometry. + * @param env The envelope of a geometry. * - * @return the OpenLayers boundary of geom. + * @return the OpenLayers boundary of env. */ - public static String jtsBoundsToOLBounds(Geometry geom) { - Coordinate[] c = geom != null ? geom.getCoordinates() : null; - - if (c == null || c.length < 2) { - return null; - } - - return "" + c[0].x + " " + c[1].y + " " + c[1].x + " " + c[0].y; + public static String jtsBoundsToOLBounds(Envelope env) { + return "" + + env.getMinX() + " " + + env.getMinY() + " " + + env.getMaxX() + " " + + env.getMaxY(); } diff -r 9be01e2e6897 -r 092e1e5020bc flys-artifacts/src/main/java/de/intevation/flys/wsplgen/FacetCreator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/FacetCreator.java Thu Oct 27 14:04:04 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/FacetCreator.java Fri Oct 28 05:54:25 2011 +0000 @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import com.vividsolutions.jts.geom.Envelope; + import de.intevation.artifacts.CallContext; import de.intevation.artifactdatabase.state.Facet; @@ -66,7 +68,7 @@ return FLYSUtils.getRiverSrid(artifact); } - protected String getWSPLGENBounds() { + protected Envelope getWSPLGENBounds() { String river = getRiver(); double kms[] = FLYSUtils.getKmRange(artifact); @@ -80,11 +82,16 @@ return null; } - return GeometryUtils.createOLBounds(a.getGeom(), b.getGeom()); + Envelope envA = a.getGeom().getEnvelopeInternal(); + Envelope envB = b.getGeom().getEnvelopeInternal(); + + envA.expandToInclude(envB); + + return envA; } - protected String getBounds() { - return GeometryUtils.getRiverBounds(getRiver()); + protected Envelope getBounds() { + return GeometryUtils.getRiverBoundary(getRiver()); } public List getFacets() { @@ -104,9 +111,9 @@ hash, getUrl()); - String bounds = getWSPLGENBounds(); + Envelope bounds = getWSPLGENBounds(); - if (bounds == null || bounds.length() == 0) { + if (bounds == null) { bounds = getBounds(); }