view flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java @ 1812:dd084cf3f284

Refactored to allow mainvalues in discharge curve diagrams, too. flys-artifacts/trunk@3141 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 02 Nov 2011 12:12:48 +0000
parents 50110699e38e
children 5364b86a0880
line wrap: on
line source
package de.intevation.flys.artifacts;

import java.util.List;

import org.w3c.dom.Document;

import org.apache.log4j.Logger;

import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;

import de.intevation.artifacts.ArtifactFactory;
import de.intevation.artifacts.CallMeta;

import de.intevation.artifactdatabase.state.Facet;
import de.intevation.artifactdatabase.state.DefaultOutput;
import de.intevation.artifactdatabase.state.State;

import de.intevation.flys.model.River;
import de.intevation.flys.model.RiverAxisKm;

import de.intevation.flys.artifacts.WMSDBArtifact.WMSDBState;
import de.intevation.flys.artifacts.model.FacetTypes;
import de.intevation.flys.artifacts.model.RiverFactory;
import de.intevation.flys.artifacts.resources.Resources;
import de.intevation.flys.utils.FLYSUtils;


public class WMSKmArtifact extends WMSDBArtifact {

    public static final String NAME = "wmskm";


    private static final Logger logger = Logger.getLogger(WMSKmArtifact.class);


    @Override
    public void setup(
        String          identifier,
        ArtifactFactory factory,
        Object          context,
        CallMeta        callMeta,
        Document        data)
    {
        logger.debug("WMSKmArtifact.setup");

        super.setup(identifier, factory, context, callMeta, data);
    }


    @Override
    public String getName() {
        return NAME;
    }


    @Override
    public State getCurrentState(Object cc) {
        State s = new WMSKmState(this);

        List<Facet> fs = facets.get(getCurrentStateId());

        DefaultOutput o = new DefaultOutput(
            "floodmap",
            "floodmap",
            "image/png",
            fs,
            "map");

        s.getOutputs().add(o);

        return s;
    }



    public static class WMSKmState extends WMSDBState implements FacetTypes {

        private static final Logger logger = Logger.getLogger(WMSKmState.class);

        protected Geometry geom;
        protected int      riverId;

        public WMSKmState(WMSDBArtifact artifact) {
            super(artifact);
            riverId = 0;
        }

        public int getRiverId() {
            if (riverId == 0) {
                String ids = artifact.getDataAsString("ids");

                try {
                    riverId = Integer.valueOf(ids);
                }
                catch (NumberFormatException nfe) {
                    logger.error("Cannot parse river id from '" + ids + "'");
                }
            }

            return riverId;
        }

        @Override
        protected String getFacetType() {
            return FLOODMAP_KMS;
        }

        @Override
        protected String getTitle(CallMeta meta) {
            return Resources.getMsg(meta, FLOODMAP_KMS, FLOODMAP_KMS);
        }

        @Override
        protected String getUrl() {
            return FLYSUtils.getUserWMSUrl(artifact.identifier());
        }

        @Override
        protected String getSrid() {
            River river = RiverFactory.getRiver(getRiverId());
            return FLYSUtils.getRiverSrid(river.getName());
        }

        @Override
        protected Envelope getExtent() {
            List<RiverAxisKm> kms = RiverAxisKm.getRiverAxisKms(getRiverId());

            Envelope max = null;

            for (RiverAxisKm km: kms) {
                Envelope env = km.getGeom().getEnvelopeInternal();

                if (max == null) {
                    max = env;
                    continue;
                }

                max.expandToInclude(env);
            }

            return max;
        }

        @Override
        protected String getFilter() {
            return "river_id=" + String.valueOf(getRiverId());
        }

        @Override
        protected String getDataString() {
            return "geom FROM river_axes_km USING UNIQUE id USING SRID 31466";
        }

    } // end of WMSKmState
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org