Revision 6948
trunk/extensions/extPublish/src/org/gvsig/remoteservices/conf/mapserver/DoMap.java | ||
---|---|---|
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 |
} |
trunk/extensions/extPublish/src/org/gvsig/remoteservices/conf/mapserver/ToMap.java | ||
---|---|---|
1 |
package org.gvsig.remoteservices.conf.mapserver; |
|
2 |
import java.awt.Rectangle; |
|
3 |
import java.io.PrintStream; |
|
4 |
|
|
5 |
public abstract class ToMap { |
|
6 |
public static class RGB { |
|
7 |
int r,g,b; |
|
8 |
public RGB(int red,int green,int blue){ |
|
9 |
r=red; |
|
10 |
g=green; |
|
11 |
b=blue; |
|
12 |
} |
|
13 |
public String toString(){ |
|
14 |
return ""+r+" "+g+" "+b; |
|
15 |
} |
|
16 |
} |
|
17 |
|
|
18 |
public static class CRS extends ToMap { |
|
19 |
boolean init = false; |
|
20 |
String crs = ""; |
|
21 |
public CRS(String crs, boolean init) { |
|
22 |
this.crs = crs; |
|
23 |
this.init =init; |
|
24 |
} |
|
25 |
|
|
26 |
public String toString() { |
|
27 |
String str = ""; |
|
28 |
if (init) |
|
29 |
str += "init="; |
|
30 |
return str+crs.toLowerCase(); |
|
31 |
} |
|
32 |
|
|
33 |
public void toMap() { |
|
34 |
toMapln("PROJECTION"); |
|
35 |
tabIn(); |
|
36 |
toMapln("\""+this+"\""); |
|
37 |
tabOut(); |
|
38 |
toMapln("END"); |
|
39 |
} |
|
40 |
} |
|
41 |
|
|
42 |
static PrintStream salida = null; |
|
43 |
static String tabstop = ""; |
|
44 |
public Rectangle extent = null; |
|
45 |
public CRS crs = null; |
|
46 |
|
|
47 |
public void setExtent(double minx, double miny, double maxx, double maxy) { |
|
48 |
extent = new Rectangle(); |
|
49 |
extent.setFrameFromDiagonal(minx, miny, maxx, maxy); |
|
50 |
} |
|
51 |
|
|
52 |
String extentToMapString(Rectangle ext) { |
|
53 |
if (ext != null) |
|
54 |
return ext.getMinX()+" "+ext.getMinY()+" "+ext.getMaxX()+" "+ext.getMaxY(); |
|
55 |
return ""; |
|
56 |
} |
|
57 |
|
|
58 |
void projectionToMap(CRS prj, boolean init) { |
|
59 |
if (prj == null) |
|
60 |
return; |
|
61 |
toMapln("PROJECTION"); |
|
62 |
if (init == true) |
|
63 |
prj.toString(); |
|
64 |
tabIn(); |
|
65 |
toMapln("\""+prj+"\""); |
|
66 |
tabOut(); |
|
67 |
toMapln("END"); |
|
68 |
} |
|
69 |
|
|
70 |
public String replicate(String str, int n) { |
|
71 |
int i; |
|
72 |
String ret = ""; |
|
73 |
for(i=0;i<n;i++){ |
|
74 |
ret += str; |
|
75 |
} |
|
76 |
return ret; |
|
77 |
} |
|
78 |
|
|
79 |
public void tabIn() { |
|
80 |
tabstop += " "; |
|
81 |
} |
|
82 |
|
|
83 |
public void tabOut() { |
|
84 |
tabstop = tabstop.substring(0,tabstop.length()-3); |
|
85 |
} |
|
86 |
|
|
87 |
void toMapln(String str){ |
|
88 |
if (salida == null) |
|
89 |
System.out.println(tabstop+str); |
|
90 |
else |
|
91 |
salida.println(tabstop+str); |
|
92 |
} |
|
93 |
} |
trunk/extensions/extPublish/src/org/gvsig/remoteservices/conf/mapserver/Test.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.awt.Dimension; |
4 | 4 |
|
5 |
import org.gvsig.remoteservices.conf.mapserver.ToMap.RGB; |
|
6 | 5 |
|
7 | 6 |
|
8 |
|
|
9 | 7 |
public class Test { |
10 | 8 |
public static void main(String args[]) { |
11 | 9 |
//testShpMap(); |
... | ... | |
15 | 13 |
} |
16 | 14 |
|
17 | 15 |
static void testShpMap() { |
18 |
String mapFileName = "/etc/mapserver/wms.map"; |
|
19 |
DoMap map = new DoMap();
|
|
20 |
map.mapName= "TEST_MAPSERVER"; |
|
21 |
map.mapStatus="ON";
|
|
22 |
map.mapUnits="METERS";
|
|
16 |
String mapFileName = null; //"/etc/mapserver/wms.map";
|
|
17 |
MapServer.ConfigFile map = new MapServer.ConfigFile();
|
|
18 |
map.mapName = "TEST_MAPSERVER";
|
|
19 |
map.mapStatus = "ON";
|
|
20 |
map.mapUnits = "METERS";
|
|
23 | 21 |
map.mapShapePath = "/home/david/cv300/"; |
24 |
map.mapcrs= new ToMap.CRS("EPSG:23030",true);
|
|
22 |
map.mapcrs = new MapServer.CRS("EPSG:23030",true);
|
|
25 | 23 |
map.setExtent(638610.4375,4222780,789330,4484662.5); |
26 | 24 |
|
27 |
DoMap.WebMap web = new DoMap.WebMap();
|
|
28 |
web.imagepath="/var/tmp/";
|
|
29 |
web.imageurl="/var/tmp/";
|
|
30 |
web.metadata=new DoMap.MetadataWeb();
|
|
31 |
web.metadata.crs= new ToMap.CRS("EPSG:23030",false);
|
|
32 |
web.metadata.title="test shape";
|
|
33 |
web.metadata.onlineresource="http://localhost/mapserver/mapserv?map=/etc/mapserver/wms.map";
|
|
34 |
map.www=web;
|
|
25 |
MapServer.ConfigFile.WebMap web = new MapServer.ConfigFile.WebMap();
|
|
26 |
web.imagepath = "/var/tmp/";
|
|
27 |
web.imageurl = "/var/tmp/";
|
|
28 |
web.metadata = new MapServer.ConfigFile.MetadataWeb();
|
|
29 |
web.metadata.crs = new MapServer.CRS("EPSG:23030",false);
|
|
30 |
web.metadata.title = "test shape";
|
|
31 |
web.metadata.onlineresource = "http://localhost/mapserver/mapserv?map=/etc/mapserver/wms.map";
|
|
32 |
map.www = web;
|
|
35 | 33 |
|
36 |
DoMap.ShpLayer capa = new DoMap.ShpLayer();
|
|
37 |
DoMap.MapClass clase = new DoMap.MapClass("autopistas");
|
|
34 |
MapServer.ShpLayer capa = new MapServer.ShpLayer();
|
|
35 |
MapServer.MapClass clase = new MapServer.MapClass("autopistas");
|
|
38 | 36 |
capa.name = "autopistas"; |
39 | 37 |
capa.title = "Autopistas de la GV"; |
40 | 38 |
capa.type="LINE"; |
41 | 39 |
capa.data="autopistas"; |
42 | 40 |
capa.extent = null; |
43 | 41 |
capa.layerClass = clase; |
44 |
clase.estilo = new DoMap.StyleMap(
|
|
45 |
new RGB(120,120,120),new RGB(200,255,0));
|
|
46 |
capa.metadata=new DoMap.MetadataLayer();
|
|
42 |
clase.estilo = new MapServer.StyleMap(
|
|
43 |
new MapServer.RGB(120,120,120),new MapServer.RGB(200,255,0));
|
|
44 |
capa.metadata=new MapServer.MetadataLayer();
|
|
47 | 45 |
capa.metadata.setExtent(638610.4375,4222780,789330,4484662.5); |
48 | 46 |
capa.metadata.metalayertitle="Autopistas gv"; |
49 |
capa.layercrs= new ToMap.CRS("EPSG:23030",true);
|
|
47 |
capa.layercrs= new MapServer.CRS("EPSG:23030",true);
|
|
50 | 48 |
map.layers.add(capa); |
51 | 49 |
|
52 | 50 |
map.generate(mapFileName); |
... | ... | |
55 | 53 |
|
56 | 54 |
static void testPostGisMap(){ |
57 | 55 |
String mapFileName = "/etc/mapserver/wms.map"; |
58 |
DoMap map = new DoMap();
|
|
56 |
MapServer.ConfigFile map = new MapServer.ConfigFile();
|
|
59 | 57 |
map.mapName= "TEST_MAPSERVER_POSTGIS"; |
60 | 58 |
map.mapStatus="ON"; |
61 | 59 |
map.mapUnits="METERS"; |
62 | 60 |
map.mapShapePath = "/home/david/cv300/"; |
63 |
map.mapcrs= new ToMap.CRS("EPSG:23030",true);
|
|
61 |
map.mapcrs= new MapServer.CRS("EPSG:23030",true);
|
|
64 | 62 |
map.setExtent(638610.4375,4222780,789330,4484662.5); |
65 | 63 |
|
66 |
DoMap.WebMap web = new DoMap.WebMap();
|
|
64 |
MapServer.WebMap web = new MapServer.WebMap();
|
|
67 | 65 |
web.imagepath="/var/tmp/"; |
68 | 66 |
web.imageurl="/var/tmp/"; |
69 |
web.metadata=new DoMap.MetadataWeb();
|
|
70 |
web.metadata.crs= new ToMap.CRS("EPSG:23030",false);
|
|
67 |
web.metadata = new MapServer.MetadataWeb();
|
|
68 |
web.metadata.crs = new MapServer.CRS("EPSG:23030",false);
|
|
71 | 69 |
web.metadata.title="test shape"; |
72 | 70 |
web.metadata.onlineresource="http://localhost/mapserver/mapserv?map=/etc/mapserver/wms.map"; |
73 | 71 |
map.www=web; |
74 | 72 |
|
75 |
DoMap.PostgisLayer capa = new DoMap.PostgisLayer();
|
|
76 |
DoMap.MapClass clase = new DoMap.MapClass("autopistas");
|
|
73 |
MapServer.PostgisLayer capa = new MapServer.PostgisLayer();
|
|
74 |
MapServer.MapClass clase = new MapServer.MapClass("autopistas");
|
|
77 | 75 |
capa.name = "autopistas"; |
78 | 76 |
capa.title = "Autopistas de la GV"; |
79 | 77 |
capa.type="LINE"; |
80 | 78 |
capa.data="autopistas"; |
81 | 79 |
capa.extent = null; |
82 | 80 |
capa.layerClass = clase; |
83 |
clase.estilo = new DoMap.StyleMap(
|
|
84 |
new RGB(120,120,120),new RGB(200,255,0));
|
|
85 |
capa.metadata=new DoMap.MetadataLayer();
|
|
81 |
clase.estilo = new MapServer.StyleMap(
|
|
82 |
new MapServer.RGB(120,120,120),new MapServer.RGB(200,255,0));
|
|
83 |
capa.metadata=new MapServer.MetadataLayer();
|
|
86 | 84 |
capa.metadata.setExtent(638610.4375,4222780,789330,4484662.5); |
87 | 85 |
capa.metadata.metalayertitle="Autopistas gv"; |
88 |
capa.layercrs= new ToMap.CRS("EPSG:23030",true);
|
|
86 |
capa.layercrs= new MapServer.CRS("EPSG:23030",true);
|
|
89 | 87 |
capa.setConnParams("david", "chkdsk", "localhost", "betel", "5432"); |
90 | 88 |
capa.tabla = "autopistas"; |
91 | 89 |
capa.data = "the_geom from "+capa.tabla; |
... | ... | |
99 | 97 |
} |
100 | 98 |
|
101 | 99 |
static void testRasterMap(){ |
102 |
String mapFileName = "/etc/mapserver/wms.map"; |
|
103 |
DoMap map = new DoMap();
|
|
100 |
String mapFileName = null; //"/etc/mapserver/wms.map";
|
|
101 |
MapServer.ConfigFile map = new MapServer.ConfigFile();
|
|
104 | 102 |
map.mapName= "TEST_MAPSERVER_RASTER"; |
105 | 103 |
map.mapStatus="ON"; |
106 | 104 |
map.mapUnits="METERS"; |
107 | 105 |
map.mapShapePath = "/home/david/cv300/"; |
108 |
map.mapcrs= new ToMap.CRS("EPSG:23030",true);
|
|
106 |
map.mapcrs= new MapServer.CRS("EPSG:23030",true);
|
|
109 | 107 |
map.setExtent(395000,97000,429000,160000); |
110 | 108 |
|
111 |
DoMap.WebMap web = new DoMap.WebMap();
|
|
109 |
MapServer.WebMap web = new MapServer.WebMap();
|
|
112 | 110 |
web.imagepath="/var/tmp/"; |
113 | 111 |
web.imageurl="/var/tmp/"; |
114 |
web.metadata=new DoMap.MetadataWeb();
|
|
115 |
web.metadata.crs= new ToMap.CRS("EPSG:23030",false);
|
|
112 |
web.metadata=new MapServer.MetadataWeb();
|
|
113 |
web.metadata.crs= new MapServer.CRS("EPSG:23030",false);
|
|
116 | 114 |
web.metadata.title="test raster"; |
117 | 115 |
web.metadata.onlineresource="http://localhost/mapserver/mapserv?map=/etc/mapserver/wms.map"; |
118 | 116 |
map.www=web; |
119 | 117 |
|
120 |
DoMap.RasterLayer capa = new DoMap.RasterLayer();
|
|
121 |
DoMap.MapClass clase = new DoMap.MapClass("raster");
|
|
118 |
MapServer.RasterLayer capa = new MapServer.RasterLayer();
|
|
119 |
MapServer.MapClass clase = new MapServer.MapClass("raster");
|
|
122 | 120 |
capa.name = "raster"; |
123 | 121 |
capa.title = "raster de la GV"; |
124 | 122 |
capa.type="RASTER"; |
125 | 123 |
capa.data="foto.tif"; |
126 | 124 |
capa.extent = null; |
127 | 125 |
capa.layerClass = clase; |
128 |
clase.estilo = new DoMap.StyleMap(
|
|
129 |
new RGB(120,120,120),new RGB(200,255,0));
|
|
130 |
capa.metadata=new DoMap.MetadataLayer();
|
|
126 |
clase.estilo = new MapServer.StyleMap(
|
|
127 |
new MapServer.RGB(120,120,120),new MapServer.RGB(200,255,0));
|
|
128 |
capa.metadata=new MapServer.MetadataLayer();
|
|
131 | 129 |
capa.metadata.setExtent(395000,97000,429000,160000); |
132 | 130 |
capa.metadata.metalayertitle="raster gv"; |
133 |
capa.layercrs= new ToMap.CRS("EPSG:23030",true);
|
|
131 |
capa.layercrs= new MapServer.CRS("EPSG:23030",true);
|
|
134 | 132 |
capa.layerClass = clase; |
135 | 133 |
map.layers.add(capa); |
136 | 134 |
|
137 | 135 |
map.generate(mapFileName); |
138 |
//map.generate(); |
|
139 |
|
|
140 |
|
|
141 | 136 |
} |
142 | 137 |
|
143 | 138 |
/*public void addAutopistas(DoMap map) { |
... | ... | |
213 | 208 |
*/ |
214 | 209 |
|
215 | 210 |
public static void testWFSCanada() { |
216 |
String mapFileName = "data/wfs.map"; |
|
217 |
DoMap map = new DoMap();
|
|
211 |
String mapFileName = null; //"data/wfs.map";
|
|
212 |
MapServer.ConfigFile map = new MapServer.ConfigFile();
|
|
218 | 213 |
map.mapName = "TEST_WFS_MAPSERVER"; |
219 | 214 |
map.mapStatus = "ON"; |
220 | 215 |
map.mapUnits = "METERS"; |
221 | 216 |
map.mapShapePath = "../data"; |
222 |
map.mapcrs= new ToMap.CRS("EPSG:23030",true);
|
|
217 |
map.mapcrs= new MapServer.CRS("EPSG:23030",true);
|
|
223 | 218 |
map.symbolset = "../etc/symbols.sym"; |
224 | 219 |
map.fontset = "../etc/fonts.txt"; |
225 | 220 |
map.mapSize = new Dimension(400,300); |
226 |
map.imageColor = new ToMap.RGB(255,255,255);
|
|
221 |
map.imageColor = new MapServer.RGB(255,255,255);
|
|
227 | 222 |
map.setExtent(-2200000d,-712631d,3072800d,3840000d); |
228 | 223 |
|
229 |
DoMap.WebMap web = new DoMap.WebMap();
|
|
224 |
MapServer.WebMap web = new MapServer.WebMap();
|
|
230 | 225 |
web.imagepath = "/ms4w/tmp/ms_tmp/"; |
231 | 226 |
web.imageurl = "/ms_tmp/"; |
232 |
web.metadata = new DoMap.MetadataWeb();
|
|
227 |
web.metadata = new MapServer.MetadataWeb();
|
|
233 | 228 |
web.metadata.setServiceAsWFS(); |
234 |
web.metadata.crs = new ToMap.CRS("EPSG:42304 EPSG:42101 EPSG:4269 EPSG:4326", false);
|
|
229 |
web.metadata.crs = new MapServer.CRS("EPSG:42304 EPSG:42101 EPSG:4269 EPSG:4326", false);
|
|
235 | 230 |
web.metadata.title = "GMap WFS Demo Server"; |
236 | 231 |
web.metadata.onlineresource = "http://127.0.0.1/cgi-bin/mapserv.exe?"; |
237 | 232 |
web.metadata.ows_schemas_location = "http://ogc.dmsolutions.ca"; |
238 | 233 |
map.www=web; |
239 | 234 |
|
240 |
map.mapcrs= new ToMap.CRS("EPSG:42304",true);
|
|
235 |
map.mapcrs= new MapServer.CRS("EPSG:42304",true);
|
|
241 | 236 |
|
242 |
DoMap.ShpLayer capa = new DoMap.ShpLayer();
|
|
243 |
DoMap.MapClass clase = new DoMap.MapClass("Canada");
|
|
244 |
clase.estilo = new DoMap.StyleMap(
|
|
245 |
new RGB(120,120,120),new RGB(200,255,0));
|
|
237 |
MapServer.ShpLayer capa = new MapServer.ShpLayer();
|
|
238 |
MapServer.MapClass clase = new MapServer.MapClass("Canada");
|
|
239 |
clase.estilo = new MapServer.StyleMap(
|
|
240 |
new MapServer.RGB(120,120,120),new MapServer.RGB(200,255,0));
|
|
246 | 241 |
clase.template = "ttt_query.html"; |
247 | 242 |
capa.name = "province"; |
248 | 243 |
capa.type="POLYGON"; |
249 | 244 |
capa.data="province"; |
250 |
capa.layercrs = new ToMap.CRS("epsg:42304", true);
|
|
245 |
capa.layercrs = new MapServer.CRS("epsg:42304", true);
|
|
251 | 246 |
capa.layerClass = clase; |
252 |
capa.metadata=new DoMap.MetadataLayer();
|
|
247 |
capa.metadata=new MapServer.MetadataLayer();
|
|
253 | 248 |
capa.metadata.setServiceAsWFS(); |
254 | 249 |
capa.metadata.title = "Provinces"; |
255 | 250 |
capa.metadata.gml_include_items = "all"; |
256 | 251 |
capa.setDump(true); |
257 | 252 |
map.layers.add(capa); |
258 | 253 |
|
259 |
map.generate(); |
|
254 |
map.generate(mapFileName);
|
|
260 | 255 |
} |
261 | 256 |
} |
trunk/extensions/extPublish/src/org/gvsig/remoteservices/conf/mapserver/MapServer.java | ||
---|---|---|
1 |
package org.gvsig.remoteservices.conf.mapserver; |
|
2 |
|
|
3 |
import java.awt.Dimension; |
|
4 |
import java.awt.Rectangle; |
|
5 |
import java.io.File; |
|
6 |
import java.io.FileNotFoundException; |
|
7 |
import java.io.FileOutputStream; |
|
8 |
import java.io.PrintStream; |
|
9 |
import java.util.ArrayList; |
|
10 |
import java.util.Iterator; |
|
11 |
|
|
12 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.CRS; |
|
13 |
|
|
14 |
|
|
15 |
/** |
|
16 |
* Genera un .MAP |
|
17 |
* ... como este: |
|
18 |
MAP |
|
19 |
NAME test_postgis |
|
20 |
STATUS ON |
|
21 |
SIZE 400 300 |
|
22 |
#SYMBOLSET ../etc/symbols.sym |
|
23 |
EXTENT 638610.4375 4222780 789330 4484662.5 |
|
24 |
UNITS METERS |
|
25 |
SHAPEPATH "/home/shapes/" |
|
26 |
IMAGECOLOR 255 255 255 |
|
27 |
#FONTSET ../etc/fonts.txt |
|
28 |
|
|
29 |
WEB |
|
30 |
# IMAGEPATH "/ms4w/tmp/ms_tmp/" |
|
31 |
# IMAGEURL "/ms_tmp/" |
|
32 |
METADATA |
|
33 |
"wms_title" "test postgis" ##required |
|
34 |
"wms_onlineresource" "http://localhost/mapserver/mapserv" ##required |
|
35 |
"wms_srs" "EPSG:42304 EPSG:42101 EPSG:4269 EPSG:4326 EPSG:23030" ##recommended |
|
36 |
END |
|
37 |
END |
|
38 |
|
|
39 |
PROJECTION |
|
40 |
"init=epsg:23030" ##required |
|
41 |
END |
|
42 |
|
|
43 |
# |
|
44 |
# Start of layer definitions |
|
45 |
# |
|
46 |
|
|
47 |
LAYER |
|
48 |
NAME "autopistas" |
|
49 |
DATA "the_geom from autopistas" |
|
50 |
CONNECTIONTYPE POSTGIS |
|
51 |
CONNECTION "user=david password=chkdsk dbname=betel host=localhost port=5434" |
|
52 |
STATUS ON |
|
53 |
TYPE LINE |
|
54 |
METADATA |
|
55 |
"wms_title" "Autopistas GV" ##required |
|
56 |
"wms_extent" "638610.4375 4222780 789330 4484662.5" |
|
57 |
END |
|
58 |
PROJECTION |
|
59 |
"init=epsg:23030" ##recommended |
|
60 |
END |
|
61 |
CLASS |
|
62 |
NAME "Autopistas" |
|
63 |
STYLE |
|
64 |
COLOR 200 255 0 |
|
65 |
OUTLINECOLOR 120 120 120 |
|
66 |
END |
|
67 |
END |
|
68 |
END |
|
69 |
|
|
70 |
END # Map File |
|
71 |
|
|
72 |
* @author david |
|
73 |
*/ |
|
74 |
|
|
75 |
public abstract class MapServer { |
|
76 |
public static class RGB { |
|
77 |
int r,g,b; |
|
78 |
public RGB(int red,int green,int blue){ |
|
79 |
r=red; |
|
80 |
g=green; |
|
81 |
b=blue; |
|
82 |
} |
|
83 |
public String toString(){ |
|
84 |
return ""+r+" "+g+" "+b; |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
public static class CRS extends MapServer { |
|
89 |
boolean init = false; |
|
90 |
String crs = ""; |
|
91 |
public CRS(String crs, boolean init) { |
|
92 |
this.crs = crs; |
|
93 |
this.init =init; |
|
94 |
} |
|
95 |
|
|
96 |
public String toString() { |
|
97 |
String str = ""; |
|
98 |
if (init) |
|
99 |
str += "init="; |
|
100 |
return str+crs.toLowerCase(); |
|
101 |
} |
|
102 |
|
|
103 |
public void toMap() { |
|
104 |
toMapln("PROJECTION"); |
|
105 |
tabIn(); |
|
106 |
toMapln("\""+this+"\""); |
|
107 |
tabOut(); |
|
108 |
toMapln("END"); |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
static PrintStream salida = null; |
|
113 |
static String tabstop = ""; |
|
114 |
public Rectangle extent = null; |
|
115 |
public CRS crs = null; |
|
116 |
|
|
117 |
public void setExtent(double minx, double miny, double maxx, double maxy) { |
|
118 |
extent = new Rectangle(); |
|
119 |
extent.setFrameFromDiagonal(minx, miny, maxx, maxy); |
|
120 |
} |
|
121 |
|
|
122 |
String extentToMapString(Rectangle ext) { |
|
123 |
if (ext != null) |
|
124 |
return ext.getMinX()+" "+ext.getMinY()+" "+ext.getMaxX()+" "+ext.getMaxY(); |
|
125 |
return ""; |
|
126 |
} |
|
127 |
|
|
128 |
void projectionToMap(CRS prj, boolean init) { |
|
129 |
if (prj == null) |
|
130 |
return; |
|
131 |
toMapln("PROJECTION"); |
|
132 |
if (init == true) |
|
133 |
prj.toString(); |
|
134 |
tabIn(); |
|
135 |
toMapln("\""+prj+"\""); |
|
136 |
tabOut(); |
|
137 |
toMapln("END"); |
|
138 |
} |
|
139 |
|
|
140 |
public String replicate(String str, int n) { |
|
141 |
int i; |
|
142 |
String ret = ""; |
|
143 |
for(i=0;i<n;i++){ |
|
144 |
ret += str; |
|
145 |
} |
|
146 |
return ret; |
|
147 |
} |
|
148 |
|
|
149 |
public void tabIn() { |
|
150 |
tabstop += " "; |
|
151 |
} |
|
152 |
|
|
153 |
public void tabOut() { |
|
154 |
tabstop = tabstop.substring(0,tabstop.length()-3); |
|
155 |
} |
|
156 |
|
|
157 |
void toMapln(String str){ |
|
158 |
if (salida == null) |
|
159 |
System.out.println(tabstop+str); |
|
160 |
else |
|
161 |
salida.println(tabstop+str); |
|
162 |
} |
|
163 |
|
|
164 |
public static class Metadata extends MapServer { |
|
165 |
public String prefix = "wms"; |
|
166 |
public String title = null; |
|
167 |
|
|
168 |
public void setServiceAsWFS() { |
|
169 |
prefix = "wfs"; |
|
170 |
} |
|
171 |
|
|
172 |
public void setServiceAsWMS() { |
|
173 |
prefix = "wms"; |
|
174 |
} |
|
175 |
public void setServiceAsWCS() { |
|
176 |
prefix = "wcs"; |
|
177 |
} |
|
178 |
// |
|
179 |
void startMetadataToMap(){ |
|
180 |
toMapln("METADATA"); |
|
181 |
tabIn(); |
|
182 |
if (title != null) |
|
183 |
toMapln("\""+prefix+"_title\" " +"\""+title+"\""); |
|
184 |
} |
|
185 |
|
|
186 |
void endMetadataToMap() { |
|
187 |
tabOut(); |
|
188 |
toMapln("END"); |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
public static class MetadataWeb extends Metadata { |
|
193 |
//Atributos wms_xxxx WEB |
|
194 |
public String onlineresource = null; |
|
195 |
public String ows_schemas_location = null; |
|
196 |
void metadataToMap(){ |
|
197 |
startMetadataToMap(); |
|
198 |
toMapln("\""+prefix+"_onlineresource\" \""+onlineresource+"\""); |
|
199 |
toMapln("\""+prefix+"_srs\" \""+crs+"\""); |
|
200 |
if (ows_schemas_location != null) |
|
201 |
toMapln("\"ows_schemas_location\" \""+ows_schemas_location+"\""); |
|
202 |
endMetadataToMap(); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
public static class MetadataLayer extends Metadata { |
|
207 |
//Atributos wms_xxxx LAYER |
|
208 |
public String metalayertitle = null; |
|
209 |
public String gml_include_items = null; |
|
210 |
void metadataToMap(){ |
|
211 |
startMetadataToMap(); |
|
212 |
if (extent != null) |
|
213 |
toMapln("\""+prefix+"_extent\" \""+extentToMapString(extent)+"\""); |
|
214 |
if (gml_include_items != null) |
|
215 |
toMapln("\"gml_include_items\" \""+gml_include_items+"\""); |
|
216 |
endMetadataToMap(); |
|
217 |
} |
|
218 |
} |
|
219 |
|
|
220 |
public static class StyleMap extends MapServer { |
|
221 |
public RGB styleColor = null; |
|
222 |
public RGB styleColorOutline = null; |
|
223 |
public StyleMap(RGB line, RGB fill) { |
|
224 |
styleColor = fill; |
|
225 |
styleColorOutline = line; |
|
226 |
} |
|
227 |
void styleToMap(){ |
|
228 |
toMapln("STYLE "); |
|
229 |
tabIn(); |
|
230 |
toMapln("COLOR "+styleColor); |
|
231 |
toMapln("OUTLINECOLOR "+styleColorOutline); |
|
232 |
tabOut(); |
|
233 |
toMapln("END"); |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
237 |
public static class WebMap extends MapServer{ |
|
238 |
public MetadataWeb metadata = null; |
|
239 |
public String imagepath = null; |
|
240 |
public String imageurl = null; |
|
241 |
void webToMap(){ |
|
242 |
toMapln("WEB"); |
|
243 |
tabIn(); |
|
244 |
toMapln("IMAGEPATH \""+imagepath+"\""); |
|
245 |
toMapln("IMAGEURL \""+imageurl+"\""); |
|
246 |
metadata.metadataToMap(); |
|
247 |
tabOut(); |
|
248 |
toMapln("END"); |
|
249 |
} |
|
250 |
} |
|
251 |
|
|
252 |
public static class MapClass extends MapServer { |
|
253 |
public String name; |
|
254 |
public StyleMap estilo = null; |
|
255 |
public String template = null; |
|
256 |
public MapClass(String n) { |
|
257 |
name = n; |
|
258 |
} |
|
259 |
public void classToMap(){ |
|
260 |
toMapln("CLASS"); |
|
261 |
tabIn(); |
|
262 |
toMapln("NAME \""+name+"\""); |
|
263 |
if (estilo != null) |
|
264 |
estilo.styleToMap(); |
|
265 |
if (template != null) |
|
266 |
toMapln("TEMPLATE "+template); |
|
267 |
tabOut(); |
|
268 |
toMapln("END"); |
|
269 |
} |
|
270 |
} |
|
271 |
|
|
272 |
public abstract static class MapLayer extends MapServer { |
|
273 |
public String name; |
|
274 |
public String title; |
|
275 |
public String status = "ON"; |
|
276 |
public String type = null; |
|
277 |
public MapClass layerClass = null; |
|
278 |
public String data; |
|
279 |
public MetadataLayer metadata = null; |
|
280 |
public boolean dump = false; |
|
281 |
public CRS layercrs=null; |
|
282 |
|
|
283 |
public void setDump(boolean d) { |
|
284 |
dump = d; |
|
285 |
} |
|
286 |
|
|
287 |
void startToMap() { |
|
288 |
toMapln("LAYER"); |
|
289 |
tabIn(); |
|
290 |
toMapln("NAME \""+name+"\""); |
|
291 |
toMapln("STATUS "+status); |
|
292 |
if (type != null) |
|
293 |
toMapln("TYPE "+type); |
|
294 |
if (dump) |
|
295 |
toMapln("DUMP TRUE # required"); |
|
296 |
} |
|
297 |
|
|
298 |
void endToMap() { |
|
299 |
tabOut(); |
|
300 |
toMapln("END # Layer"); |
|
301 |
} |
|
302 |
|
|
303 |
public abstract void layerToMap(); |
|
304 |
} |
|
305 |
|
|
306 |
public static class ShpLayer extends MapLayer { |
|
307 |
public void layerToMap() { |
|
308 |
startToMap(); |
|
309 |
toMapln("DATA \""+data+"\""); |
|
310 |
metadata.metadataToMap(); |
|
311 |
if (layercrs != null) layercrs.toMap(); |
|
312 |
if (layerClass != null) |
|
313 |
layerClass.classToMap(); |
|
314 |
endToMap(); |
|
315 |
} |
|
316 |
} |
|
317 |
|
|
318 |
public static class PostgisLayer extends MapLayer { |
|
319 |
public String user; |
|
320 |
public String pass; |
|
321 |
public String host; |
|
322 |
public String dbname; |
|
323 |
public String port; |
|
324 |
|
|
325 |
public String tabla; |
|
326 |
public String data; |
|
327 |
|
|
328 |
public void setConnParams(String user, String pass, String host, |
|
329 |
String dbname, String port) { |
|
330 |
this.user = user; |
|
331 |
this.pass = pass; |
|
332 |
this.host = host; |
|
333 |
this.dbname = dbname; |
|
334 |
this.port = port; |
|
335 |
} |
|
336 |
|
|
337 |
public void layerToMap() { |
|
338 |
startToMap(); |
|
339 |
toMapln("DATA \""+data+"\""); |
|
340 |
toMapln("CONNECTIONTYPE POSTGIS"); |
|
341 |
toMapln("CONNECTION \"user="+user+" password="+pass+" dbname="+dbname+" host="+host+" port="+port+"\""); |
|
342 |
metadata.metadataToMap(); |
|
343 |
if (layercrs != null) layercrs.toMap(); |
|
344 |
if (layerClass != null) |
|
345 |
layerClass.classToMap(); |
|
346 |
endToMap(); |
|
347 |
} |
|
348 |
} |
|
349 |
|
|
350 |
public static class RasterLayer extends MapLayer { |
|
351 |
public void layerToMap() { |
|
352 |
startToMap(); |
|
353 |
toMapln("DATA \""+data+"\""); |
|
354 |
metadata.metadataToMap(); |
|
355 |
if (layercrs != null) layercrs.toMap(); |
|
356 |
if (layerClass != null) |
|
357 |
layerClass.classToMap(); |
|
358 |
endToMap(); |
|
359 |
} |
|
360 |
} |
|
361 |
|
|
362 |
public static class ConfigFile extends MapServer { |
|
363 |
/** |
|
364 |
* Atributos wms_xxxx comunes a WEB y LAYER. |
|
365 |
* @author david |
|
366 |
*/ |
|
367 |
|
|
368 |
public String mapFileName = null; |
|
369 |
public String fName = null; |
|
370 |
public String mapName = null; |
|
371 |
public String mapStatus = null; |
|
372 |
public String mapUnits= null; |
|
373 |
public String mapShapePath; |
|
374 |
public Dimension mapSize = null; |
|
375 |
public CRS mapcrs= null; |
|
376 |
public WebMap www = null; |
|
377 |
public String symbolset = null; |
|
378 |
public String fontset = null; |
|
379 |
public RGB imageColor = null; |
|
380 |
|
|
381 |
public ArrayList layers = new ArrayList(); |
|
382 |
|
|
383 |
public ConfigFile() { |
|
384 |
} |
|
385 |
|
|
386 |
public void generate() { |
|
387 |
generate(null); |
|
388 |
} |
|
389 |
|
|
390 |
public void generate(String donde) { |
|
391 |
openMapFile(donde); |
|
392 |
toMapln("MAP"); |
|
393 |
tabIn(); |
|
394 |
toMapln("NAME "+mapName); |
|
395 |
if (mapSize != null) |
|
396 |
toMapln("SIZE "+mapSize.width+" "+mapSize.height); |
|
397 |
toMapln("EXTENT "+extentToMapString(extent)); |
|
398 |
toMapln("STATUS "+mapStatus); |
|
399 |
toMapln("UNITS "+mapUnits); |
|
400 |
toMapln("SHAPEPATH \""+mapShapePath+"\""); |
|
401 |
if (symbolset != null) |
|
402 |
toMapln("SYMBOLSET "+symbolset); |
|
403 |
if (symbolset != null) |
|
404 |
toMapln("FONTSET "+symbolset); |
|
405 |
if (imageColor != null) |
|
406 |
toMapln("IMAGECOLOR \""+imageColor); |
|
407 |
www.webToMap(); |
|
408 |
if (mapcrs != null) |
|
409 |
projectionToMap(mapcrs,true); |
|
410 |
Iterator iter = layers.iterator(); |
|
411 |
while(iter.hasNext()) { |
|
412 |
MapLayer l = (MapLayer) iter.next(); |
|
413 |
l.layerToMap(); |
|
414 |
} |
|
415 |
tabOut(); |
|
416 |
toMapln("END # Map File"); |
|
417 |
closeMapFile(); |
|
418 |
} |
|
419 |
|
|
420 |
void openMapFile(String donde) { |
|
421 |
setMapFileName(donde); |
|
422 |
if (mapFileName == null) |
|
423 |
return; |
|
424 |
File wmsmap = new File( mapFileName ); |
|
425 |
try{ |
|
426 |
//salida = new PrintStream(new BufferedOutputStream(new FileOutputStream(wmsmap))); |
|
427 |
salida = new PrintStream(new FileOutputStream(wmsmap)); |
|
428 |
} catch(FileNotFoundException e){ |
|
429 |
System.out.println("Fichero no encontrado."); |
|
430 |
} |
|
431 |
System.out.println(mapFileName+" abierto."); |
|
432 |
|
|
433 |
} |
|
434 |
|
|
435 |
void closeMapFile() { |
|
436 |
if (salida != null) |
|
437 |
salida.close(); |
|
438 |
} |
|
439 |
|
|
440 |
public String getMapFileName() { |
|
441 |
return mapFileName; |
|
442 |
} |
|
443 |
|
|
444 |
public void setMapFileName(String mapFileName) { |
|
445 |
this.mapFileName = mapFileName; |
|
446 |
} |
|
447 |
} |
|
448 |
} |
|
0 | 449 |
trunk/extensions/extPublish/src/com/iver/cit/gvsig/publish/PublishWMSControler.java | ||
---|---|---|
3 | 3 |
import java.awt.Color; |
4 | 4 |
import java.awt.geom.Rectangle2D; |
5 | 5 |
|
6 |
import org.gvsig.remoteservices.conf.mapserver.DoMap;
|
|
7 |
import org.gvsig.remoteservices.conf.mapserver.ToMap.CRS;
|
|
8 |
import org.gvsig.remoteservices.conf.mapserver.ToMap.RGB;
|
|
6 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.ConfigFile;
|
|
7 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.CRS;
|
|
8 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.RGB;
|
|
9 | 9 |
|
10 | 10 |
import com.iver.cit.gvsig.publish.gui.MapserverPanel; |
11 | 11 |
|
... | ... | |
67 | 67 |
*/ |
68 | 68 |
|
69 | 69 |
public void publish(String mapFile, String symbolsFile, String fontsFile, String onlineResource, String shapePath ){ |
70 |
DoMap map = new DoMap();
|
|
70 |
ConfigFile map = new ConfigFile();
|
|
71 | 71 |
map.mapName= "TEST_MAPSERVER"; |
72 | 72 |
map.mapStatus="ON"; |
73 | 73 |
map.mapUnits="METERS"; |
... | ... | |
75 | 75 |
map.mapcrs = new CRS(mapCtrl.getMapContext().getViewPort().getProjection().getAbrev(),true); |
76 | 76 |
map.setExtent(-1,-1,1,1); |
77 | 77 |
|
78 |
DoMap.WebMap web = new DoMap.WebMap();
|
|
78 |
ConfigFile.WebMap web = new ConfigFile.WebMap();
|
|
79 | 79 |
web.imagepath="/var/tmp/"; |
80 | 80 |
web.imageurl="/var/tmp/"; |
81 |
web.metadata=new DoMap.MetadataWeb();
|
|
81 |
web.metadata=new ConfigFile.MetadataWeb();
|
|
82 | 82 |
web.metadata.crs= new CRS(mapCtrl.getMapContext().getViewPort().getProjection().getAbrev(),false); |
83 | 83 |
|
84 | 84 |
web.metadata.title="test shape"; |
... | ... | |
88 | 88 |
for (int i= 0; i < layers.getLayersCount(); i++ ){ |
89 | 89 |
FLayer lyr= layers.getLayer(i); |
90 | 90 |
|
91 |
DoMap.ShpLayer capa1 = new DoMap.ShpLayer();
|
|
92 |
DoMap.MapClass clase = new DoMap.MapClass("autopistas");
|
|
91 |
ConfigFile.ShpLayer capa1 = new ConfigFile.ShpLayer();
|
|
92 |
ConfigFile.MapClass clase = new ConfigFile.MapClass("autopistas");
|
|
93 | 93 |
capa1.name = lyr.getName(); |
94 | 94 |
capa1.title = lyr.getName(); |
95 | 95 |
|
... | ... | |
114 | 114 |
if(lyr instanceof FLyrVect){ |
115 | 115 |
FLyrVect lyrvec2 = (FLyrVect) lyr; |
116 | 116 |
Color clr = lyrvec2.getLegend().getDefaultSymbol().getColor(); |
117 |
clase.estilo = new DoMap.StyleMap(
|
|
117 |
clase.estilo = new ConfigFile.StyleMap(
|
|
118 | 118 |
new RGB(clr.getRed(),clr.getGreen(),clr.getBlue()),new RGB(clr.getRed(),clr.getGreen(),clr.getBlue())); |
119 | 119 |
|
120 | 120 |
int alpha = lyrvec2.getLegend().getDefaultSymbol().getColor().getAlpha(); |
... | ... | |
123 | 123 |
}else{ |
124 | 124 |
System.out.println("Esto no es una capa vectorial"); |
125 | 125 |
} |
126 |
capa1.metadata=new DoMap.MetadataLayer();
|
|
126 |
capa1.metadata=new ConfigFile.MetadataLayer();
|
|
127 | 127 |
Rectangle2D extent = null; |
128 | 128 |
try { |
129 | 129 |
extent = lyr.getFullExtent(); |
Also available in: Unified diff