ogr/ogrgeometryfactory.cpp
OGRErr OGRGeometryFactory::createFromWkb(unsigned char *pabyData,
                                         OGRSpatialReference * poSR,
                                         OGRGeometry **ppoReturn,
                                         int nBytes )

{
    OGRwkbGeometryType eGeometryType;
    OGRwkbByteOrder eByteOrder;
    OGRErr      eErr;
    OGRGeometry *poGeom;

    *ppoReturn = NULL;

    if( nBytes < 5 && nBytes != -1 )
        return OGRERR_NOT_ENOUGH_DATA;

/* -------------------------------------------------------------------- */
/*      Get the byte order byte.  The extra tests are to work around    */
/*      bug sin the WKB of DB2 v7.2 as identified by Safe Software.     */
/* -------------------------------------------------------------------- */
    eByteOrder = DB2_V72_FIX_BYTE_ORDER((OGRwkbByteOrder) *pabyData);


    if( eByteOrder != wkbXDR && eByteOrder != wkbNDR )
    {
        CPLDebug( "OGR", 
                  "OGRGeometryFactory::createFromWkb() - got corrupt data.\n"
                  "%02X%02X%02X%02X%02X%02X%02X%02X\n", 
                  pabyData[0],
                  pabyData[1],
                  pabyData[2],
                  pabyData[3],
                  pabyData[4],
                  pabyData[5],
                  pabyData[6],
                  pabyData[7],
                  pabyData[8] );
        return OGRERR_CORRUPT_DATA;
    }

/* -------------------------------------------------------------------- */
/*      Get the geometry feature type.  For now we assume that          */
/*      geometry type is between 0 and 255 so we only have to fetch     */
/*      one byte.                                                       */
/* -------------------------------------------------------------------- */
    if( eByteOrder == wkbNDR )
        eGeometryType = (OGRwkbGeometryType) pabyData[1];
    else
        eGeometryType = (OGRwkbGeometryType) pabyData[4];

/* -------------------------------------------------------------------- */
/*      Instantiate a geometry of the appropriate type, and             */
/*      initialize from the input stream.                               */
/* -------------------------------------------------------------------- */
    poGeom = createGeometry( eGeometryType );
    
    if( poGeom == NULL )
        return OGRERR_UNSUPPORTED_GEOMETRY_TYPE;

/* -------------------------------------------------------------------- */
/*      Import from binary.                                             */
/* -------------------------------------------------------------------- */
    eErr = poGeom->importFromWkb( pabyData, nBytes );

/* -------------------------------------------------------------------- */
/*      Assign spatial reference system.                                */
/* -------------------------------------------------------------------- */
    if( eErr == OGRERR_NONE )
    {
        poGeom->assignSpatialReference( poSR );
        *ppoReturn = poGeom;
    }
    else
    {
        delete poGeom;
    }

    return eErr;
}
/**
 * Create a geometry object of the appropriate type from it's well known
 * binary representation.
 *
 * Note that if nBytes is passed as zero, no checking can be done on whether
 * the pabyData is sufficient.  This can result in a crash if the input
 * data is corrupt.  This function returns no indication of the number of
 * bytes from the data source actually used to represent the returned
 * geometry object.  Use OGRGeometry::WkbSize() on the returned geometry to
 * establish the number of bytes it required in WKB format.
 *
 * Also note that this is a static method, and that there
 * is no need to instantiate an OGRGeometryFactory object.  
 *
 * The C function OGR_G_CreateFromWkb() is the same as this method.
 *
 * @param pabyData pointer to the input BLOB data.
 * @param poSR pointer to the spatial reference to be assigned to the
 *             created geometry object.  This may be NULL.
 * @param ppoReturn the newly created geometry object will be assigned to the
 *                  indicated pointer on return.  This will be NULL in case
 *                  of failure.
 * @param nBytes the number of bytes available in pabyData, or -1 if it isn't
 *               known.
 *
 * @return OGRERR_NONE if all goes well, otherwise any of
 * OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or
 * OGRERR_CORRUPT_DATA may be returned.
 */
Create a geometry object of the appropriate type from it's well known
binary representation.

Note that if nBytes is passed as zero, no checking can be done on whether
the pabyData is sufficient.  This can result in a crash if the input
data is corrupt.  This function returns no indication of the number of
bytes from the data source actually used to represent the returned
geometry object.  Use OGRGeometry::WkbSize() on the returned geometry to
establish the number of bytes it required in WKB format.

Also note that this is a static method, and that there
is no need to instantiate an OGRGeometryFactory object.

The C function OGR_G_CreateFromWkb() is the same as this method.

@param pabyData pointer to the input BLOB data.
@param poSR pointer to the spatial reference to be assigned to the
created geometry object.  This may be NULL.
@param ppoReturn the newly created geometry object will be assigned to the
indicated pointer on return.  This will be NULL in case
of failure.
@param nBytes the number of bytes available in pabyData, or -1 if it isn't
known.

@return OGRERR_NONE if all goes well, otherwise any of
OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or
OGRERR_CORRUPT_DATA may be returned.
Create a geometry object of the appropriate type from it ' s well known binary representation . Note that if nBytes is passed as zero no checking can be done on whether the pabyData is sufficient . This can result in a crash if the input data is corrupt . This function returns no indication of the number of bytes from the data source actually used to represent the returned geometry object . Use OGRGeometry :: WkbSize () on the returned geometry to establish the number of bytes it required in WKB format . Also note that this is a static method and that there is no need to instantiate an OGRGeometryFactory object . The C function OGR_G_CreateFromWkb () is the same as this method . @param pabyData pointer to the input BLOB data . @param poSR pointer to the spatial reference to be assigned to the created geometry object . This may be NULL . @param ppoReturn the newly created geometry object will be assigned to the indicated pointer on return . This will be NULL in case of failure . @param nBytes the number of bytes available in pabyData or - 1 if it isn ' t known . @return OGRERR_NONE if all goes well otherwise any of OGRERR_NOT_ENOUGH_DATA OGRERR_UNSUPPORTED_GEOMETRY_TYPE or OGRERR_CORRUPT_DATA may be returned .
OGRErr OGRGeometryFactory::createFromWkb(unsigned char *pabyData,
                                         OGRSpatialReference * poSR,
                                         OGRGeometry **ppoReturn,
                                         int nBytes )
{
    OGRwkbGeometryType eGeometryType;
    OGRwkbByteOrder eByteOrder;
    OGRErr      eErr;
    OGRGeometry *poGeom;
    *ppoReturn = NULL;
    if( nBytes < 5 && nBytes != -1 )
        return OGRERR_NOT_ENOUGH_DATA;
    eByteOrder = DB2_V72_FIX_BYTE_ORDER((OGRwkbByteOrder) *pabyData);
    if( eByteOrder != wkbXDR && eByteOrder != wkbNDR )
    {
        CPLDebug( "OGR", 
                  "OGRGeometryFactory::createFromWkb() - got corrupt data.\n"
                  "%02X%02X%02X%02X%02X%02X%02X%02X\n", 
                  pabyData[0],
                  pabyData[1],
                  pabyData[2],
                  pabyData[3],
                  pabyData[4],
                  pabyData[5],
                  pabyData[6],
                  pabyData[7],
                  pabyData[8] );
        return OGRERR_CORRUPT_DATA;
    }
    if( eByteOrder == wkbNDR )
        eGeometryType = (OGRwkbGeometryType) pabyData[1];
    else
        eGeometryType = (OGRwkbGeometryType) pabyData[4];
    poGeom = createGeometry( eGeometryType );
    if( poGeom == NULL )
        return OGRERR_UNSUPPORTED_GEOMETRY_TYPE;
    eErr = poGeom->importFromWkb( pabyData, nBytes );
    if( eErr == OGRERR_NONE )
    {
        poGeom->assignSpatialReference( poSR );
        *ppoReturn = poGeom;
    }
    else
    {
        delete poGeom;
    }
    return eErr;
}
OGRErr OGRGeometryFactory :: createFromWkb ( unsigned char * pabyData , OGRSpatialReference * poSR , OGRGeometry * * ppoReturn , int nBytes ) { OGRwkbGeometryType eGeometryType ; OGRwkbByteOrder eByteOrder ; OGRErr eErr ; OGRGeometry * poGeom ; * ppoReturn = NULL ; if ( nBytes < 5 && nBytes != -1 ) return OGRERR_NOT_ENOUGH_DATA ; eByteOrder = DB2_V72_FIX_BYTE_ORDER ( ( OGRwkbByteOrder ) * pabyData ) ; if ( eByteOrder != wkbXDR && eByteOrder != wkbNDR ) { CPLDebug ( " " , " \n " " \n " , pabyData [ 0 ] , pabyData [ 1 ] , pabyData [ 2 ] , pabyData [ 3 ] , pabyData [ 4 ] , pabyData [ 5 ] , pabyData [ 6 ] , pabyData [ 7 ] , pabyData [ 8 ] ) ; return OGRERR_CORRUPT_DATA ; } if ( eByteOrder == wkbNDR ) eGeometryType = ( OGRwkbGeometryType ) pabyData [ 1 ] ; else eGeometryType = ( OGRwkbGeometryType ) pabyData [ 4 ] ; poGeom = createGeometry ( eGeometryType ) ; if ( poGeom == NULL ) return OGRERR_UNSUPPORTED_GEOMETRY_TYPE ; eErr = poGeom -> importFromWkb ( pabyData , nBytes ) ; if ( eErr == OGRERR_NONE ) { poGeom -> assignSpatialReference ( poSR ) ; * ppoReturn = poGeom ; } else { delete poGeom ; } return eErr ; }
Create a geometry object of the appropriate type from it's well known
 binary representation.
Create a geometry object of the appropriate type from it ' s well known binary representation .
/* -------------------------------------------------------------------- */ /*      Get the byte order byte.  The extra tests are to work around    */ /*      bug sin the WKB of DB2 v7.2 as identified by Safe Software.     */ /* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */ /*      Get the geometry feature type.  For now we assume that          */ /*      geometry type is between 0 and 255 so we only have to fetch     */ /*      one byte.                                                       */ /* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */ /*      Instantiate a geometry of the appropriate type, and             */ /*      initialize from the input stream.                               */ /* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */ /*      Import from binary.                                             */ /* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */ /*      Assign spatial reference system.                                */ /* -------------------------------------------------------------------- */