本文整理汇总了C++中OGRFieldDefn::GetFieldTypeName方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFieldDefn::GetFieldTypeName方法的具体用法?C++ OGRFieldDefn::GetFieldTypeName怎么用?C++ OGRFieldDefn::GetFieldTypeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRFieldDefn
的用法示例。
在下文中一共展示了OGRFieldDefn::GetFieldTypeName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReportOnLayer
static void ReportOnLayer( OGRLayer * poLayer, const char *pszWHERE,
OGRGeometry *poSpatialFilter )
{
OGRFeatureDefn *poDefn = poLayer->GetLayerDefn();
/* -------------------------------------------------------------------- */
/* Set filters if provided. */
/* -------------------------------------------------------------------- */
if( pszWHERE != NULL )
poLayer->SetAttributeFilter( pszWHERE );
if( poSpatialFilter != NULL )
poLayer->SetSpatialFilter( poSpatialFilter );
/* -------------------------------------------------------------------- */
/* Report various overall information. */
/* -------------------------------------------------------------------- */
printf( "\n" );
printf( "Layer name: %s\n", poDefn->GetName() );
if( bVerbose )
{
printf( "Geometry: %s\n",
OGRGeometryTypeToName( poDefn->GetGeomType() ) );
printf( "Feature Count: %d\n", poLayer->GetFeatureCount() );
OGREnvelope oExt;
if (poLayer->GetExtent(&oExt, TRUE) == OGRERR_NONE)
{
printf("Extent: (%f, %f) - (%f, %f)\n",
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
char *pszWKT;
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() );
if( strlen(poLayer->GetGeometryColumn()) > 0 )
printf( "Geometry Column = %s\n",
poLayer->GetGeometryColumn() );
for( int iAttr = 0; iAttr < poDefn->GetFieldCount(); iAttr++ )
{
OGRFieldDefn *poField = poDefn->GetFieldDefn( iAttr );
printf( "%s: %s (%d.%d)\n",
poField->GetNameRef(),
poField->GetFieldTypeName( poField->GetType() ),
poField->GetWidth(),
poField->GetPrecision() );
}
}
/* -------------------------------------------------------------------- */
/* Read, and dump features. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature = NULL;
if( nFetchFID == OGRNullFID && !bSummaryOnly )
{
while( (poFeature = poLayer->GetNextFeature()) != NULL )
{
poFeature->DumpReadable( NULL, papszOptions );
OGRFeature::DestroyFeature( poFeature );
}
}
else if( nFetchFID != OGRNullFID )
{
poFeature = poLayer->GetFeature( nFetchFID );
if( poFeature == NULL )
{
printf( "Unable to locate feature id %d on this layer.\n",
nFetchFID );
}
else
{
poFeature->DumpReadable( NULL, papszOptions );
OGRFeature::DestroyFeature( poFeature );
}
}
}
示例2: ReportOnLayer
//.........这里部分代码省略.........
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() )
break;
printf( "Geometry Column ");
if( nGeomFieldCount > 1 )
printf("%d ", iGeom + 1);
if( !poGFldDefn->IsNullable() )
printf("NOT NULL ");
printf("= %s\n", poGFldDefn->GetNameRef() );
}
for( int iAttr = 0; iAttr < poDefn->GetFieldCount(); iAttr++ )
{
OGRFieldDefn *poField = poDefn->GetFieldDefn( iAttr );
const char* pszType = (poField->GetSubType() != OFSTNone) ?
CPLSPrintf("%s(%s)",
poField->GetFieldTypeName( poField->GetType() ),
poField->GetFieldSubTypeName(poField->GetSubType())) :
poField->GetFieldTypeName( poField->GetType() );
printf( "%s: %s (%d.%d)",
poField->GetNameRef(),
pszType,
poField->GetWidth(),
poField->GetPrecision() );
if( !poField->IsNullable() )
printf(" NOT NULL");
if( poField->GetDefault() != NULL )
printf(" DEFAULT %s", poField->GetDefault() );
printf( "\n" );
}
}
/* -------------------------------------------------------------------- */
/* Read, and dump features. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature = NULL;
while( (poFeature = poLayer->GetNextFeature()) != NULL )
{
poFeature->DumpReadable( NULL );
OGRFeature::DestroyFeature( poFeature );
}
}
示例3: ReportOnLayer
static void ReportOnLayer( OGRLayer * poLayer, const char *pszWHERE,
OGRGeometry *poSpatialFilter )
{
OGRFeatureDefn *poDefn = poLayer->GetLayerDefn();
/* -------------------------------------------------------------------- */
/* Set filters if provided. */
/* -------------------------------------------------------------------- */
if( pszWHERE != NULL )
poLayer->SetAttributeFilter( pszWHERE );
if( poSpatialFilter != NULL )
poLayer->SetSpatialFilter( poSpatialFilter );
/* -------------------------------------------------------------------- */
/* Report various overall information. */
/* -------------------------------------------------------------------- */
printf( "\n" );
printf( "Layer name: %s\n", poDefn->GetName() );
printf( "Geometry: %s\n",
OGRGeometryTypeToName( poDefn->GetGeomType() ) );
printf( "Feature Count: %d\n", poLayer->GetFeatureCount() );
OGREnvelope oExt;
if (poLayer->GetExtent(&oExt, TRUE) == OGRERR_NONE)
{
printf("Extent: (%f, %f) - (%f, %f)\n",
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
if( bVerbose )
{
char *pszWKT;
if( poLayer->GetSpatialRef() == NULL )
pszWKT = CPLStrdup( "(NULL)" );
else
poLayer->GetSpatialRef()->exportToWkt( &pszWKT );
printf( "Layer SRS WKT: %s\n", pszWKT );
CPLFree( pszWKT );
}
for( int iAttr = 0; iAttr < poDefn->GetFieldCount(); iAttr++ )
{
OGRFieldDefn *poField = poDefn->GetFieldDefn( iAttr );
printf( "%s: %s (%d.%d)\n",
poField->GetNameRef(),
poField->GetFieldTypeName( poField->GetType() ),
poField->GetWidth(),
poField->GetPrecision() );
}
/* -------------------------------------------------------------------- */
/* Read, and dump features. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature;
while( (poFeature = poLayer->GetNextFeature()) != NULL )
{
poFeature->DumpReadable( stdout );
delete poFeature;
}
/* -------------------------------------------------------------------- */
/* Read, and dump features. */
/* -------------------------------------------------------------------- */
#ifdef notdef
OGRFeature *poFeature;
int nId = -1;
while( (nId = poTF->GetNextFeatureId_Spatial(nId)) != -1 )
{
poFeature = poTF->GetFeatureRef( nId );
}
#endif
}
示例4: ReportOnLayer
//.........这里部分代码省略.........
CPLFree(pszWKT);
if( poSRS )
{
displayDataAxisMapping(poSRS);
}
}
}
else
{
char *pszWKT = nullptr;
auto poSRS = poLayer->GetSpatialRef();
if( poSRS == nullptr )
{
pszWKT = CPLStrdup("(unknown)");
}
else
{
poSRS->exportToPrettyWkt(&pszWKT);
}
printf("Layer SRS WKT:\n%s\n", pszWKT);
CPLFree(pszWKT);
if( poSRS )
{
displayDataAxisMapping(poSRS);
}
}
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() )
break;
printf("Geometry Column ");
if( nGeomFieldCount > 1 )
printf("%d ", iGeom + 1);
if( !poGFldDefn->IsNullable() )
printf("NOT NULL ");
printf("= %s\n", poGFldDefn->GetNameRef());
}
for( int iAttr = 0; iAttr < poDefn->GetFieldCount(); iAttr++ )
{
OGRFieldDefn *poField = poDefn->GetFieldDefn(iAttr);
const char* pszType = (poField->GetSubType() != OFSTNone)
? CPLSPrintf(
"%s(%s)",
poField->GetFieldTypeName(poField->GetType()),
poField->GetFieldSubTypeName(poField->GetSubType()))
: poField->GetFieldTypeName(poField->GetType());
printf("%s: %s (%d.%d)",
poField->GetNameRef(),
pszType,
poField->GetWidth(),
poField->GetPrecision());
if( !poField->IsNullable() )
printf(" NOT NULL");
if( poField->GetDefault() != nullptr )
printf(" DEFAULT %s", poField->GetDefault());
printf("\n");
}
}
/* -------------------------------------------------------------------- */
/* Read, and dump features. */
/* -------------------------------------------------------------------- */
if( nFetchFID == OGRNullFID && !bSummaryOnly )
{
OGRFeature *poFeature = nullptr;
while( (poFeature = poLayer->GetNextFeature()) != nullptr )
{
if( !bSuperQuiet )
poFeature->DumpReadable(nullptr, papszOptions);
OGRFeature::DestroyFeature(poFeature);
}
}
else if( nFetchFID != OGRNullFID )
{
OGRFeature *poFeature = poLayer->GetFeature(nFetchFID);
if( poFeature == nullptr )
{
printf("Unable to locate feature id " CPL_FRMT_GIB
" on this layer.\n",
nFetchFID);
}
else
{
poFeature->DumpReadable(nullptr, papszOptions);
OGRFeature::DestroyFeature(poFeature);
}
}
}
示例5: ogrReadListColumn
SEXP ogrReadListColumn(OGRLayer *poLayer, SEXP FIDs, int iField, int k, int int64) {
// read feature data and return something according to the type
OGRFeatureDefn *poDefn;
OGRFieldDefn *poField;
OGRFeature *poFeature;
int iRow,nRows,nlist;
SEXP ans = R_NilValue;
nRows=length(FIDs);
// get field data from layer
installErrorHandler();
poDefn = poLayer->GetLayerDefn();
poField = poDefn->GetFieldDefn(iField);
uninstallErrorHandlerAndTriggerError();
if(poField == NULL) {
error("Error getting field %d ",iField);
}
// allocate an object for the result depending on the feature type:
installErrorHandler();
switch(poField->GetType()) {
case OFTIntegerList:
PROTECT(ans=allocVector(INTSXP,nRows));
break;
#ifdef GDALV2
case OFTInteger64List:
if (int64 == 3) {
PROTECT(ans=allocVector(STRSXP,nRows));
} else {
PROTECT(ans=allocVector(INTSXP,nRows));
}
break;
#endif
case OFTRealList:
PROTECT(ans=allocVector(REALSXP,nRows));
break;
case OFTStringList:
PROTECT(ans=allocVector(STRSXP,nRows));
break;
default:
const char *desc = poField->GetFieldTypeName(poField->GetType());
uninstallErrorHandlerAndTriggerError();
error("unsupported field type: %s", desc);
break;
}
uninstallErrorHandlerAndTriggerError();
// now go over each row and retrieve data. iRow is an index in a
// vector of FIDs
installErrorHandler();
poLayer->ResetReading();
OGRField* psField;
iRow = 0;
while((poFeature = poLayer->GetNextFeature()) != NULL) {
if (poFeature->IsFieldSet(iField)) {
// now get the value using the right type:
psField = poFeature->GetRawFieldRef(iField);
switch(poField->GetType()) {
case OFTIntegerList:
nlist = psField->IntegerList.nCount;
if (k < nlist)
INTEGER(ans)[iRow] = psField->IntegerList.paList[k];
else INTEGER(ans)[iRow]=NA_INTEGER;
break;
#ifdef GDALV2
case OFTInteger64List:
nlist = psField->Integer64List.nCount;
if (k < nlist) {
if (int64 == 3) {
// FIXME clang++
// GIntBig nVal64 = psField->Integer64List.paList[k];
char szItem[32];
snprintf(szItem, sizeof(szItem), CPL_FRMT_GIB,
psField->Integer64List.paList[k]);
SET_STRING_ELT(ans, iRow, mkChar(szItem));
} else {
GIntBig nVal64 = psField->Integer64List.paList[k];
int nVal = (nVal64 > INT_MAX) ? INT_MAX :
(nVal64 < INT_MIN) ? INT_MIN : (int) nVal64;
if (((GIntBig)nVal != nVal64) && int64 == 2) {
warning("Integer64 value clamped: feature %d", iRow);
}
INTEGER(ans)[iRow]=nVal;
}
} else {
if (int64 == 3) {
SET_STRING_ELT(ans, iRow, NA_STRING);
} else {
INTEGER(ans)[iRow]=NA_INTEGER;
}
}
break;
#endif
case OFTRealList:
nlist = psField->RealList.nCount;
if (k < nlist)
REAL(ans)[iRow] = psField->RealList.paList[k];
//.........这里部分代码省略.........
示例6: ogrReadColumn
SEXP ogrReadColumn(OGRLayer *poLayer, SEXP FIDs, int iField, int int64, int ENC_DEBUG) {
// read feature data and return something according to the type
OGRFeatureDefn *poDefn;
OGRFieldDefn *poField;
OGRFeature *poFeature;
int iRow,nRows;
SEXP ans = R_NilValue;
nRows=length(FIDs);
// get field data from layer
installErrorHandler();
poDefn = poLayer->GetLayerDefn();
poField = poDefn->GetFieldDefn(iField);
uninstallErrorHandlerAndTriggerError();
if(poField == NULL) {
error("Error getting field %d ",iField);
}
// allocate an object for the result depending on the feature type:
installErrorHandler();
switch(poField->GetType()) {
case OFTInteger:
PROTECT(ans=allocVector(INTSXP,nRows));
break;
#ifdef GDALV2
case OFTInteger64:
if (int64 ==3) {
PROTECT(ans=allocVector(STRSXP,nRows));
} else {
PROTECT(ans=allocVector(INTSXP,nRows));
}
break;
#endif
case OFTReal:
PROTECT(ans=allocVector(REALSXP,nRows));
break;
case OFTString:
PROTECT(ans=allocVector(STRSXP,nRows));
break;
case OFTDate:
PROTECT(ans=allocVector(STRSXP,nRows));
break;
case OFTDateTime:
PROTECT(ans=allocVector(STRSXP,nRows));
break;
case OFTTime:
PROTECT(ans=allocVector(STRSXP,nRows));
break;
default:
const char *desc = poField->GetFieldTypeName(poField->GetType());
uninstallErrorHandlerAndTriggerError();
error("unsupported field type: %s", desc);
break;
}
uninstallErrorHandlerAndTriggerError();
// now go over each row and retrieve data. iRow is an index in a
// vector of FIDs
/*#ifndef EJP
installErrorHandler();
for(iRow=0;iRow<nRows;iRow++){
poFeature=poLayer->GetFeature(INTEGER(FIDs)[iRow]);
if(poFeature == NULL){
error("Error getting feature FID: %d",(INTEGER(FIDs)[iRow]));
}
}
uninstallErrorHandlerAndTriggerError();
#else*/
// EJP, changed into:
installErrorHandler();
poLayer->ResetReading();
iRow = 0;
while((poFeature = poLayer->GetNextFeature()) != NULL) {
//#endif
// now get the value using the right type:
switch(poField->GetType()) {
case OFTInteger:
if (poFeature->IsFieldSet(iField))
INTEGER(ans)[iRow]=poFeature->GetFieldAsInteger(iField);
else INTEGER(ans)[iRow]=NA_INTEGER;
break;
#ifdef GDALV2
case OFTInteger64:
if (poFeature->IsFieldSet(iField)) {
if (int64 == 3) {
SET_STRING_ELT(ans, iRow,
mkChar(poFeature->GetFieldAsString(iField)));
} else {
GIntBig nVal64 = poFeature->GetFieldAsInteger64(iField);
int nVal = (nVal64 > INT_MAX) ? INT_MAX :
(nVal64 < INT_MIN) ? INT_MIN : (int) nVal64;
INTEGER(ans)[iRow]=nVal;
if (((GIntBig)nVal != nVal64) && int64 == 2) {
warning("Integer64 value clamped: feature %d", iRow);
}
}
} else {
if (int64 == 3) {
SET_STRING_ELT(ans, iRow, NA_STRING);
} else {
INTEGER(ans)[iRow]=NA_INTEGER;
//.........这里部分代码省略.........
示例7: ogrInfo
//.........这里部分代码省略.........
installErrorHandler();
OGREnvelope oExt;
if (poLayer->GetExtent(&oExt, TRUE) == OGRERR_NONE) {
PROTECT(dvec=allocVector(REALSXP,4));
pc++;
REAL(dvec)[0] = oExt.MinX;
REAL(dvec)[1] = oExt.MinY;
REAL(dvec)[2] = oExt.MaxX;
REAL(dvec)[3] = oExt.MaxY;
SET_VECTOR_ELT(ans,4,dvec);
}
uninstallErrorHandlerAndTriggerError();
PROTECT(itemnames=allocVector(STRSXP,nFields));
pc++;
PROTECT(itemtype=allocVector(INTSXP,nFields));
pc++;
PROTECT(itemwidth=allocVector(INTSXP,nFields));
pc++;
// try List types
PROTECT(itemlistmaxcount=allocVector(INTSXP,nFields));
pc++;
PROTECT(itemTypeNames=allocVector(STRSXP,nFields));
pc++;
int listFieldCount=0;
installErrorHandler();
for(iField=0; iField<nFields; iField++) {
OGRFieldDefn *poField = poDefn->GetFieldDefn(iField);
SET_STRING_ELT(itemnames,iField,mkChar(poField->GetNameRef()));
INTEGER(itemtype)[iField]=poField->GetType();
if (INTEGER(itemtype)[iField] == OFTIntegerList ||
INTEGER(itemtype)[iField] == OFTRealList ||
INTEGER(itemtype)[iField] == OFTStringList) listFieldCount++;
INTEGER(itemwidth)[iField]=poField->GetWidth();
SET_STRING_ELT(itemTypeNames,iField,mkChar(poField->GetFieldTypeName(
poField->GetType())));
INTEGER(itemlistmaxcount)[iField] = 0;
}
uninstallErrorHandlerAndTriggerError();
PROTECT(vec3=allocVector(INTSXP,1));
pc++;
INTEGER(vec3)[0]=listFieldCount;
SET_VECTOR_ELT(ans,5,vec3);
PROTECT(itemlist=allocVector(VECSXP,5));
pc++;
SET_VECTOR_ELT(itemlist,0,itemnames);
SET_VECTOR_ELT(itemlist,1,itemtype);
SET_VECTOR_ELT(itemlist,2,itemwidth);
SET_VECTOR_ELT(itemlist,3,itemTypeNames);
// try List types
if (listFieldCount > 0) {
poLayer->ResetReading();
OGRFeature* poFeature;
nCount = (int *) R_alloc((size_t) nFields, sizeof(int));
for (iField=0; iField<nFields; iField++) nCount[iField] = 0;
installErrorHandler();
OGRField* psField;
while( (poFeature = poLayer->GetNextFeature()) != NULL ) {
for(iField=0; iField<nFields; iField++) {
psField = poFeature->GetRawFieldRef(iField);
if (INTEGER(itemtype)[iField] == OFTIntegerList) {
nCount[iField] = psField->IntegerList.nCount;
if (nCount[iField] > INTEGER(itemlistmaxcount)[iField])
INTEGER(itemlistmaxcount)[iField] = nCount[iField];
} else if (INTEGER(itemtype)[iField] == OFTRealList) {
nCount[iField] = psField->RealList.nCount;
if (nCount[iField] > INTEGER(itemlistmaxcount)[iField])
INTEGER(itemlistmaxcount)[iField] = nCount[iField];
} else if (INTEGER(itemtype)[iField] == OFTStringList) {
nCount[iField] = psField->StringList.nCount;
if (nCount[iField] > INTEGER(itemlistmaxcount)[iField])
INTEGER(itemlistmaxcount)[iField] = nCount[iField];
}
}
OGRFeature::DestroyFeature( poFeature );
// delete poFeature;
}
uninstallErrorHandlerAndTriggerError();
}
SET_VECTOR_ELT(itemlist,4,itemlistmaxcount);
SET_VECTOR_ELT(ans,2,itemlist);
UNPROTECT(pc);
installErrorHandler();
#ifdef GDALV2
GDALClose( poDS );
#else
OGRDataSource::DestroyDataSource( poDS );
#endif
uninstallErrorHandlerAndTriggerError();
// delete poDS;
return(ans);
}