write method

  1. @override
void write(
  1. LByteBuffer buffer,
  2. Object geometry
)
override

Write the geometry into the ByteBuffer. The position, byteOrder, and limit are all set. The handler is not responsible for writing the record or shape type integer.

@param buffer The ByteBuffer to write to. @param geometry The geometry to write.

Implementation

@override
void write(LByteBuffer buffer, Object geometry) {
  MultiPoint mp = geometry as MultiPoint;

  Envelope box = mp.getEnvelopeInternal();
  buffer.putDouble64(box.getMinX());
  buffer.putDouble64(box.getMinY());
  buffer.putDouble64(box.getMaxX());
  buffer.putDouble64(box.getMaxY());

  buffer.putInt32(mp.getNumGeometries());

  for (int t = 0, tt = mp.getNumGeometries(); t < tt; t++) {
    Coordinate c = (mp.getGeometryN(t)).getCoordinate()!;
    buffer.putDouble64(c.x);
    buffer.putDouble64(c.y);
  }

  if (shapeType == ShapeType.MULTIPOINTZ) {
    List<double> result = [double.nan, double.nan];
    Shapeutils.zMinMax(CoordinateArraySequence(mp.getCoordinates()), result);
    List<double> zExtreame = result;

    if (zExtreame[0].isNaN) {
      buffer.putDouble64(0.0);
      buffer.putDouble64(0.0);
    } else {
      buffer.putDouble64(zExtreame[0]);
      buffer.putDouble64(zExtreame[1]);
    }

    for (int t = 0; t < mp.getNumGeometries(); t++) {
      Coordinate c = (mp.getGeometryN(t)).getCoordinate()!;
      double z = c.getZ();

      if (z.isNaN) {
        buffer.putDouble64(0.0);
      } else {
        buffer.putDouble64(z);
      }
    }
  }
  // if have M coordinates
  if (shapeType == ShapeType.MULTIPOINTM ||
      shapeType == ShapeType.MULTIPOINTZ) {
    // obtain all M values
    List<double> mvalues = [];
    for (int t = 0, tt = mp.getNumGeometries(); t < tt; t++) {
      Point point = mp.getGeometryN(t) as Point;
      mvalues.add(point.getCoordinateSequence().getM(0));
    }
    // min, max
    double min = mvalues.reduce(math.min);
    double max = mvalues.reduce(math.max);
    buffer.putDouble64(min);
    buffer.putDouble64(max);
    // encode all M values
    mvalues.forEach((x) {
      buffer.putDouble64(x);
    });
  }
}