svn-gvsig-desktop / trunk / extensions / extPublish / src / org / gvsig / remoteservices / conf / mapserver / DoMap.java @ 6920
History | View | Annotate | Download (8.01 KB)
1 |
package org.gvsig.remoteservices.conf.mapserver; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.io.File; |
5 |
import java.io.FileNotFoundException; |
6 |
import java.io.FileOutputStream; |
7 |
import java.io.PrintStream; |
8 |
import java.util.ArrayList; |
9 |
import java.util.Iterator; |
10 |
|
11 |
|
12 |
/**
|
13 |
* Genera un .MAP
|
14 |
* ... como este:
|
15 |
MAP
|
16 |
NAME test_postgis
|
17 |
STATUS ON
|
18 |
SIZE 400 300
|
19 |
#SYMBOLSET ../etc/symbols.sym
|
20 |
EXTENT 638610.4375 4222780 789330 4484662.5
|
21 |
UNITS METERS
|
22 |
SHAPEPATH "/home/shapes/"
|
23 |
IMAGECOLOR 255 255 255
|
24 |
#FONTSET ../etc/fonts.txt
|
25 |
|
26 |
WEB
|
27 |
# IMAGEPATH "/ms4w/tmp/ms_tmp/"
|
28 |
# IMAGEURL "/ms_tmp/"
|
29 |
METADATA
|
30 |
"wms_title" "test postgis" ##required
|
31 |
"wms_onlineresource" "http://localhost/mapserver/mapserv" ##required
|
32 |
"wms_srs" "EPSG:42304 EPSG:42101 EPSG:4269 EPSG:4326 EPSG:23030" ##recommended
|
33 |
END
|
34 |
END
|
35 |
|
36 |
PROJECTION
|
37 |
"init=epsg:23030" ##required
|
38 |
END
|
39 |
|
40 |
#
|
41 |
# Start of layer definitions
|
42 |
#
|
43 |
|
44 |
LAYER
|
45 |
NAME "autopistas"
|
46 |
DATA "the_geom from autopistas"
|
47 |
CONNECTIONTYPE POSTGIS
|
48 |
CONNECTION "user=david password=chkdsk dbname=betel host=localhost port=5434"
|
49 |
STATUS ON
|
50 |
TYPE LINE
|
51 |
METADATA
|
52 |
"wms_title" "Autopistas GV" ##required
|
53 |
"wms_extent" "638610.4375 4222780 789330 4484662.5"
|
54 |
END
|
55 |
PROJECTION
|
56 |
"init=epsg:23030" ##recommended
|
57 |
END
|
58 |
CLASS
|
59 |
NAME "Autopistas"
|
60 |
STYLE
|
61 |
COLOR 200 255 0
|
62 |
OUTLINECOLOR 120 120 120
|
63 |
END
|
64 |
END
|
65 |
END
|
66 |
|
67 |
END # Map File
|
68 |
|
69 |
* @author david
|
70 |
*/
|
71 |
|
72 |
public class DoMap extends ToMap { |
73 |
/**
|
74 |
* Atributos wms_xxxx comunes a WEB y LAYER.
|
75 |
* @author david
|
76 |
*/
|
77 |
public static class Metadata extends ToMap { |
78 |
public String prefix = "wms"; |
79 |
public String title = null; |
80 |
|
81 |
public void setServiceAsWFS() { |
82 |
prefix = "wfs";
|
83 |
} |
84 |
|
85 |
public void setServiceAsWMS() { |
86 |
prefix = "wms";
|
87 |
} |
88 |
public void setServiceAsWCS() { |
89 |
prefix = "wcs";
|
90 |
} |
91 |
//
|
92 |
void startMetadataToMap(){
|
93 |
toMapln("METADATA");
|
94 |
tabIn(); |
95 |
if (title != null) |
96 |
toMapln("\""+prefix+"_title\" " +"\""+title+"\""); |
97 |
} |
98 |
|
99 |
void endMetadataToMap() {
|
100 |
tabOut(); |
101 |
toMapln("END");
|
102 |
} |
103 |
} |
104 |
|
105 |
public static class MetadataWeb extends Metadata { |
106 |
//Atributos wms_xxxx WEB
|
107 |
public String onlineresource = null; |
108 |
public String ows_schemas_location = null; |
109 |
void metadataToMap(){
|
110 |
startMetadataToMap(); |
111 |
toMapln("\""+prefix+"_onlineresource\" \""+onlineresource+"\""); |
112 |
toMapln("\""+prefix+"_srs\" \""+crs+"\""); |
113 |
if (ows_schemas_location != null) |
114 |
toMapln("\"ows_schemas_location\" \""+ows_schemas_location+"\""); |
115 |
endMetadataToMap(); |
116 |
} |
117 |
} |
118 |
|
119 |
public static class MetadataLayer extends Metadata { |
120 |
//Atributos wms_xxxx LAYER
|
121 |
public String metalayertitle = null; |
122 |
public String gml_include_items = null; |
123 |
void metadataToMap(){
|
124 |
startMetadataToMap(); |
125 |
if (extent != null) |
126 |
toMapln("\""+prefix+"_extent\" \""+extentToMapString(extent)+"\""); |
127 |
if (gml_include_items != null) |
128 |
toMapln("\"gml_include_items\" \""+gml_include_items+"\""); |
129 |
endMetadataToMap(); |
130 |
} |
131 |
} |
132 |
|
133 |
public static class StyleMap extends ToMap { |
134 |
public RGB styleColor = null; |
135 |
public RGB styleColorOutline = null; |
136 |
public StyleMap(RGB line, RGB fill) {
|
137 |
styleColor = fill; |
138 |
styleColorOutline = line; |
139 |
} |
140 |
void styleToMap(){
|
141 |
toMapln("STYLE ");
|
142 |
tabIn(); |
143 |
toMapln("COLOR "+styleColor);
|
144 |
toMapln("OUTLINECOLOR "+styleColorOutline);
|
145 |
tabOut(); |
146 |
toMapln("END");
|
147 |
} |
148 |
} |
149 |
|
150 |
public static class WebMap extends ToMap{ |
151 |
public MetadataWeb metadata = null; |
152 |
public String imagepath = null; |
153 |
public String imageurl = null; |
154 |
void webToMap(){
|
155 |
toMapln("WEB");
|
156 |
tabIn(); |
157 |
toMapln("IMAGEPATH \""+imagepath+"\""); |
158 |
toMapln("IMAGEURL \""+imageurl+"\""); |
159 |
metadata.metadataToMap(); |
160 |
tabOut(); |
161 |
toMapln("END");
|
162 |
} |
163 |
} |
164 |
|
165 |
public static class MapClass extends ToMap { |
166 |
public String name; |
167 |
public StyleMap estilo = null; |
168 |
public String template = null; |
169 |
public MapClass(String n) { |
170 |
name = n; |
171 |
} |
172 |
public void classToMap(){ |
173 |
toMapln("CLASS");
|
174 |
tabIn(); |
175 |
toMapln("NAME \""+name+"\""); |
176 |
if (estilo != null) |
177 |
estilo.styleToMap(); |
178 |
if (template != null) |
179 |
toMapln("TEMPLATE "+template);
|
180 |
tabOut(); |
181 |
toMapln("END");
|
182 |
} |
183 |
} |
184 |
|
185 |
public abstract static class MapLayer extends ToMap { |
186 |
public String name; |
187 |
public String title; |
188 |
public String status = "ON"; |
189 |
public String type = null; |
190 |
public MapClass layerClass = null; |
191 |
public String data; |
192 |
public MetadataLayer metadata = null; |
193 |
public boolean dump = false; |
194 |
public CRS layercrs=null; |
195 |
|
196 |
public void setDump(boolean d) { |
197 |
dump = d; |
198 |
} |
199 |
|
200 |
void startToMap() {
|
201 |
toMapln("LAYER");
|
202 |
tabIn(); |
203 |
toMapln("NAME \""+name+"\""); |
204 |
toMapln("STATUS "+status);
|
205 |
if (type != null) |
206 |
toMapln("TYPE "+type);
|
207 |
if (dump)
|
208 |
toMapln("DUMP TRUE # required");
|
209 |
} |
210 |
|
211 |
void endToMap() {
|
212 |
tabOut(); |
213 |
toMapln("END # Layer");
|
214 |
} |
215 |
|
216 |
public abstract void layerToMap(); |
217 |
} |
218 |
|
219 |
public static class ShpLayer extends MapLayer { |
220 |
public void layerToMap() { |
221 |
startToMap(); |
222 |
toMapln("DATA \""+data+"\""); |
223 |
metadata.metadataToMap(); |
224 |
if (layercrs != null) layercrs.toMap(); |
225 |
if (layerClass != null) |
226 |
layerClass.classToMap(); |
227 |
endToMap(); |
228 |
} |
229 |
} |
230 |
|
231 |
public static class PostgisLayer extends MapLayer { |
232 |
public String user; |
233 |
public String pass; |
234 |
public String host; |
235 |
public String dbname; |
236 |
public String port; |
237 |
|
238 |
public String tabla; |
239 |
public String data; |
240 |
|
241 |
public void setConnParams(String user, String pass, String host, |
242 |
String dbname, String port) { |
243 |
this.user = user;
|
244 |
this.pass = pass;
|
245 |
this.host = host;
|
246 |
this.dbname = dbname;
|
247 |
this.port = port;
|
248 |
} |
249 |
|
250 |
public void layerToMap() { |
251 |
startToMap(); |
252 |
toMapln("DATA \""+data+"\""); |
253 |
toMapln("CONNECTIONTYPE POSTGIS");
|
254 |
toMapln("CONNECTION \"user="+user+" password="+pass+" dbname="+dbname+" host="+host+" port="+port+"\""); |
255 |
metadata.metadataToMap(); |
256 |
if (layercrs != null) layercrs.toMap(); |
257 |
if (layerClass != null) |
258 |
layerClass.classToMap(); |
259 |
endToMap(); |
260 |
} |
261 |
} |
262 |
|
263 |
public static class RasterLayer extends MapLayer { |
264 |
public void layerToMap() { |
265 |
startToMap(); |
266 |
toMapln("DATA \""+data+"\""); |
267 |
metadata.metadataToMap(); |
268 |
if (layercrs != null) layercrs.toMap(); |
269 |
if (layerClass != null) |
270 |
layerClass.classToMap(); |
271 |
endToMap(); |
272 |
} |
273 |
} |
274 |
|
275 |
public String mapFileName = null; |
276 |
public String fName = null; |
277 |
public String mapName = null; |
278 |
public String mapStatus = null; |
279 |
public String mapUnits= null; |
280 |
public String mapShapePath; |
281 |
public Dimension mapSize = null; |
282 |
public CRS mapcrs= null; |
283 |
public WebMap www = null; |
284 |
public String symbolset = null; |
285 |
public String fontset = null; |
286 |
public RGB imageColor = null; |
287 |
|
288 |
public ArrayList layers = new ArrayList(); |
289 |
|
290 |
public DoMap() {
|
291 |
} |
292 |
|
293 |
public void generate() { |
294 |
generate(null);
|
295 |
} |
296 |
|
297 |
public void generate(String donde) { |
298 |
openMapFile(donde); |
299 |
toMapln("MAP");
|
300 |
tabIn(); |
301 |
toMapln("NAME "+mapName);
|
302 |
if (mapSize != null) |
303 |
toMapln("SIZE "+mapSize.width+" "+mapSize.height); |
304 |
toMapln("EXTENT "+extentToMapString(extent));
|
305 |
toMapln("STATUS "+mapStatus);
|
306 |
toMapln("UNITS "+mapUnits);
|
307 |
toMapln("SHAPEPATH \""+mapShapePath+"\""); |
308 |
if (symbolset != null) |
309 |
toMapln("SYMBOLSET "+symbolset);
|
310 |
if (symbolset != null) |
311 |
toMapln("FONTSET "+symbolset);
|
312 |
if (imageColor != null) |
313 |
toMapln("IMAGECOLOR \""+imageColor);
|
314 |
www.webToMap(); |
315 |
if (mapcrs != null) |
316 |
projectionToMap(mapcrs,true);
|
317 |
Iterator iter = layers.iterator();
|
318 |
while(iter.hasNext()) {
|
319 |
MapLayer l = (MapLayer) iter.next(); |
320 |
l.layerToMap(); |
321 |
} |
322 |
tabOut(); |
323 |
toMapln("END # Map File");
|
324 |
closeMapFile(); |
325 |
} |
326 |
|
327 |
void openMapFile(String donde) { |
328 |
setMapFileName(donde); |
329 |
if (mapFileName == null) |
330 |
return;
|
331 |
File wmsmap = new File( mapFileName ); |
332 |
try{
|
333 |
//salida = new PrintStream(new BufferedOutputStream(new FileOutputStream(wmsmap)));
|
334 |
salida = new PrintStream(new FileOutputStream(wmsmap)); |
335 |
} catch(FileNotFoundException e){ |
336 |
System.out.println("Fichero no encontrado."); |
337 |
} |
338 |
System.out.println(mapFileName+" abierto."); |
339 |
|
340 |
} |
341 |
|
342 |
void closeMapFile() {
|
343 |
if (salida != null) |
344 |
salida.close(); |
345 |
} |
346 |
|
347 |
public String getMapFileName() { |
348 |
return mapFileName;
|
349 |
} |
350 |
|
351 |
public void setMapFileName(String mapFileName) { |
352 |
this.mapFileName = mapFileName;
|
353 |
} |
354 |
} |