Revision 11573
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/GPEKmlParser.java | ||
---|---|---|
15 | 15 |
import org.gvsig.exceptions.BaseException; |
16 | 16 |
import org.gvsig.gpe.GPEContentHandler; |
17 | 17 |
import org.gvsig.gpe.GPEErrorHandler; |
18 |
import org.gvsig.gpe.kml.bindings.header.HeaderBinding; |
|
19 | 18 |
import org.gvsig.gpe.kml.exceptions.KmlException; |
20 | 19 |
import org.gvsig.gpe.kml.exceptions.KmlHeaderParseException; |
21 |
import org.gvsig.gpe.kml.versions.AbstractKmlParser; |
|
22 |
import org.gvsig.gpe.kml.versions.KmlParsersFactory; |
|
20 |
import org.gvsig.gpe.kml.reader.AbstractKmlParser; |
|
21 |
import org.gvsig.gpe.kml.reader.KmlParsersFactory; |
|
22 |
import org.gvsig.gpe.kml.redaer.bindings.header.HeaderBinding; |
|
23 | 23 |
import org.gvsig.gpe.kml.writer.GPEKmlWriterHandler; |
24 | 24 |
import org.gvsig.gpe.writers.GPEWriterHandler; |
25 | 25 |
import org.gvsig.gpe.xml.GPEXmlParser; |
... | ... | |
68 | 68 |
* |
69 | 69 |
* $Id$ |
70 | 70 |
* $Log$ |
71 |
* Revision 1.8 2007-05-09 06:54:24 jorpiell |
|
71 |
* Revision 1.9 2007-05-11 07:06:29 jorpiell |
|
72 |
* Refactoring of some package names |
|
73 |
* |
|
74 |
* Revision 1.8 2007/05/09 06:54:24 jorpiell |
|
72 | 75 |
* Change the File by URI |
73 | 76 |
* |
74 | 77 |
* Revision 1.7 2007/05/08 09:28:17 jorpiell |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/AbstractKmlParser.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.reader; |
|
2 |
|
|
3 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
4 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
5 |
import org.xmlpull.v1.XmlPullParser; |
|
6 |
|
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
8 |
* |
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or |
|
12 |
* modify it under the terms of the GNU General Public License |
|
13 |
* as published by the Free Software Foundation; either version 2 |
|
14 |
* of the License, or (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
24 |
* |
|
25 |
* For more information, contact: |
|
26 |
* |
|
27 |
* Generalitat Valenciana |
|
28 |
* Conselleria d'Infraestructures i Transport |
|
29 |
* Av. Blasco Ib??ez, 50 |
|
30 |
* 46010 VALENCIA |
|
31 |
* SPAIN |
|
32 |
* |
|
33 |
* +34 963862235 |
|
34 |
* gvsig@gva.es |
|
35 |
* www.gvsig.gva.es |
|
36 |
* |
|
37 |
* or |
|
38 |
* |
|
39 |
* IVER T.I. S.A |
|
40 |
* Salamanca 50 |
|
41 |
* 46005 Valencia |
|
42 |
* Spain |
|
43 |
* |
|
44 |
* +34 963163400 |
|
45 |
* dac@iver.es |
|
46 |
*/ |
|
47 |
/* CVS MESSAGES: |
|
48 |
* |
|
49 |
* $Id$ |
|
50 |
* $Log$ |
|
51 |
* Revision 1.1 2007-05-11 07:06:29 jorpiell |
|
52 |
* Refactoring of some package names |
|
53 |
* |
|
54 |
* Revision 1.2 2007/05/08 09:28:17 jorpiell |
|
55 |
* Add comments to create javadocs |
|
56 |
* |
|
57 |
* Revision 1.1 2007/04/13 13:16:21 jorpiell |
|
58 |
* Add KML reading support |
|
59 |
* |
|
60 |
* |
|
61 |
*/ |
|
62 |
/** |
|
63 |
* This class must be implemented by all the classes that |
|
64 |
* implementa a KML version parser |
|
65 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
66 |
*/ |
|
67 |
public abstract class AbstractKmlParser { |
|
68 |
private XmlPullParser parser = null; |
|
69 |
private GPEKmlParser handler = null; |
|
70 |
|
|
71 |
public AbstractKmlParser(XmlPullParser parser, GPEKmlParser handler) { |
|
72 |
super(); |
|
73 |
this.parser = parser; |
|
74 |
this.handler = handler; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* @return |
|
79 |
* the supported version |
|
80 |
*/ |
|
81 |
public abstract String getVersion(); |
|
82 |
|
|
83 |
/** |
|
84 |
* Initialize the parsing process |
|
85 |
*/ |
|
86 |
public abstract void initParse() throws KmlBodyParseException; |
|
87 |
|
|
88 |
/** |
|
89 |
* @return the handler |
|
90 |
*/ |
|
91 |
public GPEKmlParser getHandler() { |
|
92 |
return handler; |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* @return the parser |
|
97 |
*/ |
|
98 |
public XmlPullParser getParser() { |
|
99 |
return parser; |
|
100 |
} |
|
101 |
} |
|
0 | 102 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/KmlParserV2_1.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.reader; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
6 |
import org.gvsig.gpe.kml.KmlTags; |
|
7 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
8 |
import org.gvsig.gpe.kml.reader.bindings.DocumentBinding; |
|
9 |
import org.xmlpull.v1.XmlPullParser; |
|
10 |
import org.xmlpull.v1.XmlPullParserException; |
|
11 |
|
|
12 |
|
|
13 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
14 |
* |
|
15 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
16 |
* |
|
17 |
* This program is free software; you can redistribute it and/or |
|
18 |
* modify it under the terms of the GNU General Public License |
|
19 |
* as published by the Free Software Foundation; either version 2 |
|
20 |
* of the License, or (at your option) any later version. |
|
21 |
* |
|
22 |
* This program is distributed in the hope that it will be useful, |
|
23 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
24 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
25 |
* GNU General Public License for more details. |
|
26 |
* |
|
27 |
* You should have received a copy of the GNU General Public License |
|
28 |
* along with this program; if not, write to the Free Software |
|
29 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
30 |
* |
|
31 |
* For more information, contact: |
|
32 |
* |
|
33 |
* Generalitat Valenciana |
|
34 |
* Conselleria d'Infraestructures i Transport |
|
35 |
* Av. Blasco Ib??ez, 50 |
|
36 |
* 46010 VALENCIA |
|
37 |
* SPAIN |
|
38 |
* |
|
39 |
* +34 963862235 |
|
40 |
* gvsig@gva.es |
|
41 |
* www.gvsig.gva.es |
|
42 |
* |
|
43 |
* or |
|
44 |
* |
|
45 |
* IVER T.I. S.A |
|
46 |
* Salamanca 50 |
|
47 |
* 46005 Valencia |
|
48 |
* Spain |
|
49 |
* |
|
50 |
* +34 963163400 |
|
51 |
* dac@iver.es |
|
52 |
*/ |
|
53 |
/* CVS MESSAGES: |
|
54 |
* |
|
55 |
* $Id$ |
|
56 |
* $Log$ |
|
57 |
* Revision 1.1 2007-05-11 07:06:29 jorpiell |
|
58 |
* Refactoring of some package names |
|
59 |
* |
|
60 |
* Revision 1.3 2007/05/08 09:28:17 jorpiell |
|
61 |
* Add comments to create javadocs |
|
62 |
* |
|
63 |
* Revision 1.2 2007/05/02 11:46:50 jorpiell |
|
64 |
* Writing tests updated |
|
65 |
* |
|
66 |
* Revision 1.2 2007/04/14 16:08:07 jorpiell |
|
67 |
* Kml writing support added |
|
68 |
* |
|
69 |
* Revision 1.1 2007/04/13 13:16:21 jorpiell |
|
70 |
* Add KML reading support |
|
71 |
* |
|
72 |
* Revision 1.1 2007/03/07 08:19:10 jorpiell |
|
73 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
74 |
* |
|
75 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
76 |
* *** empty log message *** |
|
77 |
* |
|
78 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
79 |
* Añadidos los proyectos de kml y gml antiguos |
|
80 |
* |
|
81 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
82 |
* A?adido el driver de KML |
|
83 |
* |
|
84 |
* |
|
85 |
*/ |
|
86 |
/** |
|
87 |
* This is a parser for KML 2.1 |
|
88 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
89 |
*/ |
|
90 |
public class KmlParserV2_1 extends AbstractKmlParser{ |
|
91 |
|
|
92 |
public KmlParserV2_1(XmlPullParser parser, GPEKmlParser handler) { |
|
93 |
super(parser, handler); |
|
94 |
} |
|
95 |
|
|
96 |
/* |
|
97 |
* (non-Javadoc) |
|
98 |
* @see org.gvsig.remoteClient.gmlEngine.IFeaturesParser#getVersion() |
|
99 |
*/ |
|
100 |
public String getVersion() { |
|
101 |
return "2.1"; |
|
102 |
} |
|
103 |
|
|
104 |
/* |
|
105 |
* (non-Javadoc) |
|
106 |
* @see org.gvsig.gpe.kml.versions.AbstractKmlParser#initParse() |
|
107 |
*/ |
|
108 |
public void initParse() throws KmlBodyParseException { |
|
109 |
boolean endFeature = false; |
|
110 |
int currentTag; |
|
111 |
|
|
112 |
try { |
|
113 |
String tag = getParser().getName(); |
|
114 |
currentTag = getParser().getEventType(); |
|
115 |
|
|
116 |
while (!endFeature){ |
|
117 |
switch(currentTag){ |
|
118 |
case XmlPullParser.START_TAG: |
|
119 |
if (tag.compareTo(KmlTags.DOCUMENT) == 0){ |
|
120 |
DocumentBinding.parse(getParser(), getHandler()); |
|
121 |
} |
|
122 |
break; |
|
123 |
case XmlPullParser.END_DOCUMENT: |
|
124 |
endFeature = true; |
|
125 |
|
|
126 |
break; |
|
127 |
} |
|
128 |
if (!endFeature){ |
|
129 |
currentTag = getParser().next(); |
|
130 |
tag = getParser().getName(); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
} catch (XmlPullParserException e) { |
|
135 |
throw new KmlBodyParseException (e); |
|
136 |
} catch (IOException e) { |
|
137 |
throw new KmlBodyParseException (e); |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
} |
|
0 | 142 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/KmlParsersFactory.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.reader; |
|
2 |
|
|
3 |
import java.util.Hashtable; |
|
4 |
|
|
5 |
import org.gvsig.exceptions.BaseException; |
|
6 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
7 |
import org.gvsig.gpe.kml.KmlTags; |
|
8 |
import org.gvsig.gpe.kml.exceptions.KmlImpossibleCreateParser; |
|
9 |
import org.xmlpull.v1.XmlPullParser; |
|
10 |
|
|
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-11 07:06:29 jorpiell |
|
57 |
* Refactoring of some package names |
|
58 |
* |
|
59 |
* Revision 1.3 2007/05/08 09:28:17 jorpiell |
|
60 |
* Add comments to create javadocs |
|
61 |
* |
|
62 |
* Revision 1.2 2007/05/02 11:46:50 jorpiell |
|
63 |
* Writing tests updated |
|
64 |
* |
|
65 |
* Revision 1.1 2007/04/13 13:16:21 jorpiell |
|
66 |
* Add KML reading support |
|
67 |
* |
|
68 |
* Revision 1.2 2007/04/12 10:21:52 jorpiell |
|
69 |
* Add the writers |
|
70 |
* |
|
71 |
* Revision 1.1 2007/03/07 08:19:10 jorpiell |
|
72 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
73 |
* |
|
74 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
75 |
* *** empty log message *** |
|
76 |
* |
|
77 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
78 |
* Añadidos los proyectos de kml y gml antiguos |
|
79 |
* |
|
80 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
81 |
* A?adido el driver de KML |
|
82 |
* |
|
83 |
* |
|
84 |
*/ |
|
85 |
/** |
|
86 |
* This class is used to register the differnet kml |
|
87 |
* parsers |
|
88 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
89 |
*/ |
|
90 |
public class KmlParsersFactory { |
|
91 |
private static Hashtable supportedVersions = new Hashtable(); |
|
92 |
|
|
93 |
static { |
|
94 |
supportedVersions.put("http://earth.google.com/kml/2.1",KmlParserV2_1.class); |
|
95 |
supportedVersions.put(KmlTags.UNKNOWN_VERSION,KmlParserV2_1.class); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* To create a new KML parser |
|
100 |
* @param nameSpace |
|
101 |
* KML namespace used to determine the parser to use |
|
102 |
* @param parser |
|
103 |
* XML parser used to parse the XML |
|
104 |
* @param handler |
|
105 |
* GPE parser tha contains the handlers |
|
106 |
* @return |
|
107 |
* A KML parser |
|
108 |
* @throws BaseException |
|
109 |
*/ |
|
110 |
public AbstractKmlParser createParser(String nameSpace,XmlPullParser parser, GPEKmlParser handler) throws BaseException{ |
|
111 |
Class clazz = (Class) supportedVersions.get(nameSpace); |
|
112 |
if (clazz == null){ |
|
113 |
clazz = (Class) supportedVersions.get(KmlTags.UNKNOWN_VERSION); |
|
114 |
} |
|
115 |
if (clazz != null){ |
|
116 |
Class [] args = {XmlPullParser.class,GPEKmlParser.class}; |
|
117 |
Object [] params = {parser,handler}; |
|
118 |
try { |
|
119 |
return (AbstractKmlParser)clazz.getConstructor(args).newInstance(params); |
|
120 |
} catch (Exception e) { |
|
121 |
throw new KmlImpossibleCreateParser(nameSpace,e); |
|
122 |
} |
|
123 |
} |
|
124 |
return null ; |
|
125 |
} |
|
126 |
|
|
127 |
|
|
128 |
} |
|
0 | 129 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/bindings/PlaceMarketBinding.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.reader.bindings; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
6 |
import org.gvsig.gpe.kml.KmlTags; |
|
7 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
8 |
import org.gvsig.gpe.kml.reader.bindings.geometries.LineStringTypeBinding; |
|
9 |
import org.gvsig.gpe.kml.reader.bindings.geometries.PointTypeBinding; |
|
10 |
import org.gvsig.gpe.kml.reader.bindings.geometries.PolygonTypeBinding; |
|
11 |
import org.gvsig.gpe.kml.reader.bindings.geometries.RegionBinding; |
|
12 |
import org.kxml2.io.KXmlParser; |
|
13 |
import org.xmlpull.v1.XmlPullParser; |
|
14 |
import org.xmlpull.v1.XmlPullParserException; |
|
15 |
|
|
16 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
17 |
* |
|
18 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
19 |
* |
|
20 |
* This program is free software; you can redistribute it and/or |
|
21 |
* modify it under the terms of the GNU General Public License |
|
22 |
* as published by the Free Software Foundation; either version 2 |
|
23 |
* of the License, or (at your option) any later version. |
|
24 |
* |
|
25 |
* This program is distributed in the hope that it will be useful, |
|
26 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
27 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
28 |
* GNU General Public License for more details. |
|
29 |
* |
|
30 |
* You should have received a copy of the GNU General Public License |
|
31 |
* along with this program; if not, write to the Free Software |
|
32 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
33 |
* |
|
34 |
* For more information, contact: |
|
35 |
* |
|
36 |
* Generalitat Valenciana |
|
37 |
* Conselleria d'Infraestructures i Transport |
|
38 |
* Av. Blasco Ib??ez, 50 |
|
39 |
* 46010 VALENCIA |
|
40 |
* SPAIN |
|
41 |
* |
|
42 |
* +34 963862235 |
|
43 |
* gvsig@gva.es |
|
44 |
* www.gvsig.gva.es |
|
45 |
* |
|
46 |
* or |
|
47 |
* |
|
48 |
* IVER T.I. S.A |
|
49 |
* Salamanca 50 |
|
50 |
* 46005 Valencia |
|
51 |
* Spain |
|
52 |
* |
|
53 |
* +34 963163400 |
|
54 |
* dac@iver.es |
|
55 |
*/ |
|
56 |
/* CVS MESSAGES: |
|
57 |
* |
|
58 |
* $Id$ |
|
59 |
* $Log$ |
|
60 |
* Revision 1.1 2007-05-11 07:06:29 jorpiell |
|
61 |
* Refactoring of some package names |
|
62 |
* |
|
63 |
* Revision 1.5 2007/05/09 08:36:24 jorpiell |
|
64 |
* Add the bbox to the layer |
|
65 |
* |
|
66 |
* Revision 1.4 2007/05/08 08:22:37 jorpiell |
|
67 |
* Add comments to create javadocs |
|
68 |
* |
|
69 |
* Revision 1.3 2007/04/20 08:38:59 jorpiell |
|
70 |
* Tests updating |
|
71 |
* |
|
72 |
* Revision 1.2 2007/04/13 13:16:21 jorpiell |
|
73 |
* Add KML reading support |
|
74 |
* |
|
75 |
* Revision 1.1 2007/03/07 08:19:10 jorpiell |
|
76 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
77 |
* |
|
78 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
79 |
* *** empty log message *** |
|
80 |
* |
|
81 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
82 |
* Añadidos los proyectos de kml y gml antiguos |
|
83 |
* |
|
84 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
85 |
* A?adido el driver de KML |
|
86 |
* |
|
87 |
* |
|
88 |
*/ |
|
89 |
/** |
|
90 |
* This class parses a PlaceMark tag. Example: |
|
91 |
* <p> |
|
92 |
* <pre> |
|
93 |
* <code> |
|
94 |
* <Placemark> |
|
95 |
* <name>CDATA example</name> |
|
96 |
* <description>Description example</description> |
|
97 |
* <Point> |
|
98 |
* <oordinates>102.595626,14.996729</coordinates> |
|
99 |
* </Point> |
|
100 |
* </Placemark> |
|
101 |
* </code> |
|
102 |
* </pre> |
|
103 |
* </p> |
|
104 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
105 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#placemark |
|
106 |
*/ |
|
107 |
public class PlaceMarketBinding { |
|
108 |
|
|
109 |
/** |
|
110 |
* It parses the PlaceMark tag |
|
111 |
* @param parser |
|
112 |
* The XML parser |
|
113 |
* @param handler |
|
114 |
* The GPE parser that contains the content handler and |
|
115 |
* the error handler |
|
116 |
* @return |
|
117 |
* A Feature |
|
118 |
* @throws IOException |
|
119 |
* @throws XmlPullParserException |
|
120 |
* @throws XmlPullParserException |
|
121 |
* @throws IOException |
|
122 |
*/ |
|
123 |
public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException{ |
|
124 |
boolean endFeature = false; |
|
125 |
int currentTag; |
|
126 |
|
|
127 |
String id = FeatureBinding.getID(parser, handler); |
|
128 |
Object feature = handler.getContentHandler().startFeature(id, null, null); |
|
129 |
|
|
130 |
|
|
131 |
String tag = parser.getName(); |
|
132 |
currentTag = parser.getEventType(); |
|
133 |
|
|
134 |
while (!endFeature){ |
|
135 |
switch(currentTag){ |
|
136 |
case KXmlParser.START_TAG: |
|
137 |
if (tag.compareTo(KmlTags.NAME) == 0){ |
|
138 |
parser.next(); |
|
139 |
handler.getContentHandler().addNameToFeature(parser.getText(), feature); |
|
140 |
}else if (tag.compareTo(KmlTags.DESCRIPTION) == 0){ |
|
141 |
parser.next(); |
|
142 |
String description = parser.getText(); |
|
143 |
}else if (tag.compareTo(KmlTags.VISIBILITY) == 0){ |
|
144 |
parser.next(); |
|
145 |
String visibility = parser.getText(); |
|
146 |
}else if (tag.compareTo(KmlTags.LOOKAT) == 0){ |
|
147 |
LookAtBinding.parse(parser, handler); |
|
148 |
}else if (tag.compareTo(KmlTags.STYLEURL) == 0){ |
|
149 |
parser.next(); |
|
150 |
String styleURL = parser.getText(); |
|
151 |
}else if (tag.compareTo(KmlTags.POINT) == 0){ |
|
152 |
Object point = PointTypeBinding.parse(parser, handler); |
|
153 |
handler.getContentHandler().addGeometryToFeature(point, feature); |
|
154 |
}else if (tag.compareTo(KmlTags.LINESTRING) == 0){ |
|
155 |
Object lineString = LineStringTypeBinding.parse(parser, handler); |
|
156 |
handler.getContentHandler().addGeometryToFeature(lineString, feature); |
|
157 |
}else if (tag.compareTo(KmlTags.POLYGON) == 0){ |
|
158 |
Object polygon = PolygonTypeBinding.parse(parser, handler); |
|
159 |
handler.getContentHandler().addGeometryToFeature(polygon, feature); |
|
160 |
}else if (tag.compareTo(KmlTags.REGION) == 0){ |
|
161 |
Object bbox = RegionBinding.parse(parser, handler); |
|
162 |
} |
|
163 |
break; |
|
164 |
case KXmlParser.END_TAG: |
|
165 |
if (tag.compareTo(KmlTags.PLACEMARK) == 0){ |
|
166 |
endFeature = true; |
|
167 |
handler.getContentHandler().endFeature(feature); |
|
168 |
} |
|
169 |
break; |
|
170 |
case KXmlParser.TEXT: |
|
171 |
|
|
172 |
break; |
|
173 |
} |
|
174 |
if (!endFeature){ |
|
175 |
currentTag = parser.next(); |
|
176 |
tag = parser.getName(); |
|
177 |
} |
|
178 |
} |
|
179 |
|
|
180 |
return feature; |
|
181 |
} |
|
182 |
} |
|
0 | 183 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/bindings/geometries/PolygonTypeBinding.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.reader.bindings.geometries; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
6 |
import org.gvsig.gpe.kml.KmlTags; |
|
7 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
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-11 07:06:29 jorpiell |
|
57 |
* Refactoring of some package names |
|
58 |
* |
|
59 |
* Revision 1.5 2007/05/08 08:22:37 jorpiell |
|
60 |
* Add comments to create javadocs |
|
61 |
* |
|
62 |
* Revision 1.4 2007/05/02 11:46:50 jorpiell |
|
63 |
* Writing tests updated |
|
64 |
* |
|
65 |
* Revision 1.3 2007/04/20 08:38:59 jorpiell |
|
66 |
* Tests updating |
|
67 |
* |
|
68 |
* Revision 1.2 2007/04/14 16:08:07 jorpiell |
|
69 |
* Kml writing support added |
|
70 |
* |
|
71 |
* Revision 1.1 2007/04/13 13:16:21 jorpiell |
|
72 |
* Add KML reading support |
|
73 |
* |
|
74 |
* Revision 1.1 2007/03/07 08:19:10 jorpiell |
|
75 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
76 |
* |
|
77 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
78 |
* *** empty log message *** |
|
79 |
* |
|
80 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
81 |
* Añadidos los proyectos de kml y gml antiguos |
|
82 |
* |
|
83 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
84 |
* A?adido el driver de KML |
|
85 |
* |
|
86 |
* |
|
87 |
*/ |
|
88 |
/** |
|
89 |
* It writes a Polygon tag. Example: |
|
90 |
* <p> |
|
91 |
* <pre> |
|
92 |
* <code> |
|
93 |
* <Polygon gid="_877789"> |
|
94 |
* <outerBoundaryIs> |
|
95 |
* <LinearRing> |
|
96 |
* <coordinates>0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0</coordinates> |
|
97 |
* </LinearRing> |
|
98 |
* </outerBoundaryIs> |
|
99 |
* </Polygon> |
|
100 |
* </code> |
|
101 |
* </pre> |
|
102 |
* </p> |
|
103 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
104 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#polygon |
|
105 |
*/ |
|
106 |
public class PolygonTypeBinding { |
|
107 |
|
|
108 |
/** |
|
109 |
* It parses the Polygon tag |
|
110 |
* @param parser |
|
111 |
* The XML parser |
|
112 |
* @param handler |
|
113 |
* The GPE parser that contains the content handler and |
|
114 |
* the error handler |
|
115 |
* @return |
|
116 |
* A polygon |
|
117 |
* @throws IOException |
|
118 |
* @throws XmlPullParserException |
|
119 |
* @throws XmlPullParserException |
|
120 |
* @throws IOException |
|
121 |
*/ |
|
122 |
public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException { |
|
123 |
boolean endFeature = false; |
|
124 |
int currentTag; |
|
125 |
Object polygon = null; |
|
126 |
|
|
127 |
String id = GeometryBinding.getID(parser, handler); |
|
128 |
|
|
129 |
String tag = parser.getName(); |
|
130 |
currentTag = parser.getEventType(); |
|
131 |
|
|
132 |
while (!endFeature){ |
|
133 |
switch(currentTag){ |
|
134 |
case KXmlParser.START_TAG: |
|
135 |
if (tag.compareTo(KmlTags.OUTERBOUNDARYIS) == 0){ |
|
136 |
double[][] coordinates = OuterBoundaryIsBinding.parse(parser, handler); |
|
137 |
polygon = handler.getContentHandler().startPolygon(id, |
|
138 |
coordinates[0], |
|
139 |
coordinates[1], |
|
140 |
coordinates[2], |
|
141 |
KmlTags.DEFAULT_SRS); |
|
142 |
}else if (tag.compareTo(KmlTags.INNERBOUNDARYIS) == 0){ |
|
143 |
double[][] coordinates = InnerBoundaryIsBinding.parse(parser, handler); |
|
144 |
Object innerPolygon = handler.getContentHandler().startInnerPolygon(null, |
|
145 |
coordinates[0], |
|
146 |
coordinates[1], |
|
147 |
coordinates[2], |
|
148 |
KmlTags.DEFAULT_SRS); |
|
149 |
handler.getContentHandler().endInnerPolygon(innerPolygon); |
|
150 |
handler.getContentHandler().addInnerPolygonToPolygon(innerPolygon,polygon); |
|
151 |
} |
|
152 |
break; |
|
153 |
case KXmlParser.END_TAG: |
|
154 |
if (tag.compareTo(KmlTags.POLYGON) == 0){ |
|
155 |
endFeature = true; |
|
156 |
handler.getContentHandler().endPolygon(polygon); |
|
157 |
} |
|
158 |
break; |
|
159 |
case KXmlParser.TEXT: |
|
160 |
|
|
161 |
break; |
|
162 |
} |
|
163 |
if (!endFeature){ |
|
164 |
currentTag = parser.next(); |
|
165 |
tag = parser.getName(); |
|
166 |
} |
|
167 |
} |
|
168 |
|
|
169 |
return polygon; |
|
170 |
} |
|
171 |
} |
|
0 | 172 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/bindings/geometries/DoubleBinding.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.reader.bindings.geometries; |
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
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 2 |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* Generalitat Valenciana |
|
23 |
* Conselleria d'Infraestructures i Transport |
|
24 |
* Av. Blasco Ib??ez, 50 |
|
25 |
* 46010 VALENCIA |
|
26 |
* SPAIN |
|
27 |
* |
|
28 |
* +34 963862235 |
|
29 |
* gvsig@gva.es |
|
30 |
* www.gvsig.gva.es |
|
31 |
* |
|
32 |
* or |
|
33 |
* |
|
34 |
* IVER T.I. S.A |
|
35 |
* Salamanca 50 |
|
36 |
* 46005 Valencia |
|
37 |
* Spain |
|
38 |
* |
|
39 |
* +34 963163400 |
|
40 |
* dac@iver.es |
|
41 |
*/ |
|
42 |
/* CVS MESSAGES: |
|
43 |
* |
|
44 |
* $Id$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.1 2007-05-11 07:06:29 jorpiell |
|
47 |
* Refactoring of some package names |
|
48 |
* |
|
49 |
* Revision 1.1 2007/05/09 08:36:24 jorpiell |
|
50 |
* Add the bbox to the layer |
|
51 |
* |
|
52 |
* |
|
53 |
*/ |
|
54 |
/** |
|
55 |
* It parses a double. It has to manage the |
|
56 |
* coordinates separator symbol |
|
57 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
58 |
*/ |
|
59 |
public class DoubleBinding { |
|
60 |
|
|
61 |
/** |
|
62 |
* It parses a double value |
|
63 |
* @param doubleValue |
|
64 |
* Double value like a string |
|
65 |
* @return |
|
66 |
* The double |
|
67 |
*/ |
|
68 |
public static double parse(String doubleValue){ |
|
69 |
return Double.valueOf(doubleValue).doubleValue(); |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
0 | 73 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/bindings/geometries/LinearRingBinding.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.reader.bindings.geometries; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
6 |
import org.gvsig.gpe.kml.KmlTags; |
|
7 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
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-11 07:06:29 jorpiell |
|
57 |
* Refactoring of some package names |
|
58 |
* |
|
59 |
* Revision 1.3 2007/05/08 08:22:37 jorpiell |
|
60 |
* Add comments to create javadocs |
|
61 |
* |
|
62 |
* Revision 1.2 2007/04/14 16:08:07 jorpiell |
|
63 |
* Kml writing support added |
|
64 |
* |
|
65 |
* Revision 1.1 2007/04/13 13:16:21 jorpiell |
|
66 |
* Add KML reading support |
|
67 |
* |
|
68 |
* |
|
69 |
*/ |
|
70 |
/** |
|
71 |
* It parses the linearRing KML tag. Example: |
|
72 |
* <p> |
|
73 |
* <pre> |
|
74 |
* <code> |
|
75 |
* <LinearRing> |
|
76 |
* <coordinates>0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0</coordinates> |
|
77 |
* </LinearRing> |
|
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#linearring |
|
83 |
*/ |
|
84 |
public class LinearRingBinding { |
|
85 |
|
|
86 |
/** |
|
87 |
* It parses the linearRing tag |
|
88 |
* @param parser |
|
89 |
* The XML parser |
|
90 |
* @param handler |
|
91 |
* The GPE parser that contains the content handler and |
|
92 |
* the error handler |
|
93 |
* @return |
|
94 |
* It retuns a matrix of doubles with 3 columns (x,y,z) and |
|
95 |
* one row for each coordinate. |
|
96 |
* @throws IOException |
|
97 |
* @throws XmlPullParserException |
|
98 |
* @throws XmlPullParserException |
|
99 |
* @throws IOException |
|
100 |
*/ |
|
101 |
public static double[][] parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException { |
|
102 |
boolean endFeature = false; |
|
103 |
int currentTag; |
|
104 |
double[][] coordinates = null; |
|
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.COORDINATES) == 0){ |
|
113 |
coordinates = CoordinatesTypeBinding.parse(parser, handler); |
|
114 |
} |
|
115 |
break; |
|
116 |
case KXmlParser.END_TAG: |
|
117 |
if (tag.compareTo(KmlTags.LINEARRING) == 0){ |
|
118 |
endFeature = true; |
|
119 |
} |
|
120 |
break; |
|
121 |
case KXmlParser.TEXT: |
|
122 |
|
|
123 |
break; |
|
124 |
} |
|
125 |
if (!endFeature){ |
|
126 |
currentTag = parser.next(); |
|
127 |
tag = parser.getName(); |
|
128 |
} |
|
129 |
} |
|
130 |
return coordinates; |
|
131 |
} |
|
132 |
} |
|
0 | 133 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/bindings/geometries/GeometryBinding.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.reader.bindings.geometries; |
|
2 |
|
|
3 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
4 |
import org.gvsig.gpe.kml.KmlTags; |
|
5 |
import org.xmlpull.v1.XmlPullParser; |
|
6 |
|
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
8 |
* |
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or |
|
12 |
* modify it under the terms of the GNU General Public License |
|
13 |
* as published by the Free Software Foundation; either version 2 |
|
14 |
* of the License, or (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
24 |
* |
|
25 |
* For more information, contact: |
|
26 |
* |
|
27 |
* Generalitat Valenciana |
|
28 |
* Conselleria d'Infraestructures i Transport |
|
29 |
* Av. Blasco Ib??ez, 50 |
|
30 |
* 46010 VALENCIA |
|
31 |
* SPAIN |
|
32 |
* |
|
33 |
* +34 963862235 |
|
34 |
* gvsig@gva.es |
|
35 |
* www.gvsig.gva.es |
|
36 |
* |
|
37 |
* or |
|
38 |
* |
|
39 |
* IVER T.I. S.A |
|
40 |
* Salamanca 50 |
|
41 |
* 46005 Valencia |
|
42 |
* Spain |
|
43 |
* |
|
44 |
* +34 963163400 |
|
45 |
* dac@iver.es |
|
46 |
*/ |
|
47 |
/* CVS MESSAGES: |
|
48 |
* |
|
49 |
* $Id$ |
|
50 |
* $Log$ |
|
51 |
* Revision 1.1 2007-05-11 07:06:29 jorpiell |
|
52 |
* Refactoring of some package names |
|
53 |
* |
|
54 |
* Revision 1.1 2007/05/08 08:22:37 jorpiell |
|
55 |
* Add comments to create javadocs |
|
56 |
* |
|
57 |
* Revision 1.1 2007/05/02 11:46:50 jorpiell |
|
58 |
* Writing tests updated |
|
59 |
* |
|
60 |
* |
|
61 |
*/ |
|
62 |
/** |
|
63 |
* A Geometry element is an abstract element and cannot be used |
|
64 |
* directly in a KML file. It provides a placeholder object for |
|
65 |
* all derived Geometry objects. |
|
66 |
* <br> |
|
67 |
* This class parses the common parts. |
|
68 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
69 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#geometry |
|
70 |
*/ |
|
71 |
public class GeometryBinding { |
|
72 |
|
|
73 |
/** |
|
74 |
* It returns the KML geometry id attribute value |
|
75 |
* @param parser |
|
76 |
* @param handler |
|
77 |
* @return |
|
78 |
*/ |
|
79 |
public static String getID(XmlPullParser parser,GPEKmlParser handler){ |
|
80 |
String id = null; |
|
81 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
|
82 |
if (parser.getAttributeName(i).compareTo(KmlTags.GEOMETRY_ID) == 0){ |
|
83 |
id = parser.getAttributeValue(i); |
|
84 |
} |
|
85 |
} |
|
86 |
return id; |
|
87 |
} |
|
88 |
} |
|
0 | 89 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/bindings/geometries/InnerBoundaryIsBinding.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.reader.bindings.geometries; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
6 |
import org.gvsig.gpe.kml.KmlTags; |
|
7 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
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-11 07:06:29 jorpiell |
|
57 |
* Refactoring of some package names |
|
58 |
* |
|
59 |
* Revision 1.2 2007/05/08 08:22:37 jorpiell |
|
60 |
* Add comments to create javadocs |
|
61 |
* |
|
62 |
* Revision 1.1 2007/04/14 16:08:07 jorpiell |
|
63 |
* Kml writing support added |
|
64 |
* |
|
65 |
* |
|
66 |
*/ |
|
67 |
/** |
|
68 |
* It parses the innerBoundaryIs tag. Example: |
|
69 |
* <p> |
|
70 |
* <pre> |
|
71 |
* <code> |
|
72 |
* <innerBoundaryIs> |
|
73 |
* <LinearRing> |
|
74 |
* <coordinates>10.0,10.0 10.0,40.0 40.0,40.0 40.0,10.0 10.0,10.0</coordinates> |
|
75 |
* </LinearRing> |
|
76 |
* </innerBoundaryIs> |
|
77 |
* </code> |
|
78 |
* </pre> |
|
79 |
* </p> |
|
80 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
81 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#innerboundaryis |
|
82 |
*/ |
|
83 |
public class InnerBoundaryIsBinding { |
|
84 |
|
|
85 |
/** |
|
86 |
* It parses the innerBoundary 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 |
* It retuns a matrix of doubles with 3 columns (x,y,z) and |
|
94 |
* one row for each coordinate. |
|
95 |
* @throws IOException |
|
96 |
* @throws XmlPullParserException |
|
97 |
* @throws XmlPullParserException |
|
98 |
* @throws IOException |
|
99 |
*/ |
|
100 |
public static double[][] parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException{ |
|
101 |
boolean endFeature = false; |
|
102 |
int currentTag; |
|
103 |
|
|
104 |
double[][] coordinates = null; |
|
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.LINEARRING) == 0){ |
|
113 |
coordinates = LinearRingBinding.parse(parser, handler); |
|
114 |
} |
|
115 |
break; |
|
116 |
case KXmlParser.END_TAG: |
|
117 |
if (tag.compareTo(KmlTags.INNERBOUNDARYIS) == 0){ |
|
118 |
endFeature = true; |
|
119 |
} |
|
120 |
break; |
|
121 |
case KXmlParser.TEXT: |
|
122 |
|
|
123 |
break; |
|
124 |
} |
|
125 |
if (!endFeature){ |
|
126 |
currentTag = parser.next(); |
|
127 |
tag = parser.getName(); |
|
128 |
} |
|
129 |
} |
|
130 |
return coordinates; |
|
131 |
} |
|
132 |
} |
|
0 | 133 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/bindings/geometries/PointTypeBinding.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.reader.bindings.geometries; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
6 |
import org.gvsig.gpe.kml.KmlTags; |
|
7 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
8 |
import org.kxml2.io.KXmlParser; |
|
9 |
import org.xmlpull.v1.XmlPullParser; |
|
10 |
import org.xmlpull.v1.XmlPullParserException; |
|
11 |
|
|
12 |
|
|
13 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
14 |
* |
|
15 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
16 |
* |
|
17 |
* This program is free software; you can redistribute it and/or |
|
18 |
* modify it under the terms of the GNU General Public License |
|
19 |
* as published by the Free Software Foundation; either version 2 |
|
20 |
* of the License, or (at your option) any later version. |
|
21 |
* |
|
22 |
* This program is distributed in the hope that it will be useful, |
|
23 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
24 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
25 |
* GNU General Public License for more details. |
|
26 |
* |
|
27 |
* You should have received a copy of the GNU General Public License |
|
28 |
* along with this program; if not, write to the Free Software |
|
29 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
30 |
* |
|
31 |
* For more information, contact: |
|
32 |
* |
|
33 |
* Generalitat Valenciana |
|
34 |
* Conselleria d'Infraestructures i Transport |
|
35 |
* Av. Blasco Ib??ez, 50 |
|
36 |
* 46010 VALENCIA |
|
37 |
* SPAIN |
|
38 |
* |
|
39 |
* +34 963862235 |
|
40 |
* gvsig@gva.es |
|
41 |
* www.gvsig.gva.es |
|
42 |
* |
|
43 |
* or |
|
44 |
* |
|
45 |
* IVER T.I. S.A |
|
46 |
* Salamanca 50 |
|
47 |
* 46005 Valencia |
|
48 |
* Spain |
|
49 |
* |
|
50 |
* +34 963163400 |
|
51 |
* dac@iver.es |
|
52 |
*/ |
|
53 |
/* CVS MESSAGES: |
|
54 |
* |
|
55 |
* $Id$ |
|
56 |
* $Log$ |
|
57 |
* Revision 1.1 2007-05-11 07:06:29 jorpiell |
|
58 |
* Refactoring of some package names |
|
59 |
* |
|
60 |
* Revision 1.5 2007/05/08 08:22:37 jorpiell |
|
61 |
* Add comments to create javadocs |
|
62 |
* |
|
63 |
* Revision 1.4 2007/05/02 11:46:50 jorpiell |
|
64 |
* Writing tests updated |
|
65 |
* |
|
66 |
* Revision 1.3 2007/04/20 08:38:59 jorpiell |
|
67 |
* Tests updating |
|
68 |
* |
|
69 |
* Revision 1.2 2007/04/14 16:08:07 jorpiell |
|
70 |
* Kml writing support added |
|
71 |
* |
|
72 |
* Revision 1.1 2007/04/13 13:16:21 jorpiell |
|
73 |
* Add KML reading support |
|
74 |
* |
|
75 |
* Revision 1.1 2007/03/07 08:19:10 jorpiell |
|
76 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
77 |
* |
|
78 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
79 |
* *** empty log message *** |
|
80 |
* |
|
81 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
82 |
* Añadidos los proyectos de kml y gml antiguos |
|
83 |
* |
|
84 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
85 |
* A?adido el driver de KML |
|
86 |
* |
|
87 |
* |
|
88 |
*/ |
|
89 |
/** |
|
90 |
* It parses a Point tag. Example: |
|
91 |
* <p> |
|
92 |
* <pre> |
|
93 |
* <code> |
|
94 |
* <Point gid="P6776"> |
|
95 |
* <coord><X>50.0</X><Y>50.0</Y></coord> |
|
96 |
* </Point> |
|
97 |
* </code> |
|
98 |
* </pre> |
|
99 |
* </p> |
|
100 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
101 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#point |
|
102 |
*/ |
|
103 |
public class PointTypeBinding{ |
|
104 |
|
|
105 |
/** |
|
106 |
* It parses the Point tag |
|
107 |
* @param parser |
|
108 |
* The XML parser |
|
109 |
* @param handler |
|
110 |
* The GPE parser that contains the content handler and |
|
111 |
* the error handler |
|
112 |
* @return |
|
113 |
* A point |
|
114 |
* @throws IOException |
|
115 |
* @throws XmlPullParserException |
|
116 |
* @throws XmlPullParserException |
|
117 |
* @throws IOException |
|
118 |
*/ |
|
119 |
public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException { |
|
120 |
boolean endFeature = false; |
|
121 |
int currentTag; |
|
122 |
Object point = null; |
|
123 |
|
|
124 |
String id = GeometryBinding.getID(parser, handler); |
|
125 |
|
|
126 |
|
|
127 |
String tag = parser.getName(); |
|
128 |
currentTag = parser.getEventType(); |
|
129 |
|
|
130 |
while (!endFeature){ |
|
131 |
switch(currentTag){ |
|
132 |
case KXmlParser.START_TAG: |
|
133 |
if (tag.compareTo(KmlTags.COORDINATES) == 0){ |
|
134 |
double[][] coordinates = CoordinatesTypeBinding.parse(parser, handler); |
|
135 |
point = handler.getContentHandler().startPoint(id, |
|
136 |
coordinates[0][0], |
|
137 |
coordinates[1][0], |
|
138 |
coordinates[2][0], |
|
139 |
KmlTags.DEFAULT_SRS); |
|
140 |
} |
|
141 |
break; |
|
142 |
case KXmlParser.END_TAG: |
|
143 |
if (tag.compareTo(KmlTags.POINT) == 0){ |
|
144 |
endFeature = true; |
|
145 |
handler.getContentHandler().endPoint(point); |
|
146 |
} |
|
147 |
break; |
|
148 |
case KXmlParser.TEXT: |
|
149 |
|
|
150 |
break; |
|
151 |
} |
|
152 |
if (!endFeature){ |
|
153 |
currentTag = parser.next(); |
|
154 |
tag = parser.getName(); |
|
155 |
} |
|
156 |
} |
|
157 |
|
|
158 |
return point; |
|
159 |
} |
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
} |
|
0 | 164 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/reader/bindings/geometries/CoordinatesTypeBinding.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.reader.bindings.geometries; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
6 |
import org.gvsig.gpe.kml.KmlTags; |
|
7 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
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. |
Also available in: Unified diff