01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library 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 GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.gml;
17:
18: import java.util.ArrayList;
19:
20: import com.vividsolutions.jts.geom.Coordinate;
21: import com.vividsolutions.jts.geom.Geometry;
22: import com.vividsolutions.jts.geom.GeometryFactory;
23: import com.vividsolutions.jts.geom.LineString;
24:
25: /**
26: * Creates a simple OGC LineString element.
27: *
28: * @author Ian Turton, CCG
29: * @author Rob Hranac, Vision for New York
30: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/gml/SubHandlerLineString.java $
31: * @version $Id: SubHandlerLineString.java 26168 2007-07-06 19:58:03Z jgarnett $
32: */
33: public class SubHandlerLineString extends SubHandler {
34: /** List of coordinates for LineString. */
35: private ArrayList coordinateList = new ArrayList();
36:
37: /**
38: * Empty constructor.
39: */
40: public SubHandlerLineString() {
41: }
42:
43: /**
44: * Adds a coordinate to the LineString.
45: *
46: * @param coordinate Coordinate to add to LineString.
47: */
48: public void addCoordinate(Coordinate coordinate) {
49: coordinateList.add(coordinate);
50: }
51:
52: /**
53: * Determine whether or not this LineString is ready to be created.
54: *
55: * @param message The geometry type.
56: *
57: * @return Ready for creation flag.
58: */
59: public boolean isComplete(String message) {
60: if (coordinateList.size() > 1) {
61: return true;
62: } else {
63: return false;
64: }
65: }
66:
67: /**
68: * Create the LineString.
69: *
70: * @param geometryFactory The geometry factory needed to do the build.
71: *
72: * @return JTS LineString geometry.
73: */
74: public Geometry create(GeometryFactory geometryFactory) {
75: Coordinate[] coords = (Coordinate[]) coordinateList
76: .toArray(new Coordinate[coordinateList.size()]);
77: LineString lineString = geometryFactory
78: .createLineString(coords);
79: lineString.setUserData(getSRS());
80: lineString.setSRID(getSRID());
81: return lineString;
82: }
83: }
|