Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java @ 5175:cfc5540a4eec mapgenfix
Re-add layer generation for floodmap layers (somewhat buggy though).
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Wed, 06 Mar 2013 14:14:15 +0100 |
parents | cbfdd7376009 |
children |
comparison
equal
deleted
inserted
replaced
5088:2b24073e80d9 | 5175:cfc5540a4eec |
---|---|
4 import de.intevation.flys.artifacts.FLYSArtifact; | 4 import de.intevation.flys.artifacts.FLYSArtifact; |
5 import de.intevation.flys.artifacts.access.RiverAccess; | 5 import de.intevation.flys.artifacts.access.RiverAccess; |
6 import de.intevation.flys.artifacts.model.LayerInfo; | 6 import de.intevation.flys.artifacts.model.LayerInfo; |
7 import de.intevation.flys.artifacts.model.map.WMSDBLayerFacet; | 7 import de.intevation.flys.artifacts.model.map.WMSDBLayerFacet; |
8 import de.intevation.flys.artifacts.model.map.WMSLayerFacet; | 8 import de.intevation.flys.artifacts.model.map.WMSLayerFacet; |
9 import de.intevation.flys.artifacts.model.map.WSPLGENLayerFacet; | |
10 import de.intevation.flys.artifacts.resources.Resources; | 9 import de.intevation.flys.artifacts.resources.Resources; |
11 import de.intevation.flys.utils.FLYSUtils; | 10 import de.intevation.flys.utils.FLYSUtils; |
12 import de.intevation.flys.utils.GeometryUtils; | 11 import de.intevation.flys.utils.GeometryUtils; |
13 | 12 |
14 import java.io.File; | 13 import java.io.File; |
44 | 43 |
45 /** | 44 /** |
46 * Generates flys.map file that contains layers of all | 45 * Generates flys.map file that contains layers of all |
47 * projects and types (floodmap, user defined, barriers). | 46 * projects and types (floodmap, user defined, barriers). |
48 */ | 47 */ |
49 @Override | 48 public void generate(String style, CallContext context, FLYSArtifact flys) throws IOException |
50 public void generate() throws IOException | |
51 { | 49 { |
52 // Get all directories below "shapefiles/" | 50 // Get all directories below "shapefiles/" |
53 File[] prjDirs = getProjectDirs(); | 51 File[] prjDirs = getProjectDirs(); |
54 | 52 |
55 // Look for appropriate shapefiles that we can use as layers | 53 // Look for appropriate shapefiles that we can use as layers |
57 | 55 |
58 List<String> layerSnippets = new ArrayList<String>(); | 56 List<String> layerSnippets = new ArrayList<String>(); |
59 | 57 |
60 // Generate layer snippet for each shapefile | 58 // Generate layer snippet for each shapefile |
61 for (File layerShape : layerShapes) { | 59 for (File layerShape : layerShapes) { |
62 String fileName = layerShape.getName(); | 60 String fileName = layerShape.getName(); |
61 File layerFile = null; | |
62 | |
63 if (fileName.startsWith(MS_PREFIX_BARRIERS)) { | 63 if (fileName.startsWith(MS_PREFIX_BARRIERS)) { |
64 | 64 |
65 } | 65 } |
66 else if (fileName.startsWith(MS_PREFIX_USER)) { | 66 else if (fileName.startsWith(MS_PREFIX_USER)) { |
67 File userLayer = createUserShapeLayer(layerShape); | 67 layerFile = createUserShapeLayer(layerShape); |
68 if (userLayer != null) { | 68 } |
69 layerSnippets.add(userLayer.getCanonicalPath()); | 69 else if (fileName.startsWith(MS_PREFIX_WSPLGEN) && |
70 } | 70 style != null && context != null && flys != null) { |
71 } | 71 layerFile = createFloodmapLayer(layerShape, style, context, flys); |
72 else if (fileName.startsWith(MS_PREFIX_WSPLGEN)) { | 72 } |
73 | 73 |
74 if (layerFile != null) { | |
75 layerSnippets.add(layerFile.getCanonicalPath()); | |
74 } | 76 } |
75 } | 77 } |
76 | 78 |
77 writeMapfile(layerSnippets); | 79 writeMapfile(layerSnippets); |
80 } | |
81 | |
82 @Override | |
83 public void generate() throws IOException { | |
84 generate(null, null, null); | |
78 } | 85 } |
79 | 86 |
80 /** | 87 /** |
81 * Creates a layer file used for Mapserver's mapfile which represents the | 88 * Creates a layer file used for Mapserver's mapfile which represents the |
82 * floodmap. | 89 * floodmap. |
83 * | |
84 * @param flys The FLYSArtifact that owns <i>wms</i>. | |
85 * @param wms The WMSLayerFacet that contains information for the layer. | |
86 */ | 90 */ |
87 protected void createUeskLayer( | 91 protected File createFloodmapLayer(File file, String style, CallContext context, FLYSArtifact flys) |
88 FLYSArtifact flys, | 92 throws FileNotFoundException, IOException |
89 WSPLGENLayerFacet wms, | |
90 String style, | |
91 CallContext context | |
92 ) throws FileNotFoundException, IOException | |
93 { | 93 { |
94 String uuid = uuidFromPath(file.getAbsolutePath()); | |
94 logger.debug("createUeskLayer"); | 95 logger.debug("createUeskLayer"); |
95 | 96 |
96 LayerInfo layerinfo = new LayerInfo(); | 97 LayerInfo layerinfo = new LayerInfo(); |
97 layerinfo.setName(MS_PREFIX_WSPLGEN + flys.identifier()); | 98 layerinfo.setName(MS_PREFIX_WSPLGEN + "-" + uuid); |
98 layerinfo.setType("POLYGON"); | 99 layerinfo.setType("POLYGON"); |
99 layerinfo.setDirectory(flys.identifier()); | 100 layerinfo.setDirectory(uuid); |
100 layerinfo.setData(WSPLGEN_RESULT_SHAPE); | 101 layerinfo.setData(WSPLGEN_RESULT_SHAPE); |
101 layerinfo.setTitle(Resources.getMsg(Resources.getLocale(context.getMeta()), | 102 layerinfo.setTitle(Resources.getMsg(Resources.getLocale(context.getMeta()), |
102 "floodmap.uesk", | 103 "floodmap.uesk", |
103 "Floodmap")); | 104 "Floodmap")); |
104 layerinfo.setStyle(style); | 105 layerinfo.setStyle(style); |
105 RiverAccess access = new RiverAccess(flys); | 106 RiverAccess access = new RiverAccess(flys); |
106 String river = access.getRiver(); | 107 String river = access.getRiver(); |
107 layerinfo.setSrid(FLYSUtils.getRiverDGMSrid(river)); | 108 layerinfo.setSrid(FLYSUtils.getRiverDGMSrid(river)); |
108 | 109 |
109 String name = MS_LAYER_PREFIX + wms.getName(); | 110 String name = "floodmap.layer"; //MS_LAYER_PREFIX + wms.getName(); |
110 | 111 |
111 Template template = getTemplateByName(WSPLGEN_LAYER_TEMPLATE); | 112 Template template = getTemplateByName(WSPLGEN_LAYER_TEMPLATE); |
112 if (template == null) { | 113 if (template == null) { |
113 logger.warn("Template '" + WSPLGEN_LAYER_TEMPLATE + "' found."); | 114 logger.warn("Template '" + WSPLGEN_LAYER_TEMPLATE + "' found."); |
114 return; | 115 return null; |
115 } | 116 } |
116 | 117 |
117 try { | 118 try { |
118 File dir = new File(getShapefileBaseDir(), flys.identifier()); | 119 File dir = new File(getShapefileBaseDir(), uuid); |
119 writeLayer(layerinfo, new File(dir, name), template); | 120 File layerFile = new File(dir, name); |
121 writeLayer(layerinfo, layerFile, template); | |
122 return layerFile; | |
120 } | 123 } |
121 catch (FileNotFoundException fnfe) { | 124 catch (FileNotFoundException fnfe) { |
122 logger.error(fnfe, fnfe); | 125 logger.error(fnfe, fnfe); |
123 logger.warn("Unable to write layer: " + name); | 126 logger.warn("Unable to write layer: " + name); |
127 return null; | |
124 } | 128 } |
125 } | 129 } |
126 | 130 |
127 | 131 |
128 /** | 132 /** |