OGRErr OGRPoint::importFromWkb( unsigned char * pabyData, int nSize, OGRwkbVariant eWkbVariant ) { OGRwkbByteOrder eByteOrder; OGRBoolean bIs3D = FALSE; OGRErr eErr = importPreambuleFromWkb( pabyData, nSize, eByteOrder, bIs3D, eWkbVariant ); if( eErr >= 0 ) return eErr; if ( nSize < ((bIs3D) ? 29 : 21) && nSize != -1 ) return OGRERR_NOT_ENOUGH_DATA; /* -------------------------------------------------------------------- */ /* Get the vertex. */ /* -------------------------------------------------------------------- */ memcpy( &x, pabyData + 5, 8 ); memcpy( &y, pabyData + 5 + 8, 8 ); if( OGR_SWAP( eByteOrder ) ) { CPL_SWAPDOUBLE( &x ); CPL_SWAPDOUBLE( &y ); } if( bIs3D ) { memcpy( &z, pabyData + 5 + 16, 8 ); if( OGR_SWAP( eByteOrder ) ) { CPL_SWAPDOUBLE( &z ); } nCoordDimension = 3; } else { z = 0; nCoordDimension = 2; } /* Detect NaN coordinates --> EMPTY */ if( x != x && y != y ) nCoordDimension = -nCoordDimension; return OGRERR_NONE; }
OGRErr OGRPoint::importFromWkb( unsigned char * pabyData, int nSize, OGRwkbVariant eWkbVariant ) { OGRwkbByteOrder eByteOrder = wkbNDR; flags = 0; OGRErr eErr = importPreambuleFromWkb( pabyData, nSize, eByteOrder, eWkbVariant ); pabyData += 5; if( eErr != OGRERR_NONE ) return eErr; if( nSize != -1 ) { if( (nSize < 37) && ((flags & OGR_G_3D) && (flags & OGR_G_MEASURED)) ) return OGRERR_NOT_ENOUGH_DATA; else if( (nSize < 29) && ((flags & OGR_G_3D) || (flags & OGR_G_MEASURED)) ) return OGRERR_NOT_ENOUGH_DATA; else if( nSize < 21 ) return OGRERR_NOT_ENOUGH_DATA; } /* -------------------------------------------------------------------- */ /* Get the vertex. */ /* -------------------------------------------------------------------- */ memcpy( &x, pabyData, 8 ); pabyData += 8; memcpy( &y, pabyData, 8 ); pabyData += 8; if( OGR_SWAP( eByteOrder ) ) { CPL_SWAPDOUBLE( &x ); CPL_SWAPDOUBLE( &y ); } if( flags & OGR_G_3D ) { memcpy( &z, pabyData, 8 ); pabyData += 8; if( OGR_SWAP( eByteOrder ) ) CPL_SWAPDOUBLE( &z ); } else { z = 0; } if( flags & OGR_G_MEASURED ) { memcpy( &m, pabyData, 8 ); /*pabyData += 8; */ if( OGR_SWAP( eByteOrder ) ) { CPL_SWAPDOUBLE( &m ); } } else { m = 0; } // Detect coordinates are not NaN --> NOT EMPTY. if( !(CPLIsNan(x) && CPLIsNan(y)) ) flags |= OGR_G_NOT_EMPTY_POINT; return OGRERR_NONE; }