本文整理汇总了C++中OGRGeomFieldDefn::GetNameRef方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRGeomFieldDefn::GetNameRef方法的具体用法?C++ OGRGeomFieldDefn::GetNameRef怎么用?C++ OGRGeomFieldDefn::GetNameRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRGeomFieldDefn
的用法示例。
在下文中一共展示了OGRGeomFieldDefn::GetNameRef方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EQUAL
OGRErr OGRILI2Layer::ICreateFeature( OGRFeature *poFeature ) {
char szTempBuffer[80];
const char* tid;
int iField = 0;
if( poFeatureDefn->GetFieldCount() &&
EQUAL(poFeatureDefn->GetFieldDefn(iField)->GetNameRef(), "TID") )
{
tid = poFeature->GetFieldAsString(0);
++iField;
}
else
{
snprintf( szTempBuffer, sizeof(szTempBuffer), CPL_FRMT_GIB,
poFeature->GetFID() );
tid = szTempBuffer;
}
VSILFILE* fp = poDS->GetOutputFP();
if (fp == NULL)
return OGRERR_FAILURE;
VSIFPrintfL(fp, "<%s TID=\"%s\">\n", poFeatureDefn->GetName(), tid);
// Write out Geometries
for( int iGeomField = 0;
iGeomField < poFeatureDefn->GetGeomFieldCount();
iGeomField++ )
{
OGRGeomFieldDefn *poFieldDefn
= poFeatureDefn->GetGeomFieldDefn(iGeomField);
OGRGeometry* poGeom = poFeature->GetGeomFieldRef(iGeomField);
if( poGeom != NULL )
{
CPLString iliGeomType = GetIliGeomType(poFieldDefn->GetNameRef());
OGR2ILIGeometryAppend( poGeom, fp, poFieldDefn->GetNameRef(),
iliGeomType );
}
}
// Write all "set" fields.
for( ; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poField = poFeatureDefn->GetFieldDefn( iField );
if( poFeature->IsFieldSet( iField ) )
{
const char *pszRaw = poFeature->GetFieldAsString( iField );
VSIFPrintfL(fp, "<%s>%s</%s>\n", poField->GetNameRef(), pszRaw, poField->GetNameRef());
}
}
VSIFPrintfL(fp, "</%s>\n", poFeatureDefn->GetName());
return OGRERR_NONE;
}
示例2: AddLayer
int ILI1Reader::ReadModel(ImdReader *poImdReader, const char *pszModelFilename, OGRILI1DataSource *poDS) {
poImdReader->ReadModel(pszModelFilename);
for (FeatureDefnInfos::const_iterator it = poImdReader->featureDefnInfos.begin(); it != poImdReader->featureDefnInfos.end(); ++it)
{
//CPLDebug( "OGR_ILI", "Adding OGRILI1Layer with table '%s'", it->poTableDefn->GetName() );
OGRILI1Layer* layer = new OGRILI1Layer(it->poTableDefn, it->poGeomFieldInfos, poDS);
AddLayer(layer);
//Create additional layers for surface and area geometries
for (GeomFieldInfos::const_iterator it2 = it->poGeomFieldInfos.begin(); it2 != it->poGeomFieldInfos.end(); ++it2)
{
if (it2->second.geomTable)
{
OGRFeatureDefn* poGeomTableDefn = it2->second.geomTable;
OGRGeomFieldDefn* poOGRGeomFieldDefn = poGeomTableDefn->GetGeomFieldDefn(0);
GeomFieldInfos oGeomFieldInfos;
// We add iliGeomType to recognize Ili1 geom tables
oGeomFieldInfos[poOGRGeomFieldDefn->GetNameRef()].iliGeomType = it2->second.iliGeomType;
//CPLDebug( "OGR_ILI", "Adding OGRILI1Layer with geometry table '%s'", it2->second.geomTable->GetName() );
OGRILI1Layer* geomlayer = new OGRILI1Layer(poGeomTableDefn, oGeomFieldInfos, poDS);
AddLayer(geomlayer);
}
}
}
codeBlank = poImdReader->codeBlank;
CPLDebug( "OGR_ILI", "Ili1Format blankCode '%c'", poImdReader->codeBlank );
codeUndefined = poImdReader->codeUndefined;
CPLDebug( "OGR_ILI", "Ili1Format undefinedCode '%c'", poImdReader->codeUndefined );
codeContinue = poImdReader->codeContinue;
CPLDebug( "OGR_ILI", "Ili1Format continueCode '%c'", poImdReader->codeContinue );
return 0;
}
示例3: BuildCopyFields
CPLString OGRPGDumpLayer::BuildCopyFields(int bSetFID)
{
int i = 0;
int nFIDIndex = -1;
CPLString osFieldList;
for( i = 0; i < poFeatureDefn->GetGeomFieldCount(); i++ )
{
if( osFieldList.size() > 0 )
osFieldList += ", ";
OGRGeomFieldDefn* poGFldDefn = poFeatureDefn->GetGeomFieldDefn(i);
osFieldList += OGRPGDumpEscapeColumnName(poGFldDefn->GetNameRef());
}
bFIDColumnInCopyFields = (pszFIDColumn != NULL && bSetFID);
if( bFIDColumnInCopyFields )
{
if( osFieldList.size() > 0 )
osFieldList += ", ";
nFIDIndex = poFeatureDefn->GetFieldIndex( pszFIDColumn );
osFieldList += OGRPGDumpEscapeColumnName(pszFIDColumn);
}
for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ )
{
if (i == nFIDIndex)
continue;
const char *pszName = poFeatureDefn->GetFieldDefn(i)->GetNameRef();
if( osFieldList.size() > 0 )
osFieldList += ", ";
osFieldList += OGRPGDumpEscapeColumnName(pszName);
}
return osFieldList;
}
示例4: ReportOnLayer
static void ReportOnLayer( OGRLayer * poLayer, int bVerbose )
{
OGRFeatureDefn *poDefn = poLayer->GetLayerDefn();
/* -------------------------------------------------------------------- */
/* Report various overall information. */
/* -------------------------------------------------------------------- */
printf( "\n" );
printf( "Layer name: %s\n", poLayer->GetName() );
if( bVerbose )
{
int nGeomFieldCount =
poLayer->GetLayerDefn()->GetGeomFieldCount();
if( nGeomFieldCount > 1 )
{
for(int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
printf( "Geometry (%s): %s\n", poGFldDefn->GetNameRef(),
OGRGeometryTypeToName( poGFldDefn->GetType() ) );
}
}
else
{
printf( "Geometry: %s\n",
OGRGeometryTypeToName( poLayer->GetGeomType() ) );
}
printf( "Feature Count: " CPL_FRMT_GIB "\n", poLayer->GetFeatureCount() );
OGREnvelope oExt;
if( nGeomFieldCount > 1 )
{
for(int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
if (poLayer->GetExtent(iGeom, &oExt, TRUE) == OGRERR_NONE)
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
CPLprintf("Extent (%s): (%f, %f) - (%f, %f)\n",
poGFldDefn->GetNameRef(),
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
}
}
else if ( poLayer->GetExtent(&oExt, TRUE) == OGRERR_NONE)
{
CPLprintf("Extent: (%f, %f) - (%f, %f)\n",
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
char *pszWKT;
if( nGeomFieldCount > 1 )
{
for(int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
OGRSpatialReference* poSRS = poGFldDefn->GetSpatialRef();
if( poSRS == NULL )
pszWKT = CPLStrdup( "(unknown)" );
else
{
poSRS->exportToPrettyWkt( &pszWKT );
}
printf( "SRS WKT (%s):\n%s\n",
poGFldDefn->GetNameRef(), pszWKT );
CPLFree( pszWKT );
}
}
else
{
if( poLayer->GetSpatialRef() == NULL )
pszWKT = CPLStrdup( "(unknown)" );
else
{
poLayer->GetSpatialRef()->exportToPrettyWkt( &pszWKT );
}
printf( "Layer SRS WKT:\n%s\n", pszWKT );
CPLFree( pszWKT );
}
if( strlen(poLayer->GetFIDColumn()) > 0 )
printf( "FID Column = %s\n",
poLayer->GetFIDColumn() );
for(int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
if( nGeomFieldCount == 1 &&
EQUAL(poGFldDefn->GetNameRef(), "") && poGFldDefn->IsNullable() )
//.........这里部分代码省略.........
示例5: ConfigureActiveLayer
void OGRUnionLayer::ConfigureActiveLayer()
{
AutoWarpLayerIfNecessary(iCurLayer);
ApplyAttributeFilterToSrcLayer(iCurLayer);
SetSpatialFilterToSourceLayer(papoSrcLayers[iCurLayer]);
papoSrcLayers[iCurLayer]->ResetReading();
/* Establish map */
GetLayerDefn();
OGRFeatureDefn* poSrcFeatureDefn = papoSrcLayers[iCurLayer]->GetLayerDefn();
CPLFree(panMap);
panMap = (int*) CPLMalloc(poSrcFeatureDefn->GetFieldCount() * sizeof(int));
for(int i=0; i < poSrcFeatureDefn->GetFieldCount(); i++)
{
OGRFieldDefn* poSrcFieldDefn = poSrcFeatureDefn->GetFieldDefn(i);
if( CSLFindString(papszIgnoredFields,
poSrcFieldDefn->GetNameRef() ) == -1 )
{
panMap[i] =
poFeatureDefn->GetFieldIndex(poSrcFieldDefn->GetNameRef());
}
else
{
panMap[i] = -1;
}
}
if( papoSrcLayers[iCurLayer]->TestCapability(OLCIgnoreFields) )
{
char** papszIter = papszIgnoredFields;
char** papszFieldsSrc = NULL;
while ( papszIter != NULL && *papszIter != NULL )
{
const char* pszFieldName = *papszIter;
if ( EQUAL(pszFieldName, "OGR_GEOMETRY") ||
EQUAL(pszFieldName, "OGR_STYLE") ||
poSrcFeatureDefn->GetFieldIndex(pszFieldName) >= 0 ||
poSrcFeatureDefn->GetGeomFieldIndex(pszFieldName) >= 0 )
{
papszFieldsSrc = CSLAddString(papszFieldsSrc, pszFieldName);
}
papszIter++;
}
/* Attribute fields */
int* panSrcFieldsUsed = (int*) CPLCalloc(sizeof(int),
poSrcFeatureDefn->GetFieldCount());
for(int iField = 0;
iField < poFeatureDefn->GetFieldCount(); iField++)
{
OGRFieldDefn* poFieldDefn = poFeatureDefn->GetFieldDefn(iField);
int iSrcField =
poSrcFeatureDefn->GetFieldIndex(poFieldDefn->GetNameRef());
if (iSrcField >= 0)
panSrcFieldsUsed[iSrcField] = TRUE;
}
for(int iSrcField = 0;
iSrcField < poSrcFeatureDefn->GetFieldCount(); iSrcField ++)
{
if( !panSrcFieldsUsed[iSrcField] )
{
OGRFieldDefn *poSrcDefn =
poSrcFeatureDefn->GetFieldDefn( iSrcField );
papszFieldsSrc =
CSLAddString(papszFieldsSrc, poSrcDefn->GetNameRef());
}
}
CPLFree(panSrcFieldsUsed);
/* geometry fields now */
panSrcFieldsUsed = (int*) CPLCalloc(sizeof(int),
poSrcFeatureDefn->GetGeomFieldCount());
for(int iField = 0;
iField < poFeatureDefn->GetGeomFieldCount(); iField++)
{
OGRGeomFieldDefn* poFieldDefn = poFeatureDefn->GetGeomFieldDefn(iField);
int iSrcField =
poSrcFeatureDefn->GetGeomFieldIndex(poFieldDefn->GetNameRef());
if (iSrcField >= 0)
panSrcFieldsUsed[iSrcField] = TRUE;
}
for(int iSrcField = 0;
iSrcField < poSrcFeatureDefn->GetGeomFieldCount(); iSrcField ++)
{
if( !panSrcFieldsUsed[iSrcField] )
{
OGRGeomFieldDefn *poSrcDefn =
poSrcFeatureDefn->GetGeomFieldDefn( iSrcField );
papszFieldsSrc =
CSLAddString(papszFieldsSrc, poSrcDefn->GetNameRef());
}
}
CPLFree(panSrcFieldsUsed);
papoSrcLayers[iCurLayer]->SetIgnoredFields((const char**)papszFieldsSrc);
CSLDestroy(papszFieldsSrc);
}
}
示例6: oField
OGRFeatureDefn *OGRUnionLayer::GetLayerDefn()
{
if( poFeatureDefn != NULL )
return poFeatureDefn;
poFeatureDefn = new OGRFeatureDefn( osName );
poFeatureDefn->Reference();
poFeatureDefn->SetGeomType(wkbNone);
int iCompareFirstIndex = 0;
if( osSourceLayerFieldName.size() )
{
OGRFieldDefn oField(osSourceLayerFieldName, OFTString);
poFeatureDefn->AddFieldDefn(&oField);
iCompareFirstIndex = 1;
}
if( eFieldStrategy == FIELD_SPECIFIED )
{
int i;
for(i = 0; i < nFields; i++)
poFeatureDefn->AddFieldDefn(papoFields[i]);
for(i = 0; i < nGeomFields; i++)
{
poFeatureDefn->AddGeomFieldDefn(new OGRUnionLayerGeomFieldDefn(papoGeomFields[i]), FALSE);
OGRUnionLayerGeomFieldDefn* poGeomFieldDefn =
(OGRUnionLayerGeomFieldDefn* ) poFeatureDefn->GetGeomFieldDefn(i);
if( poGeomFieldDefn->bGeomTypeSet == FALSE ||
poGeomFieldDefn->bSRSSet == FALSE )
{
for(int iLayer = 0; iLayer < nSrcLayers; iLayer++)
{
OGRFeatureDefn* poSrcFeatureDefn =
papoSrcLayers[iLayer]->GetLayerDefn();
int nIndex =
poSrcFeatureDefn->GetGeomFieldIndex(poGeomFieldDefn->GetNameRef());
if( nIndex >= 0 )
{
OGRGeomFieldDefn* poSrcGeomFieldDefn =
poSrcFeatureDefn->GetGeomFieldDefn(nIndex);
if( poGeomFieldDefn->bGeomTypeSet == FALSE )
{
poGeomFieldDefn->bGeomTypeSet = TRUE;
poGeomFieldDefn->SetType(poSrcGeomFieldDefn->GetType());
}
if( poGeomFieldDefn->bSRSSet == FALSE )
{
poGeomFieldDefn->bSRSSet = TRUE;
poGeomFieldDefn->SetSpatialRef(poSrcGeomFieldDefn->GetSpatialRef());
if( i == 0 && poGlobalSRS == NULL )
{
poGlobalSRS = poSrcGeomFieldDefn->GetSpatialRef();
if( poGlobalSRS != NULL )
poGlobalSRS->Reference();
}
}
break;
}
}
}
}
}
else if( eFieldStrategy == FIELD_FROM_FIRST_LAYER )
{
OGRFeatureDefn* poSrcFeatureDefn = papoSrcLayers[0]->GetLayerDefn();
int i;
for(i = 0; i < poSrcFeatureDefn->GetFieldCount(); i++)
poFeatureDefn->AddFieldDefn(poSrcFeatureDefn->GetFieldDefn(i));
for(i = 0; nGeomFields != - 1 && i < poSrcFeatureDefn->GetGeomFieldCount(); i++)
{
OGRGeomFieldDefn* poFldDefn = poSrcFeatureDefn->GetGeomFieldDefn(i);
poFeatureDefn->AddGeomFieldDefn(
new OGRUnionLayerGeomFieldDefn(poFldDefn), FALSE);
}
}
else if (eFieldStrategy == FIELD_UNION_ALL_LAYERS )
{
if( nGeomFields == 1 )
{
poFeatureDefn->AddGeomFieldDefn(
new OGRUnionLayerGeomFieldDefn(papoGeomFields[0]), FALSE);
}
for(int iLayer = 0; iLayer < nSrcLayers; iLayer++)
{
OGRFeatureDefn* poSrcFeatureDefn =
papoSrcLayers[iLayer]->GetLayerDefn();
/* Add any field that is found in the source layers */
int i;
for(i = 0; i < poSrcFeatureDefn->GetFieldCount(); i++)
{
OGRFieldDefn* poSrcFieldDefn = poSrcFeatureDefn->GetFieldDefn(i);
int nIndex =
poFeatureDefn->GetFieldIndex(poSrcFieldDefn->GetNameRef());
if( nIndex < 0 )
poFeatureDefn->AddFieldDefn(poSrcFieldDefn);
else
{
//.........这里部分代码省略.........
示例7: CreateFeatureViaInsert
OGRErr OGRPGDumpLayer::CreateFeatureViaInsert( OGRFeature *poFeature )
{
CPLString osCommand;
int i = 0;
int bNeedComma = FALSE;
OGRErr eErr = OGRERR_FAILURE;
int bEmptyInsert = FALSE;
if( NULL == poFeature )
{
CPLError( CE_Failure, CPLE_AppDefined,
"NULL pointer to OGRFeature passed to CreateFeatureViaInsert()." );
return eErr;
}
/* -------------------------------------------------------------------- */
/* Form the INSERT command. */
/* -------------------------------------------------------------------- */
osCommand.Printf( "INSERT INTO %s (", pszSqlTableName );
for(i = 0; i < poFeatureDefn->GetGeomFieldCount(); i++ )
{
OGRGeometry *poGeom = poFeature->GetGeomFieldRef(i);
if( poGeom != NULL )
{
if( bNeedComma )
osCommand += ", ";
OGRGeomFieldDefn* poGFldDefn = poFeature->GetGeomFieldDefnRef(i);
osCommand = osCommand + OGRPGDumpEscapeColumnName(poGFldDefn->GetNameRef()) + " ";
bNeedComma = TRUE;
}
}
if( poFeature->GetFID() != OGRNullFID && pszFIDColumn != NULL )
{
if( bNeedComma )
osCommand += ", ";
osCommand = osCommand + OGRPGDumpEscapeColumnName(pszFIDColumn) + " ";
bNeedComma = TRUE;
}
for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ )
{
if( !poFeature->IsFieldSet( i ) )
continue;
if( !bNeedComma )
bNeedComma = TRUE;
else
osCommand += ", ";
osCommand = osCommand
+ OGRPGDumpEscapeColumnName(poFeatureDefn->GetFieldDefn(i)->GetNameRef());
}
if (!bNeedComma)
bEmptyInsert = TRUE;
osCommand += ") VALUES (";
/* Set the geometry */
bNeedComma = FALSE;
for(i = 0; i < poFeatureDefn->GetGeomFieldCount(); i++ )
{
OGRGeometry *poGeom = poFeature->GetGeomFieldRef(i);
if( poGeom != NULL )
{
char *pszWKT = NULL;
OGRPGDumpGeomFieldDefn* poGFldDefn =
(OGRPGDumpGeomFieldDefn*) poFeature->GetGeomFieldDefnRef(i);
poGeom->closeRings();
poGeom->setCoordinateDimension( poGFldDefn->nCoordDimension );
if( bNeedComma )
osCommand += ", ";
if( bWriteAsHex )
{
char* pszHex = OGRGeometryToHexEWKB( poGeom, poGFldDefn->nSRSId );
osCommand += "'";
if (pszHex)
osCommand += pszHex;
osCommand += "'";
CPLFree(pszHex);
}
else
{
poGeom->exportToWkt( &pszWKT );
if( pszWKT != NULL )
{
osCommand +=
CPLString().Printf(
"GeomFromEWKT('SRID=%d;%s'::TEXT) ", poGFldDefn->nSRSId, pszWKT );
OGRFree( pszWKT );
//.........这里部分代码省略.........
示例8: GetExtent
OGRErr OGRCARTODBTableLayer::GetExtent( int iGeomField, OGREnvelope *psExtent, int bForce )
{
CPLString osSQL;
if( bDeferedCreation && RunDeferedCreationIfNecessary() != OGRERR_NONE )
return OGRERR_FAILURE;
FlushDeferedInsert();
if( iGeomField < 0 || iGeomField >= GetLayerDefn()->GetGeomFieldCount() ||
GetLayerDefn()->GetGeomFieldDefn(iGeomField)->GetType() == wkbNone )
{
if( iGeomField != 0 )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Invalid geometry field index : %d", iGeomField);
}
return OGRERR_FAILURE;
}
OGRGeomFieldDefn* poGeomFieldDefn =
poFeatureDefn->GetGeomFieldDefn(iGeomField);
/* Do not take the spatial filter into account */
osSQL.Printf( "SELECT ST_Extent(%s) FROM %s",
OGRCARTODBEscapeIdentifier(poGeomFieldDefn->GetNameRef()).c_str(),
OGRCARTODBEscapeIdentifier(osName).c_str());
json_object* poObj = poDS->RunSQL(osSQL);
json_object* poRowObj = OGRCARTODBGetSingleRow(poObj);
if( poRowObj != NULL )
{
json_object* poExtent = json_object_object_get(poRowObj, "st_extent");
if( poExtent != NULL && json_object_get_type(poExtent) == json_type_string )
{
const char* pszBox = json_object_get_string(poExtent);
const char * ptr, *ptrEndParenthesis;
char szVals[64*6+6];
ptr = strchr(pszBox, '(');
if (ptr)
ptr ++;
if (ptr == NULL ||
(ptrEndParenthesis = strchr(ptr, ')')) == NULL ||
ptrEndParenthesis - ptr > (int)(sizeof(szVals) - 1))
{
CPLError( CE_Failure, CPLE_IllegalArg,
"Bad extent representation: '%s'", pszBox);
json_object_put(poObj);
return OGRERR_FAILURE;
}
strncpy(szVals,ptr,ptrEndParenthesis - ptr);
szVals[ptrEndParenthesis - ptr] = '\0';
char ** papszTokens = CSLTokenizeString2(szVals," ,",CSLT_HONOURSTRINGS);
int nTokenCnt = 4;
if ( CSLCount(papszTokens) != nTokenCnt )
{
CPLError( CE_Failure, CPLE_IllegalArg,
"Bad extent representation: '%s'", pszBox);
CSLDestroy(papszTokens);
json_object_put(poObj);
return OGRERR_FAILURE;
}
// Take X,Y coords
// For PostGis ver >= 1.0.0 -> Tokens: X1 Y1 X2 Y2 (nTokenCnt = 4)
// For PostGIS ver < 1.0.0 -> Tokens: X1 Y1 Z1 X2 Y2 Z2 (nTokenCnt = 6)
// => X2 index calculated as nTokenCnt/2
// Y2 index caluclated as nTokenCnt/2+1
psExtent->MinX = CPLAtof( papszTokens[0] );
psExtent->MinY = CPLAtof( papszTokens[1] );
psExtent->MaxX = CPLAtof( papszTokens[nTokenCnt/2] );
psExtent->MaxY = CPLAtof( papszTokens[nTokenCnt/2+1] );
CSLDestroy(papszTokens);
json_object_put(poObj);
return OGRERR_NONE;
}
}
if( poObj != NULL )
json_object_put(poObj);
if( iGeomField == 0 )
return OGRLayer::GetExtent( psExtent, bForce );
else
return OGRLayer::GetExtent( iGeomField, psExtent, bForce );
}
示例9: OGR2SQLITEDealWithSpatialColumn
static
int OGR2SQLITEDealWithSpatialColumn(OGRLayer* poLayer,
int iGeomCol,
const LayerDesc& oLayerDesc,
const CPLString& osTableName,
OGRSQLiteDataSource* poSQLiteDS,
sqlite3* hDB,
int bSpatialiteDB,
const std::set<LayerDesc>&
WHEN_SPATIALITE(oSetLayers),
const std::set<CPLString>&
WHEN_SPATIALITE(oSetSpatialIndex)
)
{
OGRGeomFieldDefn* poGeomField =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeomCol);
CPLString osGeomColRaw;
if( iGeomCol == 0 )
osGeomColRaw = OGR2SQLITE_GetNameForGeometryColumn(poLayer);
else
osGeomColRaw = poGeomField->GetNameRef();
const char* pszGeomColRaw = osGeomColRaw.c_str();
CPLString osGeomColEscaped(OGRSQLiteEscape(pszGeomColRaw));
const char* pszGeomColEscaped = osGeomColEscaped.c_str();
CPLString osLayerNameEscaped(OGRSQLiteEscape(osTableName));
const char* pszLayerNameEscaped = osLayerNameEscaped.c_str();
CPLString osIdxNameRaw(CPLSPrintf("idx_%s_%s",
oLayerDesc.osLayerName.c_str(), pszGeomColRaw));
CPLString osIdxNameEscaped(OGRSQLiteEscapeName(osIdxNameRaw));
/* Make sure that the SRS is injected in spatial_ref_sys */
OGRSpatialReference* poSRS = poGeomField->GetSpatialRef();
if( iGeomCol == 0 && poSRS == NULL )
poSRS = poLayer->GetSpatialRef();
int nSRSId = poSQLiteDS->GetUndefinedSRID();
if( poSRS != NULL )
nSRSId = poSQLiteDS->FetchSRSId(poSRS);
CPLString osSQL;
#ifdef HAVE_SPATIALITE
bool bCreateSpatialIndex = false;
#endif
if( !bSpatialiteDB )
{
osSQL.Printf("INSERT INTO geometry_columns (f_table_name, "
"f_geometry_column, geometry_format, geometry_type, "
"coord_dimension, srid) "
"VALUES ('%s','%s','SpatiaLite',%d,%d,%d)",
pszLayerNameEscaped,
pszGeomColEscaped,
(int) wkbFlatten(poLayer->GetGeomType()),
wkbHasZ( poLayer->GetGeomType() ) ? 3 : 2,
nSRSId);
}
#ifdef HAVE_SPATIALITE
else
{
/* We detect the need for creating a spatial index by 2 means : */
/* 1) if there's an explicit reference to a 'idx_layername_geometrycolumn' */
/* table in the SQL --> old/traditional way of requesting spatial indices */
/* with spatialite. */
std::set<LayerDesc>::const_iterator oIter2 = oSetLayers.begin();
for(; oIter2 != oSetLayers.end(); ++oIter2)
{
const LayerDesc& oLayerDescIter = *oIter2;
if( EQUAL(oLayerDescIter.osLayerName, osIdxNameRaw) )
{
bCreateSpatialIndex = true;
break;
}
}
/* 2) or if there's a SELECT FROM SpatialIndex WHERE f_table_name = 'layername' */
if( !bCreateSpatialIndex )
{
std::set<CPLString>::const_iterator oIter3 = oSetSpatialIndex.begin();
for(; oIter3 != oSetSpatialIndex.end(); ++oIter3)
{
const CPLString& osNameIter = *oIter3;
if( EQUAL(osNameIter, oLayerDesc.osLayerName) )
{
bCreateSpatialIndex = true;
break;
}
}
}
if( poSQLiteDS->HasSpatialite4Layout() )
{
int nGeomType = poLayer->GetGeomType();
int nCoordDimension = 2;
if( wkbHasZ((OGRwkbGeometryType)nGeomType) )
{
nGeomType += 1000;
nCoordDimension = 3;
//.........这里部分代码省略.........
示例10: ReportOnLayer
static void ReportOnLayer( OGRLayer * poLayer, const char *pszWHERE,
const char* pszGeomField,
OGRGeometry *poSpatialFilter,
bool bListMDD,
bool bShowMetadata,
char** papszExtraMDDomains,
bool bFeatureCount,
bool bExtent,
const char* pszWKTFormat )
{
OGRFeatureDefn *poDefn = poLayer->GetLayerDefn();
/* -------------------------------------------------------------------- */
/* Set filters if provided. */
/* -------------------------------------------------------------------- */
if( pszWHERE != nullptr )
{
if( poLayer->SetAttributeFilter(pszWHERE) != OGRERR_NONE )
{
printf("FAILURE: SetAttributeFilter(%s) failed.\n", pszWHERE);
exit(1);
}
}
if( poSpatialFilter != nullptr )
{
if( pszGeomField != nullptr )
{
const int iGeomField = poDefn->GetGeomFieldIndex(pszGeomField);
if( iGeomField >= 0 )
poLayer->SetSpatialFilter(iGeomField, poSpatialFilter);
else
printf("WARNING: Cannot find geometry field %s.\n",
pszGeomField);
}
else
{
poLayer->SetSpatialFilter(poSpatialFilter);
}
}
/* -------------------------------------------------------------------- */
/* Report various overall information. */
/* -------------------------------------------------------------------- */
if( !bSuperQuiet )
{
printf("\n");
printf("Layer name: %s\n", poLayer->GetName());
}
GDALInfoReportMetadata(static_cast<GDALMajorObjectH>(poLayer),
bListMDD,
bShowMetadata,
papszExtraMDDomains);
if( bVerbose )
{
const int nGeomFieldCount =
poLayer->GetLayerDefn()->GetGeomFieldCount();
if( nGeomFieldCount > 1 )
{
for(int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
printf("Geometry (%s): %s\n", poGFldDefn->GetNameRef(),
OGRGeometryTypeToName(poGFldDefn->GetType()));
}
}
else
{
printf("Geometry: %s\n",
OGRGeometryTypeToName(poLayer->GetGeomType()));
}
if( bFeatureCount )
printf("Feature Count: " CPL_FRMT_GIB "\n",
poLayer->GetFeatureCount());
OGREnvelope oExt;
if( bExtent && nGeomFieldCount > 1 )
{
for( int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
if( poLayer->GetExtent(iGeom, &oExt, TRUE) == OGRERR_NONE )
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
CPLprintf("Extent (%s): (%f, %f) - (%f, %f)\n",
poGFldDefn->GetNameRef(),
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
}
}
else if( bExtent && poLayer->GetExtent(&oExt, TRUE) == OGRERR_NONE )
{
CPLprintf("Extent: (%f, %f) - (%f, %f)\n",
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
//.........这里部分代码省略.........
示例11: Compile
OGRErr OGRFeatureQuery::Compile( OGRFeatureDefn *poDefn,
const char * pszExpression,
int bCheck,
swq_custom_func_registrar* poCustomFuncRegistrar )
{
/* -------------------------------------------------------------------- */
/* Clear any existing expression. */
/* -------------------------------------------------------------------- */
if( pSWQExpr != NULL )
{
delete (swq_expr_node *) pSWQExpr;
pSWQExpr = NULL;
}
/* -------------------------------------------------------------------- */
/* Build list of fields. */
/* -------------------------------------------------------------------- */
char **papszFieldNames;
swq_field_type *paeFieldTypes;
int iField;
int nFieldCount = poDefn->GetFieldCount() + SPECIAL_FIELD_COUNT +
poDefn->GetGeomFieldCount();
papszFieldNames = (char **)
CPLMalloc(sizeof(char *) * nFieldCount );
paeFieldTypes = (swq_field_type *)
CPLMalloc(sizeof(swq_field_type) * nFieldCount );
for( iField = 0; iField < poDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poField = poDefn->GetFieldDefn( iField );
papszFieldNames[iField] = (char *) poField->GetNameRef();
switch( poField->GetType() )
{
case OFTInteger:
{
if( poField->GetSubType() == OFSTBoolean )
paeFieldTypes[iField] = SWQ_BOOLEAN;
else
paeFieldTypes[iField] = SWQ_INTEGER;
break;
}
case OFTInteger64:
{
if( poField->GetSubType() == OFSTBoolean )
paeFieldTypes[iField] = SWQ_BOOLEAN;
else
paeFieldTypes[iField] = SWQ_INTEGER64;
break;
}
case OFTReal:
paeFieldTypes[iField] = SWQ_FLOAT;
break;
case OFTString:
paeFieldTypes[iField] = SWQ_STRING;
break;
case OFTDate:
case OFTTime:
case OFTDateTime:
paeFieldTypes[iField] = SWQ_TIMESTAMP;
break;
default:
paeFieldTypes[iField] = SWQ_OTHER;
break;
}
}
iField = 0;
while (iField < SPECIAL_FIELD_COUNT)
{
papszFieldNames[poDefn->GetFieldCount() + iField] = (char *) SpecialFieldNames[iField];
paeFieldTypes[poDefn->GetFieldCount() + iField] = SpecialFieldTypes[iField];
++iField;
}
for( iField = 0; iField < poDefn->GetGeomFieldCount(); iField++ )
{
OGRGeomFieldDefn *poField = poDefn->GetGeomFieldDefn( iField );
int iDstField = poDefn->GetFieldCount() + SPECIAL_FIELD_COUNT + iField;
papszFieldNames[iDstField] = (char *) poField->GetNameRef();
if( *papszFieldNames[iDstField] == '\0' )
papszFieldNames[iDstField] = (char*) OGR_GEOMETRY_DEFAULT_NON_EMPTY_NAME;
paeFieldTypes[iDstField] = SWQ_GEOMETRY;
}
/* -------------------------------------------------------------------- */
/* Try to parse. */
/* -------------------------------------------------------------------- */
OGRErr eErr = OGRERR_NONE;
CPLErr eCPLErr;
//.........这里部分代码省略.........
示例12: ICreateFeature
//.........这里部分代码省略.........
bool bCoordSwap;
char* pszSRSName = GML_GetSRSName(poGeom->getSpatialReference(), poDS->IsLongSRSRequired(), &bCoordSwap);
char szLowerCorner[75], szUpperCorner[75];
if (bCoordSwap)
{
OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinY, sGeomBounds.MinX, sGeomBounds.MinZ, nCoordDimension);
OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxY, sGeomBounds.MaxX, sGeomBounds.MaxZ, nCoordDimension);
}
else
{
OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinX, sGeomBounds.MinY, sGeomBounds.MinZ, nCoordDimension);
OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxX, sGeomBounds.MaxY, sGeomBounds.MaxZ, nCoordDimension);
}
if (bWriteSpaceIndentation)
VSIFPrintfL(fp, " ");
poDS->PrintLine( fp, "<gml:boundedBy><gml:Envelope%s%s><gml:lowerCorner>%s</gml:lowerCorner><gml:upperCorner>%s</gml:upperCorner></gml:Envelope></gml:boundedBy>",
(nCoordDimension == 3) ? " srsDimension=\"3\"" : "",pszSRSName, szLowerCorner, szUpperCorner);
CPLFree(pszSRSName);
}
char** papszOptions = (bIsGML3Output) ? CSLAddString(NULL, "FORMAT=GML3") : NULL;
if (bIsGML3Output && !poDS->IsLongSRSRequired())
papszOptions = CSLAddString(papszOptions, "GML3_LONGSRS=NO");
const char* pszSRSDimensionLoc = poDS->GetSRSDimensionLoc();
if( pszSRSDimensionLoc != NULL )
papszOptions = CSLSetNameValue(papszOptions, "SRSDIMENSION_LOC", pszSRSDimensionLoc);
if (poDS->IsGML32Output())
{
if( poFeatureDefn->GetGeomFieldCount() > 1 )
papszOptions = CSLAddString(papszOptions,
CPLSPrintf("GMLID=%s.%s." CPL_FRMT_GIB,
poFeatureDefn->GetName(),
poFieldDefn->GetNameRef(),
poFeature->GetFID()));
else
papszOptions = CSLAddString(papszOptions,
CPLSPrintf("GMLID=%s.geom." CPL_FRMT_GIB,
poFeatureDefn->GetName(), poFeature->GetFID()));
}
if( !bIsGML3Output && OGR_GT_IsNonLinear(poGeom->getGeometryType()) )
{
OGRGeometry* poGeomTmp = OGRGeometryFactory::forceTo(
poGeom->clone(),OGR_GT_GetLinear(poGeom->getGeometryType()));
pszGeometry = poGeomTmp->exportToGML(papszOptions);
delete poGeomTmp;
}
else
pszGeometry = poGeom->exportToGML(papszOptions);
CSLDestroy(papszOptions);
if (bWriteSpaceIndentation)
VSIFPrintfL(fp, " ");
if( bRemoveAppPrefix )
poDS->PrintLine( fp, "<%s>%s</%s>",
poFieldDefn->GetNameRef(),
pszGeometry,
poFieldDefn->GetNameRef() );
else
poDS->PrintLine( fp, "<%s:%s>%s</%s:%s>",
pszPrefix, poFieldDefn->GetNameRef(),
pszGeometry,
pszPrefix, poFieldDefn->GetNameRef() );
CPLFree( pszGeometry );
}
}