Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/states/HWSBarriersState.java @ 6710:ffc9cb39cea7
Remove duplicate code for mapfile generation. ID problem still not fixed (#657).
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Tue, 30 Jul 2013 16:09:40 +0200 |
parents | d79bfbe55417 |
children | a56fe3bc6700 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/HWSBarriersState.java Tue Jul 30 12:33:05 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/HWSBarriersState.java Tue Jul 30 16:09:40 2013 +0200 @@ -9,51 +9,29 @@ package org.dive4elements.river.artifacts.states; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; - -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.apache.log4j.Logger; - -import org.apache.velocity.Template; - -import org.geotools.data.shapefile.ShapefileDataStore; - -import org.geotools.feature.FeatureCollection; -import org.geotools.feature.FeatureCollections; - -import org.opengis.feature.simple.SimpleFeatureType; - -import org.opengis.feature.type.GeometryDescriptor; - -import org.w3c.dom.Element; - import org.dive4elements.artifactdatabase.state.Facet; - import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.CallContext; - import org.dive4elements.artifacts.common.utils.FileTools; - import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; - import org.dive4elements.river.artifacts.D4EArtifact; - import org.dive4elements.river.artifacts.access.MapAccess; - -import org.dive4elements.river.artifacts.model.LayerInfo; - import org.dive4elements.river.artifacts.model.map.HWS; import org.dive4elements.river.artifacts.model.map.HWSContainer; import org.dive4elements.river.artifacts.model.map.HWSFactory; - -import org.dive4elements.river.utils.ArtifactMapfileGenerator; -import org.dive4elements.river.utils.RiverUtils; import org.dive4elements.river.utils.GeometryUtils; import org.dive4elements.river.utils.MapfileGenerator; +import org.dive4elements.river.utils.RiverUtils; +import org.geotools.data.shapefile.ShapefileDataStore; +import org.geotools.feature.FeatureCollection; +import org.geotools.feature.FeatureCollections; +import org.opengis.feature.simple.SimpleFeatureType; +import org.opengis.feature.type.GeometryDescriptor; +import org.w3c.dom.Element; public class HWSBarriersState extends DefaultState @@ -63,9 +41,8 @@ private static Logger logger = Logger.getLogger(HWSBarriersState.class); private static final String HWS_SHAPEFILE_LINES = "hws-lines.shp"; private static final String HWS_SHAPEFILE_POINTS = "hws-points.shp"; - private static final String USER_RGD_SHAPE = "user-rgd.shp"; - private static final String USER_RGD_ZIP = "user-rgd.zip"; - private static final String USER_RGD_FILENAME = "user-rgd"; + + @Override protected String getUIProvider() { return "map_digitize"; @@ -146,7 +123,7 @@ } if (successLines) { - createMapfile( + FloodMapState.createMapfile( artifact, artifactDir, MapfileGenerator.MS_LAYER_PREFIX + "hws-lines", @@ -156,7 +133,7 @@ "hws"); } if (successPoints) { - createMapfile( + FloodMapState.createMapfile( artifact, artifactDir, MapfileGenerator.MS_LAYER_PREFIX + "hws-points", @@ -172,7 +149,7 @@ try { ShapefileDataStore store = new ShapefileDataStore( new File(artifactDir.getCanonicalPath() + - "/" + USER_RGD_SHAPE) + "/" + FloodMapState.WSPLGEN_USER_RGD_SHAPE) .toURI().toURL()); GeometryDescriptor desc = store.getSchema().getGeometryDescriptor(); @@ -201,14 +178,14 @@ else { type = "POINT"; } - createMapfile( + FloodMapState.createMapfile( artifact, artifactDir, - MapfileGenerator.MS_LAYER_PREFIX + USER_RGD_FILENAME, - USER_RGD_SHAPE, + MapfileGenerator.MS_LAYER_PREFIX + FloodMapState.WSPLGEN_USER_RGD, + FloodMapState.WSPLGEN_USER_RGD_SHAPE, type, epsg, - "user-rgd"); + FloodMapState.WSPLGEN_USER_RGD); } catch (IOException e) { logger.warn("No mapfile for user-rgd created!"); @@ -219,7 +196,7 @@ } private boolean extractUserShp(File dir) { - File archive = new File(dir, USER_RGD_ZIP); + File archive = new File(dir, FloodMapState.WSPLGEN_USER_RGD_ZIP); boolean exists = archive.exists(); logger.debug("Zip file exists: " + exists); if (exists) { @@ -231,7 +208,7 @@ } catch (IOException ioe) { logger.warn("Zip archive " + dir + "/" - + USER_RGD_ZIP + " could not be extracted."); + + FloodMapState.WSPLGEN_USER_RGD_ZIP + " could not be extracted."); return false; } } @@ -261,7 +238,7 @@ return true; } try { - FileTools.copyFile(file, new File(target, USER_RGD_FILENAME + "." + suffix)); + FileTools.copyFile(file, new File(target, FloodMapState.WSPLGEN_USER_RGD + "." + suffix)); } catch (IOException ioe) { logger.warn ("Error while copying file " + file.getName()); @@ -275,41 +252,6 @@ FileTools.deleteRecursive(source); } - private void createMapfile( - D4EArtifact artifact, - File artifactDir, - String name, - String hwsShapefile, - String type, - String srid, - String group - ) { - LayerInfo info = new LayerInfo(); - info.setName(name + artifact.identifier()); - info.setType(type); - info.setDirectory(artifact.identifier()); - info.setTitle(name); - info.setData(hwsShapefile); - info.setSrid(srid); - info.setGroupTitle(group); - MapfileGenerator generator = new ArtifactMapfileGenerator(); - Template tpl = generator.getTemplateByName(MapfileGenerator.SHP_LAYER_TEMPLATE); - try { - File layer = new File(artifactDir.getCanonicalPath() + "/" + name); - generator.writeLayer(info, layer, tpl); - List<String> layers = new ArrayList<String>(); - layers.add(layer.getAbsolutePath()); - generator.generate(); - } - catch(FileNotFoundException fnfe) { - logger.warn("Could not find mapfile for hws layer"); - } - catch (Exception ioe) { - logger.warn("Could not create mapfile for hws layer"); - logger.warn(Arrays.toString(ioe.getStackTrace())); - } - } - @Override public void endOfLife(Artifact artifact, Object callContext) {