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@2683: ingo@2683: import java.util.List; ingo@2683: ingo@2683: import org.apache.log4j.Logger; ingo@2683: ingo@2683: import com.vividsolutions.jts.geom.Envelope; ingo@2683: teichmann@5831: import org.dive4elements.artifactdatabase.state.DefaultOutput; teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; teichmann@5831: import org.dive4elements.artifactdatabase.state.State; ingo@2683: teichmann@5831: import org.dive4elements.river.model.River; teichmann@5831: import org.dive4elements.river.model.HydrBoundary; 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@2683: ingo@2683: ingo@2683: public class WMSHydrBoundaryArtifact extends WMSDBArtifact { ingo@2683: ingo@2683: public static final String NAME = "hydr_boundary"; ingo@2683: ingo@2683: teichmann@8202: private static final Logger log = ingo@2683: Logger.getLogger(WMSHydrBoundaryArtifact.class); ingo@2683: ingo@2683: ingo@2683: @Override ingo@2683: public String getName() { ingo@2683: return NAME; ingo@2683: } ingo@2683: ingo@2683: ingo@2683: @Override ingo@2683: public State getCurrentState(Object cc) { ingo@2683: State s = new HydrBoundaryState(this); ingo@2683: bjoern@4497: List fs = getFacets(getCurrentStateId()); ingo@2683: ingo@2683: DefaultOutput o = new DefaultOutput( ingo@2683: "floodmap", ingo@2683: "floodmap", ingo@2683: "image/png", ingo@2683: fs, ingo@2683: "map"); ingo@2683: ingo@2683: s.getOutputs().add(o); ingo@2683: ingo@2683: return s; ingo@2683: } ingo@2683: ingo@2683: tom@8856: public static class HydrBoundaryState tom@8856: extends WMSDBState implements FacetTypes ingo@2683: { teichmann@8202: private static final Logger log = ingo@2683: Logger.getLogger(HydrBoundaryState.class); ingo@2683: ingo@2683: protected int riverId; ingo@2683: ingo@2683: public HydrBoundaryState(WMSDBArtifact artifact) { ingo@2683: super(artifact); ingo@2683: riverId = 0; ingo@2683: } ingo@2683: ingo@2683: @Override ingo@2683: protected String getFacetType() { ingo@2683: return FLOODMAP_HYDR_BOUNDARY; ingo@2683: } ingo@2683: ingo@2683: @Override ingo@2683: protected String getUrl() { teichmann@5865: return RiverUtils.getUserWMSUrl(artifact.identifier()); ingo@2683: } ingo@2683: ingo@2683: @Override ingo@2683: protected String getSrid() { ingo@2683: River river = RiverFactory.getRiver(getRiverId()); teichmann@5865: return RiverUtils.getRiverSrid(river.getName()); ingo@2683: } ingo@2683: ingo@2683: @Override ingo@3918: protected Envelope getExtent(boolean reproject) { aheinecke@5515: List boundaries; aheinecke@5515: String kind = getIdPart(2); aheinecke@5515: if (kind != null) { aheinecke@5515: boundaries = HydrBoundary.getHydrBoundaries(getRiverId(), aheinecke@5515: getName(), Integer.parseInt(kind)); aheinecke@5515: } else { tom@8856: boundaries = HydrBoundary.getHydrBoundaries( tom@8856: getRiverId(), getName()); aheinecke@5515: } ingo@2683: ingo@2683: Envelope max = null; ingo@2683: ingo@2683: for (HydrBoundary b: boundaries) { ingo@2683: Envelope env = b.getGeom().getEnvelopeInternal(); ingo@2683: ingo@2683: if (max == null) { ingo@2683: max = env; ingo@2683: continue; ingo@2683: } ingo@2683: ingo@2683: max.expandToInclude(env); ingo@2683: } ingo@2683: ingo@3918: return max != null && reproject ingo@3301: ? GeometryUtils.transform(max, getSrid()) ingo@3301: : max; ingo@2683: } ingo@2683: ingo@2683: @Override ingo@2683: protected String getFilter() { aheinecke@5515: String kind = getIdPart(2); aheinecke@5515: if (kind != null) { aheinecke@5515: return "river_id=" + String.valueOf(getRiverId()) aheinecke@5515: + " AND name='" + getName() + "'" aheinecke@5515: + " AND kind = " + kind; aheinecke@5515: } ingo@2683: return "river_id=" + String.valueOf(getRiverId()) ingo@2683: + " AND name='" + getName() + "'"; ingo@2683: } ingo@2683: ingo@2683: @Override ingo@2683: protected String getDataString() { ingo@2683: String srid = getSrid(); ingo@2683: teichmann@5865: if (RiverUtils.isUsingOracle()) { ingo@2683: return "geom FROM hydr_boundaries USING SRID " + srid; ingo@2683: } ingo@2683: else { tom@8856: return "geom FROM hydr_boundaries USING UNIQUE id USING SRID " tom@8856: + srid; ingo@2683: } ingo@2683: } ingo@2683: ingo@2683: @Override ingo@2683: protected String getGeometryType() { ingo@2683: return "LINE"; ingo@2683: } ingo@2683: } // end of HydrBoundaryState ingo@2683: } ingo@2683: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :