Convert LWGEOM to a char* in WKB format.
- Parameters
-
| lwgeom | geometry to convert to WKT |
| variant | output format to use (WKB_ISO, WKB_SFSQL, WKB_EXTENDED, WKB_NDR, WKB_XDR) |
Caller is responsible for freeing the returned array.
- Parameters
-
| variant. | Unsigned bitmask value. Accepts one of: WKB_ISO, WKB_EXTENDED, WKB_SFSQL. Accepts any of: WKB_NDR, WKB_HEX. For example: Variant = ( WKB_ISO | WKB_NDR ) would return the little-endian ISO form of WKB. For Example: Variant = ( WKB_EXTENDED | WKB_HEX ) would return the big-endian extended form of WKB, as hex-encoded ASCII (the "canonical form"). |
| size_out | If supplied, will return the size of the returned memory segment, including the null terminator in the case of ASCII. |
Definition at line 790 of file lwout_wkb.c.
791{
792 size_t buf_size;
793 uint8_t *buf = NULL;
794 uint8_t *wkb_out = NULL;
795
796
797 if ( size_out ) *size_out = 0;
798
799 if ( geom == NULL )
800 {
801 LWDEBUG(4,
"Cannot convert NULL into WKB.");
802 lwerror(
"Cannot convert NULL into WKB.");
803 return NULL;
804 }
805
806
808 LWDEBUGF(4,
"WKB output size: %d", buf_size);
809
810 if ( buf_size == 0 )
811 {
812 LWDEBUG(4,
"Error calculating output WKB buffer size.");
813 lwerror(
"Error calculating output WKB buffer size.");
814 return NULL;
815 }
816
817
819 {
820 buf_size = 2 * buf_size + 1;
821 LWDEBUGF(4,
"Hex WKB output size: %d", buf_size);
822 }
823
824
827 {
830 else
832 }
833
834
836
837 if ( buf == NULL )
838 {
839 LWDEBUGF(4,
"Unable to allocate %d bytes for WKB output buffer.", buf_size);
840 lwerror(
"Unable to allocate %d bytes for WKB output buffer.", buf_size);
841 return NULL;
842 }
843
844
845 wkb_out = buf;
846
847
849
850
852 {
853 *buf = '\0';
854 buf++;
855 }
856
857 LWDEBUGF(4,
"buf (%p) - wkb_out (%p) = %d", buf, wkb_out, buf - wkb_out);
858
859
860 if ( buf_size != (size_t) (buf - wkb_out) )
861 {
862 LWDEBUG(4,
"Output WKB is not the same size as the allocated buffer.");
863 lwerror(
"Output WKB is not the same size as the allocated buffer.");
865 return NULL;
866 }
867
868
869 if ( size_out ) *size_out = buf_size;
870
871 return wkb_out;
872}
void * lwalloc(size_t size)
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static size_t lwgeom_to_wkb_size(const LWGEOM *geom, uint8_t variant)
static uint8_t * lwgeom_to_wkb_buf(const LWGEOM *geom, uint8_t *buf, uint8_t variant)
References IS_BIG_ENDIAN, lwalloc(), LWDEBUG, LWDEBUGF, lwerror(), lwfree(), lwgeom_to_wkb_buf(), lwgeom_to_wkb_size(), variant, WKB_HEX, WKB_NDR, and WKB_XDR.
Referenced by cu_wkb(), cu_wkb_from_hexwkb(), cu_wkb_in(), geography_send(), LWGEOM_asBinary(), lwgeom_to_hexwkb(), polyhedralsurface_parse(), RASTER_asRaster(), RASTER_clip(), RASTER_setPixelValuesGeomval(), rt_raster_gdal_polygonize(), and WKBFromLWGEOM().