75 GeometryFactory fac=
new GeometryFactory();
76 Geometry lastShape = null;
77 List<Geometry> shapes = null;
78 while(!reader.isDone()) {
79 char event = reader.readKey();
80 if(event<'0' || event >
'9') {
81 if(event == PolyshapeWriter.KEY_SEPERATOR) {
84 throw new ParseException(
"expecting a shape key. not '"+event+
"'", -1);
89 shapes =
new ArrayList<Geometry>();
91 shapes.add(lastShape);
95 if(reader.peek()==PolyshapeWriter.KEY_ARG_START) {
97 arg = reader.readDouble();
98 if(reader.readKey()!=PolyshapeWriter.KEY_ARG_END) {
99 throw new ParseException(
"expecting an argument end", -1);
102 if(reader.isEvent()) {
103 throw new ParseException(
"Invalid input. Event should be followed by data", -1);
107 case PolyshapeWriter.KEY_POINT: {
108 lastShape =
shpFactory.createPoint(
new Coordinate(reader.readLat(),reader.readLng()));
111 case PolyshapeWriter.KEY_LINE: {
114 lastShape=fac.createLineString(reader.readPoints());
134 case PolyshapeWriter.KEY_MULTIPOINT : {
135 lastShape=fac.createMultiPoint(reader.readPoints());
138 case PolyshapeWriter.KEY_CIRCLE : {
140 throw new IllegalArgumentException(
"the input should have a radius argument");
142 GeometricShapeFactory fac2=
new GeometricShapeFactory();
143 fac2.setCentre(
new Coordinate(reader.readLat(),reader.readLng()));
144 fac2.setWidth(arg.doubleValue());
145 lastShape=fac2.createCircle();
153 case PolyshapeWriter.KEY_POLYGON: {
158 throw new ParseException(
"unhandled key: "+event, -1);
164 if(lastShape!=null) {
165 shapes.add(lastShape);
167 if(!shapes.isEmpty() && shapes.get(0)!=null) {
168 if(shapes.get(0) instanceof Point) {
169 return fac.createMultiPoint(GeometryFactory.toPointArray(shapes));
170 }
else if(shapes.get(0) instanceof LineString) {
171 return fac.createMultiLineString(GeometryFactory.toLineStringArray(shapes));
172 }
else if(shapes.get(0) instanceof Polygon) {
173 return fac.createMultiPolygon(GeometryFactory.toPolygonArray(shapes));
final GeometryFactory shpFactory
Definition: PolyshapeReader.java:42
Geometry readPolygon(XReader reader)
Definition: PolyshapeReader.java:180