本文整理汇总了C++中OGRGeomFieldDefn类的典型用法代码示例。如果您正苦于以下问题:C++ OGRGeomFieldDefn类的具体用法?C++ OGRGeomFieldDefn怎么用?C++ OGRGeomFieldDefn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OGRGeomFieldDefn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OGRILI1Layer
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;
}
示例2: GetFieldCount
int OGRFeatureDefn::IsSame( OGRFeatureDefn * poOtherFeatureDefn )
{
if (strcmp(GetName(), poOtherFeatureDefn->GetName()) == 0 &&
GetFieldCount() == poOtherFeatureDefn->GetFieldCount() &&
GetGeomFieldCount() == poOtherFeatureDefn->GetGeomFieldCount())
{
int i;
for(i=0;i<nFieldCount;i++)
{
const OGRFieldDefn* poFldDefn = GetFieldDefn(i);
const OGRFieldDefn* poOtherFldDefn = poOtherFeatureDefn->GetFieldDefn(i);
if (!poFldDefn->IsSame(poOtherFldDefn))
{
return FALSE;
}
}
for(i=0;i<nGeomFieldCount;i++)
{
OGRGeomFieldDefn* poGFldDefn = GetGeomFieldDefn(i);
OGRGeomFieldDefn* poOtherGFldDefn =
poOtherFeatureDefn->GetGeomFieldDefn(i);
if (!poGFldDefn->IsSame(poOtherGFldDefn))
{
return FALSE;
}
}
return TRUE;
}
return FALSE;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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() )
//.........这里部分代码省略.........
示例6: AutoWarpLayerIfNecessary
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);
}
}
示例7: OGRFeatureDefn
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
{
//.........这里部分代码省略.........
示例8: CPLError
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 );
//.........这里部分代码省略.........
示例9: FlushDeferedInsert
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 );
}
示例10: OGRFeature
OGRFeature *OGRGeoPackageLayer::TranslateFeature( sqlite3_stmt* hStmt )
{
/* -------------------------------------------------------------------- */
/* Create a feature from the current result. */
/* -------------------------------------------------------------------- */
int iField;
OGRFeature *poFeature = new OGRFeature( m_poFeatureDefn );
/* -------------------------------------------------------------------- */
/* Set FID if we have a column to set it from. */
/* -------------------------------------------------------------------- */
if( iFIDCol >= 0 )
poFeature->SetFID( sqlite3_column_int64( hStmt, iFIDCol ) );
else
poFeature->SetFID( iNextShapeId );
iNextShapeId++;
m_nFeaturesRead++;
/* -------------------------------------------------------------------- */
/* Process Geometry if we have a column. */
/* -------------------------------------------------------------------- */
if( iGeomCol >= 0 )
{
OGRGeomFieldDefn* poGeomFieldDefn = m_poFeatureDefn->GetGeomFieldDefn(0);
if ( sqlite3_column_type(hStmt, iGeomCol) != SQLITE_NULL &&
!poGeomFieldDefn->IsIgnored() )
{
OGRSpatialReference* poSrs = poGeomFieldDefn->GetSpatialRef();
int iGpkgSize = sqlite3_column_bytes(hStmt, iGeomCol);
GByte *pabyGpkg = (GByte *)sqlite3_column_blob(hStmt, iGeomCol);
OGRGeometry *poGeom = GPkgGeometryToOGR(pabyGpkg, iGpkgSize, poSrs);
if ( ! poGeom )
{
// Try also spatialite geometry blobs
if( OGRSQLiteLayer::ImportSpatiaLiteGeometry( pabyGpkg, iGpkgSize,
&poGeom ) != OGRERR_NONE )
{
CPLError( CE_Failure, CPLE_AppDefined, "Unable to read geometry");
}
}
poFeature->SetGeometryDirectly( poGeom );
}
}
/* -------------------------------------------------------------------- */
/* set the fields. */
/* -------------------------------------------------------------------- */
for( iField = 0; iField < m_poFeatureDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poFieldDefn = m_poFeatureDefn->GetFieldDefn( iField );
if ( poFieldDefn->IsIgnored() )
continue;
int iRawField = panFieldOrdinals[iField];
if( sqlite3_column_type( hStmt, iRawField ) == SQLITE_NULL )
continue;
switch( poFieldDefn->GetType() )
{
case OFTInteger:
poFeature->SetField( iField,
sqlite3_column_int( hStmt, iRawField ) );
break;
case OFTInteger64:
poFeature->SetField( iField,
sqlite3_column_int64( hStmt, iRawField ) );
break;
case OFTReal:
poFeature->SetField( iField,
sqlite3_column_double( hStmt, iRawField ) );
break;
case OFTBinary:
{
const int nBytes = sqlite3_column_bytes( hStmt, iRawField );
poFeature->SetField( iField, nBytes,
(GByte*)sqlite3_column_blob( hStmt, iRawField ) );
break;
}
case OFTDate:
{
const char* pszTxt = (const char*)sqlite3_column_text( hStmt, iRawField );
int nYear, nMonth, nDay;
if( sscanf(pszTxt, "%d-%d-%d", &nYear, &nMonth, &nDay) == 3 )
poFeature->SetField(iField, nYear, nMonth, nDay, 0, 0, 0, 0);
break;
}
case OFTDateTime:
{
const char* pszTxt = (const char*)sqlite3_column_text( hStmt, iRawField );
//.........这里部分代码省略.........
示例11: 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;
//.........这里部分代码省略.........
示例12: MAIN_START
//.........这里部分代码省略.........
if( papszLayers == nullptr || *papszLayers == nullptr )
{
if( iRepeat == 0 )
CPLDebug("OGR", "GetLayerCount() = %d\n",
poDS->GetLayerCount());
/* -------------------------------------------------------------------- */
/* Process each data source layer. */
/* -------------------------------------------------------------------- */
for( int iLayer = 0; iLayer < poDS->GetLayerCount(); iLayer++ )
{
OGRLayer *poLayer = poDS->GetLayer(iLayer);
if( poLayer == nullptr )
{
printf("FAILURE: Couldn't fetch advertised layer %d!\n",
iLayer);
exit(1);
}
if( !bAllLayers )
{
printf("%d: %s", iLayer + 1, poLayer->GetName());
const int nGeomFieldCount =
poLayer->GetLayerDefn()->GetGeomFieldCount();
if( nGeomFieldCount > 1 )
{
printf(" (");
for( int iGeom = 0; iGeom < nGeomFieldCount; iGeom++ )
{
if( iGeom > 0 )
printf(", ");
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->
GetGeomFieldDefn(iGeom);
printf(
"%s",
OGRGeometryTypeToName(
poGFldDefn->GetType()));
}
printf(")");
}
else if( poLayer->GetGeomType() != wkbUnknown )
printf(" (%s)",
OGRGeometryTypeToName(
poLayer->GetGeomType()));
printf("\n");
}
else
{
if( iRepeat != 0 )
poLayer->ResetReading();
ReportOnLayer(poLayer, pszWHERE,
pszGeomField, poSpatialFilter,
bListMDD, bShowMetadata, papszExtraMDDomains,
bFeatureCount, bExtent, pszWKTFormat);
}
}
}
else
{
/* -------------------------------------------------------------------- */
/* Process specified data source layers. */
示例13: 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);
}
//.........这里部分代码省略.........
示例14: delete
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;
//.........这里部分代码省略.........
示例15: VSIFPrintfL
OGRErr OGRGMLLayer::ICreateFeature( OGRFeature *poFeature )
{
int bIsGML3Output = poDS->IsGML3Output();
VSILFILE *fp = poDS->GetOutputFP();
int bWriteSpaceIndentation = poDS->WriteSpaceIndentation();
const char* pszPrefix = poDS->GetAppPrefix();
int bRemoveAppPrefix = poDS->RemoveAppPrefix();
if( !bWriter )
return OGRERR_FAILURE;
poFeature->FillUnsetWithDefault(TRUE, NULL);
if( !poFeature->Validate( OGR_F_VAL_ALL & ~OGR_F_VAL_GEOM_TYPE & ~OGR_F_VAL_ALLOW_NULL_WHEN_DEFAULT, TRUE ) )
return OGRERR_FAILURE;
if (bWriteSpaceIndentation)
VSIFPrintfL(fp, " ");
if (bIsGML3Output)
{
if( bRemoveAppPrefix )
poDS->PrintLine( fp, "<featureMember>" );
else
poDS->PrintLine( fp, "<%s:featureMember>", pszPrefix );
}
else
poDS->PrintLine( fp, "<gml:featureMember>" );
if( iNextGMLId == 0 )
{
bSameSRS = true;
for( int iGeomField = 1; iGeomField < poFeatureDefn->GetGeomFieldCount(); iGeomField++ )
{
OGRGeomFieldDefn *poFieldDefn0 = poFeatureDefn->GetGeomFieldDefn(0);
OGRGeomFieldDefn *poFieldDefn = poFeatureDefn->GetGeomFieldDefn(iGeomField);
OGRSpatialReference* poSRS0 = poFieldDefn0->GetSpatialRef();
OGRSpatialReference* poSRS = poFieldDefn->GetSpatialRef();
if( poSRS0 != NULL && poSRS == NULL )
bSameSRS = false;
else if( poSRS0 == NULL && poSRS != NULL )
bSameSRS = false;
else if( poSRS0 != NULL && poSRS != NULL &&
poSRS0 != poSRS && !poSRS0->IsSame(poSRS) )
{
bSameSRS = false;
}
}
}
if( poFeature->GetFID() == OGRNullFID )
poFeature->SetFID( iNextGMLId++ );
int nGMLIdIndex = -1;
if (bWriteSpaceIndentation)
VSIFPrintfL(fp, " ");
VSIFPrintfL(fp, "<");
if( !bRemoveAppPrefix )
VSIFPrintfL(fp, "%s:", pszPrefix);
if (bIsGML3Output)
{
nGMLIdIndex = poFeatureDefn->GetFieldIndex("gml_id");
if (nGMLIdIndex >= 0 && poFeature->IsFieldSet( nGMLIdIndex ) )
poDS->PrintLine( fp, "%s gml:id=\"%s\">",
poFeatureDefn->GetName(),
poFeature->GetFieldAsString(nGMLIdIndex) );
else
poDS->PrintLine( fp, "%s gml:id=\"%s." CPL_FRMT_GIB "\">",
poFeatureDefn->GetName(),
poFeatureDefn->GetName(),
poFeature->GetFID() );
}
else
{
nGMLIdIndex = poFeatureDefn->GetFieldIndex("fid");
if (bUseOldFIDFormat)
{
poDS->PrintLine( fp, "%s fid=\"F" CPL_FRMT_GIB "\">",
poFeatureDefn->GetName(),
poFeature->GetFID() );
}
else if (nGMLIdIndex >= 0 && poFeature->IsFieldSet( nGMLIdIndex ) )
{
poDS->PrintLine( fp, "%s fid=\"%s\">",
poFeatureDefn->GetName(),
poFeature->GetFieldAsString(nGMLIdIndex) );
}
else
{
poDS->PrintLine( fp, "%s fid=\"%s." CPL_FRMT_GIB "\">",
poFeatureDefn->GetName(),
poFeatureDefn->GetName(),
poFeature->GetFID() );
}
}
for( int iGeomField = 0; iGeomField < poFeatureDefn->GetGeomFieldCount(); iGeomField++ )
{
OGRGeomFieldDefn *poFieldDefn = poFeatureDefn->GetGeomFieldDefn(iGeomField);
//.........这里部分代码省略.........