本文整理汇总了C++中OGRFeature::GetFieldDefnRef方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFeature::GetFieldDefnRef方法的具体用法?C++ OGRFeature::GetFieldDefnRef怎么用?C++ OGRFeature::GetFieldDefnRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRFeature
的用法示例。
在下文中一共展示了OGRFeature::GetFieldDefnRef方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFeatureClass
QString QgsShapeFile::getFeatureClass(){
OGRFeature *feat = ogrLayer->GetNextFeature();
if(feat){
OGRGeometry *geom = feat->GetGeometryRef();
if(geom){
geom_type = QString(geom->getGeometryName());
char * esc_str = new char[geom_type.length()*2+1];
PQescapeString(esc_str, (const char *)geom_type, geom_type.length());
geom_type = QString(esc_str);
delete[] esc_str;
QString file(filename);
file.replace(file.length()-3, 3, "dbf");
// open the dbf file
std::ifstream dbf((const char*)file, std::ios::in | std::ios::binary);
// read header
DbaseHeader dbh;
dbf.read((char *)&dbh, sizeof(dbh));
Fda fda;
QString str_type = "varchar(";
for(int field_count = 0, bytes_read = sizeof(dbh); bytes_read < dbh.size_hdr-1; field_count++, bytes_read +=sizeof(fda)){
dbf.read((char *)&fda, sizeof(fda));
switch(fda.field_type){
case 'N': if((int)fda.field_decimal>0)
column_types.push_back("float");
else
column_types.push_back("int");
break;
case 'F': column_types.push_back("float");
break;
case 'D': column_types.push_back("date");
break;
case 'C':
str_type= QString("varchar(%1)").arg(fda.field_length);
column_types.push_back(str_type);
break;
case 'L': column_types.push_back("boolean");
break;
default:
column_types.push_back("varchar(256)");
break;
}
}
dbf.close();
int numFields = feat->GetFieldCount();
for(int n=0; n<numFields; n++)
column_names.push_back(feat->GetFieldDefnRef(n)->GetNameRef());
}else valid = false;
delete feat;
}else valid = false;
ogrLayer->ResetReading();
return valid?geom_type:NULL;
}
示例2: GetAsString
wxString wxGISFeatureDataset::GetAsString(int row, int col)
{
if(m_poLayer->GetFeatureCount() <= row)
return wxString();
else
{
OGRFeature* pFeature = GetAt(row);
OGRFieldDefn* pDef = pFeature->GetFieldDefnRef(col);
switch(pDef->GetType())
{
case OFTDate:
{
int year, mon, day, hour, min, sec, flag;
pFeature->GetFieldAsDateTime(col, &year, &mon, &day, &hour, &min, &sec, &flag);
wxDateTime dt(day, wxDateTime::Month(mon - 1), year, hour, min, sec);
return dt.Format(_("%d-%m-%Y"));//wxString::Format(_("%.2u-%.2u-%.4u"), day, mon, year );
}
case OFTTime:
{
int year, mon, day, hour, min, sec, flag;
pFeature->GetFieldAsDateTime(col, &year, &mon, &day, &hour, &min, &sec, &flag);
wxDateTime dt(day, wxDateTime::Month(mon - 1), year, hour, min, sec);
return dt.Format(_("%H:%M:%S"));//wxString::Format(_("%.2u:%.2u:%.2u"), hour, min, sec);
}
case OFTDateTime:
{
int year, mon, day, hour, min, sec, flag;
pFeature->GetFieldAsDateTime(col, &year, &mon, &day, &hour, &min, &sec, &flag);
wxDateTime dt(day, wxDateTime::Month(mon - 1), year, hour, min, sec);
return dt.Format(_("%d-%m-%Y %H:%M:%S"));//wxString::Format(_("%.2u-%.2u-%.4u %.2u:%.2u:%.2u"), day, mon, year, hour, min, sec);
}
case OFTReal:
return wxString::Format(_("%.6f"), pFeature->GetFieldAsDouble(col));
default:
return wgMB2WX(pFeature->GetFieldAsString(col));
}
//return wgMB2WX(GetAt(row)->GetFieldAsString(col));
}
}
示例3: CPLDebug
OGRFeature *OGRGeoconceptLayer::GetNextFeature()
{
OGRFeature* poFeature = NULL;
for( ;; )
{
if( !(poFeature= (OGRFeature*)ReadNextFeature_GCIO(_gcFeature)) )
{
/*
* As several features are embed in the Geoconcept file,
* when reaching the end of the feature type, resetting
* the reader would allow reading other features :
* ogrinfo -ro export.gxt FT1 FT2 ...
* will be all features for all features types !
*/
Rewind_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature),NULL);
break;
}
if( (m_poFilterGeom == NULL || FilterGeometry( poFeature->GetGeometryRef() ) )
&&
(m_poAttrQuery == NULL || m_poAttrQuery->Evaluate( poFeature )) )
{
break;
}
delete poFeature;
}
CPLDebug( "GEOCONCEPT",
"FID : %ld\n"
"%s : %s",
poFeature? poFeature->GetFID():-1L,
poFeature && poFeature->GetFieldCount()>0? poFeature->GetFieldDefnRef(0)->GetNameRef():"-",
poFeature && poFeature->GetFieldCount()>0? poFeature->GetFieldAsString(0):"");
return poFeature;
}
示例4: if
OGRFeature *OGRMDBLayer::GetNextRawFeature()
{
OGRErr err = OGRERR_NONE;
if( !poMDBTable->GetNextRow() )
return NULL;
/* -------------------------------------------------------------------- */
/* Create a feature from the current result. */
/* -------------------------------------------------------------------- */
int iField;
OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
if( pszFIDColumn != NULL && poMDBTable->GetColumnIndex(pszFIDColumn) > -1 )
poFeature->SetFID(
poMDBTable->GetColumnAsInt(poMDBTable->GetColumnIndex(pszFIDColumn)) );
else
poFeature->SetFID( iNextShapeId );
iNextShapeId++;
m_nFeaturesRead++;
/* -------------------------------------------------------------------- */
/* Set the fields. */
/* -------------------------------------------------------------------- */
for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
int iSrcField = panFieldOrdinals[iField]-1;
char *pszValue = poMDBTable->GetColumnAsString( iSrcField );
OGRFieldType eType = poFeature->GetFieldDefnRef(iField)->GetType();
if( pszValue == NULL )
/* no value */;
else if( eType == OFTBinary )
{
int nBytes = 0;
GByte* pData = poMDBTable->GetColumnAsBinary( iSrcField, &nBytes);
poFeature->SetField( iField,
nBytes,
pData );
CPLFree(pData);
}
else if ( eType == OFTInteger && EQUAL(pszValue, "true"))
{
poFeature->SetField( iField, 1 );
}
else
{
poFeature->SetField( iField, pszValue );
}
CPLFree(pszValue);
}
if( !(m_poAttrQuery == NULL
|| m_poAttrQuery->Evaluate( poFeature )) )
return poFeature;
/* -------------------------------------------------------------------- */
/* Try to extract a geometry. */
/* -------------------------------------------------------------------- */
if( eGeometryType == MDB_GEOM_PGEO && iGeomColumn >= 0)
{
int nBytes = 0;
GByte* pData = poMDBTable->GetColumnAsBinary( iGeomColumn, &nBytes);
OGRGeometry *poGeom = NULL;
if( pData != NULL )
{
err = OGRCreateFromShapeBin( pData, &poGeom, nBytes );
if( OGRERR_NONE != err )
{
CPLDebug( "MDB",
"Translation shape binary to OGR geometry failed (FID=%ld)",
(long)poFeature->GetFID() );
}
}
CPLFree(pData);
if( poGeom != NULL && OGRERR_NONE == err )
{
poGeom->assignSpatialReference( poSRS );
poFeature->SetGeometryDirectly( poGeom );
}
}
else if( eGeometryType == MDB_GEOM_GEOMEDIA && iGeomColumn >= 0)
{
int nBytes = 0;
GByte* pData = poMDBTable->GetColumnAsBinary( iGeomColumn, &nBytes);
OGRGeometry *poGeom = NULL;
if( pData != NULL )
{
err = OGRCreateFromGeomedia( pData, &poGeom, nBytes );
if( OGRERR_NONE != err )
{
CPLDebug( "MDB",
"Translation geomedia binary to OGR geometry failed (FID=%ld)",
//.........这里部分代码省略.........
示例5: if
OGRFeature *OGRMSSQLSpatialLayer::GetNextRawFeature()
{
if( GetStatement() == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* If we are marked to restart then do so, and fetch a record. */
/* -------------------------------------------------------------------- */
if( !poStmt->Fetch() )
{
delete poStmt;
poStmt = NULL;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a feature from the current result. */
/* -------------------------------------------------------------------- */
int iField;
OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
if( pszFIDColumn != NULL && poStmt->GetColId(pszFIDColumn) > -1 )
poFeature->SetFID(
CPLAtoGIntBig(poStmt->GetColData(poStmt->GetColId(pszFIDColumn))) );
else
poFeature->SetFID( iNextShapeId );
iNextShapeId++;
m_nFeaturesRead++;
/* -------------------------------------------------------------------- */
/* Set the fields. */
/* -------------------------------------------------------------------- */
for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
if ( poFeatureDefn->GetFieldDefn(iField)->IsIgnored() )
continue;
int iSrcField = panFieldOrdinals[iField];
const char *pszValue = poStmt->GetColData( iSrcField );
if( pszValue == NULL )
/* no value */;
else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
poFeature->SetField( iField,
poStmt->GetColDataLength(iSrcField),
(GByte *) pszValue );
else
poFeature->SetField( iField, pszValue );
}
/* -------------------------------------------------------------------- */
/* Try to extract a geometry. */
/* -------------------------------------------------------------------- */
if( pszGeomColumn != NULL && !poFeatureDefn->IsGeometryIgnored())
{
int iField = poStmt->GetColId( pszGeomColumn );
const char *pszGeomText = poStmt->GetColData( iField );
OGRGeometry *poGeom = NULL;
OGRErr eErr = OGRERR_NONE;
if( pszGeomText != NULL )
{
int nLength = poStmt->GetColDataLength( iField );
if ( nGeomColumnType == MSSQLCOLTYPE_GEOMETRY ||
nGeomColumnType == MSSQLCOLTYPE_GEOGRAPHY ||
nGeomColumnType == MSSQLCOLTYPE_BINARY)
{
switch ( poDS->GetGeometryFormat() )
{
case MSSQLGEOMETRY_NATIVE:
{
OGRMSSQLGeometryParser oParser( nGeomColumnType );
eErr = oParser.ParseSqlGeometry(
(unsigned char *) pszGeomText, nLength, &poGeom );
nSRSId = oParser.GetSRSId();
}
break;
case MSSQLGEOMETRY_WKB:
case MSSQLGEOMETRY_WKBZM:
eErr = OGRGeometryFactory::createFromWkb((unsigned char *) pszGeomText,
NULL, &poGeom, nLength);
break;
case MSSQLGEOMETRY_WKT:
eErr = OGRGeometryFactory::createFromWkt((char **) &pszGeomText,
NULL, &poGeom);
break;
}
}
else if (nGeomColumnType == MSSQLCOLTYPE_TEXT)
{
eErr = OGRGeometryFactory::createFromWkt((char **) &pszGeomText,
NULL, &poGeom);
}
}
if ( eErr != OGRERR_NONE )
{
//.........这里部分代码省略.........
示例6: if
OGRFeature *OGRPGeoLayer::GetNextRawFeature()
{
OGRErr err = OGRERR_NONE;
if( GetStatement() == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* If we are marked to restart then do so, and fetch a record. */
/* -------------------------------------------------------------------- */
if( !poStmt->Fetch() )
{
delete poStmt;
poStmt = NULL;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a feature from the current result. */
/* -------------------------------------------------------------------- */
int iField;
OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
if( pszFIDColumn != NULL && poStmt->GetColId(pszFIDColumn) > -1 )
poFeature->SetFID(
atoi(poStmt->GetColData(poStmt->GetColId(pszFIDColumn))) );
else
poFeature->SetFID( iNextShapeId );
iNextShapeId++;
m_nFeaturesRead++;
/* -------------------------------------------------------------------- */
/* Set the fields. */
/* -------------------------------------------------------------------- */
for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
int iSrcField = panFieldOrdinals[iField]-1;
const char *pszValue = poStmt->GetColData( iSrcField );
if( pszValue == NULL )
/* no value */;
else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
poFeature->SetField( iField,
poStmt->GetColDataLength(iSrcField),
(GByte *) pszValue );
else
poFeature->SetField( iField, pszValue );
}
/* -------------------------------------------------------------------- */
/* Try to extract a geometry. */
/* -------------------------------------------------------------------- */
if( pszGeomColumn != NULL )
{
int iField = poStmt->GetColId( pszGeomColumn );
GByte *pabyShape = (GByte *) poStmt->GetColData( iField );
int nBytes = poStmt->GetColDataLength(iField);
OGRGeometry *poGeom = NULL;
if( pabyShape != NULL )
{
err = OGRCreateFromShapeBin( pabyShape, &poGeom, nBytes );
if( OGRERR_NONE != err )
{
CPLDebug( "PGeo",
"Translation shape binary to OGR geometry failed (FID=%ld)",
(long)poFeature->GetFID() );
}
}
if( poGeom != NULL && OGRERR_NONE == err )
{
poGeom->assignSpatialReference( poSRS );
poFeature->SetGeometryDirectly( poGeom );
}
}
return poFeature;
}
示例7: if
//.........这里部分代码省略.........
if( poFD->pszPathToSequence == NULL )
continue;
CPLAssert( strlen(poFD->pszPathToSequence)
< strlen(poFD->pszFieldName)-1 );
if( strstr(poFD->pszFieldName,poFD->pszPathToSequence) != NULL )
pszPathFromSubSeq =
strstr(poFD->pszFieldName,poFD->pszPathToSequence)
+ strlen(poFD->pszPathToSequence) + 1;
else
continue;
/* -------------------------------------------------------------------- */
/* Get the sequence out of which this variable will be collected. */
/* -------------------------------------------------------------------- */
BaseType *poFieldVar = seq->var_value( iSubSeq,
poFD->pszPathToSequence );
Sequence *poSubSeq;
int nSubSeqCount;
if( poFieldVar == NULL )
continue;
poSubSeq = dynamic_cast<Sequence *>( poFieldVar );
if( poSubSeq == NULL )
continue;
nSubSeqCount = poSubSeq->number_of_rows();
/* -------------------------------------------------------------------- */
/* Allocate array to put values into. */
/* -------------------------------------------------------------------- */
OGRFieldDefn *poOFD = poFeature->GetFieldDefnRef( iField );
int *panIntList = NULL;
double *padfDblList = NULL;
char **papszStrList = NULL;
if( poOFD->GetType() == OFTIntegerList )
{
panIntList = (int *) CPLCalloc(sizeof(int),nSubSeqCount);
}
else if( poOFD->GetType() == OFTRealList )
{
padfDblList = (double *) CPLCalloc(sizeof(double),nSubSeqCount);
}
else if( poOFD->GetType() == OFTStringList )
{
papszStrList = (char **) CPLCalloc(sizeof(char*),nSubSeqCount+1);
}
else
continue;
/* -------------------------------------------------------------------- */
/* Loop, fetching subsequence values. */
/* -------------------------------------------------------------------- */
int iSubIndex;
for( iSubIndex = 0; iSubIndex < nSubSeqCount; iSubIndex++ )
{
poFieldVar = poSubSeq->var_value( iSubIndex, pszPathFromSubSeq );
if( poFieldVar == NULL )
continue;
switch( poFieldVar->type() )
{
示例8: if
OGRFeature *OGRWalkLayer::GetNextRawFeature()
{
if( GetStatement() == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* If we are marked to restart then do so, and fetch a record. */
/* -------------------------------------------------------------------- */
if( !poStmt->Fetch() )
{
delete poStmt;
poStmt = NULL;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a feature from the current result. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
if( pszFIDColumn != NULL && poStmt->GetColId(pszFIDColumn) > -1 )
poFeature->SetFID(
atoi(poStmt->GetColData(poStmt->GetColId(pszFIDColumn))) );
else
poFeature->SetFID( iNextShapeId );
iNextShapeId++;
m_nFeaturesRead++;
/* -------------------------------------------------------------------- */
/* Set the fields. */
/* -------------------------------------------------------------------- */
for( int iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
int iSrcField = panFieldOrdinals[iField]-1;
const char *pszValue = poStmt->GetColData( iSrcField );
if( pszValue == NULL )
/* no value */;
else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
poFeature->SetField( iField,
poStmt->GetColDataLength(iSrcField),
(GByte *) pszValue );
else
poFeature->SetField( iField, pszValue );
}
/* -------------------------------------------------------------------- */
/* Try to extract a geometry. */
/* -------------------------------------------------------------------- */
if( pszGeomColumn != NULL )
{
int iField = poStmt->GetColId( pszGeomColumn );
const char *pszGeomBin = poStmt->GetColData( iField );
int nGeomLength = poStmt->GetColDataLength( iField );
OGRGeometry *poGeom = NULL;
OGRErr eErr = OGRERR_NONE;
if( pszGeomBin != NULL && bGeomColumnWKB )
{
WKBGeometry *WalkGeom = (WKBGeometry *)CPLMalloc(sizeof(WKBGeometry));
if( Binary2WkbGeom((unsigned char *)pszGeomBin, WalkGeom, nGeomLength)
!= OGRERR_NONE )
{
CPLFree(WalkGeom);
return NULL;
}
eErr = TranslateWalkGeom(&poGeom, WalkGeom);
DeleteWKBGeometry(*WalkGeom);
CPLFree(WalkGeom);
}
if ( eErr != OGRERR_NONE )
{
const char *pszMessage;
switch ( eErr )
{
case OGRERR_NOT_ENOUGH_DATA:
pszMessage = "Not enough data to deserialize";
break;
case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
pszMessage = "Unsupported geometry type";
break;
case OGRERR_CORRUPT_DATA:
pszMessage = "Corrupt data";
break;
default:
pszMessage = "Unrecognized error";
}
CPLError(CE_Failure, CPLE_AppDefined,
"GetNextRawFeature(): %s", pszMessage);
}
if( poGeom != NULL && eErr == OGRERR_NONE )
{
poGeom->assignSpatialReference( poSRS );
poFeature->SetGeometryDirectly( poGeom );
//.........这里部分代码省略.........
示例9: if
OGRFeature *OGRDB2Layer::GetNextRawFeature()
{
if( GetStatement() == nullptr )
return nullptr;
/* -------------------------------------------------------------------- */
/* If we are marked to restart then do so, and fetch a record. */
/* -------------------------------------------------------------------- */
if( !m_poStmt->Fetch() ) // fail is normal for final fetch
{
// CPLDebug("OGR_DB2Layer::GetNextRawFeature","Fetch failed");
delete m_poStmt;
m_poStmt = nullptr;
return nullptr;
}
// CPLDebug("OGR_DB2Layer::GetNextRawFeature","Create feature");
/* -------------------------------------------------------------------- */
/* Create a feature from the current result. */
/* -------------------------------------------------------------------- */
int iField;
OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
if( pszFIDColumn != nullptr && m_poStmt->GetColId(pszFIDColumn) > -1 )
poFeature->SetFID(
atoi(m_poStmt->GetColData(m_poStmt->GetColId(pszFIDColumn))) );
else
poFeature->SetFID( iNextShapeId );
iNextShapeId++;
m_nFeaturesRead++;
/* -------------------------------------------------------------------- */
/* Set the fields. */
/* -------------------------------------------------------------------- */
for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
if ( poFeatureDefn->GetFieldDefn(iField)->IsIgnored() )
continue;
int iSrcField = panFieldOrdinals[iField];
const char *pszValue = m_poStmt->GetColData( iSrcField );
if( pszValue == nullptr )
poFeature->SetFieldNull( iField );
else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
poFeature->SetField( iField,
m_poStmt->GetColDataLength(iSrcField),
(GByte *) pszValue );
else
poFeature->SetField( iField, pszValue );
}
/* -------------------------------------------------------------------- */
/* Try to extract a geometry. */
/* -------------------------------------------------------------------- */
if( pszGeomColumn != nullptr && !poFeatureDefn->IsGeometryIgnored())
{
iField = m_poStmt->GetColId( pszGeomColumn );
const char *pszGeomText = m_poStmt->GetColData( iField );
OGRGeometry *poGeom = nullptr;
OGRErr eErr = OGRERR_NONE;
if( pszGeomText != nullptr )
{
eErr = OGRGeometryFactory::createFromWkt(pszGeomText,
nullptr, &poGeom);
}
if ( eErr != OGRERR_NONE )
{
const char *pszMessage;
switch ( eErr )
{
case OGRERR_NOT_ENOUGH_DATA:
pszMessage = "Not enough data to deserialize";
break;
case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
pszMessage = "Unsupported geometry type";
break;
case OGRERR_CORRUPT_DATA:
pszMessage = "Corrupt data";
break;
default:
pszMessage = "Unrecognized error";
}
CPLError(CE_Failure, CPLE_AppDefined,
"GetNextRawFeature(): %s", pszMessage);
}
if( poGeom != nullptr )
{
if ( GetSpatialRef() )
poGeom->assignSpatialReference( poSRS );
poFeature->SetGeometryDirectly( poGeom );
}
}
//.........这里部分代码省略.........
示例10: if
OGRFeature *OGRODBCLayer::GetNextRawFeature()
{
if( GetStatement() == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* If we are marked to restart then do so, and fetch a record. */
/* -------------------------------------------------------------------- */
if( !poStmt->Fetch() )
{
delete poStmt;
poStmt = NULL;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a feature from the current result. */
/* -------------------------------------------------------------------- */
int iField;
OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
if( pszFIDColumn != NULL && poStmt->GetColId(pszFIDColumn) > -1 )
poFeature->SetFID(
atoi(poStmt->GetColData(poStmt->GetColId(pszFIDColumn))) );
else
poFeature->SetFID( iNextShapeId );
iNextShapeId++;
m_nFeaturesRead++;
/* -------------------------------------------------------------------- */
/* Set the fields. */
/* -------------------------------------------------------------------- */
for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
{
int iSrcField = panFieldOrdinals[iField]-1;
const char *pszValue = poStmt->GetColData( iSrcField );
if( pszValue == NULL )
/* no value */;
else if( poFeature->GetFieldDefnRef(iField)->GetType() == OFTBinary )
poFeature->SetField( iField,
poStmt->GetColDataLength(iSrcField),
(GByte *) pszValue );
else
poFeature->SetField( iField, pszValue );
}
/* -------------------------------------------------------------------- */
/* Try to extract a geometry. */
/* -------------------------------------------------------------------- */
if( pszGeomColumn != NULL )
{
int iField = poStmt->GetColId( pszGeomColumn );
const char *pszGeomText = poStmt->GetColData( iField );
OGRGeometry *poGeom = NULL;
OGRErr eErr = OGRERR_NONE;
if( pszGeomText != NULL && !bGeomColumnWKB )
{
eErr =
OGRGeometryFactory::createFromWkt((char **) &pszGeomText,
NULL, &poGeom);
}
else if( pszGeomText != NULL && bGeomColumnWKB )
{
int nLength = poStmt->GetColDataLength( iField );
eErr =
OGRGeometryFactory::createFromWkb((unsigned char *) pszGeomText,
NULL, &poGeom, nLength);
}
if ( eErr != OGRERR_NONE )
{
const char *pszMessage;
switch ( eErr )
{
case OGRERR_NOT_ENOUGH_DATA:
pszMessage = "Not enough data to deserialize";
break;
case OGRERR_UNSUPPORTED_GEOMETRY_TYPE:
pszMessage = "Unsupported geometry type";
break;
case OGRERR_CORRUPT_DATA:
pszMessage = "Corrupt data";
break;
default:
pszMessage = "Unrecognized error";
}
CPLError(CE_Failure, CPLE_AppDefined,
"GetNextRawFeature(): %s", pszMessage);
}
if( poGeom != NULL )
poFeature->SetGeometryDirectly( poGeom );
}
//.........这里部分代码省略.........
示例11: OpenRasterScene
//.........这里部分代码省略.........
{
json_object* poProducts = json_object_object_get(poData, "products");
if( poProducts != NULL && json_object_get_type(poProducts) == json_type_object )
{
json_object* poProduct = json_object_object_get(poProducts, pszProductType);
if( poProduct != NULL && json_object_get_type(poProduct) == json_type_object )
{
json_object* poFull = json_object_object_get(poProduct, "full");
if( poFull && json_object_get_type(poFull) == json_type_string )
pszLink = json_object_get_string(poFull);
}
}
}
}
osRasterURL = pszLink ? pszLink : "";
json_object_put(poObj);
if( osRasterURL.size() == 0 )
{
CPLError(CE_Failure, CPLE_AppDefined, "Cannot find link to scene %s",
osScene.c_str());
return NULL;
}
if( strncmp(osRasterURL, "http://", strlen("http://")) == 0 )
{
osRasterURL = "http://" + osAPIKey + ":@" + osRasterURL.substr(strlen("http://"));
}
else if( strncmp(osRasterURL, "https://", strlen("https://")) == 0 )
{
osRasterURL = "https://" + osAPIKey + ":@" + osRasterURL.substr(strlen("https://"));
}
CPLString osOldHead(CPLGetConfigOption("CPL_VSIL_CURL_USE_HEAD", ""));
CPLString osOldExt(CPLGetConfigOption("CPL_VSIL_CURL_ALLOWED_EXTENSIONS", ""));
int bUseVSICURL = CSLFetchBoolean(poOpenInfo->papszOpenOptions, "RANDOM_ACCESS", TRUE);
if( bUseVSICURL && !(strncmp(osBaseURL, "/vsimem/", strlen("/vsimem/")) == 0) )
{
CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_USE_HEAD", "NO");
CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_ALLOWED_EXTENSIONS", "{noext}");
VSIStatBufL sStat;
if( VSIStatL(("/vsicurl/" + osRasterURL).c_str(), &sStat) == 0 &&
sStat.st_size > 0 )
{
osRasterURL = "/vsicurl/" + osRasterURL;
}
else
{
CPLDebug("PLSCENES", "Cannot use random access for that file");
}
}
GDALDataset* poOutDS = (GDALDataset*) GDALOpen(osRasterURL, GA_ReadOnly);
if( poOutDS )
{
poOutDS->SetDescription(poOpenInfo->pszFilename);
poOutDS->GetFileList(); /* so as to probe all auxiliary files before reseting the allowed extensions */
if( !EQUAL(pszProductType, "thumb") )
{
OGRPLScenesLayer* poLayer = new OGRPLScenesLayer(this, "ortho",
(osBaseURL + "ortho/").c_str());
papoLayers = (OGRPLScenesLayer**) CPLRealloc(papoLayers,
sizeof(OGRPLScenesLayer*) * (nLayers + 1));
papoLayers[nLayers ++] = poLayer;
/* Attach scene matadata */
poLayer->SetAttributeFilter(CPLSPrintf("id = '%s'", osScene.c_str()));
OGRFeature* poFeat = poLayer->GetNextFeature();
if( poFeat )
{
for(int i=0;i<poFeat->GetFieldCount();i++)
{
if( poFeat->IsFieldSet(i) )
{
const char* pszKey = poFeat->GetFieldDefnRef(i)->GetNameRef();
const char* pszVal = poFeat->GetFieldAsString(i);
if( strstr(pszKey, "file_size") == NULL &&
strstr(pszVal, "https://") == NULL )
{
poOutDS->SetMetadataItem(pszKey, pszVal);
}
}
}
}
delete poFeat;
}
}
if( bUseVSICURL )
{
CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_USE_HEAD",
osOldHead.size() ? osOldHead.c_str(): NULL);
CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_ALLOWED_EXTENSIONS",
osOldExt.size() ? osOldExt.c_str(): NULL);
}
return poOutDS;
}
示例12: load
bool Shape::load(const std::string& filename) {
GDALAllRegister();
GDALDataset* poDS;
poDS = (GDALDataset*)GDALOpenEx(filename.c_str(), GDAL_OF_VECTOR, NULL, NULL, NULL);
if (poDS == NULL) return false;
// 初期化
shapeObjects.clear();
minBound.x = std::numeric_limits<float>::max();
minBound.y = std::numeric_limits<float>::max();
minBound.z = std::numeric_limits<float>::max();
maxBound.x = -std::numeric_limits<float>::max();
maxBound.y = -std::numeric_limits<float>::max();
maxBound.z = -std::numeric_limits<float>::max();
int nLayers = poDS->GetLayerCount();
int i = 0;
for (int n = 0; n < nLayers; ++n) {
OGRLayer* poLayer = poDS->GetLayer(n);
shapeType = poLayer->GetGeomType();
shapeObjects.resize(shapeObjects.size() + poLayer->GetFeatureCount());
OGRFeature* poFeature;
poLayer->ResetReading();
while ((poFeature = poLayer->GetNextFeature()) != NULL) {
// 属性の名前を読み込む
std::vector<std::string> fieldNames;
for (int j = 0; j < poFeature->GetFieldCount(); ++j) {
OGRFieldDefn* poFieldDefn = poFeature->GetFieldDefnRef(j);
fieldNames.push_back(poFieldDefn->GetNameRef());
}
// 属性の値を読み込む
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
for (int j = 0; j < poFDefn->GetFieldCount(); ++j) {
OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(j);
if (poFieldDefn->GetType() == OFTInteger) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsInteger(j));
}
else if (poFieldDefn->GetType() == OFTInteger64) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsInteger(j));
}
else if (poFieldDefn->GetType() == OFTReal) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsDouble(j));
}
else if (poFieldDefn->GetType() == OFTString) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsString(j));
}
else {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsString(j));
}
}
// このshapeのベクトルデータを読み込む
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
if (poGeometry != NULL) {
if (wkbFlatten(poGeometry->getGeometryType()) == wkbPoint) {
shapeObjects[i].parts.resize(1);
shapeObjects[i].parts[0].points.resize(1);
OGRPoint* poPoint = (OGRPoint*)poGeometry;
shapeObjects[i].parts[0].points[0].x = poPoint->getX();
shapeObjects[i].parts[0].points[0].y = poPoint->getY();
updateBounds(poPoint);
}
else if (wkbFlatten(poGeometry->getGeometryType()) == wkbLineString) {
OGRLineString* poLineString = (OGRLineString*)poGeometry;
readLineString(poLineString, shapeObjects[i]);
}
else if (wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon) {
OGRPolygon* poPolygon = (OGRPolygon*)poGeometry;
readPolygon(poPolygon, shapeObjects[i]);
}
else if (wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon) {
OGRMultiPolygon* poMultiPolygon = (OGRMultiPolygon*)poGeometry;
readMultiPolygon(poMultiPolygon, shapeObjects[i]);
}
else {
// not supported
}
}
// shapeObjectsのインデックスをインクリメント
i++;
// OGRが取得したメモリを開放
OGRFeature::DestroyFeature(poFeature);
}
}
GDALClose(poDS);
return true;
}