Revision 11666

View differences:

trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/KmlTags.java
43 43
 *
44 44
 * $Id$
45 45
 * $Log$
46
 * Revision 1.8  2007-05-09 08:36:24  jorpiell
46
 * Revision 1.9  2007-05-15 12:37:45  jorpiell
47
 * Add multyGeometries
48
 *
49
 * Revision 1.8  2007/05/09 08:36:24  jorpiell
47 50
 * Add the bbox to the layer
48 51
 *
49 52
 * Revision 1.7  2007/05/08 09:28:17  jorpiell
......
96 99
	public static final String POLYGON = "Polygon";	
97 100
	public static final String OUTERBOUNDARYIS = "outerBoundaryIs";	
98 101
	public static final String INNERBOUNDARYIS = "innerBoundaryIs";	
102
	public static final String MULTIGEOMETRY = "MultiGeometry";
99 103
	
100 104
	public static final String DOCUMENT = "Document";
101 105
	public static final String FOLDER = "Folder";
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/bindings/PlaceMarketBinding.java
6 6
import org.gvsig.gpe.kml.KmlTags;
7 7
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException;
8 8
import org.gvsig.gpe.kml.reader.bindings.geometries.LineStringTypeBinding;
9
import org.gvsig.gpe.kml.reader.bindings.geometries.MultiGeometryBinding;
9 10
import org.gvsig.gpe.kml.reader.bindings.geometries.PointTypeBinding;
10 11
import org.gvsig.gpe.kml.reader.bindings.geometries.PolygonTypeBinding;
11 12
import org.gvsig.gpe.kml.reader.bindings.geometries.RegionBinding;
......
57 58
 *
58 59
 * $Id$
59 60
 * $Log$
60
 * Revision 1.1  2007-05-11 07:06:29  jorpiell
61
 * Revision 1.2  2007-05-15 12:37:45  jorpiell
62
 * Add multyGeometries
63
 *
64
 * Revision 1.1  2007/05/11 07:06:29  jorpiell
61 65
 * Refactoring of some package names
62 66
 *
63 67
 * Revision 1.5  2007/05/09 08:36:24  jorpiell
......
157 161
				}else if (tag.compareTo(KmlTags.POLYGON) == 0){
158 162
					Object polygon = PolygonTypeBinding.parse(parser, handler);
159 163
					handler.getContentHandler().addGeometryToFeature(polygon, feature);
164
				}else if (tag.compareTo(KmlTags.MULTIGEOMETRY) == 0){
165
					Object multiGeometry = MultiGeometryBinding.parse(parser, handler);
166
					handler.getContentHandler().addGeometryToFeature(multiGeometry, feature);
160 167
				}else if (tag.compareTo(KmlTags.REGION) == 0){
161 168
					Object bbox = RegionBinding.parse(parser, handler);
162 169
				}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/bindings/geometries/MultiGeometryBinding.java
1
package org.gvsig.gpe.kml.reader.bindings.geometries;
2

  
3
import java.io.IOException;
4
import java.util.Hashtable;
5

  
6
import org.gvsig.gpe.kml.GPEKmlParser;
7
import org.gvsig.gpe.kml.KmlTags;
8
import org.kxml2.io.KXmlParser;
9
import org.xmlpull.v1.XmlPullParser;
10
import org.xmlpull.v1.XmlPullParserException;
11

  
12
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
13
 *
14
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
29
 *
30
 * For more information, contact:
31
 *
32
 *  Generalitat Valenciana
33
 *   Conselleria d'Infraestructures i Transport
34
 *   Av. Blasco Ib??ez, 50
35
 *   46010 VALENCIA
36
 *   SPAIN
37
 *
38
 *      +34 963862235
39
 *   gvsig@gva.es
40
 *      www.gvsig.gva.es
41
 *
42
 *    or
43
 *
44
 *   IVER T.I. S.A
45
 *   Salamanca 50
46
 *   46005 Valencia
47
 *   Spain
48
 *
49
 *   +34 963163400
50
 *   dac@iver.es
51
 */
52
/* CVS MESSAGES:
53
 *
54
 * $Id$
55
 * $Log$
56
 * Revision 1.1  2007-05-15 12:37:45  jorpiell
57
 * Add multyGeometries
58
 *
59
 *
60
 */
61
/**
62
 * It parses a MultyGeometry tag. Example:
63
 * <p>
64
 * <pre>
65
 * <code>
66
 * &lt;MultiGeometry&gt;
67
 * &lt;Point gid="P6776"&gt;
68
 * &lt;coord&gt;&lt;X&gt;50.0&lt;/X&gt;&lt;Y&gt;50.0&lt;/Y&gt;&lt;/coord&gt;
69
 * &lt;/Point&gt;
70
 * &lt;Polygon gid="_877789"&gt;
71
 * &lt;outerBoundaryIs&gt;
72
 * &lt;LinearRing&gt;
73
 * &lt;coordinates&gt;0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0&lt;/coordinates&gt;
74
 * &lt;/LinearRing&gt;
75
 * &lt;/outerBoundaryIs&gt;
76
 * &lt;/Polygon&gt;
77
 * &lt;MultiGeometry&gt;
78
 * </code>
79
 * </pre>
80
 * </p> 
81
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
82
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#multigeometry
83
 */
84
public class MultiGeometryBinding {
85
	/**
86
	 * It parses the MultiGeometry tag
87
	 * @param parser
88
	 * The XML parser
89
	 * @param handler
90
	 * The GPE parser that contains the content handler and
91
	 * the error handler
92
	 * @return
93
	 * A multigeometry
94
	 * @throws XmlPullParserException
95
	 * @throws IOException
96
	 */
97
	public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException {
98
		boolean endFeature = false;
99
		int currentTag;
100
		Object multiGeometry = null;		
101
		
102
		String id = GeometryBinding.getID(parser, handler);
103
		
104
		multiGeometry = handler.getContentHandler().startMultiGeometry(id, KmlTags.DEFAULT_SRS);
105
		
106
		String tag = parser.getName();
107
		currentTag = parser.getEventType();
108

  
109
		while (!endFeature){
110
			switch(currentTag){
111
			case KXmlParser.START_TAG:
112
					if (tag.compareTo(KmlTags.POINT) == 0){
113
						Object point = PointTypeBinding.parse(parser, handler);
114
						handler.getContentHandler().addGeometryToMultiGeometry(point, multiGeometry);
115
					}else if (tag.compareTo(KmlTags.LINESTRING) == 0){
116
						Object lineString = LineStringTypeBinding.parse(parser, handler);
117
						handler.getContentHandler().addGeometryToMultiGeometry(lineString, multiGeometry);
118
					}if (tag.compareTo(KmlTags.POLYGON) == 0){
119
						Object polygon = PolygonTypeBinding.parse(parser, handler);
120
						handler.getContentHandler().addGeometryToMultiGeometry(polygon, multiGeometry);
121
					}
122
					break;
123
				case KXmlParser.END_TAG:
124
					if (tag.compareTo(KmlTags.MULTIGEOMETRY) == 0){						
125
						endFeature = true;	
126
						handler.getContentHandler().endMultiGeometry(multiGeometry);
127
					}
128
					break;
129
				case KXmlParser.TEXT:					
130
					
131
					break;
132
				}
133
				if (!endFeature){					
134
					currentTag = parser.next();
135
					tag = parser.getName();
136
				}
137
			}			
138
		return multiGeometry;	
139
	}
140
}
0 141

  
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/writer/geometries/MultiGeometryWriter.java
1
package org.gvsig.gpe.kml.writer.geometries;
2

  
3
import java.io.IOException;
4

  
5
import org.gvsig.gpe.GPEErrorHandler;
6
import org.gvsig.gpe.kml.KmlTags;
7
import org.gvsig.gpe.xml.writer.Writer;
8

  
9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10
 *
11
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
26
 *
27
 * For more information, contact:
28
 *
29
 *  Generalitat Valenciana
30
 *   Conselleria d'Infraestructures i Transport
31
 *   Av. Blasco Ib??ez, 50
32
 *   46010 VALENCIA
33
 *   SPAIN
34
 *
35
 *      +34 963862235
36
 *   gvsig@gva.es
37
 *      www.gvsig.gva.es
38
 *
39
 *    or
40
 *
41
 *   IVER T.I. S.A
42
 *   Salamanca 50
43
 *   46005 Valencia
44
 *   Spain
45
 *
46
 *   +34 963163400
47
 *   dac@iver.es
48
 */
49
/* CVS MESSAGES:
50
 *
51
 * $Id$
52
 * $Log$
53
 * Revision 1.1  2007-05-15 12:37:45  jorpiell
54
 * Add multyGeometries
55
 *
56
 *
57
 */
58
/**
59
 * It writes a MultyGeometry tag. Example:
60
 * <p>
61
 * <pre>
62
 * <code>
63
 * &lt;MultiGeometry&gt;
64
 * &lt;Point gid="P6776"&gt;
65
 * &lt;coord&gt;&lt;X&gt;50.0&lt;/X&gt;&lt;Y&gt;50.0&lt;/Y&gt;&lt;/coord&gt;
66
 * &lt;/Point&gt;
67
 * &lt;Polygon gid="_877789"&gt;
68
 * &lt;outerBoundaryIs&gt;
69
 * &lt;LinearRing&gt;
70
 * &lt;coordinates&gt;0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0&lt;/coordinates&gt;
71
 * &lt;/LinearRing&gt;
72
 * &lt;/outerBoundaryIs&gt;
73
 * &lt;/Polygon&gt;
74
 * &lt;MultiGeometry&gt;
75
 * </code>
76
 * </pre>
77
 * </p> 
78
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
79
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#multigeometry
80
 */
81
public class MultiGeometryWriter {
82
	/**
83
	 * It writes the MultiGeometry init tag and its value.
84
	 * @param writer
85
	 * Writer to write the labels
86
	 * @param id
87
	 * Point id
88
	 * @param longitude
89
	 * Longitude >= -180 and <= 180
90
	 * @param latitude
91
	 * Latitude >= -90 and <= 90
92
	 * @param altitude
93
	 * Meters above sea level
94
	 * @throws IOException
95
	 */
96
	public static void start(Writer writer, GPEErrorHandler errorHandler, String id) throws IOException{
97
		GeometriesWriter.startGeometry(writer, KmlTags.MULTIGEOMETRY, id);
98
	}
99
	
100
	/**
101
	 * It writes the MultiGeometry end tag
102
	 * @param writer
103
	 * Writer to write the labels
104
	 * @throws IOException
105
	 */
106
	public static void end(Writer writer, GPEErrorHandler errorHandler) throws IOException{
107
		GeometriesWriter.endGeometry(writer, KmlTags.MULTIGEOMETRY);
108
	}
109
}
0 110

  
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/writer/GPEKmlWriterHandler.java
1 1
package org.gvsig.gpe.kml.writer;
2 2

  
3
import java.io.BufferedInputStream;
4
import java.io.BufferedOutputStream;
5
import java.io.File;
6
import java.io.FileInputStream;
7
import java.io.FileNotFoundException;
8
import java.io.FileOutputStream;
9 3
import java.io.FileWriter;
10 4
import java.io.IOException;
11
import java.io.InputStream;
12
import java.util.zip.Adler32;
13
import java.util.zip.CheckedOutputStream;
14
import java.util.zip.ZipEntry;
15
import java.util.zip.ZipFile;
16
import java.util.zip.ZipOutputStream;
17 5

  
18
import org.gvsig.gpe.GPEErrorHandler;
19 6
import org.gvsig.gpe.gml.GMLTags;
20 7
import org.gvsig.gpe.kml.KmlTags;
21 8
import org.gvsig.gpe.kml.writer.features.DocumentWriter;
22 9
import org.gvsig.gpe.kml.writer.features.FolderWriter;
23 10
import org.gvsig.gpe.kml.writer.features.PlaceMarkWriter;
24 11
import org.gvsig.gpe.kml.writer.geometries.InnerBoundaryIs;
25
import org.gvsig.gpe.kml.writer.geometries.LatLonAltBoxWriter;
26
import org.gvsig.gpe.kml.writer.geometries.LatLonBoxWriter;
27 12
import org.gvsig.gpe.kml.writer.geometries.LineStringWriter;
28 13
import org.gvsig.gpe.kml.writer.geometries.LinearRingWriter;
14
import org.gvsig.gpe.kml.writer.geometries.MultiGeometryWriter;
29 15
import org.gvsig.gpe.kml.writer.geometries.PointWriter;
30 16
import org.gvsig.gpe.kml.writer.geometries.PolygonWriter;
31 17
import org.gvsig.gpe.kml.writer.geometries.RegionWriter;
32 18
import org.gvsig.gpe.xml.writer.GPEXmlWriterHandler;
33 19
import org.gvsig.gpe.xml.writer.Writer;
34
import org.xml.sax.InputSource;
35 20

  
36 21

  
37 22
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
......
78 63
 *
79 64
 * $Id$
80 65
 * $Log$
81
 * Revision 1.11  2007-05-09 08:36:24  jorpiell
66
 * Revision 1.12  2007-05-15 12:37:45  jorpiell
67
 * Add multyGeometries
68
 *
69
 * Revision 1.11  2007/05/09 08:36:24  jorpiell
82 70
 * Add the bbox to the layer
83 71
 *
84 72
 * Revision 1.10  2007/05/08 09:28:17  jorpiell
......
383 371
			getErrorHandler().addError(e);
384 372
		}		
385 373
	}
374
	
375
	/*
376
	 * (non-Javadoc)
377
	 * @see org.gvsig.gpe.writers.GPEWriterHandler#startMultiPoint(java.lang.String, java.lang.String)
378
	 */
379
	public void startMultiGeometry(String id, String srs) {
380
		try {
381
			MultiGeometryWriter.start(writer, getErrorHandler(), id);
382
		} catch (IOException e) {
383
			getErrorHandler().addError(e);
384
		}
385
	}
386
	
387
	/*
388
	 * (non-Javadoc)
389
	 * @see org.gvsig.gpe.writers.GPEWriterHandler#endMuliPoint()
390
	 */
391
	public void endMultiGeometry() {
392
		try {
393
			MultiGeometryWriter.end(writer, getErrorHandler());
394
		} catch (IOException e) {
395
			getErrorHandler().addError(e);
396
		}
397
	}
386 398
}

Also available in: Unified diff