本文整理汇总了C++中OGRLayer::GetFeature方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRLayer::GetFeature方法的具体用法?C++ OGRLayer::GetFeature怎么用?C++ OGRLayer::GetFeature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRLayer
的用法示例。
在下文中一共展示了OGRLayer::GetFeature方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VectorOpen
bool V2vProj::Compute(const data::VectorBarral * barrel)
{
OGRDataSource * poSourceDs = VectorOpen(barrel->GetSrcDataSource().c_str(),
GA_ReadOnly);
ON_SCOPE_EXIT([&]() {OGRDataSource::DestroyDataSource(poSourceDs); });
OGRDataSource * poOutputDs = VectorOpen(barrel->GetDstDataSource().c_str(),
GA_Update);
ON_SCOPE_EXIT([&]() {OGRDataSource::DestroyDataSource(poOutputDs); });
OGRLayer * poSrcLayer = poSourceDs->GetLayerByName(
barrel->GetSrcLayer().c_str());
OGRLayer * poDstLayer = poOutputDs->GetLayerByName(
barrel->GetDstLayer().c_str());
OGRSpatialReference * poSourceSRS = poSrcLayer->GetSpatialRef();
OGRCoordinateTransformation * poCT = poCT = OGRCreateCoordinateTransformation(
poSourceSRS, m_ogrSr);
OGRFeatureDefn * poDstFeatureDefn = poDstLayer->GetLayerDefn();
auto features = barrel->GetFeatures();
std::for_each(begin(features), end(features)
, [&](int fid) {
poSrcLayer->GetFeature(fid);
OGRFeature * poDstFeature = OGRFeature::CreateFeature(poDstFeatureDefn);
ON_SCOPE_EXIT([&]() {OGRFeature::DestroyFeature(poDstFeature); });
poDstFeature->SetFrom(poSrcLayer->GetFeature(fid));
OGRGeometry * poDstGeometry = poDstFeature->GetGeometryRef();
OGRGeometry * poReprojectedGeom = OGRGeometryFactory::transformWithOptions(
poDstGeometry, poCT, NULL);
poDstFeature->SetGeometryDirectly(poReprojectedGeom);
poDstLayer->CreateFeature(poDstFeature);
});
return true;
}
示例2: GetFeature
OGRFeature* OGROpenFileGDBSimpleSQLLayer::GetFeature( GIntBig nFeatureId )
{
OGRFeature* poSrcFeature = poBaseLayer->GetFeature(nFeatureId);
if( poSrcFeature == NULL )
return NULL;
if( poFeatureDefn == poBaseLayer->GetLayerDefn() )
return poSrcFeature;
else
{
OGRFeature* poFeature = new OGRFeature(poFeatureDefn);
poFeature->SetFrom(poSrcFeature);
poFeature->SetFID(poSrcFeature->GetFID());
delete poSrcFeature;
return poFeature;
}
}
示例3: GetFirstStationLine
int wxStation::GetFirstStationLine(const char *xFilename)
{
OGRDataSourceH hDS;
OGRLayer *poLayer;
OGRFeature *poFeature;
OGRLayerH hLayer;
GIntBig iBig = 1;
hDS = OGROpen( xFilename, FALSE, NULL );
if(hDS == NULL)
{
return -1; //very bad!
}
poLayer = (OGRLayer*)OGR_DS_GetLayer( hDS, 0 );
hLayer=OGR_DS_GetLayer(hDS,0);
OGR_L_ResetReading(hLayer);
poLayer->ResetReading();
poFeature = poLayer->GetFeature(iBig);
if (poFeature==NULL)
{
return -1; //If there are no stations in the csv!
}
std::string start_datetime(poFeature->GetFieldAsString(15));
if(start_datetime.empty()==true)
{
return 1;
}
if(start_datetime.empty()==false)
{
return 2;
}
}
示例4: ChangeBlockState
CPLErr GNMGenericNetwork::ChangeBlockState(GNMGFID nFID, bool bIsBlock)
{
if(!m_bIsGraphLoaded && LoadGraph() != CE_None)
{
return CE_Failure;
}
// change block state in layer
OGRLayer* poLayer = GetLayerByName(m_moFeatureFIDMap[nFID]);
if(NULL == poLayer)
{
CPLError( CE_Failure, CPLE_AppDefined, "Failed to get layer '%s'.",
m_moFeatureFIDMap[nFID].c_str() );
return CE_Failure;
}
OGRFeature* poFeature = poLayer->GetFeature(nFID);
if(NULL == poFeature)
{
CPLError( CE_Failure, CPLE_AppDefined, "Failed to get feature '"
GNMGFIDFormat"'.", nFID );
return CE_Failure;
}
if(bIsBlock)
{
poFeature->SetField( GNM_SYSFIELD_BLOCKED, GNM_BLOCK_ALL );
}
else
{
poFeature->SetField( GNM_SYSFIELD_BLOCKED, GNM_BLOCK_NONE );
}
if( poLayer->SetFeature( poFeature ) != OGRERR_NONE )
{
OGRFeature::DestroyFeature( poFeature );
CPLError( CE_Failure, CPLE_AppDefined, "Failed to update feature." );
return CE_Failure;
}
OGRFeature::DestroyFeature( poFeature );
GNMGFID nSrcFID, nTgtFID, nConFID;
// change block state in graph layer
m_poGraphLayer->ResetReading();
while ((poFeature = m_poGraphLayer->GetNextFeature()) != NULL)
{
nSrcFID = poFeature->GetFieldAsGNMGFID(GNM_SYSFIELD_SOURCE);
nTgtFID = poFeature->GetFieldAsGNMGFID(GNM_SYSFIELD_TARGET);
nConFID = poFeature->GetFieldAsGNMGFID(GNM_SYSFIELD_CONNECTOR);
int nBlockState = poFeature->GetFieldAsInteger(GNM_SYSFIELD_BLOCKED);
if(bIsBlock)
{
if(nSrcFID == nFID)
nBlockState |= GNM_BLOCK_SRC;
else if(nTgtFID == nFID)
nBlockState |= GNM_BLOCK_TGT;
else if(nConFID == nFID)
nBlockState |= GNM_BLOCK_CONN;
poFeature->SetField( GNM_SYSFIELD_BLOCKED, nBlockState );
}
else
{
if(nSrcFID == nFID)
nBlockState &= ~GNM_BLOCK_SRC;
else if(nTgtFID == nFID)
nBlockState &= ~GNM_BLOCK_TGT;
else if(nConFID == nFID)
nBlockState &= ~GNM_BLOCK_CONN;
poFeature->SetField( GNM_SYSFIELD_BLOCKED, nBlockState );
}
if( m_poGraphLayer->SetFeature( poFeature ) != OGRERR_NONE )
{
OGRFeature::DestroyFeature( poFeature );
CPLError( CE_Failure, CPLE_AppDefined, "Failed to update feature." );
return CE_Failure;
}
OGRFeature::DestroyFeature( poFeature );
}
// change block state in graph
m_oGraph.ChangeBlockState(nFID, bIsBlock);
return CE_None;
}
示例5: VectortoRaster
int Raster::VectortoRaster(const char * sVectorSourcePath,
const char * sRasterOutputPath,
const char * psFieldName,
RasterMeta * p_rastermeta ){
OGRRegisterAll();
OGRDataSource * pDSVectorInput;
pDSVectorInput = OGRSFDriverRegistrar::Open( sVectorSourcePath, FALSE );
if (pDSVectorInput == NULL)
return INPUT_FILE_ERROR;
OGRLayer * poLayer = pDSVectorInput->GetLayer(0);
// The type of the field.
OGRFeature * feat1 = poLayer->GetFeature(0);
int fieldindex = feat1->GetFieldIndex(psFieldName);
OGRFieldType fieldType = feat1->GetFieldDefnRef(fieldindex)->GetType();
OGRFeature::DestroyFeature( feat1 );
// The data type we're going to use for the file
GDALDataType OutputDataType = GDT_Byte;
// Handle field types according to their type:
switch (fieldType) {
case OFTString:
CSVWriteVectorValues(poLayer, psFieldName, sRasterOutputPath);
break;
case OFTInteger:
break;
case OFTReal:
OutputDataType = GDT_Float64;
default:
throw RasterManagerException(VECTOR_FIELD_NOT_VALID, "Type of field not recognized.");
break;
}
// Get our projection and set the rastermeta accordingly.
// -------------------------------------------------------
char *pszWKT = NULL;
OGRSpatialReference* poSRS = poLayer->GetSpatialRef();
poSRS->exportToWkt(&pszWKT);
p_rastermeta->SetProjectionRef(pszWKT);
CPLFree(pszWKT);
OSRDestroySpatialReference(poSRS);
// Create the output dataset for writing
GDALDataset * pDSOutput = CreateOutputDS(sRasterOutputPath, p_rastermeta);
// Create a list of burn-in values
// -------------------------------------------------------
std::vector<OGRGeometryH> ogrBurnGeometries;
std::vector<double> dBurnValues;
poLayer->ResetReading();
OGRFeature * ogrFeat = poLayer->GetNextFeature(); // <------- DRMEM!!! UNADDRESSABLE ACCESS of freed memory
while( ogrFeat != NULL ){
OGRGeometry * ogrGeom = ogrFeat->GetGeometryRef();
// No geometry found. Move along.
if( ogrGeom == NULL )
{
OGRFeature::DestroyFeature( ogrFeat );
continue;
}
OGRGeometry * geoClone = ogrGeom->clone(); // <------- DRMEM!!! UNADDRESSABLE ACCESS of freed memory AND LEAK 20 direct bytes
// Push a clone of this geometry onto the list of shapes to burn
ogrBurnGeometries.push_back( (OGRGeometryH) geoClone );
if (fieldType == OFTString){
// If it's a string type we burn the FID. The value is then placed in a CSV file
dBurnValues.push_back( ogrFeat->GetFID() );
}
else {
// If it's a float type or a byte type we write it directly.
dBurnValues.push_back( ogrFeat->GetFieldAsDouble(psFieldName) );
}
// GetNextFeature() creates a clone so we must delete it.
OGRFeature::DestroyFeature( ogrFeat ); // <------- DRMEM!!! UNADDRESSABLE ACCESS beyond heap bounds:
ogrFeat = poLayer->GetNextFeature(); // <------- DRMEM!!! UNADDRESSABLE ACCESS of freed memory
}
// Do the Actual Burning of Geometries.
// -------------------------------------------------------
int band = 1;
char **papszRasterizeOptions = NULL;
papszRasterizeOptions =
CSLSetNameValue( papszRasterizeOptions, "ALL_TOUCHED", "TRUE" );
CPLErr err = GDALRasterizeGeometries( pDSOutput, 1, &band,
ogrBurnGeometries.size(),
//.........这里部分代码省略.........