ingo@1650: package de.intevation.flys.wsplgen; ingo@1650: ingo@1650: import java.util.ArrayList; ingo@1650: import java.util.List; ingo@1650: ingo@1774: import com.vividsolutions.jts.geom.Envelope; ingo@1774: ingo@1650: import de.intevation.artifacts.CallContext; ingo@1650: ingo@1650: import de.intevation.artifactdatabase.state.Facet; ingo@1650: ingo@1650: import de.intevation.flys.model.CrossSectionTrack; ingo@1650: ingo@1650: import de.intevation.flys.artifacts.FLYSArtifact; ingo@1650: import de.intevation.flys.artifacts.model.FacetTypes; ingo@1650: import de.intevation.flys.artifacts.model.WMSLayerFacet; ingo@1650: import de.intevation.flys.artifacts.resources.Resources; ingo@1650: import de.intevation.flys.artifacts.states.DefaultState.ComputeType; ingo@1650: import de.intevation.flys.utils.FLYSUtils; ingo@1650: import de.intevation.flys.utils.GeometryUtils; ingo@1650: import de.intevation.flys.utils.MapfileGenerator; ingo@1650: ingo@1650: ingo@1650: public class FacetCreator implements FacetTypes { ingo@1650: ingo@1650: public static final String I18N_WSPLGEN_RESULT = "floodmap.uesk"; ingo@1650: public static final String I18N_WSPLGEN_DEFAULT = "floodmap.uesk"; ingo@1650: public static final String I18N_BARRIERS = "floodmap.barriers"; ingo@1650: public static final String I18N_BARRIERS_DEFAULT = "floodmap.barriers"; ingo@1650: ingo@1650: protected FLYSArtifact 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@1650: public FacetCreator( ingo@1650: FLYSArtifact 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: ingo@1650: protected String getRiver() { ingo@1650: return artifact.getDataAsString("river"); ingo@1650: } ingo@1650: ingo@1650: protected String getUrl() { ingo@1792: return FLYSUtils.getUserWMSUrl(artifact.identifier()); ingo@1650: } ingo@1650: ingo@1650: protected String getSrid() { ingo@1650: return FLYSUtils.getRiverSrid(artifact); ingo@1650: } ingo@1650: ingo@1774: protected Envelope getWSPLGENBounds() { ingo@1650: String river = getRiver(); ingo@1650: double kms[] = FLYSUtils.getKmRange(artifact); ingo@1650: 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@1774: 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@1650: WMSLayerFacet wsplgen = new WMSLayerFacet( ingo@1650: 0, ingo@1650: FLOODMAP_WSPLGEN, ingo@1650: Resources.getMsg( ingo@1650: cc.getMeta(), ingo@1650: I18N_WSPLGEN_RESULT, ingo@1650: I18N_WSPLGEN_DEFAULT), 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@1650: artifact.identifier() + MapfileGenerator.MS_WSPLGEN_POSTFIX); ingo@1650: wsplgen.setSrid(getSrid()); 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: ingo@1650: barriers.addLayer( ingo@1650: artifact.identifier() + MapfileGenerator.MS_BARRIERS_POSTFIX); ingo@1650: barriers.setSrid(getSrid()); ingo@1650: barriers.setExtent(getBounds()); ingo@1650: ingo@1650: tmpFacets.add(barriers); ingo@1650: } ingo@1650: ingo@1650: ingo@1650: public void finish() { ingo@1650: facets.addAll(getFacets()); ingo@1650: } ingo@1650: } // end of FacetCreator