getCoordinate method

CoordinateSequence getCoordinate(
  1. WKTTokenizer tokenizer,
  2. List<Ordinate> ordinateFlags,
  3. bool tryParen
)

** ** Reads a Coordinate from a stream using the given {@link WKTTokenizer}.

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.

@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. @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

Implementation

// * Reads a Well-Known Text representation of a {@link Geometry}
// * from a {@link Reader}.
// *
// *@param  reader           a Reader which will return a &lt;Geometry Tagged Text&gt;
// *      string (see the OpenGIS Simple Features Specification)
// *@return                  a <code>Geometry</code> read from <code>reader</code>
// *@throws  ParseException  if a parsing problem occurs
// */
// Geometry read(Reader reader)  {
//WKTTokenizer tokenizer = createTokenizer(reader);
//try {
//return readGeometryTaggedText(tokenizer);
//}
//catch (IOException e) {
//throw ParseException(e.toString());
//}
//}

///**
// * Utility function to create the tokenizer
// * @param reader a reader
// *
// * @return a WKT Tokenizer.
// */
// static WKTTokenizer createTokenizer(Reader reader) {
//  WKTTokenizer tokenizer = WKTTokenizer(reader);
//  // set tokenizer to NOT parse numbers
//  tokenizer.resetSyntax();
//  tokenizer.wordChars('a', 'z');
//  tokenizer.wordChars('A', 'Z');
//  tokenizer.wordChars(128 + 32, 255);
//  tokenizer.wordChars('0', '9');
//  tokenizer.wordChars('-', '-');
//  tokenizer.wordChars('+', '+');
//  tokenizer.wordChars('.', '.');
//  tokenizer.whitespaceChars(0, ' ');
//  tokenizer.commentChar('#');
//
//  return tokenizer;
//}

/// Reads a <code>Coordinate</Code> from a stream using the given {@link WKTTokenizer}.
/// <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.
/// @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
CoordinateSequence getCoordinate(
    WKTTokenizer tokenizer, List<Ordinate> ordinateFlags, bool tryParen) {
  bool opened = false;
  if (tryParen && isOpenerNext(tokenizer)) {
    tokenizer.next();
    opened = true;
  }

// create a sequence for one coordinate
  int offsetM = ordinateFlags.contains(Ordinate.Z) ? 1 : 0;
  CoordinateSequence sequence = csFactory.createSizeDimMeas(1,
      toDimension(ordinateFlags), ordinateFlags.contains(Ordinate.M) ? 1 : 0);
  sequence.setOrdinate(0, CoordinateSequence.X,
      precisionModel.makePrecise(getNextNumber(tokenizer)));
  sequence.setOrdinate(0, CoordinateSequence.Y,
      precisionModel.makePrecise(getNextNumber(tokenizer)));

// additionally read other vertices
  if (ordinateFlags.contains(Ordinate.Z)) {
    sequence.setOrdinate(0, CoordinateSequence.Z, getNextNumber(tokenizer));
  }
  if (ordinateFlags.contains(Ordinate.M)) {
    sequence.setOrdinate(
        0, CoordinateSequence.Z + offsetM, getNextNumber(tokenizer));
  }

  if (ordinateFlags.length == 2 &&
      this.isAllowOldJtsCoordinateSyntax &&
      isNumberNext(tokenizer)) {
    sequence.setOrdinate(0, CoordinateSequence.Z, getNextNumber(tokenizer));
  }

// read close token if it was opened here
  if (opened) {
    getNextCloser(tokenizer);
  }

  return sequence;
}