/** * Returns the next array of <code>Coordinate</code>s in the stream. * *@param tokenizer tokenizer over a stream of text in Well-known Text * format. The next element returned by the stream should be a number. *@return the next array of <code>Coordinate</code>s in the * stream. *@throws IOException if an I/O error occurs *@throws ParseException if an unexpected token was encountered * *@deprecated in favor of functions returning {@link CoordinateSequence}s */ private Coordinate[] getCoordinatesNoLeftParen(StreamTokenizer tokenizer) throws IOException, ParseException { String nextToken = null; ArrayList coordinates = new ArrayList(); coordinates.add(getPreciseCoordinate(tokenizer)); nextToken = getNextCloserOrComma(tokenizer); while (nextToken.equals(COMMA)) { coordinates.add(getPreciseCoordinate(tokenizer)); nextToken = getNextCloserOrComma(tokenizer); } Coordinate[] array = new Coordinate[coordinates.size()]; return (Coordinate[]) coordinates.toArray(array); }
/** * Returns the next array of <code>Coordinate</code>s in the stream. * *@param tokenizer tokenizer over a stream of text in Well-known Text * format. The next element returned by the stream should be L_PAREN (the * beginning of "(x1 y1, x2 y2, ..., xn yn)") or EMPTY. *@return the next array of <code>Coordinate</code>s in the * stream, or an empty array if EMPTY is the next element returned by * the stream. *@throws IOException if an I/O error occurs *@throws ParseException if an unexpected token was encountered * *@deprecated in favor of functions returning {@link CoordinateSequence}s */ private Coordinate[] getCoordinates(StreamTokenizer tokenizer) throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(tokenizer); if (nextToken.equals(EMPTY)) { return new Coordinate[] {}; } ArrayList coordinates = new ArrayList(); coordinates.add(getPreciseCoordinate(tokenizer)); nextToken = getNextCloserOrComma(tokenizer); while (nextToken.equals(COMMA)) { coordinates.add(getPreciseCoordinate(tokenizer)); nextToken = getNextCloserOrComma(tokenizer); } Coordinate[] array = new Coordinate[coordinates.size()]; return (Coordinate[]) coordinates.toArray(array); }
/** * Creates a <code>MultiPolygon</code> using the next token in the stream. * *@param tokenizer tokenizer over a stream of text in Well-known Text * format. The next tokens must form a <MultiPolygon Text>. *@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(StreamTokenizer tokenizer, EnumSet<Ordinate> ordinateFlags) throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(tokenizer); if (nextToken.equals(EMPTY)) { return geometryFactory.createMultiPolygon(); } ArrayList polygons = new ArrayList(); do { Polygon polygon = readPolygonText(tokenizer, ordinateFlags); polygons.add(polygon); nextToken = getNextCloserOrComma(tokenizer); } while (nextToken.equals(COMMA)); Polygon[] array = new Polygon[polygons.size()]; return geometryFactory.createMultiPolygon((Polygon[]) polygons.toArray(array)); }
/** * Creates a <code>Polygon</code> using the next token in the stream. * *@param tokenizer tokenizer over a stream of text in Well-known Text * format. The next tokens must form a <Polygon Text>. *@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(StreamTokenizer tokenizer, EnumSet<Ordinate> ordinateFlags) throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(tokenizer); if (nextToken.equals(EMPTY)) { return geometryFactory.createPolygon(); } ArrayList holes = new ArrayList(); LinearRing shell = readLinearRingText(tokenizer, ordinateFlags); nextToken = getNextCloserOrComma(tokenizer); while (nextToken.equals(COMMA)) { LinearRing hole = readLinearRingText(tokenizer, ordinateFlags); holes.add(hole); nextToken = getNextCloserOrComma(tokenizer); } LinearRing[] array = new LinearRing[holes.size()]; return geometryFactory.createPolygon(shell, (LinearRing[]) holes.toArray(array)); }
/** * Creates a <code>MultiLineString</code> using the next token in the stream. * *@param tokenizer tokenizer over a stream of text in Well-known Text * format. The next tokens must form a <MultiLineString Text>. *@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(StreamTokenizer tokenizer, EnumSet<Ordinate> ordinateFlags) throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(tokenizer); if (nextToken.equals(EMPTY)) { return geometryFactory.createMultiLineString(); } ArrayList lineStrings = new ArrayList(); do { LineString lineString = readLineStringText(tokenizer, ordinateFlags); lineStrings.add(lineString); nextToken = getNextCloserOrComma(tokenizer); } while (nextToken.equals(COMMA)); LineString[] array = new LineString[lineStrings.size()]; return geometryFactory.createMultiLineString((LineString[]) lineStrings.toArray(array)); }
/** * Creates a <code>GeometryCollection</code> using the next token in the * stream. * *@param tokenizer tokenizer over a stream of text in Well-known Text * format. The next tokens must form a <GeometryCollection Text>. *@return a <code>GeometryCollection</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 GeometryCollection readGeometryCollectionText(StreamTokenizer tokenizer, EnumSet<Ordinate> ordinateFlags) throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(tokenizer); if (nextToken.equals(EMPTY)) { return geometryFactory.createGeometryCollection(); } ArrayList geometries = new ArrayList(); do { Geometry geometry = readGeometryTaggedText(tokenizer); geometries.add(geometry); nextToken = getNextCloserOrComma(tokenizer); } while (nextToken.equals(COMMA)); Geometry[] array = new Geometry[geometries.size()]; return geometryFactory.createGeometryCollection((Geometry[]) geometries.toArray(array)); }
/** * Reads a <code>CoordinateSequence</Code> from a stream using the given {@link StreamTokenizer}. * <p> * All ordinate values are read, but -depending on the {@link CoordinateSequenceFactory} of the * underlying {@link GeometryFactory}- not necessarily all can be handled. Those are silently dropped. * </p> * @param tokenizer the tokenizer to use * @param ordinateFlags a bit-mask defining the ordinates to read. * @param tryParen a value indicating if a starting {@link #L_PAREN} should be probed for each coordinate. * @return a {@link CoordinateSequence} of length 1 containing the read ordinate values * *@throws IOException if an I/O error occurs *@throws ParseException if an unexpected token was encountered S */ private CoordinateSequence getCoordinateSequence(StreamTokenizer tokenizer, EnumSet<Ordinate> ordinateFlags, boolean tryParen) throws IOException, ParseException { if (getNextEmptyOrOpener(tokenizer).equals(EMPTY)) return this.csFactory.create(0, toDimension(ordinateFlags), ordinateFlags.contains(Ordinate.M) ? 1 : 0); ArrayList coordinates = new ArrayList(); do { coordinates.add(getCoordinate(tokenizer, ordinateFlags, tryParen)); } while (getNextCloserOrComma(tokenizer).equals(COMMA)); return mergeSequences(coordinates, ordinateFlags); }