teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts; ingo@2684: ingo@2684: import java.util.List; ingo@2684: ingo@2684: import org.apache.log4j.Logger; ingo@2684: ingo@2684: import com.vividsolutions.jts.geom.Envelope; ingo@2684: import com.vividsolutions.jts.geom.Geometry; ingo@2684: teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; teichmann@5831: import org.dive4elements.artifactdatabase.state.DefaultOutput; teichmann@5831: import org.dive4elements.artifactdatabase.state.State; ingo@2684: teichmann@5831: import org.dive4elements.river.model.River; teichmann@5831: import org.dive4elements.river.model.GaugeLocation; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.model.RiverFactory; teichmann@5865: import org.dive4elements.river.utils.RiverUtils; teichmann@5831: import org.dive4elements.river.utils.GeometryUtils; ingo@2684: ingo@2684: ingo@2684: public class WMSGaugeLocationArtifact extends WMSDBArtifact { ingo@2684: ingo@2684: public static final String NAME = "wmsgaugelocation"; ingo@2684: ingo@2684: teichmann@8202: private static final Logger log = ingo@2684: Logger.getLogger(WMSGaugeLocationArtifact.class); ingo@2684: ingo@2684: ingo@2684: @Override ingo@2684: public String getName() { ingo@2684: return NAME; ingo@2684: } ingo@2684: ingo@2684: ingo@2684: @Override ingo@2684: public State getCurrentState(Object cc) { ingo@2684: State s = new WMSGaugeLocationState(this); ingo@2684: bjoern@4497: List fs = getFacets(getCurrentStateId()); ingo@2684: ingo@2684: DefaultOutput o = new DefaultOutput( ingo@2684: "floodmap", ingo@2684: "floodmap", ingo@2684: "image/png", ingo@2684: fs, ingo@2684: "map"); ingo@2684: ingo@2684: s.getOutputs().add(o); ingo@2684: ingo@2684: return s; ingo@2684: } ingo@2684: ingo@2684: ingo@2684: ingo@2684: public static class WMSGaugeLocationState extends WMSDBState implements FacetTypes { ingo@2684: teichmann@8202: private static final Logger log = ingo@2684: Logger.getLogger(WMSGaugeLocationState.class); ingo@2684: ingo@2684: protected Geometry geom; ingo@2684: ingo@2684: public WMSGaugeLocationState(WMSDBArtifact artifact) { ingo@2684: super(artifact); ingo@2684: } ingo@2684: ingo@2684: @Override ingo@2684: protected String getFacetType() { ingo@2684: return FLOODMAP_GAUGE_LOCATION; ingo@2684: } ingo@2684: ingo@2684: @Override ingo@2684: protected String getUrl() { teichmann@5865: return RiverUtils.getUserWMSUrl(artifact.identifier()); ingo@2684: } ingo@2684: ingo@2684: @Override ingo@2684: protected String getSrid() { ingo@2684: River river = RiverFactory.getRiver(getRiverId()); teichmann@5865: return RiverUtils.getRiverSrid(river.getName()); ingo@2684: } ingo@2684: ingo@2684: @Override ingo@3918: protected Envelope getExtent(boolean reproject) { ingo@2684: List gauges = ingo@2684: GaugeLocation.getGaugeLocations(getRiverId(), getName()); ingo@2684: ingo@2684: Envelope max = null; ingo@2684: ingo@2684: for (GaugeLocation gauge: gauges) { ingo@2684: Envelope env = gauge.getGeom().getEnvelopeInternal(); ingo@2684: ingo@2684: if (max == null) { ingo@2684: max = env; ingo@2684: continue; ingo@2684: } ingo@2684: ingo@2684: max.expandToInclude(env); ingo@2684: } ingo@2684: ingo@3918: return max != null && reproject ingo@3301: ? GeometryUtils.transform(max, getSrid()) ingo@3301: : max; ingo@2684: } ingo@2684: ingo@2684: @Override ingo@2684: protected String getFilter() { ingo@2684: return "river_id=" + String.valueOf(getRiverId()) + ingo@2684: " and name='" + getName() + "'"; ingo@2684: } ingo@2684: ingo@2684: @Override ingo@2684: protected String getDataString() { ingo@2684: String srid = getSrid(); ingo@2684: teichmann@5865: if (RiverUtils.isUsingOracle()) { ingo@2684: return "geom FROM gauge_location USING SRID " + srid; ingo@2684: } ingo@2684: else { ingo@2684: return "geom FROM gauge_location " + ingo@2684: "USING UNIQUE id USING SRID " + srid; ingo@2684: } ingo@2684: } ingo@2684: ingo@2684: @Override ingo@2684: protected String getGeometryType() { ingo@2684: return "POINT"; ingo@2684: } ingo@2684: } ingo@2684: } ingo@2684: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :