protected int getGeometryType(Geometry geometry) {
   WkbGeometryType type = WkbGeometryType.forClass(geometry.getClass());
   if (type == null)
     throw new UnsupportedConversionException(
         String.format(
             "Can't convert geometries of type %s", geometry.getClass().getCanonicalName()));
   return type.getTypeCode();
 }
 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;
   }
 }
Exemplo n.º 3
0
 protected int getGeometryType(Geometry<P> geometry) {
   // empty geometries have the same representation as an empty geometry collection
   if (geometry.isEmpty()) {
     return WkbGeometryType.GEOMETRY_COLLECTION.getTypeCode();
   }
   WkbGeometryType type = WkbGeometryType.forClass(geometry.getClass());
   if (type == null) {
     throw new UnsupportedConversionException(
         String.format(
             "Can't convert geometries of type %s", geometry.getClass().getCanonicalName()));
   }
   return type.getTypeCode();
 }
 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;
 }
 private int getPointByteSize(Geometry geom) {
   return geom.getCoordinateDimension() * ByteBuffer.DOUBLE_SIZE;
 }
 private void writeGeometry(Geometry geom, ByteBuffer output) {
   geom.accept(new WkbVisitor(output));
 }