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.wsplgen; ingo@1650: ingo@1650: import java.util.ArrayList; ingo@1650: import java.util.List; ingo@1650: ingo@2091: import org.apache.log4j.Logger; ingo@2091: ingo@1774: import com.vividsolutions.jts.geom.Envelope; ingo@1774: teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; teichmann@5831: import org.dive4elements.artifacts.CallContext; teichmann@5831: import org.dive4elements.river.artifacts.access.RangeAccess; teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; rrenkert@5913: import org.dive4elements.river.artifacts.model.map.ShapeFacet; teichmann@5831: import org.dive4elements.river.artifacts.model.map.WMSLayerFacet; teichmann@5831: import org.dive4elements.river.artifacts.model.map.WSPLGENLayerFacet; teichmann@5831: import org.dive4elements.river.artifacts.resources.Resources; teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; teichmann@5831: import org.dive4elements.river.model.CrossSectionTrack; teichmann@5865: import org.dive4elements.river.utils.RiverUtils; teichmann@5831: import org.dive4elements.river.utils.GeometryUtils; teichmann@5831: import org.dive4elements.river.utils.MapfileGenerator; ingo@1650: ingo@1650: ingo@1650: public class FacetCreator implements FacetTypes { ingo@1650: raimund@2639: public static final String I18N_WSPLGEN_RESULT = "floodmap.uesk"; raimund@2639: public static final String I18N_WSPLGEN_DEFAULT = "floodmap.uesk"; raimund@2639: public static final String I18N_BARRIERS = "floodmap.barriers"; raimund@2639: public static final String I18N_BARRIERS_DEFAULT = "floodmap.barriers"; raimund@2639: public static final String I18N_USERSHAPE = "floodmap.usershape"; raimund@2639: public static final String I18N_USERSHAPE_DEFAULT = "floodmap.usershape"; ingo@1650: teichmann@5867: protected D4EArtifact artifact; ingo@1650: ingo@1650: protected CallContext cc; ingo@1650: ingo@1650: protected List facets; ingo@1650: protected List tmpFacets; ingo@1650: ingo@1650: protected String url; ingo@1650: protected String hash; ingo@1650: protected String stateId; ingo@1650: ingo@2091: ingo@2091: private static Logger logger = Logger.getLogger(FacetCreator.class); ingo@2091: ingo@2091: ingo@1650: public FacetCreator( teichmann@5867: D4EArtifact artifact, ingo@1650: CallContext cc, ingo@1650: String hash, ingo@1650: String sId, ingo@1650: List facets ingo@1650: ) { ingo@1650: this.tmpFacets = new ArrayList(2); ingo@1650: this.facets = facets; ingo@1650: this.artifact = artifact; ingo@1650: this.cc = cc; ingo@1650: this.hash = hash; ingo@1650: this.stateId = sId; ingo@1650: } ingo@1650: teichmann@5865: // TODO We have RiverUtils and will have RiverAccess to do this ingo@1650: protected String getRiver() { ingo@1650: return artifact.getDataAsString("river"); ingo@1650: } ingo@1650: ingo@1650: protected String getUrl() { teichmann@5865: return RiverUtils.getUserWMSUrl(artifact.identifier()); ingo@1650: } ingo@1650: ingo@1650: protected String getSrid() { teichmann@5865: return RiverUtils.getRiverSrid(artifact); ingo@1650: } ingo@1650: ingo@1774: protected Envelope getWSPLGENBounds() { ingo@1650: String river = getRiver(); teichmann@6101: RangeAccess rangeAccess = new RangeAccess(artifact); felix@4860: double kms[] = rangeAccess.getKmRange(); ingo@1650: ingo@2091: logger.debug("### getWSPLGENBounds"); ingo@2091: logger.debug("### from km: " + kms[0]); ingo@2091: logger.debug("### to km: " + kms[1]); ingo@2091: ingo@1650: CrossSectionTrack a = ingo@1650: CrossSectionTrack.getCrossSectionTrack(river, kms[0]); ingo@1650: ingo@1650: CrossSectionTrack b = ingo@1650: CrossSectionTrack.getCrossSectionTrack(river, kms[1]); ingo@1650: ingo@1650: if (a == null || b == null) { ingo@1650: return null; ingo@1650: } ingo@1650: ingo@1774: Envelope envA = a.getGeom().getEnvelopeInternal(); ingo@1774: Envelope envB = b.getGeom().getEnvelopeInternal(); ingo@1774: ingo@1774: envA.expandToInclude(envB); ingo@3925: envA = GeometryUtils.transform(envA, getSrid()); ingo@1774: ingo@2091: logger.debug("### => " + envA); ingo@2091: ingo@1774: return envA; ingo@1650: } ingo@1650: ingo@1774: protected Envelope getBounds() { ingo@1774: return GeometryUtils.getRiverBoundary(getRiver()); ingo@1650: } ingo@1650: ingo@1650: public List getFacets() { ingo@1650: return tmpFacets; ingo@1650: } ingo@1650: ingo@1650: public void createWSPLGENFacet() { ingo@4286: String river = getRiver(); teichmann@6101: RangeAccess rangeAccess = new RangeAccess(artifact); felix@4860: double kms[] = rangeAccess.getKmRange(); ingo@4286: raimund@2638: WSPLGENLayerFacet wsplgen = new WSPLGENLayerFacet( ingo@1650: 0, ingo@1650: FLOODMAP_WSPLGEN, ingo@4286: Resources.format( ingo@1650: cc.getMeta(), ingo@1650: I18N_WSPLGEN_RESULT, ingo@4286: I18N_WSPLGEN_DEFAULT, ingo@4286: river, ingo@4286: kms[0], kms[1]), ingo@1650: ComputeType.ADVANCE, ingo@1650: stateId, ingo@1650: hash, ingo@1650: getUrl()); ingo@1650: ingo@1774: Envelope bounds = getWSPLGENBounds(); ingo@1650: ingo@1774: if (bounds == null) { ingo@1650: bounds = getBounds(); ingo@1650: } ingo@1650: ingo@1650: wsplgen.addLayer( ingo@1956: MapfileGenerator.MS_WSPLGEN_PREFIX + artifact.identifier()); ingo@1650: wsplgen.setSrid(getSrid()); ingo@3925: wsplgen.setOriginalExtent(bounds); ingo@1650: wsplgen.setExtent(bounds); ingo@1650: ingo@1650: tmpFacets.add(wsplgen); ingo@1650: } ingo@1650: ingo@1650: public void createBarrierFacet() { ingo@1650: WMSLayerFacet barriers = new WMSLayerFacet( ingo@1650: 1, ingo@1775: FLOODMAP_BARRIERS, ingo@1650: Resources.getMsg( ingo@1650: cc.getMeta(), ingo@1650: I18N_BARRIERS, ingo@1650: I18N_BARRIERS_DEFAULT), ingo@1650: ComputeType.ADVANCE, ingo@1650: stateId, ingo@1650: hash, ingo@1650: getUrl()); ingo@1650: aheinecke@6331: barriers.addLayer(MapfileGenerator.MS_BARRIERS_PREFIX + artifact.identifier()); teichmann@5314: ingo@1650: barriers.setSrid(getSrid()); ingo@1650: barriers.setExtent(getBounds()); ingo@1650: ingo@1650: tmpFacets.add(barriers); ingo@1650: } ingo@1650: ingo@1650: rrenkert@5312: public void createShapeFacet( rrenkert@5312: String desc, rrenkert@5312: String layer, rrenkert@5312: String type, rrenkert@5312: int ndx) { raimund@2639: WMSLayerFacet shape = new WMSLayerFacet( raimund@2639: 1, rrenkert@5312: type, raimund@2639: Resources.getMsg( raimund@2639: cc.getMeta(), rrenkert@5312: desc, raimund@2639: I18N_USERSHAPE_DEFAULT), raimund@2639: ComputeType.ADVANCE, raimund@2639: stateId, raimund@2639: hash, raimund@2639: getUrl()); raimund@2639: raimund@2639: shape.addLayer( rrenkert@5312: layer + artifact.identifier()); raimund@2639: shape.setSrid(getSrid()); raimund@2639: shape.setExtent(getBounds()); raimund@2639: raimund@2639: tmpFacets.add(shape); raimund@2639: } raimund@2639: raimund@2639: ingo@1650: public void finish() { ingo@1650: facets.addAll(getFacets()); ingo@1650: } rrenkert@5913: rrenkert@5913: public void createExportFacet(String type) { rrenkert@5913: ShapeFacet facet = new ShapeFacet(type, type); rrenkert@5913: tmpFacets.add(facet); rrenkert@5913: } sascha@3083: } sascha@3083: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :