public byte [ ] toBytes ( ) throws IOException { ByteWriter writer = new ByteWriter ( ) ; // Write GP as the 2 byte magic number writer . writeString ( GeoPackageConstants . GEO_PACKAGE_GEOMETRY_MAGIC_NUMBER ) ; // Write a byte as the version, value of 0 = version 1 writer . writeByte ( GeoPackageConstants . GEO_PACKAGE_GEOMETRY_VERSION_1 ) ; // Build and write a flags byte byte flags = buildFlagsByte ( ) ; writer . writeByte ( flags ) ; writer . setByteOrder ( byteOrder ) ; // Write the 4 byte srs id int writer . writeInt ( srsId ) ; // Write the envelope writeEnvelope ( writer ) ; // Save off where the WKB bytes start wkbGeometryIndex = writer . size ( ) ; // Write the Well-Known Binary Geometry if not marked as empty if ( ! empty ) { GeometryWriter . writeGeometry ( writer , geometry ) ; } // Get the bytes bytes = writer . getBytes ( ) ; // Close the writer writer . close ( ) ; return bytes ; }
Write the geometry to bytes