readCoordinates method

CoordinateSequence readCoordinates(
  1. LByteBuffer buffer,
  2. int numPoints,
  3. int dimensions
)

Implementation

CoordinateSequence readCoordinates(
    final LByteBuffer buffer, final int numPoints, final int dimensions) {
  CoordinateSequence cs;
  if (shapeType == ShapeType.POLYGONM) {
    cs = Shapeutils.createCSMeas(
        geometryFactory.getCoordinateSequenceFactory(), numPoints, 3, 1);
  } else if (shapeType == ShapeType.POLYGONZ) {
    cs = Shapeutils.createCSMeas(
        geometryFactory.getCoordinateSequenceFactory(), numPoints, 4, 1);
  } else {
    cs = Shapeutils.createCS(geometryFactory.getCoordinateSequenceFactory(),
        numPoints, dimensions);
  }
  // DoubleBuffer dbuffer = buffer.asDoubleBuffer();
  List<double> ordinates = List.filled(numPoints * 2, 0.0);
  for (var i = 0; i < ordinates.length; i++) {
    ordinates[i] = buffer.getDouble64();
  }
  // dbuffer.get(ordinates);
  for (int t = 0; t < numPoints; t++) {
    cs.setOrdinate(t, CoordinateSequence.X, ordinates[t * 2]);
    cs.setOrdinate(t, CoordinateSequence.Y, ordinates[t * 2 + 1]);
  }

  if (shapeType == ShapeType.POLYGONZ) {
    // Handle Z
    buffer.position = buffer.position + 2 * 8;
    // dbuffer.position(dbuffer.position() + 2);
    for (var i = 0; i < numPoints; i++) {
      ordinates[i] = buffer.getDouble64();
    }
    // dbuffer.get(ordinates, 0, numPoints);

    for (int t = 0; t < numPoints; t++) {
      cs.setOrdinate(t, CoordinateSequence.Z, ordinates[t]);
    }
  }
  if (shapeType == ShapeType.POLYGONM || shapeType == ShapeType.POLYGONZ) {
    // Handle M
    buffer.position = buffer.position + 2 * 8;
    // dbuffer.position(dbuffer.position() + 2);
    for (var i = 0; i < numPoints; i++) {
      ordinates[i] = buffer.getDouble64();
    }
    // dbuffer.get(ordinates, 0, numPoints);

    for (int t = 0; t < numPoints; t++) {
      cs.setOrdinate(t, CoordinateSequence.M, ordinates[t]);
    }
  }

  return cs;
}