Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SQLite: fix identification of Spatialite blobs vs WKB blobs (WKB pars…

…er could be confused by particular values of SRID in Spatialite blobs, such as SRID generated by Spatialite 4)

git-svn-id: https://svn.osgeo.org/gdal/trunk@24902 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information...
commit 719988f192553ea2a411f929ae4390eaff3ee56e 1 parent 2d90875
@rouault rouault authored
Showing with 19 additions and 12 deletions.
  1. +19 −12 gdal/ogr/ogrsf_frmts/sqlite/ogrsqlitelayer.cpp
View
31 gdal/ogr/ogrsf_frmts/sqlite/ogrsqlitelayer.cpp
@@ -143,18 +143,20 @@ int OGRIsBinaryGeomCol( sqlite3_stmt *hStmt, int iCol,
OGRGeometry* poGeometry = NULL;
const int nBytes = sqlite3_column_bytes( hStmt, iCol );
CPLPushErrorHandler(CPLQuietErrorHandler);
- if( OGRGeometryFactory::createFromWkb(
- (GByte*)sqlite3_column_blob( hStmt, iCol ),
- NULL, &poGeometry, nBytes ) == OGRERR_NONE )
- {
- eGeomFormat = OSGF_WKB;
- }
- else if( OGRSQLiteLayer::ImportSpatiaLiteGeometry(
+ /* Try as spatialite first since createFromWkb() can sometimes */
+ /* interpret spatialite blobs as WKB for certain SRID values */
+ if( OGRSQLiteLayer::ImportSpatiaLiteGeometry(
(GByte*)sqlite3_column_blob( hStmt, iCol ), nBytes,
&poGeometry ) == OGRERR_NONE )
{
eGeomFormat = OSGF_SpatiaLite;
}
+ else if( OGRGeometryFactory::createFromWkb(
+ (GByte*)sqlite3_column_blob( hStmt, iCol ),
+ NULL, &poGeometry, nBytes ) == OGRERR_NONE )
+ {
+ eGeomFormat = OSGF_WKB;
+ }
else if( OGRGeometryFactory::createFromFgf(
(GByte*)sqlite3_column_blob( hStmt, iCol ),
NULL, &poGeometry, nBytes, NULL ) == OGRERR_NONE )
@@ -534,11 +536,9 @@ OGRFeature *OGRSQLiteLayer::GetNextRawFeature()
{
const int nBytes = sqlite3_column_bytes( hStmt, iGeomCol );
- if( OGRGeometryFactory::createFromWkb(
- (GByte*)sqlite3_column_blob( hStmt, iGeomCol ),
- NULL, &poGeometry, nBytes ) == OGRERR_NONE )
- poFeature->SetGeometryDirectly( poGeometry );
- else if (!bTriedAsSpatiaLite)
+ /* Try as spatialite first since createFromWkb() can sometimes */
+ /* interpret spatialite blobs as WKB for certain SRID values */
+ if (!bTriedAsSpatiaLite)
{
/* If the layer is the result of a sql select, we cannot be sure if it is */
/* WKB or SpatialLite format */
@@ -551,6 +551,13 @@ OGRFeature *OGRSQLiteLayer::GetNextRawFeature()
}
bTriedAsSpatiaLite = TRUE;
}
+
+ if( eGeomFormat == OSGF_WKB && OGRGeometryFactory::createFromWkb(
+ (GByte*)sqlite3_column_blob( hStmt, iGeomCol ),
+ NULL, &poGeometry, nBytes ) == OGRERR_NONE )
+ {
+ poFeature->SetGeometryDirectly( poGeometry );
+ }
}
else if ( eGeomFormat == OSGF_FGF )
{
Please sign in to comment.
Something went wrong with that request. Please try again.