Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 622:89aca25642d6
Implemented method stubs of MapfileGenerator. Mapfiles are successfully created corresponding meta.xml files.
gnv-artifacts/trunk@693 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 19 Feb 2010 13:28:34 +0000 |
parents | 567216b56983 |
children | 65f09139e9b3 |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Wed Feb 17 09:40:15 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Fri Feb 19 13:28:34 2010 +0000 @@ -52,9 +52,13 @@ import de.intevation.gnv.utils.StringUtils; import de.intevation.gnv.utils.WKTUtils; +import de.intevation.gnv.wms.LayerInfo; + import java.awt.Dimension; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -74,21 +78,27 @@ /** * @author Tim Englich (tim.englich@intevation.de) * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) */ -public class HorizontalCrossSectionMeshOutputState +public class HorizontalCrossSectionMeshOutputState extends OutputStateBase { private static Logger log = Logger .getLogger(HorizontalCrossSectionMeshOutputState.class); - + /** * The UID of this Class */ private static final long serialVersionUID = 3233620652465061860L; - + public static final boolean USE_INDEX_BUFFER = Boolean.getBoolean("gnv.horizontal.cross.section.mesh.index.buffer"); + public static final String META_FILE_NAME = "meta.xml"; + public static final String ISOLINES_NAME = "isolines.shp"; + public static final String POLYGON_NAME = "polygons.shp"; + public static final String LAYER_MODEL = "horizontalcrosssection"; + private String ijkQueryID; private Boolean shapeFileLock = new Boolean(true); @@ -250,6 +260,13 @@ AttributedPoint2ds result = getResult(uuid, callContext); if (result != null && (path = writeToShapeFile(uuid, result, callContext)) != null) { + + Document meta = null; + if ((meta = writeMeta(callContext, uuid, path)) != null) { + MapfileGenerator.getInstance().update(); + return meta; + } + pathElement.setTextContent(path); } } @@ -290,8 +307,8 @@ List<Pair<Object, MultiLineString>> isolines = result.getLineStrings(); - File polygonsFile = new File(shapeDir, "polygons.shp"); - File isolinesFile = new File(shapeDir, "isolines.shp"); + File polygonsFile = new File(shapeDir, POLYGON_NAME); + File isolinesFile = new File(shapeDir, ISOLINES_NAME); if (!ShapeFileWriter.writeMultiPolygonsToFile( polygonsFile, @@ -320,8 +337,6 @@ callContext.afterCall(CallContext.STORE); - MapfileGenerator.getInstance().update(); - return shapeFilePath; } finally { @@ -331,6 +346,131 @@ } } + protected Document writeMeta(CallContext context, String uuid, String path){ + InputData inputParam = inputData.get("parameterid"); + Map<Integer, PaletteManager> paletteManagers = getPalettes(context); + String paramType = null; + + if (inputParam == null || paletteManagers == null) { + log.warn("Parameter-id not found."); + paramType = LAYER_MODEL; + } + else { + Integer parameterId = Integer.parseInt(inputParam.getValue()); + PaletteManager paletteManager = paletteManagers.get(parameterId); + + paramType = LAYER_MODEL + "_" + paletteManager.getName(); + } + + + Document meta = XMLUtils.newDocument(); + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + meta, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element root = creator.create("meta"); + meta.appendChild(root); + + writePolygonMeta(context, meta, root, uuid, path, paramType); + writeIsolineMeta(context, meta, root, uuid, path, paramType); + + try { + File metaFile = new File(path, META_FILE_NAME); + + if (!metaFile.createNewFile() || !metaFile.canWrite()) { + log.error("Error while writing meta file: "+metaFile.toString()); + return null; + } + + OutputStream out = new FileOutputStream(metaFile); + XMLUtils.toStream(meta, out); + + return meta; + } + catch (FileNotFoundException fnfe) { + log.error(fnfe); + } + catch (IOException ioe) { + log.error(ioe, ioe); + } + + return meta; + } + + + protected void writePolygonMeta( + CallContext context, + Document document, + Element meta, + String uuid, + String path, + String paramType + ) { + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element layer = creator.create(LayerInfo.LAYER); + Element model = creator.create(LayerInfo.LAYER_MODEL); + Element name = creator.create(LayerInfo.LAYER_NAME); + Element type = creator.create(LayerInfo.LAYER_TYPE); + Element status = creator.create(LayerInfo.LAYER_STATUS); + Element data = creator.create(LayerInfo.LAYER_DATA); + + model.setTextContent(paramType); + name.setTextContent(uuid); + type.setTextContent("POLYGON"); + status.setTextContent("DEFAULT"); + data.setTextContent(POLYGON_NAME); + + layer.appendChild(model); + layer.appendChild(name); + layer.appendChild(type); + layer.appendChild(status); + layer.appendChild(data); + + meta.appendChild(layer); + } + + + protected void writeIsolineMeta( + CallContext context, + Document document, + Element meta, + String uuid, + String path, + String paramType + ) { + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element layer = creator.create(LayerInfo.LAYER); + Element model = creator.create(LayerInfo.LAYER_MODEL); + Element name = creator.create(LayerInfo.LAYER_NAME); + Element type = creator.create(LayerInfo.LAYER_TYPE); + Element status = creator.create(LayerInfo.LAYER_STATUS); + Element data = creator.create(LayerInfo.LAYER_DATA); + + model.setTextContent(paramType+"_isolines"); + name.setTextContent(uuid); + type.setTextContent("LINE"); + status.setTextContent("DEFAULT"); + data.setTextContent(ISOLINES_NAME); + + layer.appendChild(model); + layer.appendChild(name); + layer.appendChild(type); + layer.appendChild(status); + layer.appendChild(data); + + meta.appendChild(layer); + } + + protected AttributedPoint2ds getResult(String uuid, CallContext callContext) throws StateException { @@ -486,7 +626,7 @@ return ap2ds; } - + public AttributedPoint2ds process( Envelope boundingBox, Polygon polygon,