protected void writeTypeCodeAndSrid(
     Geometry geometry, DimensionalFlag dimension, ByteBuffer output) {
   int typeCode = getGeometryType(geometry);
   boolean hasSrid = (geometry.getSRID() > 0);
   if (hasSrid && !hasWrittenSrid) typeCode |= PostgisWkbTypeMasks.SRID_FLAG;
   if (dimension.isMeasured()) typeCode |= PostgisWkbTypeMasks.M_FLAG;
   if (dimension.is3D()) typeCode |= PostgisWkbTypeMasks.Z_FLAG;
   output.putUInt(typeCode);
   if (hasSrid && !hasWrittenSrid) {
     output.putInt(geometry.getSRID());
     hasWrittenSrid = true;
   }
 }
 private int calculateSize(Geometry geom, boolean includeSrid) {
   int size = 1 + ByteBuffer.UINT_SIZE; // size for order byte + type field
   if (geom.getSRID() > 0 && includeSrid) size += 4;
   if (geom instanceof GeometryCollection) {
     size += sizeOfGeometryCollection((GeometryCollection) geom);
   } else if (geom instanceof Polygon) {
     size += getPolygonSize((Polygon) geom);
   } else if (geom instanceof Point) {
     size += getPointByteSize(geom);
   } else if (geom instanceof PolyHedralSurface) {
     size += getPolyHedralSurfaceSize((PolyHedralSurface) geom);
   } else {
     size += ByteBuffer.UINT_SIZE; // to hold number of points
     size += getPointByteSize(geom) * geom.getNumPoints();
   }
   return size;
 }