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