本文整理汇总了C++中OGRFeatureDefn::GetGeomFieldDefn方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFeatureDefn::GetGeomFieldDefn方法的具体用法?C++ OGRFeatureDefn::GetGeomFieldDefn怎么用?C++ OGRFeatureDefn::GetGeomFieldDefn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRFeatureDefn
的用法示例。
在下文中一共展示了OGRFeatureDefn::GetGeomFieldDefn方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: AutoWarpLayerIfNecessary
void OGRUnionLayer::AutoWarpLayerIfNecessary(int iLayer)
{
if( !pabCheckIfAutoWrap[iLayer] )
{
pabCheckIfAutoWrap[iLayer] = TRUE;
for(int i=0; i<GetLayerDefn()->GetGeomFieldCount();i++)
{
OGRSpatialReference* poSRS = GetLayerDefn()->GetGeomFieldDefn(i)->GetSpatialRef();
if( poSRS != NULL )
poSRS->Reference();
OGRFeatureDefn* poSrcFeatureDefn = papoSrcLayers[iLayer]->GetLayerDefn();
int iSrcGeomField = poSrcFeatureDefn->GetGeomFieldIndex(
GetLayerDefn()->GetGeomFieldDefn(i)->GetNameRef());
if( iSrcGeomField >= 0 )
{
OGRSpatialReference* poSRS2 =
poSrcFeatureDefn->GetGeomFieldDefn(iSrcGeomField)->GetSpatialRef();
if( (poSRS == NULL && poSRS2 != NULL) ||
(poSRS != NULL && poSRS2 == NULL) )
{
CPLError(CE_Warning, CPLE_AppDefined,
"SRS of geometry field '%s' layer %s not consistent with UnionLayer SRS",
GetLayerDefn()->GetGeomFieldDefn(i)->GetNameRef(),
papoSrcLayers[iLayer]->GetName());
}
else if (poSRS != NULL && poSRS2 != NULL &&
poSRS != poSRS2 && !poSRS->IsSame(poSRS2))
{
CPLDebug("VRT", "SRS of geometry field '%s' layer %s not consistent with UnionLayer SRS. "
"Trying auto warping",
GetLayerDefn()->GetGeomFieldDefn(i)->GetNameRef(),
papoSrcLayers[iLayer]->GetName());
OGRCoordinateTransformation* poCT =
OGRCreateCoordinateTransformation( poSRS2, poSRS );
OGRCoordinateTransformation* poReversedCT = (poCT != NULL) ?
OGRCreateCoordinateTransformation( poSRS, poSRS2 ) : NULL;
if( poReversedCT != NULL )
papoSrcLayers[iLayer] = new OGRWarpedLayer(
papoSrcLayers[iLayer], iSrcGeomField, TRUE, poCT, poReversedCT);
else
{
CPLError(CE_Warning, CPLE_AppDefined,
"AutoWarpLayerIfNecessary failed to create "
"poCT or poReversedCT.");
if ( poCT != NULL )
delete poCT;
}
}
}
if( poSRS != NULL )
poSRS->Release();
}
}
}
示例3:
OGRFeatureDefn *OGRTigerLayer::GetLayerDefn()
{
OGRFeatureDefn* poFDefn = poReader->GetFeatureDefn();
if( poFDefn != NULL )
{
if( poFDefn->GetGeomFieldCount() > 0 )
poFDefn->GetGeomFieldDefn(0)->SetSpatialRef(poDS->GetSpatialRef());
}
return poFDefn;
}
示例4: OGRFeatureDefn
OGRESRIFeatureServiceLayer::OGRESRIFeatureServiceLayer(OGRESRIFeatureServiceDataset* poDS)
{
this->poDS = poDS;
OGRFeatureDefn* poSrcFeatDefn = poDS->GetUnderlyingLayer()->GetLayerDefn();
poFeatureDefn = new OGRFeatureDefn(poSrcFeatDefn->GetName());
SetDescription(poFeatureDefn->GetName());
poFeatureDefn->Reference();
poFeatureDefn->SetGeomType(wkbNone);
for(int i=0;i<poSrcFeatDefn->GetFieldCount();i++)
poFeatureDefn->AddFieldDefn(poSrcFeatDefn->GetFieldDefn(i));
for(int i=0;i<poSrcFeatDefn->GetGeomFieldCount();i++)
poFeatureDefn->AddGeomFieldDefn(poSrcFeatDefn->GetGeomFieldDefn(i));
nFeaturesRead = 0;
nLastFID = 0;
bOtherPage = FALSE;
bUseSequentialFID = FALSE;
}
示例5: poDS
OGRESRIFeatureServiceLayer::OGRESRIFeatureServiceLayer(
OGRESRIFeatureServiceDataset* poDSIn) :
poDS(poDSIn),
nFeaturesRead(0),
nLastFID(0),
bOtherPage(false),
bUseSequentialFID(false)
{
OGRFeatureDefn* poSrcFeatDefn = poDS->GetUnderlyingLayer()->GetLayerDefn();
poFeatureDefn = new OGRFeatureDefn(poSrcFeatDefn->GetName());
SetDescription(poFeatureDefn->GetName());
poFeatureDefn->Reference();
poFeatureDefn->SetGeomType(wkbNone);
for(int i=0;i<poSrcFeatDefn->GetFieldCount();i++)
poFeatureDefn->AddFieldDefn(poSrcFeatDefn->GetFieldDefn(i));
for(int i=0;i<poSrcFeatDefn->GetGeomFieldCount();i++)
poFeatureDefn->AddGeomFieldDefn(poSrcFeatDefn->GetGeomFieldDefn(i));
}
示例6: 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);
}
}
示例7: 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
{
//.........这里部分代码省略.........
示例8: oFieldDefn
int ILI1Reader::ReadTable(CPL_UNUSED const char *layername) {
char **tokens = NULL;
int ret = TRUE;
int warned = FALSE;
int geomIdx = -1;
OGRFeatureDefn *featureDef = curLayer->GetLayerDefn();
OGRFeature *feature = NULL;
bool bFeatureAdded = false;
while (ret && (tokens = ReadParseLine()) != NULL)
{
const char *firsttok = CSLGetField(tokens, 0);
if (EQUAL(firsttok, "OBJE"))
{
if (featureDef->GetFieldCount() == 0 && curLayer->GetFeatureCount() == 0)
{
CPLError( CE_Warning, CPLE_AppDefined,
"No field definition found for table: %s",
featureDef->GetName() );
// Model not read - use heuristics.
for( int fIndex=1; fIndex<CSLCount(tokens); fIndex++ )
{
char szFieldName[32];
snprintf(szFieldName, sizeof(szFieldName), "Field%02d", fIndex);
OGRFieldDefn oFieldDefn(szFieldName, OFTString);
featureDef->AddFieldDefn(&oFieldDefn);
}
}
//start new feature
if( !bFeatureAdded )
delete feature;
feature = new OGRFeature(featureDef);
for( int fIndex=1, fieldno = 0;
fIndex<CSLCount(tokens) && fieldno < featureDef->GetFieldCount();
fIndex++, fieldno++ )
{
if (!(tokens[fIndex][0] == codeUndefined && tokens[fIndex][1] == '\0')) {
#ifdef DEBUG_VERBOSE
CPLDebug( "READ TABLE OGR_ILI", "Setting Field %d (Type %d): %s",
fieldno, featureDef->GetFieldDefn(fieldno)->GetType(),
tokens[fIndex] );
#endif
if (featureDef->GetFieldDefn(fieldno)->GetType() == OFTString) {
// Interlis 1 encoding is ISO 8859-1 (Latin1) -> Recode to UTF-8
char* pszRecoded = CPLRecode(
tokens[fIndex], CPL_ENC_ISO8859_1, CPL_ENC_UTF8);
// Replace space marks
for( char* pszString = pszRecoded;
*pszString != '\0';
pszString++ ) {
if (*pszString == codeBlank) *pszString = ' ';
}
feature->SetField(fieldno, pszRecoded);
CPLFree(pszRecoded);
} else {
feature->SetField(fieldno, tokens[fIndex]);
}
if (featureDef->GetFieldDefn(fieldno)->GetType() == OFTReal
&& fieldno > 0
&& featureDef->GetFieldDefn(fieldno-1)->GetType() == OFTReal) {
// Check for Point geometry (Coord type).
// If there is no ili model read,
// we have no chance to detect the
// geometry column.
CPLString geomfldname
= featureDef->GetFieldDefn(fieldno)->GetNameRef();
// Check if name ends with _1.
if (geomfldname.size() >= 2 && geomfldname[geomfldname.size()-2]
== '_') {
geomfldname = geomfldname.substr(0, geomfldname.size()-2);
geomIdx = featureDef->GetGeomFieldIndex(geomfldname.c_str());
if (geomIdx == -1)
{
CPLError( CE_Warning, CPLE_AppDefined,
"No matching definition for field '%s' of "
"table %s found",
geomfldname.c_str(), featureDef->GetName() );
}
} else {
geomIdx = -1;
}
if (geomIdx >= 0) {
if (featureDef->GetGeomFieldDefn(geomIdx)->GetType() ==
wkbPoint) {
// Add Point geometry.
OGRPoint *ogrPoint = new OGRPoint(
CPLAtof(tokens[fIndex-1]), CPLAtof(tokens[fIndex]));
feature->SetGeomFieldDirectly(geomIdx, ogrPoint);
} else if (featureDef->GetGeomFieldDefn(geomIdx)->GetType() ==
wkbPoint25D && fieldno > 1 &&
featureDef->GetFieldDefn(fieldno-2)->GetType() ==
OFTReal) {
// Add 3D Point geometry.
OGRPoint *ogrPoint = new OGRPoint(
CPLAtof(tokens[fIndex-2]), CPLAtof(tokens[fIndex-1]),
CPLAtof(tokens[fIndex]) );
feature->SetGeomFieldDirectly(geomIdx, ogrPoint);
}
//.........这里部分代码省略.........
示例9: EditableSyncToDisk
OGRErr OGRCSVEditableLayerSynchronizer::EditableSyncToDisk(OGRLayer* poEditableLayer,
OGRLayer** ppoDecoratedLayer)
{
CPLAssert( m_poCSVLayer == *ppoDecoratedLayer );
CPLString osLayerName(m_poCSVLayer->GetName());
CPLString osFilename(m_poCSVLayer->GetFilename());
const bool bCreateCSVT = m_poCSVLayer->GetCreateCSVT();
CPLString osCSVTFilename(CPLResetExtension(osFilename, "csvt"));
VSIStatBufL sStatBuf;
const bool bHasCSVT = VSIStatL(osCSVTFilename, &sStatBuf) == 0;
CPLString osTmpFilename(osFilename);
CPLString osTmpCSVTFilename(osFilename);
if( VSIStatL(osFilename, &sStatBuf) == 0 )
{
osTmpFilename += "_ogr_tmp.csv";
osTmpCSVTFilename += "_ogr_tmp.csvt";
}
const char chDelimiter = m_poCSVLayer->GetDelimiter();
OGRCSVLayer* poCSVTmpLayer = new OGRCSVLayer( osLayerName, NULL,
osTmpFilename,
true, true, chDelimiter );
poCSVTmpLayer->BuildFeatureDefn(NULL, NULL, m_papszOpenOptions);
poCSVTmpLayer->SetCRLF( m_poCSVLayer->GetCRLF() );
poCSVTmpLayer->SetCreateCSVT( bCreateCSVT || bHasCSVT );
poCSVTmpLayer->SetWriteBOM( m_poCSVLayer->GetWriteBOM() );
if( m_poCSVLayer->GetGeometryFormat() == OGR_CSV_GEOM_AS_WKT )
poCSVTmpLayer->SetWriteGeometry( wkbNone, OGR_CSV_GEOM_AS_WKT, NULL );
OGRErr eErr = OGRERR_NONE;
OGRFeatureDefn* poEditableFDefn = poEditableLayer->GetLayerDefn();
for( int i=0; eErr == OGRERR_NONE &&
i < poEditableFDefn->GetFieldCount(); i++ )
{
OGRFieldDefn oFieldDefn(poEditableFDefn->GetFieldDefn(i));
int iGeomFieldIdx = 0;
if( (EQUAL(oFieldDefn.GetNameRef(), "WKT") &&
(iGeomFieldIdx = poEditableFDefn->GetGeomFieldIndex("")) >= 0) ||
(iGeomFieldIdx = poEditableFDefn->GetGeomFieldIndex(oFieldDefn.GetNameRef())) >= 0 )
{
OGRGeomFieldDefn oGeomFieldDefn(
poEditableFDefn->GetGeomFieldDefn(iGeomFieldIdx) );
eErr = poCSVTmpLayer->CreateGeomField( &oGeomFieldDefn );
}
else
{
eErr = poCSVTmpLayer->CreateField( &oFieldDefn );
}
}
const bool bHasXY = ( !m_poCSVLayer->GetXField().empty() &&
!m_poCSVLayer->GetYField().empty() );
const bool bHasZ = ( !m_poCSVLayer->GetZField().empty() );
if( bHasXY && !CPLFetchBool(m_papszOpenOptions, "KEEP_GEOM_COLUMNS", true) )
{
if( poCSVTmpLayer->GetLayerDefn()->GetFieldIndex(m_poCSVLayer->GetXField()) < 0 )
{
OGRFieldDefn oFieldDefn(m_poCSVLayer->GetXField(), OFTReal);
if( eErr == OGRERR_NONE )
eErr = poCSVTmpLayer->CreateField( &oFieldDefn );
}
if( poCSVTmpLayer->GetLayerDefn()->GetFieldIndex(m_poCSVLayer->GetYField()) < 0 )
{
OGRFieldDefn oFieldDefn(m_poCSVLayer->GetYField(), OFTReal);
if( eErr == OGRERR_NONE )
eErr = poCSVTmpLayer->CreateField( &oFieldDefn );
}
if( bHasZ && poCSVTmpLayer->GetLayerDefn()->GetFieldIndex(m_poCSVLayer->GetZField()) < 0 )
{
OGRFieldDefn oFieldDefn(m_poCSVLayer->GetZField(), OFTReal);
if( eErr == OGRERR_NONE )
eErr = poCSVTmpLayer->CreateField( &oFieldDefn );
}
}
int nFirstGeomColIdx = 0;
if( m_poCSVLayer->HasHiddenWKTColumn() )
{
poCSVTmpLayer->SetWriteGeometry(
poEditableFDefn->GetGeomFieldDefn(0)->GetType(),
OGR_CSV_GEOM_AS_WKT,
poEditableFDefn->GetGeomFieldDefn(0)->GetNameRef());
nFirstGeomColIdx = 1;
}
if( !(poEditableFDefn->GetGeomFieldCount() == 1 && bHasXY) )
{
for( int i=nFirstGeomColIdx; eErr == OGRERR_NONE &&
i < poEditableFDefn->GetGeomFieldCount(); i++ )
{
OGRGeomFieldDefn oGeomFieldDefn( poEditableFDefn->GetGeomFieldDefn(i) );
if( poCSVTmpLayer->GetLayerDefn()->GetGeomFieldIndex(oGeomFieldDefn.GetNameRef()) >= 0 )
continue;
eErr = poCSVTmpLayer->CreateGeomField( &oGeomFieldDefn );
}
}
OGRFeature* poFeature = NULL;
poEditableLayer->ResetReading();
//.........这里部分代码省略.........
示例10: WFS_ExprDumpAsOGCFilter
static int WFS_ExprDumpAsOGCFilter(CPLString& osFilter,
const swq_expr_node* poExpr,
int bExpectBinary,
ExprDumpFilterOptions* psOptions)
{
if( poExpr->eNodeType == SNT_COLUMN )
{
if (bExpectBinary)
return FALSE;
/* Special fields not understood by server */
if (EQUAL(poExpr->string_value, "gml_id") ||
EQUAL(poExpr->string_value, "FID") ||
EQUAL(poExpr->string_value, "OGR_GEOMETRY") ||
EQUAL(poExpr->string_value, "OGR_GEOM_WKT") ||
EQUAL(poExpr->string_value, "OGR_GEOM_AREA") ||
EQUAL(poExpr->string_value, "OGR_STYLE"))
{
CPLDebug("WFS", "Attribute refers to a OGR special field. Cannot use server-side filtering");
return FALSE;
}
const char* pszFieldname = NULL;
int nIndex;
int bSameTable = psOptions->poFDefn != NULL &&
( poExpr->table_name == NULL ||
EQUAL(poExpr->table_name, psOptions->poFDefn->GetName()) );
if( bSameTable )
{
if( (nIndex = psOptions->poFDefn->GetFieldIndex(poExpr->string_value)) >= 0 )
{
pszFieldname = psOptions->poFDefn->GetFieldDefn(nIndex)->GetNameRef();
}
else if( (nIndex = psOptions->poFDefn->GetGeomFieldIndex(poExpr->string_value)) >= 0 )
{
pszFieldname = psOptions->poFDefn->GetGeomFieldDefn(nIndex)->GetNameRef();
}
}
else if( psOptions->poDS != NULL )
{
OGRLayer* poLayer = psOptions->poDS->GetLayerByName(poExpr->table_name);
if( poLayer )
{
OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
if( (nIndex = poFDefn->GetFieldIndex(poExpr->string_value)) >= 0 )
{
pszFieldname = CPLSPrintf("%s/%s",
poLayer->GetName(),
poFDefn->GetFieldDefn(nIndex)->GetNameRef());
}
else if( (nIndex = poFDefn->GetGeomFieldIndex(poExpr->string_value)) >= 0 )
{
pszFieldname = CPLSPrintf("%s/%s",
poLayer->GetName(),
poFDefn->GetGeomFieldDefn(nIndex)->GetNameRef());
}
}
}
if( psOptions->poFDefn == NULL && psOptions->poDS == NULL )
pszFieldname = poExpr->string_value;
if( pszFieldname == NULL )
{
if( poExpr->table_name != NULL )
CPLDebug("WFS", "Field \"%s\".\"%s\" unknown. Cannot use server-side filtering",
poExpr->table_name, poExpr->string_value);
else
CPLDebug("WFS", "Field \"%s\" unknown. Cannot use server-side filtering",
poExpr->string_value);
return FALSE;
}
if (psOptions->nVersion >= 200)
osFilter += CPLSPrintf("<%sValueReference>", psOptions->pszNSPrefix);
else
osFilter += CPLSPrintf("<%sPropertyName>", psOptions->pszNSPrefix);
char* pszFieldnameXML = CPLEscapeString(pszFieldname, -1, CPLES_XML);
osFilter += pszFieldnameXML;
CPLFree(pszFieldnameXML);
if (psOptions->nVersion >= 200)
osFilter += CPLSPrintf("</%sValueReference>", psOptions->pszNSPrefix);
else
osFilter += CPLSPrintf("</%sPropertyName>", psOptions->pszNSPrefix);
return TRUE;
}
if( poExpr->eNodeType == SNT_CONSTANT )
{
if (bExpectBinary)
return FALSE;
osFilter += CPLSPrintf("<%sLiteral>", psOptions->pszNSPrefix);
if( !WFS_ExprDumpRawLitteral(osFilter, poExpr) )
return FALSE;
osFilter += CPLSPrintf("</%sLiteral>", psOptions->pszNSPrefix);
return TRUE;
}
//.........这里部分代码省略.........
示例11: oField
//.........这里部分代码省略.........
oField.SetType( OFTString );
oField.SetWidth((int)psMSField->length);
poDefn->AddFieldDefn( &oField );
break;
}
case FIELD_TYPE_TINY_BLOB:
case FIELD_TYPE_MEDIUM_BLOB:
case FIELD_TYPE_LONG_BLOB:
case FIELD_TYPE_BLOB:
{
if( psMSField->charsetnr == 63 )
oField.SetType( OFTBinary );
else
oField.SetType( OFTString );
oField.SetWidth((int)psMSField->max_length);
poDefn->AddFieldDefn( &oField );
break;
}
case FIELD_TYPE_GEOMETRY:
{
if (pszGeomColumn == nullptr)
{
pszGeomColumnTable = CPLStrdup( psMSField->table);
pszGeomColumn = CPLStrdup( psMSField->name);
}
break;
}
default:
// any other field we ignore.
break;
}
// assume a FID name first, and if it isn't there
// take a field that is not null, a primary key,
// and is an integer-like field
if( EQUAL(psMSField->name,"ogc_fid") )
{
bHasFid = TRUE;
pszFIDColumn = CPLStrdup(oField.GetNameRef());
continue;
} else
if (IS_NOT_NULL(psMSField->flags)
&& IS_PRI_KEY(psMSField->flags)
&&
(
psMSField->type == FIELD_TYPE_TINY
|| psMSField->type == FIELD_TYPE_SHORT
|| psMSField->type == FIELD_TYPE_LONG
|| psMSField->type == FIELD_TYPE_INT24
|| psMSField->type == FIELD_TYPE_LONGLONG
)
)
{
bHasFid = TRUE;
pszFIDColumn = CPLStrdup(oField.GetNameRef());
continue;
}
}
poDefn->SetGeomType( wkbNone );
if (pszGeomColumn)
{
char* pszType=nullptr;
CPLString osCommand;
char **papszRow;
// set to unknown first
poDefn->SetGeomType( wkbUnknown );
poDefn->GetGeomFieldDefn(0)->SetName( pszGeomColumn );
osCommand.Printf(
"SELECT type FROM geometry_columns WHERE f_table_name='%s'",
pszGeomColumnTable );
if( hResultSet != nullptr )
mysql_free_result( hResultSet );
hResultSet = nullptr;
if( !mysql_query( poDS->GetConn(), osCommand ) )
hResultSet = mysql_store_result( poDS->GetConn() );
papszRow = nullptr;
if( hResultSet != nullptr )
papszRow = mysql_fetch_row( hResultSet );
if( papszRow != nullptr && papszRow[0] != nullptr )
{
pszType = papszRow[0];
OGRwkbGeometryType l_nGeomType = OGRFromOGCGeomType(pszType);
poDefn->SetGeomType( l_nGeomType );
}
nSRSId = FetchSRSId();
}
return poDefn;
}
示例12: if
//.........这里部分代码省略.........
if( pszDefault != NULL )
{
if( !EQUAL(pszDefault, "NULL") &&
!STARTS_WITH_CI(pszDefault, "CURRENT_") &&
pszDefault[0] != '(' &&
pszDefault[0] != '\'' &&
CPLGetValueType(pszDefault) == CPL_VALUE_STRING )
{
int nYear, nMonth, nDay, nHour, nMinute;
float fSecond;
if( oField.GetType() == OFTDateTime &&
sscanf(pszDefault, "%d-%d-%d %d:%d:%f", &nYear, &nMonth, &nDay,
&nHour, &nMinute, &fSecond) == 6 )
{
oField.SetDefault(CPLSPrintf("'%04d/%02d/%02d %02d:%02d:%02d'",
nYear, nMonth, nDay, nHour, nMinute, (int)(fSecond+0.5)));
}
else
{
CPLString osDefault("'");
char* pszTmp = CPLEscapeString(pszDefault, -1, CPLES_SQL);
osDefault += pszTmp;
CPLFree(pszTmp);
osDefault += "'";
oField.SetDefault(osDefault);
}
}
else
{
oField.SetDefault(pszDefault);
}
}
poDefn->AddFieldDefn( &oField );
}
// set to none for now... if we have a geometry column it will be set layer.
poDefn->SetGeomType( wkbNone );
if( hResult != NULL )
{
mysql_free_result( hResult );
hResultSet = NULL;
}
if( bHasFid )
CPLDebug( "MySQL", "table %s has FID column %s.",
pszTable, pszFIDColumn );
else
CPLDebug( "MySQL",
"table %s has no FID column, FIDs will not be reliable!",
pszTable );
if (pszGeomColumn)
{
char* pszType=NULL;
// set to unknown first
poDefn->SetGeomType( wkbUnknown );
osCommand = "SELECT type, coord_dimension FROM geometry_columns WHERE f_table_name='";
osCommand += pszTable;
osCommand += "'";
hResult = NULL;
if( !mysql_query( poDS->GetConn(), osCommand ) )
hResult = mysql_store_result( poDS->GetConn() );
papszRow = NULL;
if( hResult != NULL )
papszRow = mysql_fetch_row( hResult );
if( papszRow != NULL && papszRow[0] != NULL )
{
pszType = papszRow[0];
OGRwkbGeometryType l_nGeomType = OGRFromOGCGeomType(pszType);
if( papszRow[1] != NULL && atoi(papszRow[1]) == 3 )
l_nGeomType = wkbSetZ(l_nGeomType);
poDefn->SetGeomType( l_nGeomType );
}
else if (eForcedGeomType != wkbUnknown)
poDefn->SetGeomType(eForcedGeomType);
if( bGeomColumnNotNullable )
poDefn->GetGeomFieldDefn(0)->SetNullable(FALSE);
if( hResult != NULL )
mysql_free_result( hResult ); //Free our query results for finding type.
hResult = NULL;
}
// Fetch the SRID for this table now
nSRSId = FetchSRSId();
return poDefn;
}