Revision 11475 trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/bindings/geometries/LineStringTypeBinding.java
LineStringTypeBinding.java | ||
---|---|---|
1 | 1 |
package org.gvsig.gpe.gml.bindings.geometries; |
2 | 2 |
|
3 | 3 |
import java.io.IOException; |
4 |
import java.util.Hashtable; |
|
4 | 5 |
|
5 | 6 |
import org.gvsig.gpe.gml.GMLTags; |
6 | 7 |
import org.gvsig.gpe.gml.GPEGmlParser; |
8 |
import org.gvsig.gpe.gml.utils.CoordsContainer; |
|
9 |
import org.gvsig.gpe.gml.utils.GMLUtilsParser; |
|
7 | 10 |
import org.kxml2.io.KXmlParser; |
8 | 11 |
import org.xmlpull.v1.XmlPullParser; |
9 | 12 |
import org.xmlpull.v1.XmlPullParserException; |
... | ... | |
52 | 55 |
* |
53 | 56 |
* $Id$ |
54 | 57 |
* $Log$ |
55 |
* Revision 1.1 2007-05-07 07:06:46 jorpiell |
|
58 |
* Revision 1.2 2007-05-07 12:58:42 jorpiell |
|
59 |
* Add some methods to manage the multigeometries |
|
60 |
* |
|
61 |
* Revision 1.1 2007/05/07 07:06:46 jorpiell |
|
56 | 62 |
* Add a constructor with the name and the description fields |
57 | 63 |
* |
58 | 64 |
* |
59 | 65 |
*/ |
60 | 66 |
/** |
67 |
* It parses a gml:LineStringType object. Example: |
|
68 |
* <p> |
|
69 |
* <pre> |
|
70 |
* <code> |
|
71 |
* <LineString> |
|
72 |
* <coord><X>56.1</X><Y>0.45</Y></coord> |
|
73 |
* <coord><X>67.23</X><Y>0.98</Y></coord> |
|
74 |
* </LineString> |
|
75 |
* </code> |
|
76 |
* </pre> |
|
77 |
* </p> |
|
61 | 78 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
62 | 79 |
*/ |
63 | 80 |
public class LineStringTypeBinding { |
64 | 81 |
|
82 |
/** |
|
83 |
* It parses the gml:LineString 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 line |
|
91 |
* @throws XmlPullParserException |
|
92 |
* @throws IOException |
|
93 |
*/ |
|
65 | 94 |
public static Object parse(XmlPullParser parser,GPEGmlParser handler) throws XmlPullParserException, IOException { |
66 | 95 |
boolean endFeature = false; |
67 | 96 |
int currentTag; |
97 |
CoordsContainer coordsContainer = null; |
|
68 | 98 |
Object lineString = null; |
69 | 99 |
|
70 |
String srsName = AGeometryBinding.getSrsName(parser, handler); |
|
71 |
String id = AGeometryBinding.getID(parser, handler); |
|
100 |
Hashtable attributes = GMLUtilsParser.getAttributes(parser); |
|
101 |
String srsName = GeometryAttributesBinding.getSrs(attributes); |
|
102 |
String id = GeometryAttributesBinding.getID(attributes); |
|
72 | 103 |
|
73 |
|
|
74 | 104 |
String tag = parser.getName(); |
75 | 105 |
currentTag = parser.getEventType(); |
76 | 106 |
|
... | ... | |
78 | 108 |
switch(currentTag){ |
79 | 109 |
case KXmlParser.START_TAG: |
80 | 110 |
if (tag.compareTo(GMLTags.GML_COORDINATES) == 0){ |
81 |
double[][] coordinates = CoordinatesBinding.parse(parser, handler); |
|
111 |
double[][] coordinates = CoordinatesTypeBinding.parse(parser, handler);
|
|
82 | 112 |
lineString = handler.getContentHandler().startLineString(id, |
83 | 113 |
coordinates[0], |
84 | 114 |
coordinates[1], |
85 | 115 |
coordinates[2], |
86 | 116 |
srsName); |
117 |
}else if (tag.compareTo(GMLTags.GML_COORD) == 0){ |
|
118 |
double[] coordinates = CoordTypeBinding.parse(parser, handler); |
|
119 |
if (coordsContainer == null){ |
|
120 |
coordsContainer = new CoordsContainer(); |
|
121 |
} |
|
122 |
coordsContainer.addCoordinates(coordinates); |
|
87 | 123 |
} |
88 | 124 |
break; |
89 | 125 |
case KXmlParser.END_TAG: |
90 |
if (tag.compareTo(GMLTags.GML_LINESTRING) == 0){
|
|
126 |
if (tag.compareTo(GMLTags.GML_LINESTRING) == 0){ |
|
91 | 127 |
endFeature = true; |
128 |
//If the file contains the COORD tag instead of the |
|
129 |
//coordinates |
|
130 |
if (coordsContainer != null){ |
|
131 |
double[][] coordinates = coordsContainer.getCoordinates(); |
|
132 |
lineString = handler.getContentHandler().startLineString(id, |
|
133 |
coordinates[0], |
|
134 |
coordinates[1], |
|
135 |
coordinates[2], |
|
136 |
srsName); |
|
137 |
} |
|
92 | 138 |
handler.getContentHandler().endLineString(lineString); |
93 | 139 |
} |
94 | 140 |
break; |
Also available in: Unified diff