root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / utils / GeoPointPersistence.java @ 5217
History | View | Annotate | Download (19 KB)
1 |
package org.gvsig.georeferencing.utils; |
---|---|
2 |
import java.awt.Dimension; |
3 |
import java.awt.geom.Point2D; |
4 |
import java.awt.geom.Rectangle2D; |
5 |
import java.io.BufferedOutputStream; |
6 |
import java.io.File; |
7 |
import java.io.FileOutputStream; |
8 |
import java.io.IOException; |
9 |
import java.io.OutputStream; |
10 |
import java.io.OutputStreamWriter; |
11 |
import java.io.StringWriter; |
12 |
import java.util.ArrayList; |
13 |
|
14 |
import javax.xml.parsers.DocumentBuilder; |
15 |
import javax.xml.parsers.DocumentBuilderFactory; |
16 |
import javax.xml.parsers.ParserConfigurationException; |
17 |
|
18 |
import org.apache.crimson.jaxp.DocumentBuilderFactoryImpl; |
19 |
import org.apache.xml.serialize.OutputFormat; |
20 |
import org.apache.xml.serialize.XMLSerializer; |
21 |
import org.cresques.cts.ProjectionPool; |
22 |
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog; |
23 |
import org.gvsig.georeferencing.layers.FLyrGeoRaster; |
24 |
import org.gvsig.georeferencing.layers.FLyrPoints; |
25 |
import org.gvsig.georeferencing.layers.GeoPoint; |
26 |
import org.w3c.dom.Document; |
27 |
import org.w3c.dom.Element; |
28 |
import org.w3c.dom.Node; |
29 |
import org.w3c.dom.NodeList; |
30 |
import org.xml.sax.SAXException; |
31 |
|
32 |
import com.iver.andami.PluginServices; |
33 |
import com.iver.cit.gvsig.fmap.DriverException; |
34 |
import com.iver.cit.gvsig.fmap.ViewPort; |
35 |
import com.iver.cit.gvsig.gui.View; |
36 |
|
37 |
/**
|
38 |
* Clase que controla la persistencia de la capa de puntos.
|
39 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
40 |
*/
|
41 |
public class GeoPointPersistence{ |
42 |
//**********************Vars**********************************
|
43 |
private ArrayList geoPointList = null; |
44 |
private Document xmlDoc = null; |
45 |
private Element generalTag = null; |
46 |
private FLyrPoints lyrPoints = null; |
47 |
private double[] lastViewPort = null; |
48 |
//**********************End Vars******************************
|
49 |
|
50 |
//**********************Methods*******************************
|
51 |
/**
|
52 |
* Constructor
|
53 |
*/
|
54 |
public GeoPointPersistence(){}
|
55 |
|
56 |
/**
|
57 |
* Constructor
|
58 |
* @param geoPointList Lista de geopuntos
|
59 |
*/
|
60 |
public GeoPointPersistence(FLyrPoints lyrPoints){
|
61 |
this.geoPointList = lyrPoints.getListPoint();
|
62 |
this.lyrPoints = lyrPoints;
|
63 |
} |
64 |
|
65 |
/**
|
66 |
* Carga la lista de puntos desde un fichero
|
67 |
* @param file Nombre del fichero
|
68 |
* @return Array con la lista de puntos
|
69 |
*/
|
70 |
public void loadPointList(String file){ |
71 |
try {
|
72 |
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
73 |
DocumentBuilder db = dbf.newDocumentBuilder();
|
74 |
File f = new File(file); |
75 |
Document doc = db.parse(f);
|
76 |
|
77 |
if(doc.getDocumentElement().getTagName().equals("GeoPoints")){ |
78 |
NodeList nodeList = doc.getDocumentElement().getChildNodes(); |
79 |
lyrPoints.clear(); |
80 |
for(int i=0;i<nodeList.getLength();i++){ |
81 |
Node node = nodeList.item(i); |
82 |
if(node.getNodeName().equals("FLyrGeoRaster")){ |
83 |
NodeList nl = node.getChildNodes(); |
84 |
lastViewPort = processFlyrGeoRasterNodeValue(nl); |
85 |
} |
86 |
if(node.getNodeName().equals("GeoPoint")){ |
87 |
NodeList nl = node.getChildNodes(); |
88 |
processGeoPointNodeValue(nl); |
89 |
} |
90 |
} |
91 |
this.geoPointList = lyrPoints.getListPoint();
|
92 |
} |
93 |
} catch (ParserConfigurationException e) { |
94 |
return;
|
95 |
} catch (SAXException e1) {
|
96 |
return;
|
97 |
} catch (IOException e1) { |
98 |
return;
|
99 |
} |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Crea el XML con la lista de puntos y la salva a disco
|
104 |
* @param file
|
105 |
*/
|
106 |
public void savePointList(String file){ |
107 |
this.geoPointList = lyrPoints.getListPoint();
|
108 |
try {
|
109 |
DocumentBuilderFactory dbFactory = DocumentBuilderFactoryImpl.newInstance();
|
110 |
DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
|
111 |
xmlDoc = docBuilder.newDocument(); |
112 |
} catch(Exception e) { |
113 |
System.out.println(e);
|
114 |
} |
115 |
|
116 |
generalTag = xmlDoc.createElement("GeoPoints");
|
117 |
xmlDoc.appendChild(generalTag); |
118 |
|
119 |
createXMLFLyrGeoRasterNode(lyrPoints.getLyrGeoRaster()); |
120 |
|
121 |
for(int i=0;i<geoPointList.size();i++) |
122 |
createXMLGeoPointNode((GeoPoint)(geoPointList.get(i)), i); |
123 |
|
124 |
|
125 |
XML2File(Document2Text(), file); |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Crea el fichero Ascii con la lista de puntos y la salva a disco
|
130 |
* @param file
|
131 |
*/
|
132 |
public void saveAsciiPointList(String file){ |
133 |
this.geoPointList = lyrPoints.getListPoint();
|
134 |
for(int i=0;i<geoPointList.size();i++){ |
135 |
//TODO: FALTA IMPLEMENTAR LA EXPORTACI?N DE LA TABLA
|
136 |
} |
137 |
} |
138 |
//****************************************************
|
139 |
|
140 |
/**
|
141 |
* Aplica una transformaci?n al extent dependiendo de si el extent de la imagen
|
142 |
* original ha cambiado o no. Si la capa FLyrGeoRaster cargada tiene un extent
|
143 |
* distinto al que se ha salvado en el fichero de puntos esto significa que el
|
144 |
* extent de la miniimagen que tiene los puntos relativos a las coordenadas de la
|
145 |
* imagen en pixels ha de sufrir un desplazamiento.
|
146 |
* @param imgExtent Extent de la imagen
|
147 |
* @param miniExtent ViewPor del miniextent a transformar
|
148 |
* @return ViewPort ViewPort del miniextent transformado
|
149 |
*/
|
150 |
private ViewPort transformMiniExtent(Rectangle2D imgExtent, ViewPort miniExtent){ |
151 |
if( lastViewPort[0] != imgExtent.getMinX() || |
152 |
lastViewPort[1] != imgExtent.getMinY() ||
|
153 |
lastViewPort[2] != imgExtent.getWidth() ||
|
154 |
lastViewPort[3] != imgExtent.getHeight()){
|
155 |
Rectangle2D r = new Rectangle2D.Double(); |
156 |
r.setRect( miniExtent.getExtent().getMinX() - (lastViewPort[0] - imgExtent.getMinX()),
|
157 |
miniExtent.getExtent().getMinY() - (lastViewPort[1] - imgExtent.getMinY()),
|
158 |
miniExtent.getExtent().getWidth(), |
159 |
miniExtent.getExtent().getHeight()); |
160 |
miniExtent.setExtent(r); |
161 |
} |
162 |
return miniExtent;
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* Aplica una transformaci?n al centro del extent dependiendo de si el extent de la imagen
|
167 |
* original ha cambiado o no.
|
168 |
*/
|
169 |
private Point2D transformCenter(Rectangle2D imgExtent, Point2D center){ |
170 |
if( lastViewPort[0] != imgExtent.getMinX() || |
171 |
lastViewPort[1] != imgExtent.getMinY() ||
|
172 |
lastViewPort[2] != imgExtent.getWidth() ||
|
173 |
lastViewPort[3] != imgExtent.getHeight()){
|
174 |
Point2D c = new Point2D.Double(); |
175 |
c.setLocation(center.getX() - (lastViewPort[0] - imgExtent.getMinX()),
|
176 |
center.getY() - (lastViewPort[1] - imgExtent.getMinY()));
|
177 |
return c;
|
178 |
} |
179 |
return center;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* Obtiene el valor del extent de la imagen obtenido desde un nodo
|
184 |
* XML. A partir de este valor obtenido crea un punto en la capa.
|
185 |
*/
|
186 |
private double[] processFlyrGeoRasterNodeValue(NodeList nl){ |
187 |
double[] res = null; |
188 |
for(int j=0;j<nl.getLength();j++){ |
189 |
Node geoNode = nl.item(j); |
190 |
if(geoNode.getNodeName().equals("ViewPort")){ |
191 |
res = new double[4]; |
192 |
NodeList vpChildNodes = geoNode.getChildNodes(); |
193 |
for(int i=0;i<vpChildNodes.getLength();i++){ |
194 |
Node vpNode = vpChildNodes.item(i); |
195 |
if(vpNode.getNodeName().equals("Extent")){ |
196 |
NodeList extentChildNodes = vpNode.getChildNodes(); |
197 |
for(int k=0;k<extentChildNodes.getLength();k++){ |
198 |
Node extentNode = extentChildNodes.item(k); |
199 |
if(extentNode.getNodeName().equals("X")) |
200 |
res[0] = Double.valueOf(extentNode.getFirstChild().getNodeValue()).doubleValue(); |
201 |
if(extentNode.getNodeName().equals("Y")) |
202 |
res[1] = Double.valueOf(extentNode.getFirstChild().getNodeValue()).doubleValue(); |
203 |
if(extentNode.getNodeName().equals("Width")) |
204 |
res[2] = Double.valueOf(extentNode.getFirstChild().getNodeValue()).doubleValue(); |
205 |
if(extentNode.getNodeName().equals("Height")) |
206 |
res[3] = Double.valueOf(extentNode.getFirstChild().getNodeValue()).doubleValue(); |
207 |
} |
208 |
} |
209 |
} |
210 |
} |
211 |
} |
212 |
return res;
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* Obtiene el valor de un punto georeferenciado obtenido desde un nodo
|
217 |
* XML. A partir de este valor obtenido crea un punto en la capa.
|
218 |
*/
|
219 |
private void processGeoPointNodeValue(NodeList nl){ |
220 |
Point2D leftCenter = null, rightCenter = null; |
221 |
ViewPort leftViewPort = null, rightViewPort = null; |
222 |
double pX = 0D, pY = 0D, mX = 0D, mY = 0D; |
223 |
boolean active = false; |
224 |
for(int j=0;j<nl.getLength();j++){ |
225 |
Node geoNode = nl.item(j); |
226 |
if(geoNode.getNodeName().equals("PixelX")) |
227 |
pX = Double.valueOf(geoNode.getFirstChild().getNodeValue()).doubleValue();
|
228 |
if(geoNode.getNodeName().equals("PixelY")) |
229 |
pY = Double.valueOf(geoNode.getFirstChild().getNodeValue()).doubleValue();
|
230 |
if(geoNode.getNodeName().equals("MapX")) |
231 |
mX = Double.valueOf(geoNode.getFirstChild().getNodeValue()).doubleValue();
|
232 |
if(geoNode.getNodeName().equals("MapY")) |
233 |
mY = Double.valueOf(geoNode.getFirstChild().getNodeValue()).doubleValue();
|
234 |
if(geoNode.getNodeName().equals("Active")) |
235 |
active = Boolean.valueOf(geoNode.getFirstChild().getNodeValue()).booleanValue();
|
236 |
if(geoNode.getNodeName().equals("LeftCenterPoint")) |
237 |
leftCenter = processCenterPoint(geoNode.getChildNodes()); |
238 |
if(geoNode.getNodeName().equals("RightCenterPoint")) |
239 |
rightCenter = processCenterPoint(geoNode.getChildNodes()); |
240 |
if(geoNode.getNodeName().equals("LeftViewPort")) |
241 |
leftViewPort = processViewPort(geoNode.getChildNodes()); |
242 |
if(geoNode.getNodeName().equals("RightViewPort")) |
243 |
rightViewPort = processViewPort(geoNode.getChildNodes()); |
244 |
} |
245 |
|
246 |
Point2D p = new Point2D.Double(); |
247 |
p.setLocation(pX, pY); |
248 |
Point2D m = new Point2D.Double(); |
249 |
m.setLocation(mX, mY); |
250 |
|
251 |
lyrPoints.getPointManager().newEmptyPoint(); |
252 |
View theView = null; |
253 |
try{
|
254 |
theView = (View)PluginServices.getMDIManager().getActiveView();
|
255 |
}catch(ClassCastException exc){ |
256 |
return;
|
257 |
} |
258 |
int pos = lyrPoints.getCountPoints() -1; |
259 |
try{
|
260 |
leftViewPort = transformMiniExtent(lyrPoints.getLyrGeoRaster().getFullExtent(), leftViewPort); |
261 |
leftCenter = transformCenter(lyrPoints.getLyrGeoRaster().getFullExtent(), leftCenter); |
262 |
}catch(DriverException ex){}
|
263 |
lyrPoints.setPointActive(pos, active); |
264 |
lyrPoints.setLeftCenterPoint(pos,leftCenter); |
265 |
lyrPoints.setRightCenterPoint(pos, rightCenter); |
266 |
lyrPoints.setLeftViewPort(pos, leftViewPort); |
267 |
lyrPoints.setRightViewPort(pos, rightViewPort); |
268 |
lyrPoints.getPointManager().updateData(pos + 1, p, m, lyrPoints.getPointManager().getDialog(), theView);
|
269 |
|
270 |
if(lyrPoints.getCountPoints() > 0){ |
271 |
GeoreferencingDialog grd = lyrPoints.getPointManager().getDialog(); |
272 |
grd.getConectorPanel().getDataPointsTabPanel(). |
273 |
getSelectPointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints()); |
274 |
grd.getConectorPanel().getDataPointsTabPanel(). |
275 |
getTablePointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints()); |
276 |
lyrPoints.getPointManager().selectPoint(0, grd);
|
277 |
} |
278 |
//lyrPoints.addPoint(p, m);
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* Procesa un nodo correspondiente a un extent
|
283 |
* @param nodeList Lista de nodos
|
284 |
* @return Rectangle2D
|
285 |
*/
|
286 |
private Rectangle2D processExtent(NodeList nodeList){ |
287 |
Rectangle2D r = new Rectangle2D.Double(); |
288 |
double x = 0D, y = 0D, width = 0D, height = 0D; |
289 |
for(int j=0;j<nodeList.getLength();j++){ |
290 |
Node node = nodeList.item(j); |
291 |
if(node.getNodeName().equals("X")) |
292 |
x = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
|
293 |
if(node.getNodeName().equals("Y")) |
294 |
y = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
|
295 |
if(node.getNodeName().equals("Width")) |
296 |
width = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
|
297 |
if(node.getNodeName().equals("Height")) |
298 |
height = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
|
299 |
} |
300 |
r.setRect(x, y, width, height); |
301 |
return r;
|
302 |
} |
303 |
|
304 |
/**
|
305 |
* Procesa un nodo correspondiente a la dimension de un viewPort
|
306 |
* @param nodeList Lista de nodos
|
307 |
* @return Rectangle2D
|
308 |
*/
|
309 |
private Dimension processImageSize(NodeList nodeList){ |
310 |
Dimension d = new Dimension(); |
311 |
double x = 0D, y = 0D; |
312 |
for(int j=0;j<nodeList.getLength();j++){ |
313 |
Node node = nodeList.item(j); |
314 |
if(node.getNodeName().equals("Width")) |
315 |
x = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
|
316 |
if(node.getNodeName().equals("Height")) |
317 |
y = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
|
318 |
} |
319 |
d.setSize(x, y); |
320 |
return d;
|
321 |
} |
322 |
|
323 |
/**
|
324 |
* Procesa el nodo correspondiente a un viewport de una mini imagen
|
325 |
* @param nodeList Lista de nodos
|
326 |
* @return ViewPort obtenido
|
327 |
*/
|
328 |
private ViewPort processViewPort(NodeList nodeList){
|
329 |
ViewPort vp = new ViewPort(null); |
330 |
for(int j=0;j<nodeList.getLength();j++){ |
331 |
Node node = nodeList.item(j); |
332 |
if(node.getNodeName().equals("Projection")) |
333 |
vp.setProjection(ProjectionPool.get(node.getFirstChild().getNodeValue())); |
334 |
if(node.getNodeName().equals("Extent")) |
335 |
vp.setExtent(processExtent(node.getChildNodes())); |
336 |
if(node.getNodeName().equals("Dimension")) |
337 |
vp.setImageSize(processImageSize(node.getChildNodes())); |
338 |
} |
339 |
vp.setScale(); |
340 |
return vp;
|
341 |
} |
342 |
|
343 |
/**
|
344 |
* Procesa un node correspondiente a un punto central de una
|
345 |
* mini imagen
|
346 |
* @param nodeList Lista de elementos del nodo centro
|
347 |
* @return Punto obtenido
|
348 |
*/
|
349 |
private Point2D processCenterPoint(NodeList nodeList){ |
350 |
Point2D p = new Point2D.Double(); |
351 |
double x = 0D, y = 0D; |
352 |
for(int j=0;j<nodeList.getLength();j++){ |
353 |
Node node = nodeList.item(j); |
354 |
if(node.getNodeName().equals("X")) |
355 |
x = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
|
356 |
if(node.getNodeName().equals("Y")) |
357 |
y = Double.valueOf(node.getFirstChild().getNodeValue()).doubleValue();
|
358 |
} |
359 |
p.setLocation(x, y); |
360 |
return p;
|
361 |
} |
362 |
|
363 |
//****************************************************
|
364 |
|
365 |
/**
|
366 |
* Crea un elemento simple xml de la forma <elem>texNode</elem>
|
367 |
* a?adiendoselo al elemento padre pasado por par?metro
|
368 |
* @param parent Elemento padre del XML
|
369 |
* @param elem tag
|
370 |
* @param textNode valor
|
371 |
*/
|
372 |
private void createSimpleElement(Element parent, String elem, String textNode){ |
373 |
Element itemlevel1 = null; |
374 |
itemlevel1 = xmlDoc.createElement(elem); |
375 |
itemlevel1.appendChild(xmlDoc.createTextNode(textNode)); |
376 |
parent.appendChild(itemlevel1); |
377 |
} |
378 |
|
379 |
/**
|
380 |
* Crear un bloque que representa un viewport
|
381 |
* @param parent Elemento padre del XML
|
382 |
* @param elem tag
|
383 |
* @param values lista de valores
|
384 |
*/
|
385 |
private void createViewPortNode(Element parent, String elem, String[] values){ |
386 |
Element itemlevel1 = null; |
387 |
Element itemlevel2 = null; |
388 |
itemlevel1 = xmlDoc.createElement(elem); |
389 |
createSimpleElement(itemlevel1, "Projection", values[6]); |
390 |
itemlevel2 = xmlDoc.createElement("Extent");
|
391 |
createSimpleElement(itemlevel2, "X", values[0]); |
392 |
createSimpleElement(itemlevel2, "Y", values[1]); |
393 |
createSimpleElement(itemlevel2, "Width", values[2]); |
394 |
createSimpleElement(itemlevel2, "Height", values[3]); |
395 |
itemlevel1.appendChild(itemlevel2); |
396 |
itemlevel2 = xmlDoc.createElement("Dimension");
|
397 |
createSimpleElement(itemlevel2, "Width", values[4]); |
398 |
createSimpleElement(itemlevel2, "Height", values[5]); |
399 |
itemlevel1.appendChild(itemlevel2); |
400 |
parent.appendChild(itemlevel1); |
401 |
} |
402 |
|
403 |
/**
|
404 |
* Convierte la capa a georreferenciar a un elemento XML que ser? a?adidoo al
|
405 |
* documento.
|
406 |
* @param lyrGeo Capa a georreferenciar
|
407 |
*/
|
408 |
private void createXMLFLyrGeoRasterNode(FLyrGeoRaster lyrGeo) { |
409 |
Element xmlGeoPoint;
|
410 |
xmlGeoPoint = xmlDoc.createElement("FLyrGeoRaster");
|
411 |
generalTag.appendChild(xmlGeoPoint); |
412 |
xmlGeoPoint.setAttribute("Name", lyrGeo.getName());
|
413 |
String[] vpData = {String.valueOf(lyrGeo.getMinX()), |
414 |
String.valueOf(lyrGeo.getMinY()),
|
415 |
String.valueOf(lyrGeo.getWidth()),
|
416 |
String.valueOf(lyrGeo.getHeight()),
|
417 |
String.valueOf(lyrGeo.getImageWidth()),
|
418 |
String.valueOf(lyrGeo.getImageHeight()),
|
419 |
lyrGeo.getProjection().getAbrev()}; |
420 |
createViewPortNode(xmlGeoPoint, "ViewPort", vpData);
|
421 |
} |
422 |
|
423 |
/**
|
424 |
* Convierte un geopunto a un elemento XML que ser? a?adido al
|
425 |
* documento.
|
426 |
* @param geoPoint GeoPoint
|
427 |
* @param i Posici?n del punto en la lista
|
428 |
*/
|
429 |
private void createXMLGeoPointNode(GeoPoint geoPoint, int i) { |
430 |
Element xmlGeoPoint;
|
431 |
Element itemlevel1;
|
432 |
|
433 |
xmlGeoPoint = xmlDoc.createElement("GeoPoint");
|
434 |
xmlGeoPoint.setAttribute("n", String.valueOf(i)); |
435 |
generalTag.appendChild(xmlGeoPoint); |
436 |
|
437 |
createSimpleElement(xmlGeoPoint, "PixelX", String.valueOf(geoPoint.pixelPoint.getX())); |
438 |
createSimpleElement(xmlGeoPoint, "PixelY", String.valueOf(geoPoint.pixelPoint.getY())); |
439 |
createSimpleElement(xmlGeoPoint, "MapX", String.valueOf(geoPoint.mapPoint.getX())); |
440 |
createSimpleElement(xmlGeoPoint, "MapY", String.valueOf(geoPoint.mapPoint.getY())); |
441 |
createSimpleElement(xmlGeoPoint, "Active", String.valueOf(geoPoint.active)); |
442 |
|
443 |
itemlevel1 = xmlDoc.createElement("LeftCenterPoint");
|
444 |
createSimpleElement(itemlevel1, "X", String.valueOf(geoPoint.leftCenterPoint.getX())); |
445 |
createSimpleElement(itemlevel1, "Y", String.valueOf(geoPoint.leftCenterPoint.getY())); |
446 |
xmlGeoPoint.appendChild(itemlevel1); |
447 |
|
448 |
itemlevel1 = xmlDoc.createElement("RightCenterPoint");
|
449 |
createSimpleElement(itemlevel1, "X", String.valueOf(geoPoint.rightCenterPoint.getX())); |
450 |
createSimpleElement(itemlevel1, "Y", String.valueOf(geoPoint.rightCenterPoint.getY())); |
451 |
xmlGeoPoint.appendChild(itemlevel1); |
452 |
|
453 |
String[] values1 = {String.valueOf(geoPoint.leftViewPort.getExtent().getX()), |
454 |
String.valueOf(geoPoint.leftViewPort.getExtent().getY()),
|
455 |
String.valueOf(geoPoint.leftViewPort.getExtent().getWidth()),
|
456 |
String.valueOf(geoPoint.leftViewPort.getExtent().getHeight()),
|
457 |
String.valueOf(geoPoint.leftViewPort.getImageWidth()),
|
458 |
String.valueOf(geoPoint.leftViewPort.getImageHeight()),
|
459 |
geoPoint.leftViewPort.getProjection().getAbrev()}; |
460 |
createViewPortNode(xmlGeoPoint, "LeftViewPort", values1);
|
461 |
|
462 |
String[] values2 = {String.valueOf(geoPoint.rightViewPort.getExtent().getX()), |
463 |
String.valueOf(geoPoint.rightViewPort.getExtent().getY()),
|
464 |
String.valueOf(geoPoint.rightViewPort.getExtent().getWidth()),
|
465 |
String.valueOf(geoPoint.rightViewPort.getExtent().getHeight()),
|
466 |
String.valueOf(geoPoint.rightViewPort.getImageWidth()),
|
467 |
String.valueOf(geoPoint.rightViewPort.getImageHeight()),
|
468 |
geoPoint.rightViewPort.getProjection().getAbrev()}; |
469 |
|
470 |
createViewPortNode(xmlGeoPoint, "RightViewPort", values2);
|
471 |
} |
472 |
|
473 |
//****************************************************
|
474 |
|
475 |
/**
|
476 |
* escribe a disco el texto XML
|
477 |
* @param textXML Texto XML
|
478 |
* @param fileName Nombre del fichero
|
479 |
*/
|
480 |
private void XML2File(String textXML, String fileName) { |
481 |
try {
|
482 |
OutputStream fout= new FileOutputStream(fileName); |
483 |
OutputStream bout= new BufferedOutputStream(fout); |
484 |
OutputStreamWriter out = new OutputStreamWriter(bout); |
485 |
out.write(textXML); |
486 |
out.flush(); |
487 |
out.close(); |
488 |
}catch (IOException e) { |
489 |
System.out.println(e.getMessage());
|
490 |
} |
491 |
} |
492 |
|
493 |
/**
|
494 |
* Convierte el objeto Document que contiene el XML construido a
|
495 |
* texto XML para que podamos salvarlo a disco.
|
496 |
* @return Cadena de texto XML
|
497 |
*/
|
498 |
private String Document2Text() { |
499 |
StringWriter strWriter = null; |
500 |
XMLSerializer xmlSerializer = null;
|
501 |
OutputFormat outFormat = null;
|
502 |
try {
|
503 |
xmlSerializer = new XMLSerializer();
|
504 |
strWriter = new StringWriter(); |
505 |
outFormat = new OutputFormat();
|
506 |
|
507 |
outFormat.setEncoding("ISO-8859-15");
|
508 |
outFormat.setIndenting(true);
|
509 |
outFormat.setIndent(4);
|
510 |
|
511 |
xmlSerializer.setOutputCharStream(strWriter); |
512 |
xmlSerializer.setOutputFormat(outFormat); |
513 |
xmlSerializer.serialize(xmlDoc); |
514 |
strWriter.close(); |
515 |
} catch (IOException ioEx) { |
516 |
System.out.println("Error : " + ioEx); |
517 |
} |
518 |
return strWriter.toString();
|
519 |
} |
520 |
|
521 |
//**********************End Methods***************************
|
522 |
} |