ingo@1650: package de.intevation.flys.wsplgen; ingo@1650: ingo@1774: import com.vividsolutions.jts.geom.Envelope; ingo@1774: ingo@1650: import de.intevation.artifactdatabase.state.Facet; ingo@3302: import de.intevation.artifacts.CallContext; christian@5023: import de.intevation.flys.artifacts.FLYSArtifact; felix@4860: import de.intevation.flys.artifacts.access.RangeAccess; ingo@1650: import de.intevation.flys.artifacts.model.FacetTypes; ingo@3302: import de.intevation.flys.artifacts.model.map.WMSLayerFacet; ingo@3302: import de.intevation.flys.artifacts.model.map.WSPLGENLayerFacet; ingo@1650: import de.intevation.flys.artifacts.resources.Resources; ingo@1650: import de.intevation.flys.artifacts.states.DefaultState.ComputeType; christian@5022: import de.intevation.flys.mapserver.MapfileGenerator; ingo@3302: import de.intevation.flys.model.CrossSectionTrack; ingo@1650: import de.intevation.flys.utils.FLYSUtils; ingo@1650: import de.intevation.flys.utils.GeometryUtils; ingo@1650: christian@5023: import java.util.ArrayList; christian@5023: import java.util.List; christian@5023: christian@5023: import org.apache.log4j.Logger; christian@5023: 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: 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@2091: ingo@2091: private static Logger logger = Logger.getLogger(FacetCreator.class); ingo@2091: ingo@2091: 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: felix@4860: // TODO We have FLYSUtils 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() { 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(); felix@4860: RangeAccess rangeAccess = new RangeAccess(artifact, null); 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(); felix@4860: RangeAccess rangeAccess = new RangeAccess(artifact, null); 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( christian@5023: MapfileGenerator.MS_PREFIX_WSPLGEN + 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: ingo@1650: barriers.addLayer( christian@5023: MapfileGenerator.MS_PREFIX_WSPLGEN + artifact.identifier()); ingo@1650: barriers.setSrid(getSrid()); ingo@1650: barriers.setExtent(getBounds()); ingo@1650: ingo@1650: tmpFacets.add(barriers); ingo@1650: } ingo@1650: ingo@1650: raimund@2639: public void createUserShapeFacet() { raimund@2639: WMSLayerFacet shape = new WMSLayerFacet( raimund@2639: 1, raimund@2639: FLOODMAP_USERSHAPE, raimund@2639: Resources.getMsg( raimund@2639: cc.getMeta(), raimund@2639: I18N_USERSHAPE, raimund@2639: I18N_USERSHAPE_DEFAULT), raimund@2639: ComputeType.ADVANCE, raimund@2639: stateId, raimund@2639: hash, raimund@2639: getUrl()); raimund@2639: raimund@2639: shape.addLayer( christian@5076: MapfileGenerator.MS_PREFIX_USER + 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: } sascha@3083: } sascha@3083: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :