readSpatialiteGeometry method

Geometry readSpatialiteGeometry()

Implementation

Geometry readSpatialiteGeometry() {
  int start = dis.readByte();
  if (start != 0x00) {
    throw ArgumentError("Not a geometry, start byte != 0x00");
  }
// determine byte order
  int byteOrderWKB = dis.readByte();

// always set byte order, since it may change from geometry to geometry
  if (byteOrderWKB == WKBConstants.wkbNDR) {
    dis.setOrder(Endian.little);
  } else if (byteOrderWKB == WKBConstants.wkbXDR) {
    dis.setOrder(Endian.big);
  } else if (isStrict) {
    throw new ParseException(
        "Unknown geometry byte order (not NDR or XDR): $byteOrderWKB");
  }
//if not strict and not XDR or NDR, then we just use the dis default set at the
//start of the geometry (if a multi-geometry).  This  allows WBKReader to work
//with Spatialite native BLOB WKB, as well as other WKB variants that might just
//specify endian-ness at the start of the multigeometry.

  SRID = dis.readInt();

  // 6 - 13 MBR_MIN_X a double value [little- big-endian ordered, accordingly with the
  // precedent one]
  // corresponding to the MBR minimum X coordinate for this GEOMETRY
  // 14 - 21 MBR_MIN_Y a double value corresponding to the MBR minimum Y coordinate
  // 22 - 29 MBR_MAX_X a double value corresponding to the MBR maximum X coordinate
  // 30 - 37 MBR_MAX_Y a double value corresponding to the MBR maximum Y coordinate
  double mbrMinX = dis.readDouble();
  double mbrMinY = dis.readDouble();
  double mbrMaxX = dis.readDouble();
  double mbrMaxY = dis.readDouble();

  // // 38 MBR_END [hex 7C] a GEOMETRY encoded BLOB value must always have an 0x7C byte in
  // this
  // // position
  int mbrEnd = dis.readByte();
  if (mbrEnd != 0x7C) {
    throw new ArgumentError("Not a geometry, MBR_END != 0x7C");
  }

  int typeInt = dis.readInt();
  int geometryType = typeInt & 0xff;
  // determine if Z values are present
  bool hasZ = (typeInt & 0x80000000) != 0;
  inputDimension = hasZ ? 3 : 2;

  // only allocate ordValues buffer if necessary
  if (ordValues == null || ordValues!.length < inputDimension)
    ordValues = List.filled(inputDimension, 0.0);

  late Geometry geom;
  switch (geometryType) {
    case WKBConstants.wkbPoint:
      geom = readPoint();
      break;
    case WKBConstants.wkbLineString:
      geom = readLineString();
      break;
    case WKBConstants.wkbPolygon:
      geom = readPolygon();
      break;
    case WKBConstants.wkbMultiPoint:
      geom = readMultiPoint();
      break;
    case WKBConstants.wkbMultiLineString:
      geom = readMultiLineString();
      break;
    case WKBConstants.wkbMultiPolygon:
      geom = readMultiPolygon();
      break;
    case WKBConstants.wkbGeometryCollection:
      geom = readGeometryCollection();
      break;
    default:
      throw new ParseException("Unknown WKB type $geometryType");
  }
  setSRID(geom, SRID);
  return geom;
}