write method
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, dynamic geometry) {
MultiLineString multi = geometry as MultiLineString;
Envelope box = multi.getEnvelopeInternal();
buffer.putDouble64(box.getMinX());
buffer.putDouble64(box.getMinY());
buffer.putDouble64(box.getMaxX());
buffer.putDouble64(box.getMaxY());
final int numParts = multi.getNumGeometries();
final List<CoordinateSequence> lines = [];
final List<double> zExtreame = [double.nan, double.nan];
final int npoints = multi.getNumPoints();
buffer.putInt32(numParts);
buffer.putInt32(npoints);
{
int idx = 0;
for (int i = 0; i < numParts; i++) {
lines[i] =
(multi.getGeometryN(i) as LineString).getCoordinateSequence();
buffer.putInt32(idx);
idx = idx + lines[i].size();
}
}
for (int lineN = 0; lineN < lines.length; lineN++) {
CoordinateSequence coords = lines[lineN];
if (shapeType == ShapeType.ARCZ) {
Shapeutils.zMinMax(coords, zExtreame);
}
final int ncoords = coords.size();
for (int t = 0; t < ncoords; t++) {
buffer.putDouble64(coords.getX(t));
buffer.putDouble64(coords.getY(t));
}
}
if (shapeType == ShapeType.ARCZ) {
if (zExtreame[0].isNaN) {
buffer.putDouble64(0.0);
buffer.putDouble64(0.0);
} else {
buffer.putDouble64(zExtreame[0]);
buffer.putDouble64(zExtreame[1]);
}
for (int lineN = 0; lineN < lines.length; lineN++) {
final CoordinateSequence coords = lines[lineN];
final int ncoords = coords.size();
double z;
for (int t = 0; t < ncoords; t++) {
z = coords.getOrdinate(t, 2);
if (z.isNaN) {
buffer.putDouble64(0.0);
} else {
buffer.putDouble64(z);
}
}
}
}
// if there are M coordinates
if (shapeType == ShapeType.ARCZ || shapeType == ShapeType.ARCM) {
// get M values list
List<double> mvalues = [];
for (int t = 0, tt = multi.getNumGeometries(); t < tt; t++) {
LineString line = multi.getGeometryN(t) as LineString;
CoordinateSequence seq = line.getCoordinateSequence();
for (int i = 0; i < seq.size(); i++) {
mvalues.add(line.getCoordinateSequence().getM(i));
}
}
// 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);
});
}
}