|
|
|
svn_geotools
|
Author: bencaradocdavies
Date: 2009-10-25 00:33:55 -0400 (Sun, 25 Oct 2009) New Revision: 34232 Modified: branches/geometry/spike/geometry/src/main/java/org/osgeo/geometry/WKTReader.java Log: Committed WKT reader with types other than point and linestring commented. (This should compile.) Modified: branches/geometry/spike/geometry/src/main/java/org/osgeo/geometry/WKTReader.java =================================================================== --- branches/geometry/spike/geometry/src/main/java/org/osgeo/geometry/WKTReader.java 2009-10-25 04:31:14 UTC (rev 34231) +++ branches/geometry/spike/geometry/src/main/java/org/osgeo/geometry/WKTReader.java 2009-10-25 04:33:55 UTC (rev 34232) @@ -397,7 +397,7 @@ return readPointText(); } else if (type.equalsIgnoreCase("LINESTRING")) { return readLineStringText(); - } else if (type.equalsIgnoreCase("LINEARRING")) { + } /*else if (type.equalsIgnoreCase("LINEARRING")) { return readLinearRingText(); } else if (type.equalsIgnoreCase("POLYGON")) { return readPolygonText(); @@ -415,7 +415,7 @@ return readCompoundCurveText(); } else if (type.equalsIgnoreCase("CURVEPOLYGON")) { return readCurvePolygonText(); - } + }*/ throw new ParseException("Unknown geometry type: " + type, -1); } @@ -626,267 +626,267 @@ return result; } - private LineString readCompoundCurveText() throws IOException, ParseException { - List<LineString> lineStrings = getLineStrings(); +// private LineString readCompoundCurveText() throws IOException, ParseException { +// List<LineString> lineStrings = getLineStrings(); +// +// if (lineStrings.isEmpty()) { +// // return an empty lineString? +// return geometryBuilder.createLineString(null, geometryBuilder +// .createPoints(new ArrayList<Point>())); +// } +// if (lineStrings.size() == 1) { +// return lineStrings.get(0); +// } +// // we must gather these all into one - removing duplicates! +// List<Point> coords = new ArrayList<Point>(); +// for (LineString segment : lineStrings) { +// List<Point> segmentPoints = Arrays.asList(segment.getPoints()); +// coords.addAll(segmentPoints.subList(0, segmentPoints.size() - 1)); +// } +// LineString last = lineStrings.get(lineStrings.size() - 1); +// Point end = last.getPointN(last.getNumPoints() - 1); +// coords.add(end); +// +// return geometryBuilder.createLineString(coords.toArray(new Point[coords.size()])); +// } +// +// /** +// * Handles mixed line string notation - either LineString (the default) or CircularCurve. +// * Isolated as a seperate method as I think we will need to call this from the polygon code. +// * +// * @return List of LineString (defined in a mixed format) +// * @throws IOException +// * @throws ParseException +// */ +// List<LineString> getLineStrings() throws IOException, ParseException { +// ArrayList<LineString> lineStrings = new ArrayList<LineString>(); +// String nextWord = getNextEmptyOrOpener(); +// if (nextWord.equals(EMPTY)) { +// return lineStrings; +// } +// // must be an opener! +// nextWord = COMMA; +// while (nextWord.equals(COMMA)) { +// nextWord = getNextWord(); +// if (nextWord.equals(L_PAREN)) { +// List<Point> coords = getPointList(false); +// LineString lineString = geometryBuilder.createLineString(coords +// .toArray(new Point[coords.size()])); +// lineStrings.add(lineString); +// } else if (nextWord.equalsIgnoreCase("CIRCULARSTRING")) { +// LineString circularString = readCircularStringText(); +// lineStrings.add(circularString); +// } +// nextWord = getNextCloserOrComma(); +// } +// return lineStrings; +// } +// +// /** +// * This method will read a LineString, CircularString or CompoundCurve and return the result as +// * a LinearRing. +// * +// * @return LinearRing +// * <p> +// * This method expects either "EMPTY", "(", "CIRCULARSTRING", or "COMPOIUNDCURVE" to +// * start out with. +// * +// * @throws IOException +// * @throws ParseException +// */ +// private LinearRing readCurvedLinearRingText() throws IOException, ParseException { +// Point ring[] = null; +// +// String nextWord = getNextWord(); +// if (nextWord.equals(L_PAREN)) { +// List<Point> coords = getPointList(false); +// ring = coords.toArray(new Point[coords.size()]); +// } else if (nextWord.equalsIgnoreCase("CIRCULARSTRING")) { +// LineString circularString = readCircularStringText(); +// ring = circularString.getPoints(); +// } else if (nextWord.equalsIgnoreCase("COMPOUNDCURVE")) { +// LineString circularString = readCompoundCurveText(); +// ring = circularString.getPoints(); +// } else { +// parseError(L_PAREN + ", CIRCULARSTRING or COMPOUNDCURVE"); +// } +// return geometryBuilder.createLinearRing(ring); +// } +// +// /** +// * Creates a <code>LinearRing</code> using the next token in the stream. +// * +// *@return a <code>LinearRing</code> specified by the next token in the stream +// *@throws IOException +// * if an I/O error occurs +// *@throws ParseException +// * if the coordinates used to create the <code>LinearRing</code> do not form a +// * closed linestring, or if an unexpected token was encountered +// */ +// private LinearRing readLinearRingText() throws IOException, ParseException { +// return geometryBuilder.createLinearRing(getPoints()); +// } +// +// /** +// * Creates a <code>MultiPoint</code> using the next token in the stream. +// * +// *@return a <code>MultiPoint</code> specified by the next token in the stream +// *@throws IOException +// * if an I/O error occurs +// *@throws ParseException +// * if an unexpected token was encountered +// */ +// private MultiPoint readMultiPointText() throws IOException, ParseException { +// return geometryBuilder.createMultiPoint(toPoints(getPoints())); +// } +// +// /** +// * Creates an array of <code>Point</code>s having the given <code>Point</code> s. +// * +// *@param coordinates +// * the <code>Point</code>s with which to create the <code>Point</code>s +// *@return <code>Point</code>s created using this <code>WKTReader</code> s +// * <code>GeometryFactory</code> +// */ +// private Point[] toPoints(Point[] coordinates) { +// ArrayList points = new ArrayList(); +// for (int i = 0; i < coordinates.length; i++) { +// points.add(geometryBuilder.createPoint(coordinates[i])); +// } +// return (Point[]) points.toArray(new Point[] {}); +// } +// +// /** +// * Creates a <code>Polygon</code> using the next token in the stream. +// * +// *@return a <code>Polygon</code> specified by the next token in the stream +// *@throws ParseException +// * if the coordinates used to create the <code>Polygon</code> shell and holes do not +// * form closed linestrings, or if an unexpected token was encountered. +// *@throws IOException +// * if an I/O error occurs +// */ +// private Polygon readPolygonText() throws IOException, ParseException { +// String nextToken = getNextEmptyOrOpener(); +// if (nextToken.equals(EMPTY)) { +// return geometryBuilder.createPolygon(geometryBuilder.createLinearRing(new Point[] {}), +// new LinearRing[] {}); +// } +// ArrayList holes = new ArrayList(); +// LinearRing shell = readLinearRingText(); +// nextToken = getNextCloserOrComma(); +// while (nextToken.equals(COMMA)) { +// LinearRing hole = readLinearRingText(); +// holes.add(hole); +// nextToken = getNextCloserOrComma(); +// } +// LinearRing[] array = new LinearRing[holes.size()]; +// return geometryBuilder.createPolygon(shell, (LinearRing[]) holes.toArray(array)); +// } +// +// private Polygon readCurvePolygonText() throws IOException, ParseException { +// String nextToken = getNextEmptyOrOpener(); +// if (nextToken.equals(EMPTY)) { +// return geometryBuilder.createPolygon(geometryBuilder.createLinearRing(new Point[] {}), +// new LinearRing[] {}); +// } +// if (!nextToken.equals(L_PAREN)) { +// parseError("Ring expected"); +// } +// LinearRing shell = readCurvedLinearRingText(); +// ArrayList holes = new ArrayList(); +// nextToken = getNextCloserOrComma(); +// while (nextToken.equals(COMMA)) { +// LinearRing hole = readCurvedLinearRingText(); +// holes.add(hole); +// nextToken = getNextCloserOrComma(); +// } +// LinearRing[] array = new LinearRing[holes.size()]; +// return geometryBuilder.createPolygon(shell, (LinearRing[]) holes.toArray(array)); +// } +// +// /** +// * Creates a <code>MultiLineString</code> using the next token in the stream. +// * +// *@return a <code>MultiLineString</code> specified by the next token in the stream +// *@throws IOException +// * if an I/O error occurs +// *@throws ParseException +// * if an unexpected token was encountered +// */ +// private MultiLineString readMultiLineStringText() throws IOException, ParseException { +// String nextToken = getNextEmptyOrOpener(); +// if (nextToken.equals(EMPTY)) { +// return geometryBuilder.createMultiLineString(new LineString[] {}); +// } +// ArrayList lineStrings = new ArrayList(); +// LineString lineString = readLineStringText(); +// lineStrings.add(lineString); +// nextToken = getNextCloserOrComma(); +// while (nextToken.equals(COMMA)) { +// lineString = readLineStringText(); +// lineStrings.add(lineString); +// nextToken = getNextCloserOrComma(); +// } +// LineString[] array = new LineString[lineStrings.size()]; +// return geometryBuilder.createMultiLineString((LineString[]) lineStrings.toArray(array)); +// } +// +// /** +// * Creates a <code>MultiPolygon</code> using the next token in the stream. +// * +// *@return a <code>MultiPolygon</code> specified by the next token in the stream, or if if the +// * coordinates used to create the <code>Polygon</code> shells and holes do not form +// * closed linestrings. +// *@throws IOException +// * if an I/O error occurs +// *@throws ParseException +// * if an unexpected token was encountered +// */ +// private MultiPolygon readMultiPolygonText() throws IOException, ParseException { +// String nextToken = getNextEmptyOrOpener(); +// if (nextToken.equals(EMPTY)) { +// return geometryBuilder.createMultiPolygon(new Polygon[] {}); +// } +// ArrayList polygons = new ArrayList(); +// Polygon polygon = readPolygonText(); +// polygons.add(polygon); +// nextToken = getNextCloserOrComma(); +// while (nextToken.equals(COMMA)) { +// polygon = readPolygonText(); +// polygons.add(polygon); +// nextToken = getNextCloserOrComma(); +// } +// Polygon[] array = new Polygon[polygons.size()]; +// return geometryBuilder.createMultiPolygon((Polygon[]) polygons.toArray(array)); +// } +// +// /** +// * Creates a <code>MultiGeometry</code> using the next token in the stream. +// * +// * @return a <code>MultiGeometry</code> specified by the next token in the stream +// * @throws ParseException +// * if the coordinates used to create a <code>Polygon</code> shell and holes do not +// * form closed linestrings, or if an unexpected token was encountered +// * @throws IOException +// * if an I/O error occurs +// */ +// private MultiGeometry readMultiGeometryText() throws IOException, ParseException { +// String nextToken = getNextEmptyOrOpener(); +// if (nextToken.equals(EMPTY)) { +// return geometryBuilder.createMultiGeometry(new Geometry[] {}); +// } +// ArrayList geometries = new ArrayList(); +// Geometry geometry = readGeometryTaggedText(); +// geometries.add(geometry); +// nextToken = getNextCloserOrComma(); +// while (nextToken.equals(COMMA)) { +// geometry = readGeometryTaggedText(); +// geometries.add(geometry); +// nextToken = getNextCloserOrComma(); +// } +// Geometry[] array = new Geometry[geometries.size()]; +// return geometryBuilder.createMultiGeometry((Geometry[]) geometries.toArray(array)); +// } - if (lineStrings.isEmpty()) { - // return an empty lineString? - return geometryBuilder.createLineString(null, geometryBuilder - .createPoints(new ArrayList<Point>())); - } - if (lineStrings.size() == 1) { - return lineStrings.get(0); - } - // we must gather these all into one - removing duplicates! - List<Point> coords = new ArrayList<Point>(); - for (LineString segment : lineStrings) { - List<Point> segmentPoints = Arrays.asList(segment.getPoints()); - coords.addAll(segmentPoints.subList(0, segmentPoints.size() - 1)); - } - LineString last = lineStrings.get(lineStrings.size() - 1); - Point end = last.getPointN(last.getNumPoints() - 1); - coords.add(end); - - return geometryBuilder.createLineString(coords.toArray(new Point[coords.size()])); - } - - /** - * Handles mixed line string notation - either LineString (the default) or CircularCurve. - * Isolated as a seperate method as I think we will need to call this from the polygon code. - * - * @return List of LineString (defined in a mixed format) - * @throws IOException - * @throws ParseException - */ - List<LineString> getLineStrings() throws IOException, ParseException { - ArrayList<LineString> lineStrings = new ArrayList<LineString>(); - String nextWord = getNextEmptyOrOpener(); - if (nextWord.equals(EMPTY)) { - return lineStrings; - } - // must be an opener! - nextWord = COMMA; - while (nextWord.equals(COMMA)) { - nextWord = getNextWord(); - if (nextWord.equals(L_PAREN)) { - List<Point> coords = getPointList(false); - LineString lineString = geometryBuilder.createLineString(coords - .toArray(new Point[coords.size()])); - lineStrings.add(lineString); - } else if (nextWord.equalsIgnoreCase("CIRCULARSTRING")) { - LineString circularString = readCircularStringText(); - lineStrings.add(circularString); - } - nextWord = getNextCloserOrComma(); - } - return lineStrings; - } - - /** - * This method will read a LineString, CircularString or CompoundCurve and return the result as - * a LinearRing. - * - * @return LinearRing - * <p> - * This method expects either "EMPTY", "(", "CIRCULARSTRING", or "COMPOIUNDCURVE" to - * start out with. - * - * @throws IOException - * @throws ParseException - */ - private LinearRing readCurvedLinearRingText() throws IOException, ParseException { - Point ring[] = null; - - String nextWord = getNextWord(); - if (nextWord.equals(L_PAREN)) { - List<Point> coords = getPointList(false); - ring = coords.toArray(new Point[coords.size()]); - } else if (nextWord.equalsIgnoreCase("CIRCULARSTRING")) { - LineString circularString = readCircularStringText(); - ring = circularString.getPoints(); - } else if (nextWord.equalsIgnoreCase("COMPOUNDCURVE")) { - LineString circularString = readCompoundCurveText(); - ring = circularString.getPoints(); - } else { - parseError(L_PAREN + ", CIRCULARSTRING or COMPOUNDCURVE"); - } - return geometryBuilder.createLinearRing(ring); - } - - /** - * Creates a <code>LinearRing</code> using the next token in the stream. - * - *@return a <code>LinearRing</code> specified by the next token in the stream - *@throws IOException - * if an I/O error occurs - *@throws ParseException - * if the coordinates used to create the <code>LinearRing</code> do not form a - * closed linestring, or if an unexpected token was encountered - */ - private LinearRing readLinearRingText() throws IOException, ParseException { - return geometryBuilder.createLinearRing(getPoints()); - } - - /** - * Creates a <code>MultiPoint</code> using the next token in the stream. - * - *@return a <code>MultiPoint</code> specified by the next token in the stream - *@throws IOException - * if an I/O error occurs - *@throws ParseException - * if an unexpected token was encountered - */ - private MultiPoint readMultiPointText() throws IOException, ParseException { - return geometryBuilder.createMultiPoint(toPoints(getPoints())); - } - - /** - * Creates an array of <code>Point</code>s having the given <code>Point</code> s. - * - *@param coordinates - * the <code>Point</code>s with which to create the <code>Point</code>s - *@return <code>Point</code>s created using this <code>WKTReader</code> s - * <code>GeometryFactory</code> - */ - private Point[] toPoints(Point[] coordinates) { - ArrayList points = new ArrayList(); - for (int i = 0; i < coordinates.length; i++) { - points.add(geometryBuilder.createPoint(coordinates[i])); - } - return (Point[]) points.toArray(new Point[] {}); - } - - /** - * Creates a <code>Polygon</code> using the next token in the stream. - * - *@return a <code>Polygon</code> specified by the next token in the stream - *@throws ParseException - * if the coordinates used to create the <code>Polygon</code> shell and holes do not - * form closed linestrings, or if an unexpected token was encountered. - *@throws IOException - * if an I/O error occurs - */ - private Polygon readPolygonText() throws IOException, ParseException { - String nextToken = getNextEmptyOrOpener(); - if (nextToken.equals(EMPTY)) { - return geometryBuilder.createPolygon(geometryBuilder.createLinearRing(new Point[] {}), - new LinearRing[] {}); - } - ArrayList holes = new ArrayList(); - LinearRing shell = readLinearRingText(); - nextToken = getNextCloserOrComma(); - while (nextToken.equals(COMMA)) { - LinearRing hole = readLinearRingText(); - holes.add(hole); - nextToken = getNextCloserOrComma(); - } - LinearRing[] array = new LinearRing[holes.size()]; - return geometryBuilder.createPolygon(shell, (LinearRing[]) holes.toArray(array)); - } - - private Polygon readCurvePolygonText() throws IOException, ParseException { - String nextToken = getNextEmptyOrOpener(); - if (nextToken.equals(EMPTY)) { - return geometryBuilder.createPolygon(geometryBuilder.createLinearRing(new Point[] {}), - new LinearRing[] {}); - } - if (!nextToken.equals(L_PAREN)) { - parseError("Ring expected"); - } - LinearRing shell = readCurvedLinearRingText(); - ArrayList holes = new ArrayList(); - nextToken = getNextCloserOrComma(); - while (nextToken.equals(COMMA)) { - LinearRing hole = readCurvedLinearRingText(); - holes.add(hole); - nextToken = getNextCloserOrComma(); - } - LinearRing[] array = new LinearRing[holes.size()]; - return geometryBuilder.createPolygon(shell, (LinearRing[]) holes.toArray(array)); - } - - /** - * Creates a <code>MultiLineString</code> using the next token in the stream. - * - *@return a <code>MultiLineString</code> specified by the next token in the stream - *@throws IOException - * if an I/O error occurs - *@throws ParseException - * if an unexpected token was encountered - */ - private MultiLineString readMultiLineStringText() throws IOException, ParseException { - String nextToken = getNextEmptyOrOpener(); - if (nextToken.equals(EMPTY)) { - return geometryBuilder.createMultiLineString(new LineString[] {}); - } - ArrayList lineStrings = new ArrayList(); - LineString lineString = readLineStringText(); - lineStrings.add(lineString); - nextToken = getNextCloserOrComma(); - while (nextToken.equals(COMMA)) { - lineString = readLineStringText(); - lineStrings.add(lineString); - nextToken = getNextCloserOrComma(); - } - LineString[] array = new LineString[lineStrings.size()]; - return geometryBuilder.createMultiLineString((LineString[]) lineStrings.toArray(array)); - } - - /** - * Creates a <code>MultiPolygon</code> using the next token in the stream. - * - *@return a <code>MultiPolygon</code> specified by the next token in the stream, or if if the - * coordinates used to create the <code>Polygon</code> shells and holes do not form - * closed linestrings. - *@throws IOException - * if an I/O error occurs - *@throws ParseException - * if an unexpected token was encountered - */ - private MultiPolygon readMultiPolygonText() throws IOException, ParseException { - String nextToken = getNextEmptyOrOpener(); - if (nextToken.equals(EMPTY)) { - return geometryBuilder.createMultiPolygon(new Polygon[] {}); - } - ArrayList polygons = new ArrayList(); - Polygon polygon = readPolygonText(); - polygons.add(polygon); - nextToken = getNextCloserOrComma(); - while (nextToken.equals(COMMA)) { - polygon = readPolygonText(); - polygons.add(polygon); - nextToken = getNextCloserOrComma(); - } - Polygon[] array = new Polygon[polygons.size()]; - return geometryBuilder.createMultiPolygon((Polygon[]) polygons.toArray(array)); - } - - /** - * Creates a <code>MultiGeometry</code> using the next token in the stream. - * - * @return a <code>MultiGeometry</code> specified by the next token in the stream - * @throws ParseException - * if the coordinates used to create a <code>Polygon</code> shell and holes do not - * form closed linestrings, or if an unexpected token was encountered - * @throws IOException - * if an I/O error occurs - */ - private MultiGeometry readMultiGeometryText() throws IOException, ParseException { - String nextToken = getNextEmptyOrOpener(); - if (nextToken.equals(EMPTY)) { - return geometryBuilder.createMultiGeometry(new Geometry[] {}); - } - ArrayList geometries = new ArrayList(); - Geometry geometry = readGeometryTaggedText(); - geometries.add(geometry); - nextToken = getNextCloserOrComma(); - while (nextToken.equals(COMMA)) { - geometry = readGeometryTaggedText(); - geometries.add(geometry); - nextToken = getNextCloserOrComma(); - } - Geometry[] array = new Geometry[geometries.size()]; - return geometryBuilder.createMultiGeometry((Geometry[]) geometries.toArray(array)); - } - } ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ GeoTools-commits mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-commits |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |