Skip to content

Commit

Permalink
make relaxed lookup optional and add a switch -relaxedFieldNameMatch …
Browse files Browse the repository at this point in the history
…to ogr2ogr to allow it
  • Loading branch information
jef-n committed Oct 3, 2013
1 parent 66723a4 commit a12311e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 26 deletions.
23 changes: 17 additions & 6 deletions gdal/apps/ogr2ogr.cpp
Expand Up @@ -91,7 +91,8 @@ static TargetLayerInfo* SetupTargetLayer( OGRDataSource *poSrcDS,
int bExplodeCollections,
const char* pszZField,
char **papszFieldMap,
const char* pszWHERE );
const char* pszWHERE,
int bExactFieldNameMatch );

static void FreeTargetLayerInfo(TargetLayerInfo* psInfo);

Expand Down Expand Up @@ -866,6 +867,7 @@ int main( int nArgc, char ** papszArgv )
const char *pszSourceSRSDef = NULL;
OGRSpatialReference *poOutputSRS = NULL;
int bNullifyOutputSRS = FALSE;
int bExactFieldNameMatch = TRUE;
OGRSpatialReference *poSourceSRS = NULL;
char *pszNewLayerName = NULL;
const char *pszWHERE = NULL;
Expand Down Expand Up @@ -992,6 +994,10 @@ int main( int nArgc, char ** papszArgv )
{
bUpdate = TRUE;
}
else if( EQUAL(papszArgv[iArg],"-relaxedFieldNameMatch") )
{
bExactFieldNameMatch = FALSE;
}
else if( EQUAL(papszArgv[iArg],"-fid") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
Expand Down Expand Up @@ -1770,7 +1776,8 @@ int main( int nArgc, char ** papszArgv )
bExplodeCollections,
pszZField,
papszFieldMap,
pszWHERE );
pszWHERE,
bExactFieldNameMatch );

poPassedLayer->ResetReading();

Expand Down Expand Up @@ -1925,7 +1932,8 @@ int main( int nArgc, char ** papszArgv )
bExplodeCollections,
pszZField,
papszFieldMap,
pszWHERE );
pszWHERE,
bExactFieldNameMatch );

if( psInfo == NULL && !bSkipFailures )
exit(1);
Expand Down Expand Up @@ -2199,7 +2207,8 @@ int main( int nArgc, char ** papszArgv )
bExplodeCollections,
pszZField,
papszFieldMap,
pszWHERE );
pszWHERE,
bExactFieldNameMatch );

poPassedLayer->ResetReading();

Expand Down Expand Up @@ -2319,6 +2328,7 @@ static void Usage(const char* pszAdditionalMsg, int bShort)
" [-wrapdateline][-datelineoffset val]\n"
" [[-simplify tolerance] | [-segmentize max_dist]]\n"
" [-addfields]\n"
" [-relaxedFieldNameMatch]\n"
" [-fieldTypeToString All|(type1[,type2]*)] [-unsetFieldWidth]\n"
" [-fieldmap identity | index1[,index2]*]\n"
" [-splitlistfields] [-maxsubfields val]\n"
Expand Down Expand Up @@ -2483,7 +2493,8 @@ static TargetLayerInfo* SetupTargetLayer( OGRDataSource *poSrcDS,
int bExplodeCollections,
const char* pszZField,
char **papszFieldMap,
const char* pszWHERE )
const char* pszWHERE,
int bExactFieldNameMatch )
{
OGRLayer *poDstLayer;
OGRFeatureDefn *poSrcFDefn;
Expand Down Expand Up @@ -3019,7 +3030,7 @@ static TargetLayerInfo* SetupTargetLayer( OGRDataSource *poSrcDS,
for( iField = 0; iField < nSrcFieldCount; iField++ )
{
OGRFieldDefn* poSrcFieldDefn = poSrcFDefn->GetFieldDefn(iField);
int iDstField = poDstLayer->FindFieldIndex(poSrcFieldDefn->GetNameRef());
int iDstField = poDstLayer->FindFieldIndex(poSrcFieldDefn->GetNameRef(), bExactFieldNameMatch);
if (iDstField >= 0)
panMap[iField] = iDstField;
else
Expand Down
2 changes: 1 addition & 1 deletion gdal/ogr/ogr_api.h
Expand Up @@ -412,7 +412,7 @@ OGRErr CPL_DLL OGR_L_CreateFeature( OGRLayerH, OGRFeatureH );
OGRErr CPL_DLL OGR_L_DeleteFeature( OGRLayerH, long );
OGRFeatureDefnH CPL_DLL OGR_L_GetLayerDefn( OGRLayerH );
OGRSpatialReferenceH CPL_DLL OGR_L_GetSpatialRef( OGRLayerH );
int CPL_DLL OGR_L_FindFieldIndex( OGRLayerH, const char * );
int CPL_DLL OGR_L_FindFieldIndex( OGRLayerH, const char *, int bExactMatch );
int CPL_DLL OGR_L_GetFeatureCount( OGRLayerH, int );
OGRErr CPL_DLL OGR_L_GetExtent( OGRLayerH, OGREnvelope *, int );
OGRErr CPL_DLL OGR_L_GetExtentEx( OGRLayerH, int iGeomField,
Expand Down
6 changes: 3 additions & 3 deletions gdal/ogr/ogrsf_frmts/generic/ogrlayer.cpp
Expand Up @@ -846,19 +846,19 @@ OGRFeatureDefnH OGR_L_GetLayerDefn( OGRLayerH hLayer )
/* OGR_L_FindFieldIndex() */
/************************************************************************/

int OGR_L_FindFieldIndex( OGRLayerH hLayer, const char *pszFieldName )
int OGR_L_FindFieldIndex( OGRLayerH hLayer, const char *pszFieldName, int bExactMatch )

{
VALIDATE_POINTER1( hLayer, "OGR_L_FindFieldIndex", NULL );

return ((OGRLayer *)hLayer)->FindFieldIndex( pszFieldName );
return ((OGRLayer *)hLayer)->FindFieldIndex( pszFieldName, bExactMatch );
}

/************************************************************************/
/* FindFieldIndex() */
/************************************************************************/

int OGRLayer::FindFieldIndex( const char *pszFieldName )
int OGRLayer::FindFieldIndex( const char *pszFieldName, int bExactMatch )
{
return GetLayerDefn()->GetFieldIndex( pszFieldName );
}
Expand Down
4 changes: 2 additions & 2 deletions gdal/ogr/ogrsf_frmts/oci/ogr_oci.h
Expand Up @@ -252,7 +252,7 @@ class OGROCILayer : public OGRLayer
public:
OGROCILayer();
virtual ~OGROCILayer();
virtual int FindFieldIndex( const char *pszFieldName ) { return OGRLayer::FindFieldIndex( pszFieldName ); }
virtual int FindFieldIndex( const char *pszFieldName, int bExactMatch ) { return OGRLayer::FindFieldIndex( pszFieldName, bExactMatch ); }

virtual void ResetReading();
virtual OGRFeature *GetNextRawFeature();
Expand Down Expand Up @@ -313,7 +313,7 @@ class OGROCIWritableLayer : public OGROCILayer
virtual OGRSpatialReference *GetSpatialRef() { return poSRS; }
virtual OGRErr CreateField( OGRFieldDefn *poField,
int bApproxOK = TRUE );
virtual int FindFieldIndex( const char *pszFieldName );
virtual int FindFieldIndex( const char *pszFieldName, int bExactMatch );

// following methods are not base class overrides
void SetOptions( char ** );
Expand Down
6 changes: 3 additions & 3 deletions gdal/ogr/ogrsf_frmts/oci/ogrociwritablelayer.cpp
Expand Up @@ -492,13 +492,13 @@ OGRErr OGROCIWritableLayer::TranslateToSDOGeometry( OGRGeometry * poGeometry,
return OGRERR_FAILURE;
}

int OGROCIWritableLayer::FindFieldIndex( const char *pszFieldName )
int OGROCIWritableLayer::FindFieldIndex( const char *pszFieldName, int bExactMatch )
{
int iField = GetLayerDefn()->GetFieldIndex( pszFieldName );

// try laundered version
if( iField < 0 )
if( !bExactMatch && iField < 0 )
{
// try laundered version
OGROCISession *poSession = poDS->GetSession();
char *pszSafeName = CPLStrdup( pszFieldName );

Expand Down
16 changes: 8 additions & 8 deletions gdal/ogr/ogrsf_frmts/ogrsf_frmts.dox
Expand Up @@ -2070,16 +2070,16 @@ by the OGRSFDriverManager.

/**

\fn int OGR_L_FindFieldIndex( OGRLayerH hLayer, const char * );
\fn int OGR_L_FindFieldIndex( OGRLayerH hLayer, const char *, int bExactMatch );

\brief Find the index of field in a layer.

The returned number is the index of the field in the layers, or -1 if the
field doesn't exist.

If the field doesn't exists in the given form the driver might apply
some changes to make it match, like those it might do if the layer was
created (eg. like LAUNDER in the OCI driver).
If bExact match is set and the field doesn't exists in the given form the
driver might apply some changes to make it match, like those it might do if
the layer was created (eg. like LAUNDER in the OCI driver).

This method is the same as the C++ method OGRLayer::FindFieldIndex().

Expand All @@ -2089,16 +2089,16 @@ by the OGRSFDriverManager.

/**

\fn int OGRLayer::FindFieldIndex( const char * );
\fn int OGRLayer::FindFieldIndex( const char *, int bExactMatch );

\brief Find the index of field in the layer.

The returned number is the index of the field in the layers, or -1 if the
field doesn't exist.

If the field doesn't exists in the given form the driver might apply
some changes to make it match, like those it might do if the layer was
created (eg. like LAUNDER in the OCI driver).
If bExact match is set and the field doesn't exists in the given form the
driver might apply some changes to make it match, like those it might do if
the layer was created (eg. like LAUNDER in the OCI driver).

This method is the same as the C function OGR_L_FindFieldIndex().

Expand Down
2 changes: 1 addition & 1 deletion gdal/ogr/ogrsf_frmts/ogrsf_frmts.h
Expand Up @@ -98,7 +98,7 @@ class CPL_DLL OGRLayer
virtual const char *GetName();
virtual OGRwkbGeometryType GetGeomType();
virtual OGRFeatureDefn *GetLayerDefn() = 0;
virtual int FindFieldIndex( const char *pszFieldName );
virtual int FindFieldIndex( const char *pszFieldName, int bExactMatch );

virtual OGRSpatialReference *GetSpatialRef();

Expand Down
4 changes: 2 additions & 2 deletions gdal/swig/include/ogr.i
Expand Up @@ -747,8 +747,8 @@ public:
return OGR_L_RollbackTransaction(self);
}

int FindFieldIndex( const char *pszFieldName ) {
return OGR_L_FindFieldIndex(self, pszFieldName);
int FindFieldIndex( const char *pszFieldName, int bExactMatch ) {
return OGR_L_FindFieldIndex(self, pszFieldName, bExactMatch );
}

%newobject GetSpatialRef;
Expand Down

0 comments on commit a12311e

Please sign in to comment.