Revision 19680
trunk/libraries/libGPE-KML/src-test/org/gvsig/gpe/kml/parser/v21/kml/KMLSampleTest.java | ||
---|---|---|
88 | 88 |
Layer layer = layers[0]; |
89 | 89 |
assertEquals(layer.getName(), "KML Samples"); |
90 | 90 |
assertEquals(layer.getDescription(), "Unleash your creativity with the help of these examples!"); |
91 |
assertEquals(layer.getLayers().size(), 5);
|
|
91 |
assertEquals(layer.getLayers().size(), 6);
|
|
92 | 92 |
//Sublayer 1 |
93 | 93 |
Layer layer1 = layer.getLayerAt(0); |
94 | 94 |
assertEquals(layer1.getName(), "Placemarks"); |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/coordinates/IKmlCoordinatesIterator.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.parser.v21.coordinates; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.GPEDefaults; |
|
6 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
|
7 |
import org.gvsig.gpe.parser.ICoordinateIterator; |
|
8 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
|
9 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
|
10 |
|
|
11 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
12 |
* |
|
13 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
14 |
* |
|
15 |
* This program is free software; you can redistribute it and/or |
|
16 |
* modify it under the terms of the GNU General Public License |
|
17 |
* as published by the Free Software Foundation; either version 2 |
|
18 |
* of the License, or (at your option) any later version. |
|
19 |
* |
|
20 |
* This program is distributed in the hope that it will be useful, |
|
21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23 |
* GNU General Public License for more details. |
|
24 |
* |
|
25 |
* You should have received a copy of the GNU General Public License |
|
26 |
* along with this program; if not, write to the Free Software |
|
27 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
28 |
* |
|
29 |
* For more information, contact: |
|
30 |
* |
|
31 |
* Generalitat Valenciana |
|
32 |
* Conselleria d'Infraestructures i Transport |
|
33 |
* Av. Blasco Ib??ez, 50 |
|
34 |
* 46010 VALENCIA |
|
35 |
* SPAIN |
|
36 |
* |
|
37 |
* +34 963862235 |
|
38 |
* gvsig@gva.es |
|
39 |
* www.gvsig.gva.es |
|
40 |
* |
|
41 |
* or |
|
42 |
* |
|
43 |
* IVER T.I. S.A |
|
44 |
* Salamanca 50 |
|
45 |
* 46005 Valencia |
|
46 |
* Spain |
|
47 |
* |
|
48 |
* +34 963163400 |
|
49 |
* dac@iver.es |
|
50 |
*/ |
|
51 |
/* CVS MESSAGES: |
|
52 |
* |
|
53 |
* $Id$ |
|
54 |
* $Log$ |
|
55 |
* |
|
56 |
*/ |
|
57 |
/** |
|
58 |
* @author Jorge Piera Llodr? (jorge.piera@iver.es) |
|
59 |
*/ |
|
60 |
public interface IKmlCoordinatesIterator extends ICoordinateIterator { |
|
61 |
|
|
62 |
/** |
|
63 |
* It initializes a coordinates iterator and put the |
|
64 |
* parsing pointer in the specified tag |
|
65 |
* @param parser |
|
66 |
* The XML parser |
|
67 |
* @param handler |
|
68 |
* The GPE parser that contains the content handler and |
|
69 |
* the error handler |
|
70 |
* @param lastTag |
|
71 |
* The last tag |
|
72 |
* @throws XmlStreamException |
|
73 |
* @throws IOException |
|
74 |
*/ |
|
75 |
public void initialize(IXmlStreamReader parser,GPEDeafultKmlParser handler,String lastTag) throws XmlStreamException, IOException; |
|
76 |
|
|
77 |
/** |
|
78 |
* This method advances the stream reader until the last |
|
79 |
* tag of the coordinates iterator. |
|
80 |
*/ |
|
81 |
public void parseAll()throws XmlStreamException; |
|
82 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/coordinates/CoordinatesTypeIterator.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.parser.v21.coordinates; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.util.StringTokenizer; |
|
5 |
|
|
6 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
|
7 |
import org.gvsig.gpe.kml.parser.v21.geometries.DoubleBinding; |
|
8 |
import org.gvsig.gpe.kml.utils.KmlTags; |
|
9 |
import org.gvsig.gpe.utils.StringUtils; |
|
10 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
|
11 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
|
12 |
import org.gvsig.gpe.xml.utils.CompareUtils; |
|
13 |
|
|
14 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
15 |
* |
|
16 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
17 |
* |
|
18 |
* This program is free software; you can redistribute it and/or |
|
19 |
* modify it under the terms of the GNU General Public License |
|
20 |
* as published by the Free Software Foundation; either version 2 |
|
21 |
* of the License, or (at your option) any later version. |
|
22 |
* |
|
23 |
* This program is distributed in the hope that it will be useful, |
|
24 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
26 |
* GNU General Public License for more details. |
|
27 |
* |
|
28 |
* You should have received a copy of the GNU General Public License |
|
29 |
* along with this program; if not, write to the Free Software |
|
30 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
31 |
* |
|
32 |
* For more information, contact: |
|
33 |
* |
|
34 |
* Generalitat Valenciana |
|
35 |
* Conselleria d'Infraestructures i Transport |
|
36 |
* Av. Blasco Ib??ez, 50 |
|
37 |
* 46010 VALENCIA |
|
38 |
* SPAIN |
|
39 |
* |
|
40 |
* +34 963862235 |
|
41 |
* gvsig@gva.es |
|
42 |
* www.gvsig.gva.es |
|
43 |
* |
|
44 |
* or |
|
45 |
* |
|
46 |
* IVER T.I. S.A |
|
47 |
* Salamanca 50 |
|
48 |
* 46005 Valencia |
|
49 |
* Spain |
|
50 |
* |
|
51 |
* +34 963163400 |
|
52 |
* dac@iver.es |
|
53 |
*/ |
|
54 |
/* CVS MESSAGES: |
|
55 |
* |
|
56 |
* $Id:CoordinatesTypeBinding.java 357 2008-01-09 17:50:08Z jpiera $ |
|
57 |
* $Log$ |
|
58 |
* Revision 1.2 2007/06/07 14:53:59 jorpiell |
|
59 |
* Add the schema support |
|
60 |
* |
|
61 |
* Revision 1.1 2007/05/11 07:06:29 jorpiell |
|
62 |
* Refactoring of some package names |
|
63 |
* |
|
64 |
* Revision 1.4 2007/05/09 08:36:24 jorpiell |
|
65 |
* Add the bbox to the layer |
|
66 |
* |
|
67 |
* Revision 1.3 2007/05/08 08:22:37 jorpiell |
|
68 |
* Add comments to create javadocs |
|
69 |
* |
|
70 |
* Revision 1.2 2007/04/14 16:08:07 jorpiell |
|
71 |
* Kml writing support added |
|
72 |
* |
|
73 |
* Revision 1.1 2007/04/13 13:16:21 jorpiell |
|
74 |
* Add KML reading support |
|
75 |
* |
|
76 |
* Revision 1.1 2007/03/07 08:19:10 jorpiell |
|
77 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
78 |
* |
|
79 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
80 |
* *** empty log message *** |
|
81 |
* |
|
82 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
83 |
* AƱadidos los proyectos de kml y gml antiguos |
|
84 |
* |
|
85 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
86 |
* A?adido el driver de KML |
|
87 |
* |
|
88 |
* |
|
89 |
*/ |
|
90 |
/** |
|
91 |
* This class parses a coordinates tag. Example: |
|
92 |
* <p> |
|
93 |
* <pre> |
|
94 |
* <code> |
|
95 |
* <coordinates>60.0,60.0 60.0,90.0 90.0,90.0</coordinates> |
|
96 |
* </code> |
|
97 |
* </pre> |
|
98 |
* </p> |
|
99 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
100 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#coordinates |
|
101 |
*/ |
|
102 |
public class CoordinatesTypeIterator extends KmlCoodinatesIterator{ |
|
103 |
private StringTokenizer coordinatesString = null; |
|
104 |
|
|
105 |
/** |
|
106 |
* It parses the gml:coordinates 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 |
* It retuns a matrix of doubles with 3 columns (x,y,z) and |
|
114 |
* one row for each coordinate. |
|
115 |
* @throws XmlStreamException |
|
116 |
* @throws IOException |
|
117 |
*/ |
|
118 |
/* (non-Javadoc) |
|
119 |
* @see org.gvsig.gpe.gml.parser.v2.coordinates.GmlCoodinatesIterator#initialize(org.gvsig.gpe.xml.stream.IXmlStreamReader, org.gvsig.gpe.gml.parser.GPEDefaultGmlParser, java.lang.String) |
|
120 |
*/ |
|
121 |
public void initialize(IXmlStreamReader parser, |
|
122 |
GPEDeafultKmlParser handler, String lastTag) |
|
123 |
throws XmlStreamException, IOException { |
|
124 |
super.initialize(parser, handler, lastTag); |
|
125 |
|
|
126 |
boolean endFeature = false; |
|
127 |
int currentTag; |
|
128 |
|
|
129 |
String tag = parser.getName(); |
|
130 |
currentTag = parser.getEventType(); |
|
131 |
|
|
132 |
while (!endFeature){ |
|
133 |
switch(currentTag){ |
|
134 |
case IXmlStreamReader.START_TAG: |
|
135 |
if (CompareUtils.compareWithOutNamespace(tag,KmlTags.COORDINATES)){ |
|
136 |
parser.next(); |
|
137 |
String coordinatesTag = parser.getText().trim(); |
|
138 |
if (dimension == -1){ |
|
139 |
dimension = caculateDimension(coordinatesTag); |
|
140 |
} |
|
141 |
coordinatesString = new StringTokenizer(coordinatesTag); |
|
142 |
//Parses until the last tag... |
|
143 |
parseAll(); |
|
144 |
return; |
|
145 |
} |
|
146 |
break; |
|
147 |
case IXmlStreamReader.END_TAG: |
|
148 |
if (CompareUtils.compareWithOutNamespace(tag,KmlTags.COORDINATES)){ |
|
149 |
endFeature = true; |
|
150 |
} |
|
151 |
break; |
|
152 |
case IXmlStreamReader.TEXT: |
|
153 |
|
|
154 |
break; |
|
155 |
} |
|
156 |
if (!endFeature){ |
|
157 |
currentTag = parser.next(); |
|
158 |
tag = parser.getName(); |
|
159 |
} |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
/** |
|
164 |
* Calculates the dimension from a array of coordinates |
|
165 |
* @param coordinatesTag |
|
166 |
* @return |
|
167 |
*/ |
|
168 |
private int caculateDimension(String coordinatesTag) { |
|
169 |
String firstPair; |
|
170 |
StringTokenizer st = new StringTokenizer(coordinatesTag); |
|
171 |
if (st.hasMoreTokens()){ |
|
172 |
firstPair = st.nextToken(); |
|
173 |
}else{ |
|
174 |
firstPair = coordinatesTag; |
|
175 |
} |
|
176 |
return StringUtils.splitString(firstPair, KmlTags.COORDINATES_SEPARATOR).length; |
|
177 |
} |
|
178 |
|
|
179 |
/* |
|
180 |
* (non-Javadoc) |
|
181 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#hasNext() |
|
182 |
*/ |
|
183 |
public boolean hasNext() throws IOException { |
|
184 |
return coordinatesString.hasMoreTokens(); |
|
185 |
} |
|
186 |
|
|
187 |
/* |
|
188 |
* (non-Javadoc) |
|
189 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#next(double[]) |
|
190 |
*/ |
|
191 |
public void next(double[] buffer) throws IOException { |
|
192 |
String next = coordinatesString.nextToken(); |
|
193 |
String[] coordinates = org.gvsig.gpe.utils.StringUtils.splitString(next.trim(),KmlTags.COORDINATES_SEPARATOR); |
|
194 |
for (int i=0 ; i<coordinates.length ; i++){ |
|
195 |
buffer[i] = handler.getProfile().getDoubleBinding().parse(coordinates[i]); |
|
196 |
} |
|
197 |
} |
|
198 |
|
|
199 |
|
|
200 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/coordinates/KmlCoodinatesIterator.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.parser.v21.coordinates; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.util.StringTokenizer; |
|
5 |
|
|
6 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
|
7 |
import org.gvsig.gpe.kml.utils.KmlTags; |
|
8 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
|
9 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
|
10 |
import org.gvsig.gpe.xml.utils.CompareUtils; |
|
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 |
* |
|
57 |
*/ |
|
58 |
/** |
|
59 |
* @author Jorge Piera Llodr? (jorge.piera@iver.es) |
|
60 |
*/ |
|
61 |
public abstract class KmlCoodinatesIterator implements IKmlCoordinatesIterator { |
|
62 |
protected IXmlStreamReader parser = null; |
|
63 |
protected GPEDeafultKmlParser handler = null; |
|
64 |
protected String lastTag = null; |
|
65 |
protected int dimension = 0; |
|
66 |
protected StringTokenizer coordinatesString = null; |
|
67 |
|
|
68 |
/* (non-Javadoc) |
|
69 |
* @see org.gvsig.gpe.gml.parser.IGmlCoordinatesIterator#initialize(org.gvsig.gpe.xml.stream.IXmlStreamReader, org.gvsig.gpe.gml.parser.GPEDefaultGmlParser, java.lang.String) |
|
70 |
*/ |
|
71 |
public void initialize(IXmlStreamReader parser, |
|
72 |
GPEDeafultKmlParser handler, String lastTag) |
|
73 |
throws XmlStreamException, IOException { |
|
74 |
this.parser = parser; |
|
75 |
this.handler = handler; |
|
76 |
this.lastTag = lastTag; |
|
77 |
this.dimension = -1; |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
/* (non-Javadoc) |
|
82 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#getDimension() |
|
83 |
*/ |
|
84 |
public int getDimension() { |
|
85 |
return dimension; |
|
86 |
} |
|
87 |
|
|
88 |
/* (non-Javadoc) |
|
89 |
* @see org.gvsig.gpe.gml.parser.IGmlCoordinatesIterator#parseAll() |
|
90 |
*/ |
|
91 |
public void parseAll() throws XmlStreamException { |
|
92 |
String tag = parser.getName(); |
|
93 |
int currentTag = parser.getEventType(); |
|
94 |
boolean endCoordinates = false; |
|
95 |
|
|
96 |
while (!endCoordinates){ |
|
97 |
switch(currentTag){ |
|
98 |
case IXmlStreamReader.END_TAG: |
|
99 |
if (CompareUtils.compareWithOutNamespace(tag,lastTag)){ |
|
100 |
endCoordinates = true; |
|
101 |
} |
|
102 |
break; |
|
103 |
} |
|
104 |
if (!endCoordinates){ |
|
105 |
currentTag = parser.next(); |
|
106 |
tag = parser.getName(); |
|
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/coordinates/LatLonBoxIterator.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.parser.v21.coordinates; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
|
6 |
import org.gvsig.gpe.kml.utils.KmlTags; |
|
7 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
|
8 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
|
9 |
|
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
11 |
* |
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
13 |
* |
|
14 |
* This program is free software; you can redistribute it and/or |
|
15 |
* modify it under the terms of the GNU General Public License |
|
16 |
* as published by the Free Software Foundation; either version 2 |
|
17 |
* of the License, or (at your option) any later version. |
|
18 |
* |
|
19 |
* This program is distributed in the hope that it will be useful, |
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
* GNU General Public License for more details. |
|
23 |
* |
|
24 |
* You should have received a copy of the GNU General Public License |
|
25 |
* along with this program; if not, write to the Free Software |
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
27 |
* |
|
28 |
* For more information, contact: |
|
29 |
* |
|
30 |
* Generalitat Valenciana |
|
31 |
* Conselleria d'Infraestructures i Transport |
|
32 |
* Av. Blasco Ib??ez, 50 |
|
33 |
* 46010 VALENCIA |
|
34 |
* SPAIN |
|
35 |
* |
|
36 |
* +34 963862235 |
|
37 |
* gvsig@gva.es |
|
38 |
* www.gvsig.gva.es |
|
39 |
* |
|
40 |
* or |
|
41 |
* |
|
42 |
* IVER T.I. S.A |
|
43 |
* Salamanca 50 |
|
44 |
* 46005 Valencia |
|
45 |
* Spain |
|
46 |
* |
|
47 |
* +34 963163400 |
|
48 |
* dac@iver.es |
|
49 |
*/ |
|
50 |
/* CVS MESSAGES: |
|
51 |
* |
|
52 |
* $Id:LatLonBoxBinding.java 357 2008-01-09 17:50:08Z jpiera $ |
|
53 |
* $Log$ |
|
54 |
* Revision 1.1 2007/05/11 07:06:29 jorpiell |
|
55 |
* Refactoring of some package names |
|
56 |
* |
|
57 |
* Revision 1.1 2007/05/09 08:36:24 jorpiell |
|
58 |
* Add the bbox to the layer |
|
59 |
* |
|
60 |
* |
|
61 |
*/ |
|
62 |
/** |
|
63 |
* This class parses a LatLonBox tag. Example: |
|
64 |
* <p> |
|
65 |
* <pre> |
|
66 |
* <code> |
|
67 |
* <LatLonAltBox> |
|
68 |
* <north>43.374</north> |
|
69 |
* <south>42.983</south> |
|
70 |
* <east>-0.335</east> |
|
71 |
* <west>-1.423</west> |
|
72 |
* <rotation>39.37878630116985</rotation> |
|
73 |
* </LatLonAltBox> |
|
74 |
* </code> |
|
75 |
* </pre> |
|
76 |
* </p> |
|
77 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
78 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#latlonbox |
|
79 |
*/ |
|
80 |
public class LatLonBoxIterator extends KmlCoodinatesIterator{ |
|
81 |
double[] min = null; |
|
82 |
double[] max = null; |
|
83 |
int iterations = 0; |
|
84 |
|
|
85 |
/** |
|
86 |
* It parses the LatLonAltBox 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 Bounding box |
|
94 |
* @throws IOException |
|
95 |
* @throws XmlStreamException |
|
96 |
*/ |
|
97 |
public Object parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException { |
|
98 |
boolean endFeature = false; |
|
99 |
int currentTag; |
|
100 |
Object bbox = null; |
|
101 |
min = new double[3]; |
|
102 |
max = new double[3]; |
|
103 |
double rotation; |
|
104 |
iterations = 0; |
|
105 |
dimension = 2; |
|
106 |
|
|
107 |
String id = handler.getProfile().getGeometryBinding().getID(parser, handler); |
|
108 |
|
|
109 |
String tag = parser.getName(); |
|
110 |
currentTag = parser.getEventType(); |
|
111 |
|
|
112 |
while (!endFeature){ |
|
113 |
switch(currentTag){ |
|
114 |
case IXmlStreamReader.START_TAG: |
|
115 |
if (tag.compareTo(KmlTags.NORTH) == 0){ |
|
116 |
parser.next(); |
|
117 |
max[1] = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
118 |
}else if (tag.compareTo(KmlTags.SOUTH) == 0){ |
|
119 |
parser.next(); |
|
120 |
min[1] = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
121 |
}else if (tag.compareTo(KmlTags.EAST) == 0){ |
|
122 |
parser.next(); |
|
123 |
max[0] = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
124 |
}else if (tag.compareTo(KmlTags.WEST) == 0){ |
|
125 |
parser.next(); |
|
126 |
min[0] = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
127 |
}else if (tag.compareTo(KmlTags.ROTATION) == 0){ |
|
128 |
parser.next(); |
|
129 |
rotation = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
130 |
} |
|
131 |
break; |
|
132 |
case IXmlStreamReader.END_TAG: |
|
133 |
if (tag.compareTo(KmlTags.LATLONBOX) == 0){ |
|
134 |
endFeature = true; |
|
135 |
bbox = handler.getContentHandler().startBbox(id, this, KmlTags.DEFAULT_SRS); |
|
136 |
handler.getContentHandler().endBbox(bbox); |
|
137 |
} |
|
138 |
break; |
|
139 |
case IXmlStreamReader.TEXT: |
|
140 |
|
|
141 |
break; |
|
142 |
} |
|
143 |
if (!endFeature){ |
|
144 |
currentTag = parser.next(); |
|
145 |
tag = parser.getName(); |
|
146 |
} |
|
147 |
} |
|
148 |
return bbox; |
|
149 |
} |
|
150 |
|
|
151 |
/* |
|
152 |
* (non-Javadoc) |
|
153 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#hasNext() |
|
154 |
*/ |
|
155 |
public boolean hasNext() throws IOException { |
|
156 |
if (iterations < 2){ |
|
157 |
return true; |
|
158 |
} |
|
159 |
return false; |
|
160 |
} |
|
161 |
|
|
162 |
/* |
|
163 |
* (non-Javadoc) |
|
164 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#next(double[]) |
|
165 |
*/ |
|
166 |
public void next(double[] buffer) throws IOException { |
|
167 |
if (iterations == 0){ |
|
168 |
for (int i=0 ; i<buffer.length ; i++){ |
|
169 |
buffer[i] = min[i]; |
|
170 |
} |
|
171 |
iterations = 1; |
|
172 |
} |
|
173 |
if (iterations == 1){ |
|
174 |
for (int i=0 ; i<buffer.length ; i++){ |
|
175 |
buffer[i] = max[i]; |
|
176 |
} |
|
177 |
iterations = 2; |
|
178 |
} |
|
179 |
} |
|
180 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/coordinates/LatLonAltBoxIterator.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.parser.v21.coordinates; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
|
6 |
import org.gvsig.gpe.kml.utils.KmlTags; |
|
7 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
|
8 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
|
9 |
|
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
11 |
* |
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
13 |
* |
|
14 |
* This program is free software; you can redistribute it and/or |
|
15 |
* modify it under the terms of the GNU General Public License |
|
16 |
* as published by the Free Software Foundation; either version 2 |
|
17 |
* of the License, or (at your option) any later version. |
|
18 |
* |
|
19 |
* This program is distributed in the hope that it will be useful, |
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
* GNU General Public License for more details. |
|
23 |
* |
|
24 |
* You should have received a copy of the GNU General Public License |
|
25 |
* along with this program; if not, write to the Free Software |
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
27 |
* |
|
28 |
* For more information, contact: |
|
29 |
* |
|
30 |
* Generalitat Valenciana |
|
31 |
* Conselleria d'Infraestructures i Transport |
|
32 |
* Av. Blasco Ib??ez, 50 |
|
33 |
* 46010 VALENCIA |
|
34 |
* SPAIN |
|
35 |
* |
|
36 |
* +34 963862235 |
|
37 |
* gvsig@gva.es |
|
38 |
* www.gvsig.gva.es |
|
39 |
* |
|
40 |
* or |
|
41 |
* |
|
42 |
* IVER T.I. S.A |
|
43 |
* Salamanca 50 |
|
44 |
* 46005 Valencia |
|
45 |
* Spain |
|
46 |
* |
|
47 |
* +34 963163400 |
|
48 |
* dac@iver.es |
|
49 |
*/ |
|
50 |
/* CVS MESSAGES: |
|
51 |
* |
|
52 |
* $Id:LatLonAltBoxBinding.java 357 2008-01-09 17:50:08Z jpiera $ |
|
53 |
* $Log$ |
|
54 |
* Revision 1.1 2007/05/11 07:06:29 jorpiell |
|
55 |
* Refactoring of some package names |
|
56 |
* |
|
57 |
* Revision 1.1 2007/05/09 08:36:24 jorpiell |
|
58 |
* Add the bbox to the layer |
|
59 |
* |
|
60 |
* |
|
61 |
*/ |
|
62 |
/** |
|
63 |
* This class parses a LatLonAltBox tag. Example: |
|
64 |
* <p> |
|
65 |
* <pre> |
|
66 |
* <code> |
|
67 |
* <LatLonAltBox> |
|
68 |
* <north>43.374</north> |
|
69 |
* <south>42.983</south> |
|
70 |
* <east>-0.335</east> |
|
71 |
* <west>-1.423</west> |
|
72 |
* <minAltitude>0</minAltitude> |
|
73 |
* <maxAltitude>0</maxAltitude> |
|
74 |
* </LatLonAltBox> |
|
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#latlonaltbox |
|
80 |
*/ |
|
81 |
public class LatLonAltBoxIterator extends KmlCoodinatesIterator{ |
|
82 |
double[] min = null; |
|
83 |
double[] max = null; |
|
84 |
int iterations = 0; |
|
85 |
|
|
86 |
/** |
|
87 |
* It parses the LatLonAltBox 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 |
* A Bounding box |
|
95 |
* @throws IOException |
|
96 |
* @throws XmlStreamException |
|
97 |
*/ |
|
98 |
public Object parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException { |
|
99 |
boolean endFeature = false; |
|
100 |
int currentTag; |
|
101 |
Object bbox = null; |
|
102 |
min = new double[3]; |
|
103 |
max = new double[3]; |
|
104 |
double rotation; |
|
105 |
iterations = 0; |
|
106 |
dimension = 3; |
|
107 |
|
|
108 |
String id = handler.getProfile().getGeometryBinding().getID(parser, handler); |
|
109 |
|
|
110 |
String tag = parser.getName(); |
|
111 |
currentTag = parser.getEventType(); |
|
112 |
|
|
113 |
while (!endFeature){ |
|
114 |
switch(currentTag){ |
|
115 |
case IXmlStreamReader.START_TAG: |
|
116 |
if (tag.compareTo(KmlTags.NORTH) == 0){ |
|
117 |
parser.next(); |
|
118 |
max[1] = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
119 |
}else if (tag.compareTo(KmlTags.SOUTH) == 0){ |
|
120 |
parser.next(); |
|
121 |
min[1] = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
122 |
}else if (tag.compareTo(KmlTags.EAST) == 0){ |
|
123 |
parser.next(); |
|
124 |
max[0] = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
125 |
}else if (tag.compareTo(KmlTags.WEST) == 0){ |
|
126 |
parser.next(); |
|
127 |
min[0] = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
128 |
}else if (tag.compareTo(KmlTags.MINALTITUDE) == 0){ |
|
129 |
parser.next(); |
|
130 |
min[2] = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
131 |
}else if (tag.compareTo(KmlTags.MAXALTITUDE) == 0){ |
|
132 |
parser.next(); |
|
133 |
max[2] = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
134 |
} |
|
135 |
break; |
|
136 |
case IXmlStreamReader.END_TAG: |
|
137 |
if (tag.compareTo(KmlTags.LATLONALTBOX) == 0){ |
|
138 |
endFeature = true; |
|
139 |
bbox = handler.getContentHandler().startBbox(id, this, KmlTags.DEFAULT_SRS); |
|
140 |
handler.getContentHandler().endBbox(bbox); |
|
141 |
} |
|
142 |
break; |
|
143 |
case IXmlStreamReader.TEXT: |
|
144 |
|
|
145 |
break; |
|
146 |
} |
|
147 |
if (!endFeature){ |
|
148 |
currentTag = parser.next(); |
|
149 |
tag = parser.getName(); |
|
150 |
} |
|
151 |
} |
|
152 |
return bbox; |
|
153 |
} |
|
154 |
|
|
155 |
/* |
|
156 |
* (non-Javadoc) |
|
157 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#hasNext() |
|
158 |
*/ |
|
159 |
public boolean hasNext() throws IOException { |
|
160 |
if (iterations < 2){ |
|
161 |
return true; |
|
162 |
} |
|
163 |
return false; |
|
164 |
} |
|
165 |
|
|
166 |
/* |
|
167 |
* (non-Javadoc) |
|
168 |
* @see org.gvsig.gpe.parser.ICoordinateIterator#next(double[]) |
|
169 |
*/ |
|
170 |
public void next(double[] buffer) throws IOException { |
|
171 |
if (iterations == 0){ |
|
172 |
for (int i=0 ; i<buffer.length ; i++){ |
|
173 |
buffer[i] = min[i]; |
|
174 |
} |
|
175 |
iterations = 1; |
|
176 |
return; |
|
177 |
} |
|
178 |
if (iterations == 1){ |
|
179 |
for (int i=0 ; i<buffer.length ; i++){ |
|
180 |
buffer[i] = max[i]; |
|
181 |
} |
|
182 |
iterations = 2; |
|
183 |
} |
|
184 |
} |
|
185 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/features/ElementBinding.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.IOException; |
4 | 4 |
|
5 |
import org.gvsig.gpe.gml.utils.GMLUtilsParser; |
|
6 | 5 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
6 |
import org.gvsig.gpe.kml.utils.KMLUtilsParser; |
|
7 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
|
7 | 8 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
8 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
|
9 | 9 |
|
10 | 10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
11 | 11 |
* |
... | ... | |
99 | 99 |
if (!(tag.compareTo(elementRootType)==0)){ |
100 | 100 |
if (!isInitialized){ |
101 | 101 |
String elementName = getElementName(elementRootType); |
102 |
element = handler.getContentHandler().startElement(GMLUtilsParser.removeBlancSymbol(elementName),
|
|
102 |
element = handler.getContentHandler().startElement(KMLUtilsParser.removeBlancSymbol(elementName),
|
|
103 | 103 |
null, |
104 | 104 |
type, |
105 | 105 |
parentElement); |
... | ... | |
114 | 114 |
endFeature = true; |
115 | 115 |
if (!isInitialized){ |
116 | 116 |
String elementName = getElementName(elementRootType); |
117 |
element = handler.getContentHandler().startElement(GMLUtilsParser.removeBlancSymbol(elementName),
|
|
117 |
element = handler.getContentHandler().startElement(KMLUtilsParser.removeBlancSymbol(elementName),
|
|
118 | 118 |
value, |
119 | 119 |
type, |
120 | 120 |
parentElement); |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/geometries/LatLonBoxBinding.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.parser.v21.geometries; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
|
6 |
import org.gvsig.gpe.kml.utils.KmlTags; |
|
7 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
|
8 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
|
9 |
|
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
11 |
* |
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
13 |
* |
|
14 |
* This program is free software; you can redistribute it and/or |
|
15 |
* modify it under the terms of the GNU General Public License |
|
16 |
* as published by the Free Software Foundation; either version 2 |
|
17 |
* of the License, or (at your option) any later version. |
|
18 |
* |
|
19 |
* This program is distributed in the hope that it will be useful, |
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
* GNU General Public License for more details. |
|
23 |
* |
|
24 |
* You should have received a copy of the GNU General Public License |
|
25 |
* along with this program; if not, write to the Free Software |
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
27 |
* |
|
28 |
* For more information, contact: |
|
29 |
* |
|
30 |
* Generalitat Valenciana |
|
31 |
* Conselleria d'Infraestructures i Transport |
|
32 |
* Av. Blasco Ib??ez, 50 |
|
33 |
* 46010 VALENCIA |
|
34 |
* SPAIN |
|
35 |
* |
|
36 |
* +34 963862235 |
|
37 |
* gvsig@gva.es |
|
38 |
* www.gvsig.gva.es |
|
39 |
* |
|
40 |
* or |
|
41 |
* |
|
42 |
* IVER T.I. S.A |
|
43 |
* Salamanca 50 |
|
44 |
* 46005 Valencia |
|
45 |
* Spain |
|
46 |
* |
|
47 |
* +34 963163400 |
|
48 |
* dac@iver.es |
|
49 |
*/ |
|
50 |
/* CVS MESSAGES: |
|
51 |
* |
|
52 |
* $Id:LatLonBoxBinding.java 357 2008-01-09 17:50:08Z jpiera $ |
|
53 |
* $Log$ |
|
54 |
* Revision 1.1 2007/05/11 07:06:29 jorpiell |
|
55 |
* Refactoring of some package names |
|
56 |
* |
|
57 |
* Revision 1.1 2007/05/09 08:36:24 jorpiell |
|
58 |
* Add the bbox to the layer |
|
59 |
* |
|
60 |
* |
|
61 |
*/ |
|
62 |
/** |
|
63 |
* This class parses a LatLonBox tag. Example: |
|
64 |
* <p> |
|
65 |
* <pre> |
|
66 |
* <code> |
|
67 |
* <LatLonAltBox> |
|
68 |
* <north>43.374</north> |
|
69 |
* <south>42.983</south> |
|
70 |
* <east>-0.335</east> |
|
71 |
* <west>-1.423</west> |
|
72 |
* <rotation>39.37878630116985</rotation> |
|
73 |
* </LatLonAltBox> |
|
74 |
* </code> |
|
75 |
* </pre> |
|
76 |
* </p> |
|
77 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
78 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#latlonbox |
|
79 |
*/ |
|
80 |
public class LatLonBoxBinding { |
|
81 |
|
|
82 |
/** |
|
83 |
* It parses the LatLonAltBox tag |
|
84 |
* @param parser |
|
85 |
* The XML parser |
|
86 |
* @param handler |
|
87 |
* The GPE parser that contains the content handler and |
|
88 |
* the error handler |
|
89 |
* @return |
|
90 |
* A Bounding box |
|
91 |
* @throws IOException |
|
92 |
* @throws XmlStreamException |
|
93 |
*/ |
|
94 |
public Object parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException { |
|
95 |
boolean endFeature = false; |
|
96 |
int currentTag; |
|
97 |
Object bbox = null; |
|
98 |
double north = 0; |
|
99 |
double south = 0; |
|
100 |
double east = 0; |
|
101 |
double west = 0; |
|
102 |
double rotation = 0; |
|
103 |
|
|
104 |
String id = handler.getProfile().getGeometryBinding().getID(parser, handler); |
|
105 |
|
|
106 |
String tag = parser.getName(); |
|
107 |
currentTag = parser.getEventType(); |
|
108 |
|
|
109 |
while (!endFeature){ |
|
110 |
switch(currentTag){ |
|
111 |
case IXmlStreamReader.START_TAG: |
|
112 |
if (tag.compareTo(KmlTags.NORTH) == 0){ |
|
113 |
parser.next(); |
|
114 |
north = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
115 |
}else if (tag.compareTo(KmlTags.SOUTH) == 0){ |
|
116 |
parser.next(); |
|
117 |
south = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
118 |
}else if (tag.compareTo(KmlTags.EAST) == 0){ |
|
119 |
parser.next(); |
|
120 |
east = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
121 |
}else if (tag.compareTo(KmlTags.WEST) == 0){ |
|
122 |
parser.next(); |
|
123 |
west = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
124 |
}else if (tag.compareTo(KmlTags.ROTATION) == 0){ |
|
125 |
parser.next(); |
|
126 |
rotation = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
127 |
} |
|
128 |
break; |
|
129 |
case IXmlStreamReader.END_TAG: |
|
130 |
if (tag.compareTo(KmlTags.LATLONBOX) == 0){ |
|
131 |
endFeature = true; |
|
132 |
double[] x = {west,east}; |
|
133 |
double[] y = {south,north}; |
|
134 |
double[] z = {0,0}; |
|
135 |
bbox = handler.getContentHandler().startBbox(id, x, y, z, KmlTags.DEFAULT_SRS); |
|
136 |
handler.getContentHandler().endBbox(bbox); |
|
137 |
} |
|
138 |
break; |
|
139 |
case IXmlStreamReader.TEXT: |
|
140 |
|
|
141 |
break; |
|
142 |
} |
|
143 |
if (!endFeature){ |
|
144 |
currentTag = parser.next(); |
|
145 |
tag = parser.getName(); |
|
146 |
} |
|
147 |
} |
|
148 |
return bbox; |
|
149 |
} |
|
150 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/geometries/LatLonAltBoxBinding.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.parser.v21.geometries; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
|
6 |
import org.gvsig.gpe.kml.utils.KmlTags; |
|
7 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
|
8 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
|
9 |
|
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
11 |
* |
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
13 |
* |
|
14 |
* This program is free software; you can redistribute it and/or |
|
15 |
* modify it under the terms of the GNU General Public License |
|
16 |
* as published by the Free Software Foundation; either version 2 |
|
17 |
* of the License, or (at your option) any later version. |
|
18 |
* |
|
19 |
* This program is distributed in the hope that it will be useful, |
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
* GNU General Public License for more details. |
|
23 |
* |
|
24 |
* You should have received a copy of the GNU General Public License |
|
25 |
* along with this program; if not, write to the Free Software |
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
27 |
* |
|
28 |
* For more information, contact: |
|
29 |
* |
|
30 |
* Generalitat Valenciana |
|
31 |
* Conselleria d'Infraestructures i Transport |
|
32 |
* Av. Blasco Ib??ez, 50 |
|
33 |
* 46010 VALENCIA |
|
34 |
* SPAIN |
|
35 |
* |
|
36 |
* +34 963862235 |
|
37 |
* gvsig@gva.es |
|
38 |
* www.gvsig.gva.es |
|
39 |
* |
|
40 |
* or |
|
41 |
* |
|
42 |
* IVER T.I. S.A |
|
43 |
* Salamanca 50 |
|
44 |
* 46005 Valencia |
|
45 |
* Spain |
|
46 |
* |
|
47 |
* +34 963163400 |
|
48 |
* dac@iver.es |
|
49 |
*/ |
|
50 |
/* CVS MESSAGES: |
|
51 |
* |
|
52 |
* $Id:LatLonAltBoxBinding.java 357 2008-01-09 17:50:08Z jpiera $ |
|
53 |
* $Log$ |
|
54 |
* Revision 1.1 2007/05/11 07:06:29 jorpiell |
|
55 |
* Refactoring of some package names |
|
56 |
* |
|
57 |
* Revision 1.1 2007/05/09 08:36:24 jorpiell |
|
58 |
* Add the bbox to the layer |
|
59 |
* |
|
60 |
* |
|
61 |
*/ |
|
62 |
/** |
|
63 |
* This class parses a LatLonAltBox tag. Example: |
|
64 |
* <p> |
|
65 |
* <pre> |
|
66 |
* <code> |
|
67 |
* <LatLonAltBox> |
|
68 |
* <north>43.374</north> |
|
69 |
* <south>42.983</south> |
|
70 |
* <east>-0.335</east> |
|
71 |
* <west>-1.423</west> |
|
72 |
* <minAltitude>0</minAltitude> |
|
73 |
* <maxAltitude>0</maxAltitude> |
|
74 |
* </LatLonAltBox> |
|
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#latlonaltbox |
|
80 |
*/ |
|
81 |
public class LatLonAltBoxBinding { |
|
82 |
|
|
83 |
/** |
|
84 |
* It parses the LatLonAltBox tag |
|
85 |
* @param parser |
|
86 |
* The XML parser |
|
87 |
* @param handler |
|
88 |
* The GPE parser that contains the content handler and |
|
89 |
* the error handler |
|
90 |
* @return |
|
91 |
* A Bounding box |
|
92 |
* @throws IOException |
|
93 |
* @throws XmlStreamException |
|
94 |
*/ |
|
95 |
public Object parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException { |
|
96 |
boolean endFeature = false; |
|
97 |
int currentTag; |
|
98 |
Object bbox = null; |
|
99 |
double north = 0; |
|
100 |
double south = 0; |
|
101 |
double east = 0; |
|
102 |
double west = 0; |
|
103 |
double minAltitude = 0; |
|
104 |
double maxAltitude = 0; |
|
105 |
|
|
106 |
String id = handler.getProfile().getGeometryBinding().getID(parser, handler); |
|
107 |
|
|
108 |
String tag = parser.getName(); |
|
109 |
currentTag = parser.getEventType(); |
|
110 |
|
|
111 |
while (!endFeature){ |
|
112 |
switch(currentTag){ |
|
113 |
case IXmlStreamReader.START_TAG: |
|
114 |
if (tag.compareTo(KmlTags.NORTH) == 0){ |
|
115 |
parser.next(); |
|
116 |
north = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
117 |
}else if (tag.compareTo(KmlTags.SOUTH) == 0){ |
|
118 |
parser.next(); |
|
119 |
south = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
120 |
}else if (tag.compareTo(KmlTags.EAST) == 0){ |
|
121 |
parser.next(); |
|
122 |
east = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
123 |
}else if (tag.compareTo(KmlTags.WEST) == 0){ |
|
124 |
parser.next(); |
|
125 |
west = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
126 |
}else if (tag.compareTo(KmlTags.MINALTITUDE) == 0){ |
|
127 |
parser.next(); |
|
128 |
minAltitude = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
129 |
}else if (tag.compareTo(KmlTags.MAXALTITUDE) == 0){ |
|
130 |
parser.next(); |
|
131 |
maxAltitude = handler.getProfile().getDoubleBinding().parse(parser.getText()); |
|
132 |
} |
|
133 |
break; |
|
134 |
case IXmlStreamReader.END_TAG: |
|
135 |
if (tag.compareTo(KmlTags.LATLONALTBOX) == 0){ |
|
136 |
endFeature = true; |
|
137 |
double[] x = {west,east}; |
|
138 |
double[] y = {south,north}; |
|
139 |
double[] z = {minAltitude,maxAltitude}; |
|
140 |
bbox = handler.getContentHandler().startBbox(id, x, y, z, KmlTags.DEFAULT_SRS); |
|
141 |
handler.getContentHandler().endBbox(bbox); |
|
142 |
} |
|
143 |
break; |
|
144 |
case IXmlStreamReader.TEXT: |
|
145 |
|
|
146 |
break; |
|
147 |
} |
|
148 |
if (!endFeature){ |
|
149 |
currentTag = parser.next(); |
|
150 |
tag = parser.getName(); |
|
151 |
} |
|
152 |
} |
|
153 |
return bbox; |
|
154 |
} |
|
155 |
} |
|
156 |
|
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/geometries/CoordinatesTypeBinding.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.parser.v21.geometries; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
|
6 |
import org.gvsig.gpe.kml.utils.KmlTags; |
|
7 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
|
8 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
|
9 |
|
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
11 |
* |
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
13 |
* |
|
14 |
* This program is free software; you can redistribute it and/or |
|
15 |
* modify it under the terms of the GNU General Public License |
|
16 |
* as published by the Free Software Foundation; either version 2 |
|
17 |
* of the License, or (at your option) any later version. |
|
18 |
* |
|
19 |
* This program is distributed in the hope that it will be useful, |
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
* GNU General Public License for more details. |
|
23 |
* |
|
24 |
* You should have received a copy of the GNU General Public License |
|
25 |
* along with this program; if not, write to the Free Software |
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
27 |
* |
|
28 |
* For more information, contact: |
|
29 |
* |
|
30 |
* Generalitat Valenciana |
|
31 |
* Conselleria d'Infraestructures i Transport |
|
32 |
* Av. Blasco Ib??ez, 50 |
|
33 |
* 46010 VALENCIA |
|
34 |
* SPAIN |
|
35 |
* |
|
36 |
* +34 963862235 |
|
37 |
* gvsig@gva.es |
|
38 |
* www.gvsig.gva.es |
|
39 |
* |
|
40 |
* or |
|
41 |
* |
|
42 |
* IVER T.I. S.A |
|
43 |
* Salamanca 50 |
|
44 |
* 46005 Valencia |
|
45 |
* Spain |
|
46 |
* |
|
47 |
* +34 963163400 |
|
48 |
* dac@iver.es |
|
49 |
*/ |
|
50 |
/* CVS MESSAGES: |
|
51 |
* |
|
52 |
* $Id:CoordinatesTypeBinding.java 357 2008-01-09 17:50:08Z jpiera $ |
|
53 |
* $Log$ |
|
54 |
* Revision 1.2 2007/06/07 14:53:59 jorpiell |
|
55 |
* Add the schema support |
|
56 |
* |
|
57 |
* Revision 1.1 2007/05/11 07:06:29 jorpiell |
|
58 |
* Refactoring of some package names |
|
59 |
* |
|
60 |
* Revision 1.4 2007/05/09 08:36:24 jorpiell |
|
61 |
* Add the bbox to the layer |
|
62 |
* |
|
63 |
* Revision 1.3 2007/05/08 08:22:37 jorpiell |
|
64 |
* Add comments to create javadocs |
|
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 class parses a coordinates tag. Example: |
|
88 |
* <p> |
|
89 |
* <pre> |
|
90 |
* <code> |
|
91 |
* <coordinates>60.0,60.0 60.0,90.0 90.0,90.0</coordinates> |
|
92 |
* </code> |
|
93 |
* </pre> |
|
94 |
* </p> |
|
95 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
96 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#coordinates |
|
97 |
*/ |
|
98 |
public class CoordinatesTypeBinding { |
|
99 |
|
|
100 |
/** |
|
101 |
* It parses the coordinates tag |
|
102 |
* @param parser |
|
103 |
* The XML parser |
|
104 |
* @param handler |
|
105 |
* The GPE parser that contains the content handler and |
|
106 |
* the error handler |
|
107 |
* @return |
|
108 |
* It retuns a matrix of doubles with 3 columns (x,y,z) and |
|
109 |
* one row for each coordinate. |
|
110 |
* @throws IOException |
|
111 |
* @throws XmlStreamException |
|
112 |
*/ |
|
113 |
public double[][] parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException { |
|
114 |
boolean endFeature = false; |
|
115 |
int currentTag; |
|
116 |
|
|
117 |
double[][] aCoordinates = null; |
|
118 |
|
|
119 |
|
|
120 |
String tag = parser.getName(); |
|
121 |
currentTag = parser.getEventType(); |
|
122 |
|
|
123 |
while (!endFeature){ |
|
124 |
switch(currentTag){ |
|
125 |
case IXmlStreamReader.START_TAG: |
|
126 |
if (tag.compareTo(KmlTags.COORDINATES) == 0){ |
|
127 |
parser.next(); |
|
128 |
String sCoordinates = parser.getText(); |
|
129 |
if (sCoordinates != null){ |
|
130 |
for (int i=0 ; i<sCoordinates.length() ; i++){ |
|
131 |
if (Character.isSpace(sCoordinates.charAt(i))){ |
|
132 |
sCoordinates = sCoordinates.substring(1, sCoordinates.length() -1); |
|
133 |
}else{ |
|
134 |
break; |
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
String[] coordinates = sCoordinates.split("[ \t\n]"); |
|
139 |
aCoordinates = new double[3][coordinates.length]; |
|
140 |
for (int i=0 ; i<coordinates.length ; i++){ |
|
141 |
String[] coordinate = coordinates[i].trim().split(KmlTags.COORDINATES_SEPARATOR); |
|
142 |
aCoordinates[0][i] = handler.getProfile().getDoubleBinding().parse(coordinate[0]); |
|
143 |
aCoordinates[1][i] = handler.getProfile().getDoubleBinding().parse(coordinate[1]); |
|
144 |
if (coordinate.length == 3){ |
|
145 |
aCoordinates[2][i] = handler.getProfile().getDoubleBinding().parse(coordinate[2]); |
|
146 |
} |
|
147 |
} |
|
148 |
} |
|
149 |
break; |
|
150 |
case IXmlStreamReader.END_TAG: |
|
151 |
if (tag.compareTo(KmlTags.COORDINATES) == 0){ |
|
152 |
endFeature = true; |
|
153 |
} |
|
154 |
break; |
|
155 |
case IXmlStreamReader.TEXT: |
|
156 |
|
|
157 |
break; |
|
158 |
} |
|
159 |
if (!endFeature){ |
|
160 |
currentTag = parser.next(); |
|
161 |
tag = parser.getName(); |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
return aCoordinates; |
|
166 |
} |
|
167 |
|
|
168 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/geometries/LineStringTypeBinding.java | ||
---|---|---|
3 | 3 |
import java.io.IOException; |
4 | 4 |
|
5 | 5 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
6 |
import org.gvsig.gpe.kml.parser.v21.coordinates.CoordinatesTypeIterator; |
|
6 | 7 |
import org.gvsig.gpe.kml.utils.KmlTags; |
7 | 8 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
8 | 9 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
... | ... | |
128 | 129 |
switch(currentTag){ |
129 | 130 |
case IXmlStreamReader.START_TAG: |
130 | 131 |
if (tag.compareTo(KmlTags.COORDINATES) == 0){ |
131 |
double[][] coordinates = handler.getProfile().getCoordinatesTypeBinding().parse(parser, handler); |
|
132 |
CoordinatesTypeIterator coordinatesIterator = handler.getProfile().getCoordinatesTypeBinding(); |
|
133 |
coordinatesIterator.initialize(parser, handler, KmlTags.LINESTRING); |
|
132 | 134 |
lineString = handler.getContentHandler().startLineString(id, |
133 |
coordinates[0], |
|
134 |
coordinates[1], |
|
135 |
coordinates[2], |
|
136 |
KmlTags.DEFAULT_SRS); |
|
135 |
coordinatesIterator, |
|
136 |
KmlTags.DEFAULT_SRS); |
|
137 |
return lineString; |
|
137 | 138 |
} |
138 | 139 |
break; |
139 | 140 |
case IXmlStreamReader.END_TAG: |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/geometries/PolygonTypeBinding.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
6 | 6 |
import org.gvsig.gpe.kml.utils.KmlTags; |
7 |
import org.gvsig.gpe.xml.stream.XmlStreamException;
|
|
7 |
import org.gvsig.gpe.parser.ICoordinateIterator;
|
|
8 | 8 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
9 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
|
9 | 10 |
|
10 | 11 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
11 | 12 |
* |
... | ... | |
134 | 135 |
switch(currentTag){ |
135 | 136 |
case IXmlStreamReader.START_TAG: |
136 | 137 |
if (tag.compareTo(KmlTags.OUTERBOUNDARYIS) == 0){ |
137 |
double[][] coordinates = handler.getProfile().getOuterBoundaryIsBinding().parse(parser, handler); |
|
138 |
OuterBoundaryIsBinding coordinatesBinding = handler.getProfile().getOuterBoundaryIsBinding(); |
|
139 |
ICoordinateIterator coordinatesIterator = coordinatesBinding.parse(parser, handler); |
|
138 | 140 |
polygon = handler.getContentHandler().startPolygon(id, |
139 |
coordinates[0], |
|
140 |
coordinates[1], |
|
141 |
coordinates[2], |
|
142 |
KmlTags.DEFAULT_SRS); |
|
141 |
coordinatesIterator, |
|
142 |
KmlTags.DEFAULT_SRS); |
|
143 | 143 |
}else if (tag.compareTo(KmlTags.INNERBOUNDARYIS) == 0){ |
144 |
double[][] coordinates = handler.getProfile().getInnerBoundaryIsBinding().parse(parser, handler); |
|
145 |
Object innerPolygon = handler.getContentHandler().startInnerPolygon(null, |
|
146 |
coordinates[0], |
|
147 |
coordinates[1], |
|
148 |
coordinates[2], |
|
149 |
KmlTags.DEFAULT_SRS); |
|
144 |
InnerBoundaryIsBinding innerPolygonBinding = handler.getProfile().getInnerBoundaryIsBinding(); |
|
145 |
ICoordinateIterator coordinatesIterator = innerPolygonBinding.parse(parser, handler); |
|
146 |
Object innerPolygon = handler.getContentHandler().startInnerPolygon(id, |
|
147 |
coordinatesIterator, |
|
148 |
KmlTags.DEFAULT_SRS); |
|
150 | 149 |
handler.getContentHandler().endInnerPolygon(innerPolygon); |
151 | 150 |
handler.getContentHandler().addInnerPolygonToPolygon(innerPolygon,polygon); |
152 | 151 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/geometries/LinearRingBinding.java | ||
---|---|---|
3 | 3 |
import java.io.IOException; |
4 | 4 |
|
5 | 5 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
6 |
import org.gvsig.gpe.kml.parser.v21.coordinates.CoordinatesTypeIterator; |
|
6 | 7 |
import org.gvsig.gpe.kml.utils.KmlTags; |
8 |
import org.gvsig.gpe.parser.ICoordinateIterator; |
|
7 | 9 |
import org.gvsig.gpe.warnings.PolygonNotClosedWarning; |
8 | 10 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
9 | 11 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
... | ... | |
103 | 105 |
* @throws XmlStreamException |
104 | 106 |
* @throws IOException |
105 | 107 |
*/ |
106 |
public double[][] parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException {
|
|
108 |
public ICoordinateIterator parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException {
|
|
107 | 109 |
boolean endFeature = false; |
108 | 110 |
int currentTag; |
109 |
double[][] coordinates = null; |
|
110 |
|
|
111 |
|
|
111 | 112 |
String tag = parser.getName(); |
112 | 113 |
currentTag = parser.getEventType(); |
113 | 114 |
|
... | ... | |
115 | 116 |
switch(currentTag){ |
116 | 117 |
case IXmlStreamReader.START_TAG: |
117 | 118 |
if (tag.compareTo(KmlTags.COORDINATES) == 0){ |
118 |
coordinates = handler.getProfile().getCoordinatesTypeBinding().parse(parser, handler); |
|
119 |
CoordinatesTypeIterator coordinatesIteartor = handler.getProfile().getCoordinatesTypeBinding(); |
|
120 |
coordinatesIteartor.initialize(parser, handler, KmlTags.LINEARRING); |
|
121 |
if (coordinatesIteartor != null){ |
|
122 |
return coordinatesIteartor; |
|
123 |
} |
|
119 | 124 |
} |
120 | 125 |
break; |
121 | 126 |
case IXmlStreamReader.END_TAG: |
... | ... | |
131 | 136 |
currentTag = parser.next(); |
132 | 137 |
tag = parser.getName(); |
133 | 138 |
} |
134 |
} |
|
135 |
//The first and the last coordinates has to be the same |
|
136 |
if ((coordinates[0][0] != coordinates[0][coordinates[0].length - 1]) || |
|
137 |
(coordinates[1][0] != coordinates[1][coordinates[1].length - 1]) || |
|
138 |
(coordinates[2][0] != coordinates[2][coordinates[2].length - 1])){ |
|
139 |
handler.getErrorHandler().addWarning(new PolygonNotClosedWarning(coordinates)); |
|
140 |
} |
|
141 |
return coordinates; |
|
139 |
} |
|
140 |
return null; |
|
142 | 141 |
} |
143 | 142 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/parser/v21/geometries/InnerBoundaryIsBinding.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser; |
6 | 6 |
import org.gvsig.gpe.kml.utils.KmlTags; |
7 |
import org.gvsig.gpe.parser.ICoordinateIterator; |
|
8 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
|
7 | 9 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
8 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
|
|
10 |
import org.gvsig.gpe.xml.utils.CompareUtils;
|
|
9 | 11 |
|
10 | 12 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
11 | 13 |
* |
... | ... | |
98 | 100 |
* @throws XmlStreamException |
99 | 101 |
* @throws IOException |
100 | 102 |
*/ |
101 |
public double[][] parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException{
|
|
103 |
public ICoordinateIterator parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException {
|
|
102 | 104 |
boolean endFeature = false; |
103 | 105 |
int currentTag; |
104 | 106 |
|
105 |
double[][] coordinates = null; |
|
106 |
|
|
107 | 107 |
String tag = parser.getName(); |
108 | 108 |
currentTag = parser.getEventType(); |
109 | 109 |
|
110 | 110 |
while (!endFeature){ |
111 | 111 |
switch(currentTag){ |
112 | 112 |
case IXmlStreamReader.START_TAG: |
113 |
if (tag.compareTo(KmlTags.LINEARRING) == 0){ |
|
114 |
coordinates = handler.getProfile().getLinearRingBinding().parse(parser, handler); |
|
113 |
if (CompareUtils.compareWithOutNamespace(tag,KmlTags.LINEARRING)){ |
|
114 |
return handler.getProfile().getLinearRingBinding(). |
|
115 |
parse(parser, handler); |
|
115 | 116 |
} |
116 | 117 |
break; |
117 | 118 |
case IXmlStreamReader.END_TAG: |
118 |
if (tag.compareTo(KmlTags.INNERBOUNDARYIS) == 0){
|
|
119 |
if (CompareUtils.compareWithOutNamespace(tag,KmlTags.INNERBOUNDARYIS)){
|
|
119 | 120 |
endFeature = true; |
120 | 121 |
} |
121 | 122 |
break; |
Also available in: Unified diff