Revision 611

View differences:

org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.37/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.37</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.37/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.37/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.37/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.37/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.37/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.37/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.37/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.37</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.37/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.37/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.37/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.37/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();
39
		}
40
		if (href != null) {
41
			writer.writeStartElement(Kml2_1_Tags.ICON);
42
			writer.writeStartElement(Kml2_1_Tags.HREF);
43
			writer.writeValue(href);
44
			writer.writeEndElement();
45

  
46
			writer.writeEndElement();
47
		}
48

  
49
		
50
		writer.writeEndElement();
51

  
52
		
53
	}
54

  
55
	public float getHeading() {
56
		return heading;
57
	}
58

  
59
	public void setHeading(float heading) {
60
		this.heading = heading;
61
	}
62

  
63
	public String getHref() {
64
		return href;
65
	}
66

  
67
	public void setHref(String href) {
68
		this.href = href;
69
	}
70

  
71
}
72

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

  
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7

  
8
import org.gvsig.fmap.dal.exception.DataException;
9
import org.gvsig.fmap.dal.feature.Feature;
10
import org.gvsig.fmap.dal.feature.FeatureSet;
11
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
12
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
13
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
14
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
15
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
16
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
17
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
18
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IPictureMarkerSymbol;
19
import org.gvsig.tools.dispose.DisposableIterator;
20

  
21

  
22
public class StyleUtils {
23
    
24
    public static Map<ISymbol, KmlStyle> getSymbolStyles(
25
        FLyrVect vlayer,
26
        FeatureSet fset,
27
        boolean balloon,
28
        String[] flds) throws Exception {
29
        
30
        boolean preventMarker = false;
31

  
32
        IVectorLegend leg = (IVectorLegend) vlayer.getLegend();
33
        Map<ISymbol, KmlStyle> resp = new HashMap<ISymbol, KmlStyle>();
34
        
35
        ISymbol defaultSym = leg.getDefaultSymbol();
36
        KmlStyle defaultStyle = getStyle(defaultSym);
37
        if (defaultSym != null && defaultStyle != null) {
38
            /*
39
             * This is used to set an empty icon style because
40
             * the geometry is not originally a point or multipoint 
41
             */
42
            preventMarker = !(defaultStyle instanceof KmlIconStyle);
43
            KmlCompoundStyle cs = new KmlCompoundStyle(); 
44
            cs.addStyle(defaultStyle);
45
            if (balloon) {
46
                // Not used, see javadoc of KmlBalloonStyle 
47
                // cs.addStyle(new KmlBalloonStyle(flds, "balloonStyle"));
48
            }
49
            if (preventMarker) {
50
                cs.addStyle(new KmlIconStyle());
51
            }
52
            cs.setId("defaultStyle");
53
            resp.put(defaultSym, cs);
54
        }
55
        
56
        if (leg instanceof IClassifiedVectorLegend) {
57
            
58
            IClassifiedVectorLegend cLeg = (IClassifiedVectorLegend) leg;
59
            ISymbol[] symbolsAux = cLeg.getSymbols();
60
            if (fset == null || symbolsAux.length < fset.getSize()) {
61
                
62
                for (int i=0; i < symbolsAux.length; i++) {
63
                    ISymbol s = symbolsAux[i];
64
                    KmlStyle style = getStyle(s);
65
                    if (s != null && style != null) {
66
                        preventMarker = !(style instanceof KmlIconStyle);
67
                        KmlCompoundStyle cs = new KmlCompoundStyle(); 
68
                        cs.addStyle(style);
69
                        if (balloon) {
70
                            // Not used, see javadoc of KmlBalloonStyle 
71
                            // cs.addStyle(new KmlBalloonStyle(flds, "bs" + Integer.toString(i)));
72
                        }
73
                        if (preventMarker) {
74
                            cs.addStyle(new KmlIconStyle());
75
                        }
76
                        cs.setId(Integer.toString(i));
77
                        resp.put(s, cs);
78
                    }
79
                }
80
            } else {
81
                DisposableIterator diter = null;
82
                diter = fset.fastIterator();
83
                Feature feat = null;
84
                int ind = 0;
85
                while (diter.hasNext()) {
86
                    feat = (Feature) diter.next();
87
                    ISymbol s = leg.getSymbolByFeature(feat);
88
                    KmlStyle style = getStyle(s);
89
                    if (s != null && style != null) {
90
                        preventMarker = !(style instanceof KmlIconStyle);
91
                        KmlCompoundStyle cs = new KmlCompoundStyle(); 
92
                        cs.addStyle(style);
93
                        if (balloon) {
94
                            // Not used, see javadoc of KmlBalloonStyle 
95
                            // cs.addStyle(new KmlBalloonStyle(flds, "bs" + Integer.toString(ind)));
96
                        }
97
                        if (preventMarker) {
98
                            cs.addStyle(new KmlIconStyle());
99
                        }
100
                        cs.setId(Integer.toString(ind));
101
                        resp.put(s, cs);
102
                        ind++;
103
                    }
104
                }
105
            }
106
        }
107
        return resp;
108
    }
109

  
110
    /**
111
     * Returns null if it cannot be rendered in KML
112
     * 
113
     * @param s
114
     * @return
115
     */
116
    public static KmlStyle getStyle(ISymbol s) {
117
        
118
        if (s == null) {
119
            return null;
120
        }
121
        
122
        if (s instanceof IPictureMarkerSymbol) {
123
            IPictureMarkerSymbol pms = (IPictureMarkerSymbol) s;
124
            String str = pms.getSource().toString();
125
            if (str != null && str.indexOf("http") == 0) {
126
                KmlIconStyle icoStyle = new KmlIconStyle();
127
                icoStyle.setColor(((IMarkerSymbol) s).getColor());
128
                icoStyle.setHref(str);
129
                float angKml = (float) radToKmlDeg(((IMarkerSymbol) s).getRotation());
130
                icoStyle.setHeading(angKml);
131
                return icoStyle;
132
            } else {
133
                // Simple marker not supported
134
                return null;
135
            }
136
        }
137
        
138
        if (s instanceof ILineSymbol) {
139
            ILineSymbol lSym = (ILineSymbol) s;
140
            KmlLineStyle lStyle = new KmlLineStyle();
141
            lStyle.setColor(lSym.getColor());
142
            lStyle.setWidth((float) lSym.getLineWidth());
143
            return lStyle;
144
        }
145

  
146
        if (s instanceof IFillSymbol) {
147
            
148
            IFillSymbol fSym = (IFillSymbol) s;
149
            KmlCompoundStyle cStyle = new KmlCompoundStyle();
150
            KmlLineStyle lStyle = new KmlLineStyle();
151
            ILineSymbol lSym = fSym.getOutline();
152
            lStyle.setColor(lSym.getColor());
153
            lStyle.setWidth((float) lSym.getLineWidth());
154

  
155
            KmlPolygonStyle fStyle = new KmlPolygonStyle();
156
            fStyle.setColor(fSym.getFillColor());
157
            fStyle.setOutline(fSym.hasOutline());
158
            fStyle.setFill(fSym.hasFill());
159
            
160
            cStyle.addStyle(lStyle);
161
            cStyle.addStyle(fStyle);
162
            return cStyle;
163
        }
164
        // Not supported
165
        return null;
166
    }
167
    
168
    
169
    public static double kmlDegToRad(double angleDegree) {
170
        double deg = 90 - angleDegree;
171
        return Math.toRadians(deg);
172
    }
173
    
174
    public static double radToKmlDeg(double rad) {
175
        double angleDegree = Math.toDegrees(rad);
176
        double deg = 90 - angleDegree;
177
        if (deg >= 360) {
178
            deg = deg - 360;
179
        }
180
        if (deg < 0) {
181
            deg = deg + 360;
182
        }
183
        return deg;
184
    }    
185
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.37/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlColorStyle.java
1
package org.gvsig.gpe.exportto.kml.style;
2

  
3
import java.awt.Color;
4

  
5
public abstract class KmlColorStyle extends KmlStyle {
6
	protected Color color = new Color(220, 10, 20, 80);
7

  
8
	public Color getColor() {
9
		return color;
10
	}
11

  
12
	public void setColor(Color color) {
13
		this.color = color;
14
	}
15
}
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.37/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlLabelStyle.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
 * Labels are exported as features. Google Earth will render the attribute <name>
13
 * with this color.
14
 */
15
public class KmlLabelStyle extends KmlColorStyle {
16
	
17
	protected float scale = 1;
18

  
19
	public float getScale() {
20
		return scale;
21
	}
22

  
23
	public void setScale(float scale) {
24
		this.scale = scale;
25
	}
26

  
27
	@Override
28
	public void writeXml(IXmlStreamWriter writer) throws IOException {
29
		writer.writeStartElement(Kml2_1_Tags.LABEL_STYLE);
30

  
31
		writer.writeStartElement(Kml2_1_Tags.COLOR);
32
		writer.writeValue(KmlUtilsParser.fromColorToABGR(color));
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff