getLength method

  1. @override
int getLength(
  1. dynamic geometry
)
override

Get the length of the given geometry Object in bytes not 16-bit words. This is easier to keep track of, since the ByteBuffer deals with bytes. Do not include the 8 bytes of record.

@param geometry The geometry to analyze. @return The number of bytes the shape will take up.

Implementation

@override
int getLength(dynamic geometry) {
  MultiPolygon multi;

  if (geometry is MultiPolygon) {
    multi = geometry;
  } else {
    multi = geometryFactory.createMultiPolygon([geometry as Polygon]);
  }

  int nrings = 0;

  for (int t = 0; t < multi.getNumGeometries(); t++) {
    Polygon p = multi.getGeometryN(t) as Polygon;
    nrings = nrings + 1 + p.getNumInteriorRing();
  }

  int npoints = multi.getNumPoints();
  int length;

  if (shapeType == ShapeType.POLYGONZ) {
    length = 44 +
        (4 * nrings) +
        (16 * npoints) +
        (8 * npoints) +
        16 +
        (8 * npoints) +
        16;
  } else if (shapeType == ShapeType.POLYGONM) {
    length = 44 + (4 * nrings) + (16 * npoints) + (8 * npoints) + 16;
  } else if (shapeType == ShapeType.POLYGON) {
    length = 44 + (4 * nrings) + (16 * npoints);
  } else {
    throw StateError("Expected ShapeType of Polygon, got $shapeType");
  }
  return length;
}