svn-gvsig-desktop / trunk / extensions / extPublish / src / org / gvsig / remoteservices / conf / mapserver / MapServerConfiguration.java @ 10626
History | View | Annotate | Download (28.6 KB)
1 |
package org.gvsig.remoteservices.conf.mapserver; |
---|---|
2 |
|
3 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
4 |
*
|
5 |
* Copyright (C) 2004-2006 IVER T.I. and Generalitat Valenciana.
|
6 |
*
|
7 |
* This program is free software; you can redistribute it and/or
|
8 |
* modify it under the terms of the GNU General Public License
|
9 |
* as published by the Free Software Foundation; either version 2
|
10 |
* of the License, or (at your option) any later version.
|
11 |
*
|
12 |
* This program is distributed in the hope that it will be useful,
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
* GNU General Public License for more details.
|
16 |
*
|
17 |
* You should have received a copy of the GNU General Public License
|
18 |
* along with this program; if not, write to the Free Software
|
19 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
*
|
21 |
* For more information, contact:
|
22 |
*
|
23 |
* Generalitat Valenciana
|
24 |
* Conselleria d'Infraestructures i Transport
|
25 |
* Av. Blasco Ib??ez, 50
|
26 |
* 46010 VALENCIA
|
27 |
* SPAIN
|
28 |
*
|
29 |
* +34 963862235
|
30 |
* gvsig@gva.es
|
31 |
* www.gvsig.gva.es
|
32 |
*
|
33 |
* or
|
34 |
*
|
35 |
* IVER T.I. S.A
|
36 |
* Salamanca 50
|
37 |
* 46005 Valencia
|
38 |
* Spain
|
39 |
*
|
40 |
* +34 963163400
|
41 |
* dac@iver.es
|
42 |
*/
|
43 |
/* CVS MESSAGES:
|
44 |
*
|
45 |
* $Id$
|
46 |
* $Log$
|
47 |
* Revision 1.11 2007-03-06 16:50:30 caballero
|
48 |
* Exceptions
|
49 |
*
|
50 |
* Revision 1.10 2006/11/28 17:58:07 jvhigon
|
51 |
* problemas con publicacion en WCS.
|
52 |
*
|
53 |
* Revision 1.9 2006/11/22 14:15:35 dagilgon
|
54 |
* *** empty log message ***
|
55 |
*
|
56 |
* Revision 1.8 2006/11/22 12:48:21 jorpiell
|
57 |
* Subidos algunos cambios para ver las capas en forma de ?rbol
|
58 |
*
|
59 |
* Revision 1.7 2006/11/17 13:40:18 jorpiell
|
60 |
* A?adido el nuevo panel donde se muestran las capas
|
61 |
*
|
62 |
* Revision 1.6 2006/11/17 13:33:59 dagilgon
|
63 |
* *** empty log message ***
|
64 |
*
|
65 |
* Revision 1.5 2006/11/13 08:25:04 dagilgon
|
66 |
* a?adidas "etiquetas" CLASS (completada) y JOIN
|
67 |
*
|
68 |
* Revision 1.4 2006/10/18 07:56:56 dagilgon
|
69 |
* a?adidos los outputformats
|
70 |
*
|
71 |
* Revision 1.3 2006/10/17 11:51:09 dagilgon
|
72 |
* outputformats
|
73 |
*
|
74 |
* Revision 1.2 2006/10/16 11:40:36 dagilgon
|
75 |
* arreglado path de mapserver
|
76 |
*
|
77 |
* Revision 1.1 2006/10/05 13:22:23 jvhigon
|
78 |
* Debido al refactor del nobre en la libreria de maapserver y geoserver. Mapserver --> MapserverConfig
|
79 |
*
|
80 |
* Revision 1.25 2006/09/19 07:34:00 dagilgon
|
81 |
* Corregida salida duplicada del campo crs en matadataweb
|
82 |
*
|
83 |
* Revision 1.24 2006/09/19 00:30:31 luisw2
|
84 |
* Soporte para WCS en mapserver. Pendiente de verificar que va
|
85 |
*
|
86 |
* Revision 1.23 2006/09/18 08:41:22 dagilgon
|
87 |
* A?adida clase leyend y label
|
88 |
*
|
89 |
* Revision 1.22 2006/09/14 12:06:16 jorpiell
|
90 |
* A?adido el constructor con dos colores para el stylemap
|
91 |
*
|
92 |
* Revision 1.21 2006/09/13 12:08:31 luisw2
|
93 |
* Adding WCS to mapserver ...
|
94 |
*
|
95 |
* Revision 1.19 2006/09/08 18:03:18 jorpiell
|
96 |
* El EPSG se escribe en min?sculas y los times se escriben en orden
|
97 |
*
|
98 |
* Revision 1.18 2006/09/08 17:58:01 jorpiell
|
99 |
* El EPSG se escribe en min?sculas y los times se escriben en orden
|
100 |
*
|
101 |
* Revision 1.17 2006/09/08 12:50:20 jorpiell
|
102 |
* Se tiene en cuanta el par?metro TIME
|
103 |
*
|
104 |
* Revision 1.16 2006/09/08 10:50:05 jorpiell
|
105 |
* A?adida la opci?n de generar una capa POSTGIS
|
106 |
*
|
107 |
* Revision 1.15 2006/09/08 10:14:04 luisw2
|
108 |
* IRSLayer Added
|
109 |
*
|
110 |
* Revision 1.14 2006/09/08 07:12:03 luisw2
|
111 |
* Minor corrections for raster; abstract added
|
112 |
*
|
113 |
* Revision 1.13 2006/09/07 19:25:01 luisw2
|
114 |
* Correcciones en metadata
|
115 |
*
|
116 |
* Revision 1.12 2006/09/07 19:20:51 jorpiell
|
117 |
* Classpath modificado
|
118 |
*
|
119 |
* Revision 1.11 2006/09/07 19:16:30 jorpiell
|
120 |
* *** empty log message ***
|
121 |
*
|
122 |
* Revision 1.10 2006/09/07 18:11:06 luisw2
|
123 |
* Adding Time to mapserver ...
|
124 |
*
|
125 |
* Revision 1.9 2006/09/07 16:34:28 luisw2
|
126 |
* A?adido size
|
127 |
*
|
128 |
* Revision 1.8 2006/09/07 16:10:45 luisw2
|
129 |
* a?adido flush() en el close;
|
130 |
*
|
131 |
* Revision 1.7 2006/09/07 12:59:44 jorpiell
|
132 |
* Enganchada la interfaz gr?fica con el generador de ficheros
|
133 |
*
|
134 |
* Revision 1.6 2006/09/07 12:51:54 jorpiell
|
135 |
* Enganchada la interfaz gr?fica con el generador de ficheros
|
136 |
*
|
137 |
* Revision 1.5 2006/09/07 12:47:39 jorpiell
|
138 |
* A?adida la expression en el classMap
|
139 |
*
|
140 |
* Revision 1.4 2006/09/07 11:19:40 jvhigon
|
141 |
* A?adido soporte para multiples class en una layer, y para layer sdentro de layer
|
142 |
*
|
143 |
* Revision 1.3 2006/09/01 06:59:00 luisw2
|
144 |
* Headers mofification
|
145 |
*
|
146 |
*/
|
147 |
import java.awt.Color; |
148 |
import java.awt.Dimension; |
149 |
import java.awt.Point; |
150 |
import java.awt.geom.Rectangle2D; |
151 |
import java.io.File; |
152 |
import java.io.FileNotFoundException; |
153 |
import java.io.FileOutputStream; |
154 |
import java.io.PrintStream; |
155 |
import java.util.ArrayList; |
156 |
import java.util.Iterator; |
157 |
|
158 |
import org.gvsig.remoteservices.conf.IRSLayer; |
159 |
|
160 |
/**
|
161 |
* Allows to write a .map Mapserver configuration file.
|
162 |
*
|
163 |
* @author David Gilsanz
|
164 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
165 |
*/
|
166 |
|
167 |
/* MAP
|
168 |
NAME test_postgis
|
169 |
STATUS ON
|
170 |
SIZE 400 300
|
171 |
#SYMBOLSET ../etc/symbols.sym
|
172 |
EXTENT 638610.4375 4222780 789330 4484662.5
|
173 |
UNITS METERS
|
174 |
SHAPEPATH "/home/shapes/"
|
175 |
IMAGECOLOR 255 255 255
|
176 |
#FONTSET ../etc/fonts.txt
|
177 |
|
178 |
WEB
|
179 |
# IMAGEPATH "/ms4w/tmp/ms_tmp/"
|
180 |
# IMAGEURL "/ms_tmp/"
|
181 |
METADATA
|
182 |
"wms_title" "test postgis" ##required
|
183 |
"wms_onlineresource" "http://localhost/mapserver/mapserv" ##required
|
184 |
"wms_srs" "EPSG:42304 EPSG:42101 EPSG:4269 EPSG:4326 EPSG:23030" ##recommended
|
185 |
END
|
186 |
END
|
187 |
|
188 |
PROJECTION
|
189 |
"init=epsg:23030" ##required
|
190 |
END
|
191 |
|
192 |
#
|
193 |
# Start of layer definitions
|
194 |
#
|
195 |
|
196 |
LAYER
|
197 |
NAME "autopistas"
|
198 |
DATA "the_geom from autopistas"
|
199 |
CONNECTIONTYPE POSTGIS
|
200 |
CONNECTION "user=david password=pwd dbname=betel host=localhost port=5434"
|
201 |
STATUS ON
|
202 |
TYPE LINE
|
203 |
METADATA
|
204 |
"wms_title" "Autopistas GV" ##required
|
205 |
"wms_extent" "638610.4375 4222780 789330 4484662.5"
|
206 |
END
|
207 |
PROJECTION
|
208 |
"init=epsg:23030" ##recommended
|
209 |
END
|
210 |
CLASS
|
211 |
NAME "Autopistas"
|
212 |
STYLE
|
213 |
COLOR 200 255 0
|
214 |
OUTLINECOLOR 120 120 120
|
215 |
END
|
216 |
END
|
217 |
END
|
218 |
|
219 |
END # Map File
|
220 |
*/
|
221 |
public abstract class MapServerConfiguration { |
222 |
public static final String SHP_TYPE_LINE = "LINE"; |
223 |
public static final String SHP_TYPE_POLYLINE = "POLYLINE"; |
224 |
public static final String SHP_TYPE_POINT = "POINT"; |
225 |
public static final String SHP_TYPE_POLYGON = "POLYGON"; |
226 |
|
227 |
public static class RGB { |
228 |
int r,g,b;
|
229 |
public RGB(int red,int green,int blue){ |
230 |
r=red; |
231 |
g=green; |
232 |
b=blue; |
233 |
} |
234 |
public String toString(){ |
235 |
return ""+r+" "+g+" "+b; |
236 |
} |
237 |
} |
238 |
|
239 |
public static class CRS extends MapServerConfiguration { |
240 |
boolean init = false; |
241 |
String crs = ""; |
242 |
public CRS(String crs, boolean init) { |
243 |
this.crs = crs;
|
244 |
this.init =init;
|
245 |
} |
246 |
|
247 |
public String toString() { |
248 |
String str = ""; |
249 |
if (init){
|
250 |
str += "init=";
|
251 |
return str+crs.toLowerCase();
|
252 |
} |
253 |
return crs; //LWS .toLowerCase(); |
254 |
} |
255 |
|
256 |
public void toMap() { |
257 |
toMapln("PROJECTION");
|
258 |
tabIn(); |
259 |
toMapln("\""+this+"\""); |
260 |
tabOut(); |
261 |
toMapln("END");
|
262 |
} |
263 |
|
264 |
public void setCrs(String crs){ |
265 |
this.crs = crs;
|
266 |
} |
267 |
|
268 |
/**
|
269 |
* @return Returns the crs.
|
270 |
*/
|
271 |
public String getCrs() { |
272 |
return crs;
|
273 |
} |
274 |
} |
275 |
|
276 |
public static class OutputFormat extends MapServerConfiguration { |
277 |
/*
|
278 |
OUTPUTFORMAT
|
279 |
NAME GEOTIFF_INT16
|
280 |
DRIVER "GDAL/GTiff"
|
281 |
IMAGEMODE INT16
|
282 |
EXTENSION "tif"
|
283 |
END
|
284 |
*/
|
285 |
public String name = null; |
286 |
public String driver = null; |
287 |
public String imageMode = null; |
288 |
public String extension = null; |
289 |
|
290 |
/**
|
291 |
* Creates a new OutputFormat.
|
292 |
* @param name
|
293 |
* @param driver
|
294 |
* @param imageMode
|
295 |
* @param extension
|
296 |
*/
|
297 |
public OutputFormat(String name, String driver, String imageMode, String extension) { |
298 |
this.name = name;
|
299 |
this.driver = driver;
|
300 |
this.imageMode = imageMode;
|
301 |
this.extension = extension;
|
302 |
} |
303 |
|
304 |
public void toMap() { |
305 |
toMapln("OUTPUTFORMAT");
|
306 |
tabIn(); |
307 |
toMapln("NAME "+name+""); |
308 |
toMapln("DRIVER \""+driver+"\""); |
309 |
toMapln("IMAGEMODE "+imageMode+""); |
310 |
toMapln("EXTENSION \""+extension+"\""); |
311 |
tabOut(); |
312 |
toMapln("END");
|
313 |
} |
314 |
} |
315 |
public static class Label extends MapServerConfiguration{ |
316 |
|
317 |
public String angle = null; |
318 |
public String antialias = null; |
319 |
public RGB backgroundcolor = null; |
320 |
public RGB backgroundshadowcolor = null; |
321 |
public Point backgroundshadowsize = null; |
322 |
public String buffer = null; |
323 |
public RGB color = null; |
324 |
public String encoding = null; |
325 |
public String force = null; |
326 |
public String maxsize = null; |
327 |
public String mindistance = null; |
328 |
public String minfeaturesize = null; |
329 |
public String minsize = null; |
330 |
public Point offset = null; |
331 |
public RGB outlinecolor = null; |
332 |
public String partials = null; |
333 |
public String position = null; |
334 |
public RGB shadowcolor = null; |
335 |
public Point shadowsize = null; |
336 |
public String size = null; |
337 |
public String type = null; |
338 |
public String wrap = null; |
339 |
|
340 |
public void tomap(){ |
341 |
toMapln("LABEL");
|
342 |
tabIn(); |
343 |
if(angle != null) |
344 |
toMapln("ANGLE "+angle.toUpperCase()+""); |
345 |
if(antialias != null) |
346 |
toMapln("ANTIALIAS \""+antialias+"\""); |
347 |
if(backgroundcolor != null) |
348 |
toMapln("BACKGROUNDCOLOR "+backgroundcolor.toString()+""); |
349 |
if(backgroundshadowcolor != null) |
350 |
toMapln("BACKGROUNDSHADOWCOLOR "+backgroundshadowcolor.toString()+""); |
351 |
if(backgroundshadowsize != null) |
352 |
toMapln("BACKGROUNDSHADOWSIZE "+backgroundshadowsize.toString()+""); |
353 |
if(buffer != null) |
354 |
toMapln("BUFFER \""+buffer+"\""); |
355 |
if(color != null) |
356 |
toMapln("COLOR "+color.toString()+""); |
357 |
if(encoding != null) |
358 |
toMapln("ENCODING \""+encoding+"\""); |
359 |
if(force != null) |
360 |
toMapln("FORCE \""+force+"\""); |
361 |
if(maxsize != null) |
362 |
toMapln("MAXSIZE "+maxsize+""); |
363 |
if(mindistance != null) |
364 |
toMapln("MINDISTANCE "+mindistance+""); |
365 |
if(minfeaturesize != null) |
366 |
toMapln("MINFEATURESIZE "+minfeaturesize+"" +""); |
367 |
if(minsize != null) |
368 |
toMapln("MINSIZE "+minsize+""); |
369 |
if(offset != null) |
370 |
toMapln("OFFSET "+offset.toString()+""); |
371 |
if(outlinecolor != null) |
372 |
toMapln("OUTLINECOLOR "+outlinecolor.toString()+""); |
373 |
if(partials != null) |
374 |
toMapln("PARTIALS \""+partials+"\""); |
375 |
if(position != null) |
376 |
toMapln("POSITION \""+position+"\""); |
377 |
if(shadowcolor!= null) |
378 |
toMapln("SHADOWCOLOR "+shadowcolor.toString()+""); |
379 |
if(shadowsize != null) |
380 |
toMapln("SHADOWSIZE "+shadowsize.toString()+""); |
381 |
if(size != null) |
382 |
toMapln("SIZE \""+size.toUpperCase()+"\""); |
383 |
if(type != null) |
384 |
toMapln("TYPE \""+type+"\""); |
385 |
if(wrap != null) |
386 |
toMapln("WRAP \""+wrap+"\""); |
387 |
tabOut(); |
388 |
toMapln("END");
|
389 |
} |
390 |
} |
391 |
|
392 |
public static class Legend extends MapServerConfiguration{ |
393 |
public RGB imagecolor = null; |
394 |
public RGB outlinecolor = null; |
395 |
public String interlace = null; |
396 |
public Label legendlabel = null; |
397 |
public String position = null; |
398 |
public Point keysize = null; |
399 |
public Point keyspacing = null; |
400 |
public String postlabelcache = null; |
401 |
public String status = null; |
402 |
public String template = null; |
403 |
public String transparent = null; |
404 |
|
405 |
public void toMap(){ |
406 |
toMapln("LEGEND");
|
407 |
tabIn(); |
408 |
if(imagecolor != null) |
409 |
toMapln("IMAGECOLOR "+imagecolor.toString());
|
410 |
if(outlinecolor != null) |
411 |
toMapln("OUTLINECOLOR "+outlinecolor.toString());
|
412 |
if(interlace != null){ |
413 |
toMapln("INTERLACE \""+interlace.toUpperCase()+"\""); |
414 |
} |
415 |
if(legendlabel != null){ |
416 |
legendlabel.tomap(); |
417 |
} |
418 |
if(position != null) |
419 |
toMapln("POSITION \""+position+"\""); |
420 |
if(keysize != null) |
421 |
toMapln("KEYSIZE "+keysize.toString());
|
422 |
if(keyspacing != null) |
423 |
toMapln("KEYSPACING "+keyspacing.toString());
|
424 |
if(postlabelcache != null) |
425 |
toMapln("POSTLABELCACHE \""+postlabelcache+"\""); |
426 |
if(status != null) |
427 |
toMapln("STATUS \""+status.toUpperCase()+"\""); |
428 |
if(template!=null){ |
429 |
toMapln("TEMPLATE \""+template+"\""); |
430 |
} |
431 |
if(transparent != null){ |
432 |
toMapln("TRANSPARENT \""+transparent.toUpperCase()+"\""); |
433 |
} |
434 |
tabOut(); |
435 |
toMapln("END");
|
436 |
} |
437 |
} |
438 |
|
439 |
public static class Metadata extends MapServerConfiguration { |
440 |
public String prefix = "wms"; |
441 |
public String title = null; |
442 |
public String abstrac = null; |
443 |
public String label = null; |
444 |
public String name = null; |
445 |
|
446 |
public void setServiceAsWFS() { |
447 |
prefix = "wfs";
|
448 |
} |
449 |
|
450 |
public void setServiceAsWMS() { |
451 |
prefix = "wms";
|
452 |
} |
453 |
public void setServiceAsWCS() { |
454 |
prefix = "wcs";
|
455 |
} |
456 |
//
|
457 |
void startMetadataToMap(){
|
458 |
toMapln("METADATA");
|
459 |
tabIn(); |
460 |
if (name != null) |
461 |
toMapln("\""+prefix+"_name\" \""+name+"\""); |
462 |
if (label != null) |
463 |
toMapln("\""+prefix+"_label\" \""+label+"\""); |
464 |
if (title != null) |
465 |
toMapln("\""+prefix+"_title\" " +"\""+title+"\""); |
466 |
if (abstrac != null) |
467 |
toMapln("\""+prefix+"_abstract\" " +"\""+abstrac+"\""); |
468 |
if (crs != null) |
469 |
toMapln("\""+prefix+"_srs\" \""+crs+"\""); |
470 |
if (extent != null) |
471 |
toMapln("\""+prefix+"_extent\" \""+extentToMapString()+"\""); |
472 |
} |
473 |
|
474 |
void endMetadataToMap() {
|
475 |
tabOut(); |
476 |
toMapln("END");
|
477 |
} |
478 |
} |
479 |
|
480 |
public static class MetadataWeb extends Metadata { |
481 |
//Atributos wms_xxxx WEB
|
482 |
public String onlineresource = null; |
483 |
public String ows_schemas_location = null; |
484 |
public String timeFormat = null; |
485 |
public String keywordlist = null; |
486 |
public String description = null; |
487 |
|
488 |
void metadataToMap(){
|
489 |
startMetadataToMap(); |
490 |
if (keywordlist != null) |
491 |
toMapln("\""+prefix+"_keywordlist\" \""+keywordlist+"\""); |
492 |
toMapln("\""+prefix+"_onlineresource\" \""+onlineresource+"\""); |
493 |
//if (crs != null)
|
494 |
// toMapln("\""+prefix+"_srs\" \""+crs+"\"");
|
495 |
if (ows_schemas_location != null) |
496 |
toMapln("\"ows_schemas_location\" \""+ows_schemas_location+"\""); |
497 |
if (timeFormat != null) |
498 |
toMapln("\""+prefix+"_timeformat\" \""+timeFormat+"\""); |
499 |
if (description != null) |
500 |
toMapln("\""+prefix+"_description\" \""+description+"\""); |
501 |
endMetadataToMap(); |
502 |
} |
503 |
} |
504 |
|
505 |
public static class MetadataLayer extends Metadata { |
506 |
//Atributos wms_xxxx LAYER
|
507 |
public String gml_include_items = null; |
508 |
public String timeExtent = null; |
509 |
public String timeDefault = null; |
510 |
public String timeItem = null; |
511 |
// WCS
|
512 |
public String description = null; |
513 |
public String resolution = null; |
514 |
public String formats = null; |
515 |
public String bandCount = null; |
516 |
public String nativeFormat = null; |
517 |
public String rangesetAxes = null; |
518 |
public String rangesetLabels = null; |
519 |
public String rangesetName = null; |
520 |
|
521 |
public void setRangeset(String str) { |
522 |
rangesetAxes = rangesetLabels = rangesetName = str; |
523 |
} |
524 |
|
525 |
void metadataToMap(){
|
526 |
startMetadataToMap(); |
527 |
if (gml_include_items != null) |
528 |
toMapln("\"gml_include_items\" \""+gml_include_items+"\""); |
529 |
// WMS with TIME
|
530 |
if (timeExtent != null) |
531 |
toMapln("\""+prefix+"_timeextent\" \""+timeExtent+"\""); |
532 |
if (timeDefault != null) |
533 |
toMapln("\""+prefix+"_timedefault\" \""+timeDefault+"\""); |
534 |
if (timeItem != null) |
535 |
toMapln("\""+prefix+"_timeitem\" \""+timeItem+"\""); |
536 |
// WCS
|
537 |
if (description != null) |
538 |
toMapln("\""+prefix+"_description\" \""+description+"\""); |
539 |
if (resolution != null) |
540 |
toMapln("\""+prefix+"_resolution\" \""+resolution+"\""); |
541 |
if (formats != null) |
542 |
toMapln("\""+prefix+"_formats\" \""+formats+"\""); |
543 |
if (bandCount != null) |
544 |
toMapln("\""+prefix+"_bandcount\" \""+bandCount+"\""); |
545 |
if (nativeFormat != null) |
546 |
toMapln("\""+prefix+"_nativeformat\" \""+nativeFormat+"\""); |
547 |
if (rangesetAxes != null) |
548 |
toMapln("\""+prefix+"_rangeset_axes\" \""+rangesetAxes+"\""); |
549 |
if (rangesetLabels != null) |
550 |
toMapln("\""+prefix+"_rangeset_labels\" \""+rangesetLabels+"\""); |
551 |
if (rangesetName != null) |
552 |
toMapln("\""+prefix+"_rangeset_name\" \""+rangesetName+"\""); |
553 |
|
554 |
endMetadataToMap(); |
555 |
} |
556 |
} |
557 |
|
558 |
public static class StyleMap extends MapServerConfiguration { |
559 |
public RGB styleColor = null; |
560 |
public RGB styleColorOutline = null; |
561 |
public int size = -1; |
562 |
public StyleMap(RGB line, RGB fill) {
|
563 |
styleColor = fill; |
564 |
styleColorOutline = line; |
565 |
} |
566 |
public StyleMap(Color color, Color outLineColor) { |
567 |
RGB rgbStyleColor = null;
|
568 |
RGB rgbStyleColorOutline = null;
|
569 |
try{
|
570 |
rgbStyleColor = (new RGB(color.getRed(),
|
571 |
color.getGreen(), |
572 |
color.getBlue())); |
573 |
}catch(NullPointerException e){ |
574 |
//Line color is empty
|
575 |
} |
576 |
try{
|
577 |
rgbStyleColorOutline = (new RGB(outLineColor.getRed(),
|
578 |
outLineColor.getGreen(), |
579 |
outLineColor.getBlue())); |
580 |
}catch(NullPointerException e){ |
581 |
//Fill color is empty
|
582 |
} |
583 |
styleColor = rgbStyleColor; |
584 |
styleColorOutline = rgbStyleColorOutline; |
585 |
} |
586 |
void styleToMap(){
|
587 |
toMapln("STYLE ");
|
588 |
tabIn(); |
589 |
if (styleColor != null){ |
590 |
toMapln("COLOR "+styleColor);
|
591 |
} |
592 |
if (styleColorOutline != null){ |
593 |
toMapln("OUTLINECOLOR "+styleColorOutline);
|
594 |
} |
595 |
if (size > -1) |
596 |
toMapln("SIZE "+size);
|
597 |
tabOut(); |
598 |
toMapln("END");
|
599 |
} |
600 |
} |
601 |
|
602 |
public static class WebMap extends MapServerConfiguration{ |
603 |
public MetadataWeb metadata = null; |
604 |
public String imagepath = null; |
605 |
public String imageurl = null; |
606 |
public String log = null; |
607 |
|
608 |
void webToMap(){
|
609 |
toMapln("WEB");
|
610 |
tabIn(); |
611 |
if (log != null) |
612 |
toMapln("LOG \""+log+"\""); |
613 |
toMapln("IMAGEPATH \""+imagepath+"\""); |
614 |
toMapln("IMAGEURL \""+imageurl+"\""); |
615 |
metadata.metadataToMap(); |
616 |
tabOut(); |
617 |
toMapln("END");
|
618 |
} |
619 |
} |
620 |
public static class JoinMap extends MapServerConfiguration{ |
621 |
|
622 |
public String connection=null; |
623 |
public String connectiontype=null; |
624 |
public String from=null; |
625 |
public String name=null; |
626 |
public String table=null; |
627 |
public String template=null; |
628 |
public String to=null; |
629 |
public String type=null; |
630 |
|
631 |
void tomap(){
|
632 |
toMapln("JOIN");
|
633 |
tabIn(); |
634 |
if (connection != null) |
635 |
toMapln("CONNECTION \"" + connection+"\""); |
636 |
if (connectiontype != null) |
637 |
toMapln("CONNECTIONTYPE \"" + connectiontype+"\""); |
638 |
if (from != null) |
639 |
toMapln("FROM \"" + from+"\""); |
640 |
if (name != null) |
641 |
toMapln("NAME \"" + name+"\""); |
642 |
if (table != null) |
643 |
toMapln("TABLE \"" + table+"\""); |
644 |
if (to != null) |
645 |
toMapln("TO \"" + to+"\""); |
646 |
if (type != null) |
647 |
toMapln("TYPE \"" + type+"\""); |
648 |
tabOut(); |
649 |
toMapln("END");
|
650 |
|
651 |
} |
652 |
} |
653 |
|
654 |
public static class MapClass extends MapServerConfiguration { |
655 |
public RGB backgroundcolor=null; |
656 |
public RGB color=null; |
657 |
public String debug=null; |
658 |
public String expression=null; |
659 |
public JoinMap join=null; |
660 |
public String keyimage=null; |
661 |
public Label etiqueta = null; |
662 |
public String maxscale =null; |
663 |
public String maxsize=null; |
664 |
public String minscale=null; |
665 |
public String minsize=null; |
666 |
public String name; |
667 |
public RGB outlinecolor=null; |
668 |
public int size=-1; |
669 |
public StyleMap estilo = null; |
670 |
public String symbol=null; |
671 |
public String template = null; |
672 |
public String text=null; |
673 |
public MapClass(String n) { |
674 |
name = n; |
675 |
} |
676 |
public void classToMap(){ |
677 |
toMapln("CLASS");
|
678 |
tabIn(); |
679 |
if (backgroundcolor != null) |
680 |
toMapln("BACKGROUND \"" + backgroundcolor.toString()+"\""); |
681 |
if (color != null) |
682 |
toMapln("COLOR \"" + color.toString()+"\""); |
683 |
if (debug != null) |
684 |
toMapln("DEBUG \"" + debug+"\""); |
685 |
if (expression != null) |
686 |
toMapln("EXPRESSION " + expression+""); |
687 |
if (join != null) |
688 |
join.tomap(); |
689 |
if (keyimage != null) |
690 |
toMapln("KEYIMAGE \"" + keyimage+"\""); |
691 |
if (maxscale != null) |
692 |
toMapln("MAXSCALE \"" + maxscale+"\""); |
693 |
if (maxsize != null) |
694 |
toMapln("MAXSIZE \"" + maxsize+"\""); |
695 |
if (minscale != null) |
696 |
toMapln("MINSCALE \"" + minscale+"\""); |
697 |
if (minsize != null) |
698 |
toMapln("MINSIZE \"" + minsize+"\""); |
699 |
if (outlinecolor != null) |
700 |
toMapln("OUTLINECOLOR \"" + outlinecolor.toString()+"\""); |
701 |
if (size > -1) |
702 |
toMapln("SIZE "+size);
|
703 |
if (estilo != null) |
704 |
estilo.styleToMap(); |
705 |
if (symbol != null) |
706 |
toMapln("SYMBOL \"" + symbol+"\""); |
707 |
if (template != null) |
708 |
toMapln("TEMPLATE \"" + template+"\""); |
709 |
if (text != null) |
710 |
toMapln("TEXT \"" + text+"\""); |
711 |
|
712 |
toMapln("NAME \""+name+"\""); |
713 |
if (template != null) |
714 |
toMapln("TEMPLATE \""+template+"\""); |
715 |
if (etiqueta != null) |
716 |
etiqueta.tomap(); |
717 |
tabOut(); |
718 |
toMapln("END");
|
719 |
} |
720 |
} |
721 |
|
722 |
public abstract static class MapLayer extends MapServerConfiguration |
723 |
implements IRSLayer {
|
724 |
public String name = null; |
725 |
public String title=null; |
726 |
public String status = "ON"; |
727 |
public String type = null; |
728 |
public int transparency = -1; |
729 |
public ArrayList classList = null; |
730 |
public ArrayList layerList = null; |
731 |
public String data = null; |
732 |
public MetadataLayer metadata = null; |
733 |
public boolean dump = false; |
734 |
public CRS layercrs=null; |
735 |
public String tileIndex = null; |
736 |
public String tileItem = null; |
737 |
|
738 |
|
739 |
public MapLayer() {
|
740 |
super();
|
741 |
metadata=new MetadataLayer();
|
742 |
} |
743 |
|
744 |
public void setDump(boolean d) { |
745 |
dump = d; |
746 |
} |
747 |
|
748 |
void startToMap() {
|
749 |
toMapln("LAYER");
|
750 |
tabIn(); |
751 |
toMapln("NAME \""+name+"\""); |
752 |
if (title != null) |
753 |
// toMapln("TITLE \""+title+"\"");
|
754 |
toMapln("STATUS "+status);
|
755 |
if (transparency > -1) |
756 |
toMapln("TRANSPARENCY " + transparency);
|
757 |
if (tileIndex != null) |
758 |
toMapln("TILEINDEX \""+tileIndex+"\""); |
759 |
if (tileItem != null) |
760 |
toMapln("TILEITEM \""+tileItem+"\""); |
761 |
if (type != null) |
762 |
toMapln("TYPE "+type);
|
763 |
if (dump)
|
764 |
toMapln("DUMP TRUE # required");
|
765 |
if (data != null) |
766 |
toMapln("DATA \""+data+"\""); |
767 |
} |
768 |
|
769 |
void endToMap() {
|
770 |
tabOut(); |
771 |
toMapln("END # Layer");
|
772 |
} |
773 |
|
774 |
public void addClass(MapClass c) { |
775 |
if (classList == null) |
776 |
classList = new ArrayList(); |
777 |
classList.add(c); |
778 |
} |
779 |
|
780 |
public void classListToMap() { |
781 |
if (classList != null) { |
782 |
Iterator iter = classList.iterator();
|
783 |
while (iter.hasNext()) {
|
784 |
MapClass c = (MapClass) iter.next(); |
785 |
c.classToMap(); |
786 |
} |
787 |
} |
788 |
|
789 |
} |
790 |
|
791 |
public void addLayer(MapLayer c) { |
792 |
if (layerList == null) |
793 |
layerList = new ArrayList(); |
794 |
layerList.add(c); |
795 |
} |
796 |
|
797 |
public void layerListToMap() { |
798 |
if (layerList != null) { |
799 |
Iterator iter = layerList.iterator();
|
800 |
tabIn(); |
801 |
while (iter.hasNext()) {
|
802 |
MapLayer l = (MapLayer) iter.next(); |
803 |
l.layerToMap(); |
804 |
} |
805 |
tabOut(); |
806 |
} |
807 |
} |
808 |
|
809 |
public abstract void layerToMap(); |
810 |
|
811 |
public String getName() { |
812 |
return name;
|
813 |
} |
814 |
|
815 |
public void setName(String name) { |
816 |
this.name = name;
|
817 |
metadata.name = name; |
818 |
setTitle(name); |
819 |
} |
820 |
|
821 |
public String getTitle() { |
822 |
return title;
|
823 |
} |
824 |
|
825 |
public void setTitle(String title) { |
826 |
this.title = title;
|
827 |
metadata.title = title; |
828 |
} |
829 |
|
830 |
public void setExtent(double minx, double miny, double maxx, double maxy) { |
831 |
super.setExtent(minx, miny, maxx, maxy);
|
832 |
metadata.setExtent(extent); |
833 |
} |
834 |
|
835 |
public void setExtent(Rectangle2D extent) { |
836 |
super.setExtent(extent);
|
837 |
metadata.setExtent(extent); |
838 |
} |
839 |
|
840 |
} |
841 |
|
842 |
public static class ShpLayer extends MapLayer { |
843 |
public void layerToMap() { |
844 |
startToMap(); |
845 |
metadata.metadataToMap(); |
846 |
if (layercrs != null) layercrs.toMap(); |
847 |
classListToMap(); |
848 |
endToMap(); |
849 |
} |
850 |
} |
851 |
|
852 |
public static class PostgisLayer extends MapLayer { |
853 |
public String user; |
854 |
public String pass; |
855 |
public String host; |
856 |
public String dbname; |
857 |
public String port; |
858 |
|
859 |
public String tabla; |
860 |
public String data; |
861 |
|
862 |
public void setConnParams(String user, String pass, String host, |
863 |
String dbname, String port) { |
864 |
this.user = user;
|
865 |
this.pass = pass;
|
866 |
this.host = host;
|
867 |
this.dbname = dbname;
|
868 |
this.port = port;
|
869 |
} |
870 |
|
871 |
public void layerToMap() { |
872 |
startToMap(); |
873 |
toMapln("DATA \""+data+"\""); |
874 |
toMapln("CONNECTIONTYPE POSTGIS");
|
875 |
StringBuffer connection = new StringBuffer(); |
876 |
connection.append("CONNECTION \"user="+user);
|
877 |
if (pass != null){ |
878 |
connection.append(" password="+pass);
|
879 |
} |
880 |
connection.append(" dbname="+dbname+" host="+host+" port="+port+"\""); |
881 |
toMapln(connection.toString()); |
882 |
metadata.metadataToMap(); |
883 |
if (layercrs != null) layercrs.toMap(); |
884 |
classListToMap(); |
885 |
endToMap(); |
886 |
} |
887 |
} |
888 |
|
889 |
public static class RasterLayer extends MapLayer { |
890 |
public void layerToMap() { |
891 |
startToMap(); |
892 |
metadata.metadataToMap(); |
893 |
if (layercrs != null) layercrs.toMap(); |
894 |
classListToMap(); |
895 |
endToMap(); |
896 |
} |
897 |
} |
898 |
|
899 |
public static class ConfigFile extends MapServerConfiguration { |
900 |
/**
|
901 |
* Atributos wms_xxxx comunes a WEB y LAYER.
|
902 |
* @author david
|
903 |
*/
|
904 |
|
905 |
public String mapFileName = null; |
906 |
public String fName = null; |
907 |
public String mapName = null; |
908 |
public String mapStatus = null; |
909 |
public String mapUnits= null; |
910 |
public String mapShapePath; |
911 |
public Dimension mapSize = null; |
912 |
public CRS mapcrs= null; |
913 |
public WebMap www = null; |
914 |
public String symbolset = null; |
915 |
public String fontset = null; |
916 |
public RGB imageColor = null; |
917 |
public Legend leyenda = null; |
918 |
|
919 |
private ArrayList outputFormats = new ArrayList(); |
920 |
private ArrayList layers = new ArrayList(); |
921 |
|
922 |
public ConfigFile() {
|
923 |
www = new MapServerConfiguration.WebMap();
|
924 |
www.metadata=new MapServerConfiguration.MetadataWeb();
|
925 |
} |
926 |
|
927 |
public void generate() { |
928 |
generate(null);
|
929 |
} |
930 |
|
931 |
public void generate(String donde) { |
932 |
openMapFile(donde); |
933 |
toMapln("MAP");
|
934 |
tabIn(); |
935 |
toMapln("NAME "+mapName);
|
936 |
if (mapSize != null) |
937 |
toMapln("SIZE "+mapSize.width+" "+mapSize.height); |
938 |
if (extent != null) |
939 |
toMapln("EXTENT "+extentToMapString());
|
940 |
toMapln("STATUS "+mapStatus);
|
941 |
toMapln("UNITS "+mapUnits);
|
942 |
// OUTPUTFORMATS
|
943 |
{ |
944 |
Iterator iter = outputFormats.iterator();
|
945 |
while(iter.hasNext()) {
|
946 |
OutputFormat o = (OutputFormat) iter.next(); |
947 |
o.toMap(); |
948 |
} |
949 |
} |
950 |
|
951 |
toMapln("SHAPEPATH \""+mapShapePath+"\""); |
952 |
/*
|
953 |
toMapln("OUTPUTFORMAT");
|
954 |
tabIn();
|
955 |
toMapln("NAME GEOTIFFINT16");
|
956 |
toMapln("DRIVER \"GDAL/GTiff\"");
|
957 |
toMapln("IMAGEMODE INT16");
|
958 |
toMapln("EXTENSION \"tif\"");
|
959 |
tabOut();
|
960 |
toMapln("END");
|
961 |
toMapln("OUTPUTFORMAT");
|
962 |
tabIn();
|
963 |
toMapln("NAME IMG");
|
964 |
toMapln("DRIVER \"GDAL/HFA\"");
|
965 |
toMapln("IMAGEMODE BYTE");
|
966 |
toMapln("EXTENSION \"img\"");
|
967 |
tabOut();
|
968 |
toMapln("END");
|
969 |
toMapln("OUTPUTFORMAT");
|
970 |
tabIn();
|
971 |
toMapln("NAME GEOTIFF");
|
972 |
toMapln("DRIVER \"GDAL/GTiff\"");
|
973 |
toMapln("IMAGEMODE BYTE");
|
974 |
toMapln("EXTENSION \"tif\"");
|
975 |
tabOut();
|
976 |
toMapln("END");
|
977 |
*/
|
978 |
if (symbolset != null) |
979 |
toMapln("SYMBOLSET "+symbolset);
|
980 |
if (symbolset != null) |
981 |
toMapln("FONTSET "+symbolset);
|
982 |
if (imageColor != null) |
983 |
toMapln("IMAGECOLOR \""+imageColor+"\""); |
984 |
if(leyenda!=null){ |
985 |
leyenda.toMap(); |
986 |
} |
987 |
www.webToMap(); |
988 |
if (mapcrs != null) |
989 |
projectionToMap(mapcrs,true);
|
990 |
// LAYERS
|
991 |
{ |
992 |
Iterator iter = layers.iterator();
|
993 |
while(iter.hasNext()) {
|
994 |
MapLayer l = (MapLayer) iter.next(); |
995 |
l.layerToMap(); |
996 |
} |
997 |
} |
998 |
tabOut(); |
999 |
toMapln("END # Map File");
|
1000 |
closeMapFile(); |
1001 |
} |
1002 |
|
1003 |
void openMapFile(String donde) { |
1004 |
setMapFileName(donde); |
1005 |
if (mapFileName == null) |
1006 |
return;
|
1007 |
File wmsmap = new File( mapFileName ); |
1008 |
if (wmsmap.exists());
|
1009 |
wmsmap.delete(); |
1010 |
try{
|
1011 |
//salida = new PrintStream(new BufferedOutputStream(new FileOutputStream(wmsmap)));
|
1012 |
salida = new PrintStream(new FileOutputStream(wmsmap)); |
1013 |
} catch(FileNotFoundException e){ |
1014 |
System.out.println("Fichero no encontrado."); |
1015 |
} |
1016 |
System.out.println(mapFileName+" abierto."); |
1017 |
|
1018 |
} |
1019 |
|
1020 |
void closeMapFile() {
|
1021 |
if (salida != null) { |
1022 |
salida.flush(); |
1023 |
salida.close(); |
1024 |
} |
1025 |
} |
1026 |
|
1027 |
public String getMapFileName() { |
1028 |
return mapFileName;
|
1029 |
} |
1030 |
|
1031 |
public void setMapFileName(String mapFileName) { |
1032 |
this.mapFileName = mapFileName;
|
1033 |
} |
1034 |
|
1035 |
public void add(MapLayer l) { |
1036 |
layers.add(l); |
1037 |
} |
1038 |
public int layersCnt() { |
1039 |
return layers.size();
|
1040 |
} |
1041 |
public MapLayer getLayer(int i) { |
1042 |
return (MapLayer) layers.get(i);
|
1043 |
} |
1044 |
public void add(OutputFormat of) { |
1045 |
outputFormats.add(of); |
1046 |
} |
1047 |
} |
1048 |
|
1049 |
static PrintStream salida = null; |
1050 |
static String tabstop = ""; |
1051 |
public Rectangle2D extent = null; |
1052 |
public CRS crs = null; |
1053 |
|
1054 |
/**
|
1055 |
*
|
1056 |
* @param minx
|
1057 |
* @param miny
|
1058 |
* @param maxx
|
1059 |
* @param maxy
|
1060 |
*/
|
1061 |
public void setExtent(double minx, double miny, double maxx, double maxy) { |
1062 |
extent = new Rectangle2D.Double(); |
1063 |
extent.setFrameFromDiagonal(minx, miny, maxx, maxy); |
1064 |
} |
1065 |
|
1066 |
public void setExtent(Rectangle2D extent) { |
1067 |
this.extent = extent;
|
1068 |
} |
1069 |
|
1070 |
|
1071 |
public static String extentToMapString(Rectangle2D ext) { |
1072 |
if (ext != null) |
1073 |
return ext.getMinX()+" "+ext.getMinY()+" "+ext.getMaxX()+" "+ext.getMaxY(); |
1074 |
return ""; |
1075 |
} |
1076 |
|
1077 |
public static Rectangle2D stringToExtent(String ext) { |
1078 |
String[] coordinates = ext.split(" "); |
1079 |
if (coordinates.length == 4){ |
1080 |
try{
|
1081 |
return new Rectangle2D.Double(new Double(coordinates[0]).doubleValue(), |
1082 |
new Double(coordinates[1]).doubleValue(), |
1083 |
new Double(coordinates[2]).doubleValue(), |
1084 |
new Double(coordinates[3]).doubleValue()); |
1085 |
}catch(Exception e){ |
1086 |
//
|
1087 |
} |
1088 |
} |
1089 |
return null; |
1090 |
} |
1091 |
|
1092 |
String extentToMapString() {
|
1093 |
if (extent != null) |
1094 |
return extentToMapString(extent);
|
1095 |
return ""; |
1096 |
} |
1097 |
|
1098 |
void projectionToMap(CRS prj, boolean init) { |
1099 |
if (prj == null) |
1100 |
return;
|
1101 |
toMapln("PROJECTION");
|
1102 |
if (init == true) |
1103 |
prj.toString(); |
1104 |
tabIn(); |
1105 |
toMapln("\""+prj+"\""); |
1106 |
tabOut(); |
1107 |
toMapln("END");
|
1108 |
} |
1109 |
|
1110 |
public String replicate(String str, int n) { |
1111 |
int i;
|
1112 |
String ret = ""; |
1113 |
for(i=0;i<n;i++){ |
1114 |
ret += str; |
1115 |
} |
1116 |
return ret;
|
1117 |
} |
1118 |
|
1119 |
public void tabIn() { |
1120 |
tabstop += " ";
|
1121 |
} |
1122 |
|
1123 |
public void tabOut() { |
1124 |
tabstop = tabstop.substring(0,tabstop.length()-3); |
1125 |
} |
1126 |
|
1127 |
void toMapln(String str){ |
1128 |
if (salida == null) |
1129 |
System.out.println(tabstop+str);
|
1130 |
else
|
1131 |
salida.println(tabstop+str); |
1132 |
} |
1133 |
} |