Revision 760

View differences:

org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
  <modelVersion>4.0.0</modelVersion>
4
  <artifactId>org.gvsig.gpe.exportto</artifactId>
5
  <packaging>pom</packaging>
6

  
7
  
8
  <parent>
9
      <groupId>org.gvsig</groupId>
10
      <artifactId>org.gvsig.gpe</artifactId>
11
      <version>2.1.58</version>
12
  </parent>
13
  
14

  
15
  <modules>
16
    <module>org.gvsig.gpe.exportto.kml</module>  
17
    <module>org.gvsig.gpe.exportto.generic</module>  
18
  </modules>
19
</project>
20

  
21

  
22

  
23

  
24

  
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.generic/src/main/java/org/gvsig/gpe/exportto/generic/util/CoordinatesSequencePoint.java
1
package org.gvsig.gpe.exportto.generic.util;
2

  
3
import java.io.IOException;
4

  
5
import org.gvsig.fmap.geom.primitive.Point;
6
import org.gvsig.gpe.lib.api.parser.ICoordinateIterator;
7
import org.gvsig.gpe.lib.api.writer.ICoordinateSequence;
8

  
9
public class CoordinatesSequencePoint implements
10
ICoordinateSequence, ICoordinateIterator {
11
    
12
	double[] points = null;
13
	int index = 0;
14

  
15

  
16
	public CoordinatesSequencePoint(Point point) {
17
	    
18
	    if (point.getDimension() == 3) {
19
            // 2dZ
20
	        this.points = new double[3];
21
	        points[0] = point.getX();
22
	        points[1] = point.getY();
23
	        points[2] = point.getCoordinateAt(2);
24
	        index = 3;
25
	    } else {
26
	        // 2d
27
	        this.points = new double[2];
28
	        points[0] = point.getX();
29
	        points[1] = point.getY();
30
	        index = 2;
31
	    }
32
	    
33
	}
34

  
35
	public int getSize() {
36
		return 1;
37
	}
38

  
39
	public ICoordinateIterator iterator() {
40
		return this;
41
	}
42

  
43
	public int getDimension() {
44
		return points.length;
45
	}
46

  
47
	public boolean hasNext() throws IOException {
48
		return (index > 0);
49
	}
50

  
51
	public void next(double[] buffer) throws IOException {
52
		buffer[0] = points[0];
53
		buffer[1] = points[1];
54
		if ((buffer.length == 3) && (points.length == 3)){
55
			buffer[2] = points[2];
56
		}
57
		index--;
58
	}
59
	
60
	
61
}
62

  
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.generic/src/main/java/org/gvsig/gpe/exportto/generic/util/CoordinatesSequenceBbox.java
1
package org.gvsig.gpe.exportto.generic.util;
2

  
3
import java.awt.geom.Rectangle2D;
4
import java.io.IOException;
5

  
6
import org.gvsig.gpe.lib.api.parser.ICoordinateIterator;
7
import org.gvsig.gpe.lib.api.writer.ICoordinateSequence;
8

  
9
public class CoordinatesSequenceBbox implements
10
ICoordinateSequence, ICoordinateIterator {
11
    
12
	Rectangle2D bbox = null;
13
	int index = 0;
14
	
15
	public CoordinatesSequenceBbox(Rectangle2D bbox){
16
		this.bbox = bbox;
17
	}
18
	
19
	public int getSize() {
20
		return 2;
21
	}
22

  
23
	public ICoordinateIterator iterator() {
24
		return this;
25
	}
26

  
27
	public int getDimension() {
28
		return 2;
29
	}
30

  
31
	public boolean hasNext() throws IOException {
32
		if (index <=1){
33
			return true;
34
		}
35
		return false;
36
	}
37

  
38
	public void next(double[] buffer) throws IOException {
39
		if (index == 0){
40
			buffer[0] = bbox.getMinX();
41
			buffer[1] = bbox.getMinY();
42
		}else if (index == 1){
43
			buffer[0] = bbox.getMaxX();
44
			buffer[1] = bbox.getMaxY();
45
		}
46
		index++;
47
	}
48

  
49
}
50

  
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.generic/src/main/java/org/gvsig/gpe/exportto/generic/util/CoordinatesSequenceGeneralPath.java
1
package org.gvsig.gpe.exportto.generic.util;
2

  
3
import java.awt.geom.PathIterator;
4
import java.io.IOException;
5

  
6
import org.gvsig.gpe.lib.api.parser.ICoordinateIterator;
7
import org.gvsig.gpe.lib.api.writer.ICoordinateSequence;
8

  
9
public class CoordinatesSequenceGeneralPath implements
10
ICoordinateSequence, ICoordinateIterator { 
11
    
12
	private PathIterator it = null;
13
	int size = 0;
14
	boolean hasMoreGeoemtries = true;
15
	
16
	public CoordinatesSequenceGeneralPath(PathIterator it) {
17
		super();
18
		this.it = it;
19
	}
20

  
21
	public int getSize() {
22
		return size;
23
	}
24
	
25
	public void initialize(){
26
		size = 0;
27
	}
28
	
29
	public boolean hasMoreGeometries(){
30
		return hasMoreGeoemtries;
31
	}
32
	
33
	public ICoordinateIterator iterator() {
34
		return this;
35
	}
36
	
37
	public int getDimension() {
38
		return 2;
39
	}
40
	
41
	public boolean hasNext() throws IOException {
42
		if (it.isDone()){
43
			hasMoreGeoemtries = false;
44
			return false;
45
		}
46
		double[] coords = new double[2];
47
		int type = it.currentSegment(coords);		
48
		/*
49
		if (type == PathIterator.SEG_CLOSE){
50
			hasMoreGeoemtries = false;
51
		}
52
		*/
53
		return ((type != PathIterator.SEG_MOVETO) || (size == 0));		
54
	}
55
	
56
	public void next(double[] buffer) throws IOException {
57
		it.currentSegment(buffer);		
58
		it.next();	
59
		size++;
60
	}
61
	
62
}
63

  
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.generic/src/main/java/org/gvsig/gpe/exportto/generic/util/GeometryToGPEWriter.java
1
package org.gvsig.gpe.exportto.generic.util;
2

  
3
import java.awt.geom.PathIterator;
4

  
5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
7

  
8
import org.gvsig.fmap.geom.Geometry;
9
import org.gvsig.fmap.geom.GeometryLocator;
10
import org.gvsig.fmap.geom.aggregate.MultiCurve;
11
import org.gvsig.fmap.geom.aggregate.MultiPoint;
12
import org.gvsig.fmap.geom.aggregate.MultiSurface;
13
import org.gvsig.fmap.geom.exception.CreateGeometryException;
14
import org.gvsig.fmap.geom.primitive.Curve;
15
import org.gvsig.fmap.geom.primitive.Envelope;
16
import org.gvsig.fmap.geom.primitive.Point;
17
import org.gvsig.fmap.geom.primitive.Surface;
18
import org.gvsig.gpe.lib.api.writer.IGPEWriterHandler;
19
import org.gvsig.tools.locator.LocatorException;
20

  
21

  
22
/**
23
 * 
24
 * Utility class to write gvSIG geometries in a GPE writer.
25
 * 
26
 * @author jldominguez (I have removed the reprojection methods/fields)
27
 */
28
public class GeometryToGPEWriter {
29
    
30
    private static Logger logger = LoggerFactory.getLogger(GeometryToGPEWriter.class);
31
    
32
	private IGPEWriterHandler writer = null;
33
	//To know if the geometry is multiple
34
	// private boolean isMultiple = false;
35
	//To reproject geometries
36
	/*
37
	private IProjection projOrig = null;
38
	private IProjection projDest = null;
39
	private ICoordTrans coordTrans = null;
40
	*/
41
	private String srs = null;
42

  
43
	public GeometryToGPEWriter(IGPEWriterHandler writer) {
44
		this.writer = writer;
45
	}
46

  
47
	
48
	
49
    public String getCrs() {
50
        return srs;
51
    }
52

  
53

  
54
    
55
    public void setCrs(String thesrs) {
56
        this.srs = thesrs;
57
    }
58

  
59

  
60
    /**
61
	 * It writes a geometry
62
	 * @param geom
63
	 * The geometry to write
64
	 * @param crs
65
	 * The coordinates reference system
66
	 */
67
	public void writeGeometry(Geometry geom, boolean addLabelPoint) {
68
	    
69
	    if (geom == null) {
70
	        logger.error("GPE Writer cannot write geometry.",
71
	            new Exception("Geometry is NULL"));
72
	        return;
73
	    }
74
	    // ====================================================
75
		if (geom instanceof MultiPoint) {
76
			writeMultiPoint((MultiPoint) geom);
77
			return;
78
		}
79
        if (geom instanceof MultiCurve) {
80
            writeMultiLine((MultiCurve) geom, addLabelPoint);
81
            return;
82
        }
83
        if (geom instanceof MultiSurface) {
84
            writeMultiPolygon((MultiSurface) geom, addLabelPoint);
85
            return;
86
        }
87
        // ====================================================
88
        if (geom instanceof Point) {
89
            writePoint((Point) geom);
90
            return;
91
        }
92
        if (geom instanceof Curve) {
93
            writeLine((Curve) geom, addLabelPoint);
94
            return;
95
        }
96
        if (geom instanceof Surface) {
97
            writePolygon((Surface) geom, addLabelPoint);
98
            return;
99
        }
100
        // ====================================================
101
        logger.error("GPE Writer cannot write geometry",
102
            new Exception("Unexpected geometry: " + geom.getClass().getName()));
103
	}
104

  
105

  
106

  
107

  
108
	/**
109
	 * Writes a point in 2D
110
	 * @param point
111
	 * The point to write
112
	 * @param crs
113
	 * The coordinates reference system
114
	 */
115
	private void writePoint(Point point) {
116
		writer.startPoint(null, new CoordinatesSequencePoint(point), srs);
117
		writer.endPoint();
118
	}
119

  
120
	/**
121
	 * Writes a multipoint in 2D
122
	 * @param point
123
	 * The point to write
124
	 * @param crs
125
	 * The coordinates reference system
126
	 */
127
	private void writeMultiPoint(MultiPoint multi){
128
		writer.startMultiPoint(null, srs);
129
		for (int i=0 ; i<multi.getPrimitivesNumber() ; i++) {
130
		    Point p = multi.getPointAt(i);
131
			writePoint(p);
132
		}
133
		writer.endMultiPoint();
134
	}
135

  
136
	/**
137
	 * Writes a line in 2D
138
	 * @param line
139
	 * The line to write
140
	 * @param crs
141
	 * The coordinates reference system
142
	 * @param geometries
143
	 * The parsed geometries
144
	 */
145
	private void writeLine(Curve curve, boolean addLabelPoint) {
146
	    
147
		boolean ismulti = isMultiple(curve.getPathIterator(null));
148
		/*
149
         * Start ===================================================
150
         */
151
        if (addLabelPoint) {
152
            Point po = null;
153
            try {
154
                po = getLabelPoint(curve.getPathIterator(null), curve.getEnvelope());
155
            } catch (Exception ex) {
156
                logger.info("While getting label point.", ex);
157
                return;
158
            }
159
            writer.startMultiGeometry(null, srs);
160
            CoordinatesSequencePoint pseq = new CoordinatesSequencePoint(po);
161
            writer.startPoint(null, pseq, srs);
162
            writer.endPoint();
163
        } else {
164
            if (ismulti) {
165
                writer.startMultiLineString(null, srs);
166
            }
167
        }		
168
        /*
169
         * Body ===================================================
170
         */
171
        CoordinatesSequenceGeneralPath sequence =
172
		    new CoordinatesSequenceGeneralPath(curve.getPathIterator(null));
173
		writer.startLineString(null, sequence, srs);
174
		writer.endLineString();
175
		if (ismulti) {
176
	        while (sequence.hasMoreGeometries()){
177
	            sequence.initialize();
178
	            writer.startLineString(null, sequence, srs);
179
	            writer.endLineString(); 
180
	        }
181
		}
182
		/*
183
         * End ===================================================
184
         */		
185
		if (addLabelPoint) {
186
            writer.endMultiGeometry();
187
        } else {
188
            if (ismulti) {
189
                writer.endMultiLineString();
190
            }
191
        }		
192
	}
193
	
194
	
195
    private void writeMultiLine(MultiCurve mcurve, boolean addLabelPoint) {
196
        
197
        if (addLabelPoint) {
198
            Point po = null;
199
            try {
200
                po = getLabelPoint(mcurve.getPathIterator(null), mcurve.getEnvelope());
201
            } catch (Exception exc) {
202
                logger.info("While getting label point.", exc);
203
                return;
204
            }
205
            writer.startMultiGeometry(null, srs);
206
            CoordinatesSequencePoint pseq = new CoordinatesSequencePoint(po);
207
            writer.startPoint(null, pseq, srs);
208
            writer.endPoint();            
209
        } else {
210
            writer.startMultiLineString(null, srs);
211
        }
212
        /*
213
         * Body =======================================
214
         */
215
        CoordinatesSequenceGeneralPath sequence =
216
            new CoordinatesSequenceGeneralPath(mcurve.getPathIterator(null));
217
        
218
        writer.startLineString(null, sequence, srs);
219
        writer.endLineString(); 
220
        while (sequence.hasMoreGeometries()){
221
            sequence.initialize();
222
            writer.startLineString(null, sequence, srs);
223
            writer.endLineString(); 
224
        }
225
        /*
226
         * End ======================================
227
         */
228
        if (addLabelPoint) {
229
            writer.endMultiGeometry();
230
        } else {
231
            writer.endMultiLineString();
232
        }
233
        
234
    }
235
	
236
	
237
	
238
	
239
	/**
240
	 * Writes a polygon in 2D
241
	 * @param polygon
242
	 * The polygon to write
243
	 * @param crs
244
	 * The coordinates reference system
245
	 * @param geometries
246
	 * The parsed geometries
247
	 */
248
	private void writePolygon(Surface surface, boolean addLabelPoint) {
249
	    
250
	    boolean ismulti = isMultiple(surface.getPathIterator(null));
251
	    CoordinatesSequenceGeneralPath sequence = null;
252
	    /*
253
         * Start ===================================================
254
         */
255
	    if (addLabelPoint) {
256
	        Point po = null;
257
	        try {
258
	            po = surface.getInteriorPoint();
259
	        } catch (Exception ex) {
260
	            logger.info("While getting label point.", ex);
261
	            return;
262
	        }
263
            writer.startMultiGeometry(null, srs);
264
	        CoordinatesSequencePoint pseq = new CoordinatesSequencePoint(po);
265
	        writer.startPoint(null, pseq, srs);
266
	        writer.endPoint();
267
	    } else {
268
	        if (ismulti) {
269
	            writer.startMultiPolygon(null, srs);
270
	        }
271
	    }
272
		/*
273
		 * Body ===================================================
274
		 */
275
		sequence = new CoordinatesSequenceGeneralPath(surface.getPathIterator(null));
276
		writer.startPolygon(null, sequence, srs);
277
		writer.endPolygon();
278
        if (ismulti) {
279
            while (sequence.hasMoreGeometries()){
280
                sequence.initialize();
281
                writer.startPolygon(null, sequence, srs);
282
                writer.endPolygon();
283
            }
284
        }
285
        /*
286
         * End ===================================================
287
         */
288
		if (addLabelPoint) {
289
		    writer.endMultiGeometry();
290
		} else {
291
		    if (ismulti) {
292
		        writer.endMultiPolygon();
293
		    }
294
		}
295
	}
296
	
297
	
298
    private Point getLabelPoint(PathIterator pathIterator, Envelope envelope) throws
299
    Exception {
300
        
301
        if (pathIterator == null || envelope == null) {
302
            throw new Exception("Null iterator or envelope");
303
        }
304
        
305
        double bestx = 0;
306
        double besty = 0;
307
        double cx = envelope.getCenter(0);
308
        double cy = envelope.getCenter(1);
309
        double dist = Double.MAX_VALUE;
310
        double auxdist = 0;
311
        
312
        double[] coords = new double[6];
313
        while (!pathIterator.isDone()) {
314
            pathIterator.currentSegment(coords);
315
            auxdist = getDist2(cx, cy, coords[0], coords[1]);
316
            if (auxdist < dist) {
317
                dist = auxdist;
318
                bestx = coords[0];
319
                besty = coords[1];
320
            }
321
            pathIterator.next();
322
        }
323
        Point resp = GeometryLocator.getGeometryManager().createPoint(
324
            bestx, besty, Geometry.SUBTYPES.GEOM2D);
325
        return resp;
326
    }
327
    
328
    
329
    private Point getLabelPoint(MultiSurface msurf) throws Exception {
330
        
331
        if (msurf == null) {
332
            throw new Exception("Surface is Null");
333
        }
334
        
335
        int n = msurf.getPrimitivesNumber();
336
        Surface surf = null;
337
        Surface bigsurf = null;
338
        double importance = 0;
339
        double auximportance = 0;
340
        Envelope env = null;
341
        long nverts = 0;
342
        for (int i=0; i<n; i++) {
343
            surf = (Surface) msurf.getPrimitiveAt(i);
344
            nverts = surf.getNumVertices();
345
            env = surf.getEnvelope();
346
            auximportance = nverts * env.getLength(0) * env.getLength(1);
347
            if (auximportance >= importance) {
348
                importance = auximportance;
349
                bigsurf = surf;
350
            }
351
        }
352
        if (bigsurf != null) {
353
            return bigsurf.getInteriorPoint();
354
        } else {
355
            return msurf.getInteriorPoint();
356
        }
357
    }
358

  
359
    /**
360
     * Returns (dist ^ 2) between points a and b
361
     * @param ax
362
     * @param ay
363
     * @param bx
364
     * @param by
365
     * @return
366
     */
367
    private double getDist2(
368
        double ax, double ay,
369
        double bx, double by) {
370
        
371
        double dx = bx - ax; 
372
        double dy = by - ay;
373
        return (dx * dx) + (dy * dy); 
374
    }
375

  
376

  
377

  
378
    private void writeMultiPolygon(MultiSurface msurface, boolean addLabelPoint) {
379
        
380
        if (addLabelPoint) {
381
            Point po = null;
382
            try {
383
                po = getLabelPoint(msurface);
384
            } catch (Exception ex) {
385
                logger.info("While getting label point.", ex); 
386
                return;
387
            }
388
            
389
            writer.startMultiGeometry(null, srs);
390
            CoordinatesSequencePoint pseq = new CoordinatesSequencePoint(po);
391
            writer.startPoint(null, pseq, srs);
392
            writer.endPoint();     
393
        } else {
394
            writer.startMultiPolygon(null, srs);
395
        }
396
        /*
397
         * Body ==============================================
398
         */
399
        CoordinatesSequenceGeneralPath sequence =
400
            new CoordinatesSequenceGeneralPath(msurface.getPathIterator(null));
401
        writer.startPolygon(null, sequence, srs);
402
        writer.endPolygon();    
403
        while (sequence.hasMoreGeometries()){
404
            sequence.initialize();
405
            writer.startPolygon(null, sequence, srs);
406
            writer.endPolygon();
407
        }
408
        /*
409
         * End ==============================================
410
         */
411
        if (addLabelPoint) {
412
            writer.endMultiGeometry();
413
        } else {
414
            writer.endMultiPolygon();
415
        }
416
        
417
    }	
418
	
419
	/**
420
	 * Return if the geometry is multiple	
421
	 * @param path
422
	 * @return
423
	 */
424
	public boolean isMultiple(PathIterator path){
425
		double[] coords = new double[2];
426
		int type = 0;
427
		int numGeometries = 0;
428
		while (!path.isDone()){
429
			type = path.currentSegment(coords);
430
			 switch (type) {
431
			 	case PathIterator.SEG_MOVETO:
432
			 		numGeometries++;
433
			 		if (numGeometries == 2){
434
			 			return true;
435
			 		}
436
			 		break;
437
			 	default:
438
			 		break;
439
			 }
440
			 path.next();
441
		}
442
		return false;
443
	}
444

  
445

  
446

  
447

  
448

  
449

  
450

  
451

  
452

  
453

  
454

  
455

  
456

  
457

  
458

  
459
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.generic/src/main/java/org/gvsig/gpe/exportto/generic/ExporttoGPEGenericLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gpe.exportto.generic;
25

  
26
import org.gvsig.gpe.lib.api.GPELibrary;
27
import org.gvsig.tools.library.AbstractLibrary;
28
import org.gvsig.tools.library.LibraryException;
29

  
30
/**
31
 * Library with common things to be used by
32
 * GPE export libraries
33
 * 
34
 * @author gvSIG Team
35
 * @version $Id$
36
 */
37
public class ExporttoGPEGenericLibrary extends AbstractLibrary {
38

  
39
    public void doRegistration() {
40
        require(GPELibrary.class);
41
    }
42

  
43
    protected void doInitialize() throws LibraryException {
44
        // Nothing to do
45
    }
46

  
47
    protected void doPostInitialize() throws LibraryException {
48
        
49
    }
50

  
51
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.generic/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.gpe.exportto.generic.ExporttoGPEGenericLibrary
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.generic/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
  <modelVersion>4.0.0</modelVersion>
4
  <artifactId>org.gvsig.gpe.exportto.generic</artifactId>
5
  <packaging>jar</packaging>
6
  <name>${project.artifactId}</name>
7
  
8
  <parent>
9
    <groupId>org.gvsig</groupId>
10
    <artifactId>org.gvsig.gpe.exportto</artifactId>
11
    <version>2.1.58</version>
12
  </parent>
13

  
14
  <dependencies>
15
  
16
    <dependency>
17
      <groupId>org.gvsig</groupId>
18
      <artifactId>org.gvsig.gpe.lib.api</artifactId>
19
      <scope>compile</scope>
20
    </dependency>
21
    
22
    <dependency>
23
        <groupId>org.gvsig</groupId>
24
        <artifactId>org.gvsig.tools.lib</artifactId>
25
        <scope>compile</scope>
26
    </dependency>
27

  
28
    <dependency>
29
        <groupId>org.gvsig</groupId>
30
        <artifactId>org.gvsig.fmap.geometry.api</artifactId>    
31
        <scope>compile</scope>        
32
    </dependency>
33

  
34
  </dependencies>
35
</project>
36

  
37

  
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/ExporttoKMLProviderFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gpe.exportto.kml;
25

  
26
import org.cresques.cts.IProjection;
27

  
28
import org.gvsig.exportto.swing.ExporttoSwingManager;
29
import org.gvsig.exportto.swing.prov.file.AbstractExporttoFileProviderFactory;
30
import org.gvsig.fmap.dal.DataTypes;
31
import org.gvsig.fmap.dal.feature.FeatureStore;
32
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.dynobject.DynObject;
35
import org.gvsig.tools.service.ServiceException;
36
import org.gvsig.tools.service.spi.Provider;
37
import org.gvsig.tools.service.spi.ProviderServices;
38

  
39
/**
40
 * Factory of file {@link ExportoProvider} objects.
41
 * 
42
 * @author gvSIG Team
43
 * @version $Id$
44
 */
45
public class ExporttoKMLProviderFactory extends
46
    AbstractExporttoFileProviderFactory {
47

  
48
    private static final String PROVIDER_NAME = "KML";
49
    protected static final String PARAMETER_LAYER = "FLyrVect";
50

  
51
    public ExporttoKMLProviderFactory() {
52
        super(new int[] {
53
        		ExporttoSwingManager.VECTORIAL_TABLE_WITH_GEOMETRY
54
        });
55
    }
56
    
57
    public void initialize() {
58
        parametersDefinition =
59
            ToolsLocator.getDynObjectManager().createDynClass(getName(),
60
                getDescription());
61
        parametersDefinition.addDynField(PARAMETER_FEATURESTORE)
62
            .setType(DataTypes.OBJECT).setMandatory(true)
63
            .setClassOfValue(FeatureStore.class);
64
        parametersDefinition.addDynField(PARAMETER_PROJECTION)
65
            .setType(DataTypes.CRS).setMandatory(false);
66
        parametersDefinition.addDynField(PARAMETER_LAYER)
67
        .setType(DataTypes.OBJECT).setMandatory(false)
68
        .setClassOfValue(FLyrVect.class);
69
    }
70
    
71
    public Provider create(DynObject parameters, ProviderServices services)
72
        throws ServiceException {
73
        
74
        return new ExporttoKMLProvider(services,
75
            (FLyrVect) parameters.getDynValue(PARAMETER_LAYER));
76
    }
77

  
78
    public String getName() {
79
        return PROVIDER_NAME;
80
    }
81
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/panel/KMLOptionsPanel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gpe.exportto.kml.panel;
25

  
26
import java.awt.BorderLayout;
27
import java.awt.FlowLayout;
28
import java.awt.GridBagConstraints;
29
import java.awt.GridBagLayout;
30
import java.awt.Insets;
31
import java.util.ArrayList;
32

  
33
import javax.swing.JCheckBox;
34
import javax.swing.JComboBox;
35
import javax.swing.JComponent;
36
import javax.swing.JLabel;
37
import javax.swing.JPanel;
38

  
39
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41

  
42
import org.gvsig.exportto.swing.ExporttoSwingLocator;
43
import org.gvsig.exportto.swing.ExporttoSwingManager;
44
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException;
45
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel;
46
import org.gvsig.gpe.lib.api.writer.IGPEWriterHandler;
47
import org.gvsig.gpe.lib.spi.GPEProviderLocator;
48

  
49

  
50
/**
51
 * 
52
 * This addditional panel lets user choose KML
53
 * version and other options.
54
 * 
55
 * @author gvSIG Team
56
 * @version $Id$
57
 * 
58
 */
59
public class KMLOptionsPanel extends JPanel implements ExporttoSwingProviderPanel {
60

  
61
    private static final long serialVersionUID = -3278172717881233447L;
62

  
63
    private static final Logger LOG = LoggerFactory
64
        .getLogger(KMLOptionsPanel.class);
65
    
66
    private static final ExporttoSwingManager EXPORTTO_SWING_MANAGER =
67
        ExporttoSwingLocator.getSwingManager();
68

  
69
    private boolean offerLabels = false;
70
    private boolean offerReproj = false;
71
    
72
    private JCheckBox labelsChk = null;
73
    private JCheckBox reproChk = null;
74
    private JCheckBox balloonsChk = null;
75
    
76
    private JComboBox versionCombo = null;
77
    
78
    public KMLOptionsPanel(boolean ofrLabels, boolean ofrReproj) {
79
        super();
80
        offerLabels = ofrLabels;
81
        offerReproj = ofrReproj;
82
        init();
83
    }
84

  
85
    private void init() {
86
        
87
        this.setLayout(new BorderLayout());
88
        
89
        FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
90
        JPanel topPanel = new JPanel(fl);
91
        // ====================================================
92
        JPanel gridPanel = new JPanel();
93
        gridPanel.setLayout(new GridBagLayout());
94
        GridBagConstraints gbc = new GridBagConstraints();
95
        
96
        gbc.anchor = GridBagConstraints.WEST;
97
        gbc.insets = new Insets(3, 3, 3, 3);
98
        
99
        gbc.gridx = 0;
100
        gbc.gridy = 0;
101
        gbc.gridwidth = 3;
102
        gridPanel.add(new JLabel(EXPORTTO_SWING_MANAGER.getTranslation("_Choose_KML_version")), gbc);
103
        gbc.gridx = 3;
104
        gbc.gridwidth = 3;
105
        gridPanel.add(getVersionsCombo(), gbc);
106
        // =====================
107
        gbc.gridx = 0;
108
        gbc.gridy = 1;
109
        gbc.gridwidth = 1;
110
        gridPanel.add(getBalloonsCheckbox(), gbc);
111
        gbc.gridx = 1;
112
        gbc.gridwidth = 5;
113
        gridPanel.add(new JLabel(EXPORTTO_SWING_MANAGER.getTranslation(
114
                "_Show_attributes_in_balloon")), gbc);
115
        // =====================
116
        gbc.gridx = 0;
117
        gbc.gridy = 2;
118
        gbc.gridwidth = 1;
119
        gridPanel.add(getLabelsCheckbox(offerLabels), gbc);
120
        gbc.gridx = 1;
121
        gbc.gridwidth = 5;
122
        JLabel lbl_lbl = new JLabel(EXPORTTO_SWING_MANAGER.getTranslation("" +
123
        		"_Use_labels_Label_point_will_be_added_to_non_points"));
124
        lbl_lbl.setEnabled(offerLabels);
125
        gridPanel.add(lbl_lbl, gbc);
126
        // ====================================================
127
        gbc.gridx = 0;
128
        gbc.gridy = 3;
129
        gbc.gridwidth = 1;
130
        gridPanel.add(getReproCheckbox(offerReproj), gbc);
131
        gbc.gridx = 1;
132
        gbc.gridwidth = 5;
133
        JLabel rep_lbl = new JLabel(EXPORTTO_SWING_MANAGER.getTranslation(
134
            "_Force_to_EPSG_4326"));
135
        rep_lbl.setEnabled(offerReproj);
136
        gridPanel.add(rep_lbl, gbc);
137
        // ====================================================
138
        topPanel.add(gridPanel);
139
        this.add(topPanel, BorderLayout.NORTH);
140
    }
141

  
142
    private JCheckBox getLabelsCheckbox(boolean enabled) {
143
        
144
        if (labelsChk == null) {
145
            labelsChk = new JCheckBox("");
146
            labelsChk.setSelected(false);
147
            labelsChk.setEnabled(enabled);
148
        }
149
        return labelsChk;
150
    }
151
    
152
    private JCheckBox getReproCheckbox(boolean enabled) {
153
        
154
        if (reproChk == null) {
155
            reproChk = new JCheckBox("");
156
            reproChk.setSelected(true);
157
            reproChk.setEnabled(enabled);
158
        }
159
        return reproChk;
160
    }
161
    
162
    private JCheckBox getBalloonsCheckbox() {
163
        
164
        if (balloonsChk == null) {
165
            balloonsChk = new JCheckBox("");
166
            balloonsChk.setSelected(false);
167
        }
168
        return balloonsChk;
169
    }
170
    
171

  
172
    private JComboBox getVersionsCombo() {
173
        
174
        if (versionCombo == null) {
175
            versionCombo = new JComboBox();
176
            ArrayList list = GPEProviderLocator.getGPEProviderManager().getWriterHandlerByFormat("kml");
177
            IGPEWriterHandler item = null;
178
            String longn = null;
179
            String shortn = null;
180
            for (int i=0; i<list.size(); i++) {
181
                item = (IGPEWriterHandler) list.get(i);
182
                longn = item.getFormat();
183
                shortn = getShortWithVersion(longn);
184
                if (longn != null && shortn != null) {
185
                    versionCombo.addItem(new FormatListItem(longn, shortn));
186
                }
187
            }
188
        }
189
        return versionCombo;
190
    }
191

  
192
    public String getPanelTitle() {
193
        return EXPORTTO_SWING_MANAGER.getTranslation("_KML_options");
194
    }
195

  
196
    public boolean isValidPanel() throws ExporttoPanelValidationException {
197
        return getLongFormat() != null;
198
    }
199
    
200
    
201
    /**
202
     * Returns null if not valid format
203
     */
204
    private String getShortWithVersion(String fmt) {
205
        // Example: "text/xml; subtype=gml/2.1.2" => "gml"
206
        if (fmt == null) {
207
            return null;
208
        }
209
        String[] parts = fmt.split(";");
210
        String aux = "";
211
        if (parts.length > 1) {
212
            aux = parts[1].trim();
213
        } else {
214
            return null;
215
        }
216
        parts = aux.split("=");
217
        if (parts.length > 1) {
218
            aux = parts[1].trim();
219
            // Example: aux = "gml/2.1.2"
220
            aux = aux.replaceAll("/", " ");
221
            return aux.toUpperCase();
222
        } else {
223
            return null;
224
        }
225
    }    
226

  
227
    public void enterPanel() {
228
        
229
    }
230

  
231
    public JComponent asJComponent() {
232
        return this;
233
    }
234
    
235
    public class FormatListItem {
236
        
237
        private String longName = "";
238
        private String shortName = "";
239
        
240
        public FormatListItem(String longname, String shortname) {
241
            longName = longname;
242
            shortName = shortname;
243
        }
244
        
245
        public String toString() {
246
            return shortName;
247
        }
248
        
249
        public String getLongFormat() {
250
            return longName;
251
        }
252
    }
253
    
254
    // ==================================================
255
    // ==================================================
256
    
257
    public String getLongFormat() {
258
        Object obj = this.getVersionsCombo().getSelectedItem();
259
        if (obj instanceof FormatListItem) {
260
            return ((FormatListItem) obj).getLongFormat();
261
        } else {
262
            return null;
263
        }
264
    }
265
    
266
    public boolean useLabels() {
267
        return this.getLabelsCheckbox(false).isSelected();
268
    }
269

  
270
    public boolean useBalloons() {
271
        return this.getBalloonsCheckbox().isSelected();
272
    }
273
    
274
    public boolean mustReprojectToEpsg4326() {
275
        return this.getReproCheckbox(true).isSelected();
276
    }
277
    
278
    
279

  
280
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlCompoundStyle.java
1
package org.gvsig.gpe.exportto.kml.style;
2

  
3
import java.io.IOException;
4
import java.util.ArrayList;
5
import java.util.List;
6

  
7
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter;
8

  
9
public class KmlCompoundStyle extends KmlStyle {
10
	
11
	protected KmlIconStyle iconStyle = null;
12
	protected KmlLineStyle lineStyle = null;
13
	protected KmlPolygonStyle polygonStyle = null;
14
	protected KmlLabelStyle labelStyle = null;
15
	// protected KmlBalloonStyle balloonStyle = null;
16
	
17
	
18
	public void writeXml(IXmlStreamWriter writer) throws IOException {
19
		if (iconStyle != null)
20
			iconStyle.writeXml(writer);
21
		if (lineStyle != null)
22
			lineStyle.writeXml(writer);
23
		if (polygonStyle != null)
24
			polygonStyle.writeXml(writer);
25
		if (labelStyle != null)
26
			labelStyle.writeXml(writer);
27
		/*
28
        if (balloonStyle != null)
29
            balloonStyle.writeXml(writer);
30
            */
31
	}
32
	
33
	public void addStyles(List<KmlStyle> list) {
34
	    
35
	    if (list != null) {
36
	        for (int i=0; i<list.size(); i++) {
37
	            addStyle(list.get(i));
38
	        }
39
	    }
40
	}
41
	
42

  
43
	public List<KmlStyle> getStyles() {
44
        
45
	    List<KmlStyle> resp = new ArrayList<KmlStyle>();
46
	    if (iconStyle != null) {
47
	        resp.add(iconStyle);
48
	    }
49
        if (lineStyle != null) {
50
            resp.add(lineStyle);
51
        }
52
        if (polygonStyle != null) {
53
            resp.add(polygonStyle);
54
        }
55
        if (labelStyle != null) {
56
            resp.add(labelStyle);
57
        }
58
	    return resp;
59
    }
60
	
61
	
62
	public void addStyle(KmlStyle sty) {
63
	    if (sty instanceof KmlIconStyle) {
64
	        this.iconStyle = (KmlIconStyle) sty;
65
	        return;
66
	    }
67
        if (sty instanceof KmlLineStyle) {
68
            this.lineStyle = (KmlLineStyle) sty;
69
            return;
70
        }
71
        if (sty instanceof KmlPolygonStyle) {
72
            this.polygonStyle = (KmlPolygonStyle) sty;
73
            return;
74
        }
75
        if (sty instanceof KmlLabelStyle) {
76
            this.labelStyle = (KmlLabelStyle) sty;
77
            return;
78
        }
79
        if (sty instanceof KmlCompoundStyle) {
80
            this.addStyles(((KmlCompoundStyle) sty).getStyles()); 
81
            return;
82
        }
83
	}
84

  
85
	public KmlIconStyle getIconStyle() {
86
		return iconStyle;
87
	}
88

  
89
	public KmlLineStyle getLineStyle() {
90
		return lineStyle;
91
	}
92

  
93
	public KmlPolygonStyle getPolygonStyle() {
94
		return polygonStyle;
95
	}
96

  
97
	public KmlLabelStyle getLabelStyle() {
98
		return labelStyle;
99
	}
100
    
101
	/*
102
    public KmlBalloonStyle getBalloonStyle() {
103
        return balloonStyle;
104
    }
105
    */
106
}
107

  
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlBalloonStyle.java
1
package org.gvsig.gpe.exportto.kml.style;
2

  
3
import java.io.IOException;
4

  
5
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags;
6
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter;
7

  
8

  
9
/**
10
 * Balloon style to show when user clicks on marker.
11
 * Currently not used because CDDATA is not written properly
12
 * (writer escapes it)
13
 * 
14
 * @author jldominguez
15
 *
16
 */
17
public class KmlBalloonStyle extends KmlStyle {
18

  
19
    private String[] fields = new String[0];
20
    
21
    public KmlBalloonStyle(String[] flds, String id) {
22
        setId(id);
23
        if (flds != null) {
24
            fields = flds;
25
        }
26
    }
27
    
28
    public void writeXml(IXmlStreamWriter writer) throws IOException {
29
        
30
        writer.writeStartElement(Kml2_1_Tags.BALLOON_STYLE);
31
        writer.writeStartElement(Kml2_1_Tags.TEXT);
32

  
33
        // ====================================
34
        String cddata = "<![CDATA[";
35
        cddata = cddata + htmlTable();
36
        cddata = cddata + "]]>";
37
        // ====================================
38
        writer.writeValue(cddata);
39
        writer.writeEndElement();
40
        writer.writeEndElement();
41
        
42
        /*
43
  <Style id="golf-balloon-style">
44
    <BalloonStyle>
45
      <text>
46
        <![CDATA[
47
          <table>
48
          <tr><td>This is $[name]</td><td> : </td><td>This is $[name]</td></tr>
49
          <tr><td>This is hole $[holeNumber]</td><td> : </td><td>This is $[name]</td></tr>
50
          <tr><td>The par for this hole is $[holePar]</td><td> : </td><td>This is $[name]</td></tr>
51
          <tr><td>The yardage is $[holeYardage]</td><td> : </td><td><b>This is $[name]</b></td></tr>
52
          </table>
53
        ]]>
54
      </text>
55
    </BalloonStyle>
56
  </Style>
57
           */
58

  
59
        
60
        
61
    }
62

  
63
    private String htmlTable() {
64
        
65
        String resp = "<table>\n";
66
        String aux = null;
67
        String auxrep = null;
68
        for (int i=0; i<fields.length; i++) {
69
            aux = fields[i];
70
            auxrep = aux.replace(' ', '_');
71
            auxrep = "$[" + auxrep + "]";
72
            resp = resp + "<tr><td>" + aux + "</td><td> : </td><td><b>" + auxrep + "</b></td></tr>\n";
73
        }
74
        resp = resp + "</table>\n";
75
        return resp;
76
    }
77

  
78
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlLineStyle.java
1
package org.gvsig.gpe.exportto.kml.style;
2

  
3
import java.io.IOException;
4

  
5
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags;
6
import org.gvsig.gpe.prov.kml.utils.KmlUtilsParser;
7
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter;
8

  
9
public class KmlLineStyle extends KmlColorStyle {
10
	public float getWidth() {
11
		return width;
12
	}
13

  
14
	public void setWidth(float width) {
15
		this.width = width;
16
	}
17

  
18
	protected float width = 1;
19

  
20
	@Override
21
	public void writeXml(IXmlStreamWriter writer) throws IOException {
22
		writer.writeStartElement(Kml2_1_Tags.LINE_STYLE);
23
		
24
		writer.writeStartElement(Kml2_1_Tags.COLOR);
25
		writer.writeValue(KmlUtilsParser.fromColorToABGR(color));
26
		writer.writeEndElement();
27
		writer.writeStartElement(Kml2_1_Tags.WIDTH);
28
		writer.writeValue(width);		
29
		writer.writeEndElement();
30
		
31
		writer.writeEndElement();
32
	}
33

  
34

  
35
}
36

  
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlPolygonStyle.java
1
package org.gvsig.gpe.exportto.kml.style;
2

  
3
import java.io.IOException;
4

  
5
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags;
6
import org.gvsig.gpe.prov.kml.utils.KmlUtilsParser;
7
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter;
8

  
9
/**
10
 * @author Francisco Jos? Pe?arrubia (fjp@scolab.es)
11
 * 
12
 * To convert from a symbol to a polygon style we will need a PolygonStyle
13
 * and a LineStyle if the outline has some width or to specify the color
14
 * @see @KmlCompoundStyle
15
 */
16
public class KmlPolygonStyle extends KmlColorStyle {
17
	protected boolean fill = true;
18
	protected boolean outline;
19

  
20
	public boolean isFill() {
21
		return fill;
22
	}
23

  
24
	public void setFill(boolean fill) {
25
		this.fill = fill;
26
	}
27

  
28
	public boolean isOutline() {
29
		return outline;
30
	}
31

  
32
	public void setOutline(boolean outline) {
33
		this.outline = outline;
34
	}
35

  
36
	@Override
37
	public void writeXml(IXmlStreamWriter writer) throws IOException {
38
		writer.writeStartElement(Kml2_1_Tags.POLY_STYLE);
39

  
40
		writer.writeStartElement(Kml2_1_Tags.COLOR);
41
		writer.writeValue(KmlUtilsParser.fromColorToABGR(color));
42
		writer.writeEndElement();
43
		if (!fill) {
44
			writer.writeStartElement(Kml2_1_Tags.POLY_FILL);
45
			writer.writeValue(0);
46
			writer.writeEndElement();
47
		}
48
		if (outline) {
49
			writer.writeStartElement(Kml2_1_Tags.POLY_OUTLINE);
50
			writer.writeValue(1);
51
			writer.writeEndElement();
52
		}
53

  
54
		writer.writeEndElement();
55

  
56
	}
57

  
58
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.58/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlIconStyle.java
1
package org.gvsig.gpe.exportto.kml.style;
2

  
3
import java.io.IOException;
4

  
5
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags;
6
import org.gvsig.gpe.prov.kml.utils.KmlUtilsParser;
7
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter;
8

  
9
public class KmlIconStyle extends KmlColorStyle {
10
	
11
	protected float heading = 0;
12
	protected String href = null;
13
	protected float scale = 1;
14

  
15
	public float getScale() {
16
		return scale;
17
	}
18

  
19
	public void setScale(float scale) {
20
		this.scale = scale;
21
	}
22
	
23
	
24
	public void writeXml(IXmlStreamWriter writer) throws IOException {
25
		writer.writeStartElement(Kml2_1_Tags.ICON_STYLE);
26

  
27
		writer.writeStartElement(Kml2_1_Tags.COLOR);
28
		writer.writeValue(KmlUtilsParser.fromColorToABGR(color));
29
		writer.writeEndElement();
30
		
31
		writer.writeStartElement(Kml2_1_Tags.HEADING);
32
		writer.writeValue(heading);
33
		writer.writeEndElement();
34
		
35
		if (scale != 1) {
36
			writer.writeStartElement(Kml2_1_Tags.SCALE);
37
			writer.writeValue(scale);
38
			writer.writeEndElement();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff