本文整理汇总了C++中OGRGeomFieldDefn::GetSpatialRef方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRGeomFieldDefn::GetSpatialRef方法的具体用法?C++ OGRGeomFieldDefn::GetSpatialRef怎么用?C++ OGRGeomFieldDefn::GetSpatialRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRGeomFieldDefn
的用法示例。
在下文中一共展示了OGRGeomFieldDefn::GetSpatialRef方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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() )
//.........这里部分代码省略.........
示例2: 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
{
//.........这里部分代码省略.........
示例3: 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 );
//.........这里部分代码省略.........
示例4: 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;
//.........这里部分代码省略.........
示例5: ReportOnLayer
//.........这里部分代码省略.........
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);
}
const auto displayDataAxisMapping = [](const OGRSpatialReference* poSRS) {
const auto mapping = poSRS->GetDataAxisToSRSAxisMapping();
printf("Data axis to CRS axis mapping: ");
for( size_t i = 0; i < mapping.size(); i++ )
{
if( i > 0 )
{
printf(",");
}
printf("%d", mapping[i]);
}
printf("\n");
};
if( nGeomFieldCount > 1 )
{
for(int iGeom = 0;iGeom < nGeomFieldCount; iGeom ++ )
{
OGRGeomFieldDefn* poGFldDefn =
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeom);
OGRSpatialReference* poSRS = poGFldDefn->GetSpatialRef();
char *pszWKT = nullptr;
if( poSRS == nullptr )
{
pszWKT = CPLStrdup("(unknown)");
}
else
{
CPLString osWKTFormat("FORMAT=");
osWKTFormat += pszWKTFormat;
const char* const apszWKTOptions[] =
{ osWKTFormat.c_str(), "MULTILINE=YES", nullptr };
poSRS->exportToWkt(&pszWKT, apszWKTOptions);
}
printf("SRS WKT (%s):\n%s\n",
poGFldDefn->GetNameRef(), pszWKT);
CPLFree(pszWKT);
if( poSRS )
{
displayDataAxisMapping(poSRS);
}
}
}
else
{
char *pszWKT = nullptr;
auto poSRS = poLayer->GetSpatialRef();
if( poSRS == nullptr )
{
pszWKT = CPLStrdup("(unknown)");
}
else
示例6: ICreateFeature
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);
//.........这里部分代码省略.........