本文整理汇总了C++中OGRLayer类的典型用法代码示例。如果您正苦于以下问题:C++ OGRLayer类的具体用法?C++ OGRLayer怎么用?C++ OGRLayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OGRLayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OGRRegisterAll
MapExtruder::MapExtruder(const char* map2dFile,double height)
{
_map2dFile = map2dFile;
_height = height;
OGRRegisterAll();
OGRDataSource *poDS = OGRSFDriverRegistrar::Open(_map2dFile,FALSE);
if( poDS == NULL)
{
printf("Open failed.\n");
exit(1);
}
_map2d = new OGRMultiPolygon();
OGRLayer *poLayer;
poLayer = poDS->GetLayer(0);
OGRFeature *poFeature;
poLayer->ResetReading();
while((poFeature = poLayer->GetNextFeature())!=NULL)
{
OGRGeometry *poGeometry;
poGeometry = poFeature ->GetGeometryRef();
if(poGeometry!=NULL)
{
if(poGeometry ->getGeometryType()==wkbPolygon)
_map2d->addGeometry((OGRPolygon*) poGeometry);
if(poGeometry ->getGeometryType()==wkbMultiPolygon)
{
int nPolygons = ((OGRMultiPolygon*)poGeometry)->getNumGeometries();
for(int i=0;i<nPolygons;i++)
_map2d->addGeometry((OGRPolygon*)(((OGRMultiPolygon*)poGeometry)->getGeometryRef(i)));
}
}
}
extrusion();
}
示例2: file
ogr_index_featureset<filterT>::ogr_index_featureset(mapnik::context_ptr const & ctx,
OGRLayer & layer,
filterT const& filter,
std::string const& index_file,
std::string const& encoding)
: ctx_(ctx),
layer_(layer),
layerdef_(layer.GetLayerDefn()),
filter_(filter),
tr_(new transcoder(encoding)),
fidcolumn_(layer_.GetFIDColumn()),
feature_envelope_()
{
#ifdef SHAPE_MEMORY_MAPPED_FILE
boost::optional<mapnik::mapped_region_ptr> memory = mapnik::mapped_memory_cache::instance().find(index_file, true);
if (memory)
{
boost::interprocess::ibufferstream file(static_cast<char*>((*memory)->get_address()),(*memory)->get_size());
ogr_index<filterT,boost::interprocess::ibufferstream >::query(filter,file,ids_);
}
#else
#if defined (WINDOWS)
std::ifstream file(mapnik::utf8_to_utf16(index_file), std::ios::in | std::ios::binary);
#else
std::ifstream file(index_file.c_str(), std::ios::in | std::ios::binary);
#endif
ogr_index<filterT,std::ifstream>::query(filter,file,ids_);
#endif
std::sort(ids_.begin(),ids_.end());
MAPNIK_LOG_DEBUG(ogr) << "ogr_index_featureset: Query size=" << ids_.size();
itr_ = ids_.begin();
// reset reading
layer_.ResetReading();
}
示例3: OGROpen
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: transcoder
ogr_featureset::ogr_featureset(mapnik::context_ptr const & ctx,
OGRLayer & layer,
OGRGeometry & extent,
std::string const& encoding)
: ctx_(ctx),
layer_(layer),
layerdef_(layer.GetLayerDefn()),
tr_(new transcoder(encoding)),
fidcolumn_(layer_.GetFIDColumn ()),
count_(0)
{
layer_.SetSpatialFilter (&extent);
}
示例5: CPLFormFilename
CPLErr GNMFileNetwork::LoadNetworkLayer(const char *pszLayername)
{
// check if not loaded
for(size_t i = 0; i < m_apoLayers.size(); ++i)
{
if(EQUAL(m_apoLayers[i]->GetName(), pszLayername))
return CE_None;
}
const char* pszExt = m_poLayerDriver->GetMetadataItem(GDAL_DMD_EXTENSION);
CPLString soFile = CPLFormFilename(m_soNetworkFullName, pszLayername, pszExt);
GDALDataset *poDS = (GDALDataset*) GDALOpenEx( soFile, GDAL_OF_VECTOR |
GDAL_OF_UPDATE, NULL, NULL, NULL );
if( NULL == poDS )
{
CPLError( CE_Failure, CPLE_OpenFailed, "Open '%s' file failed",
soFile.c_str() );
return CE_Failure;
}
OGRLayer* poLayer = poDS->GetLayer(0);
if(NULL == poLayer)
{
CPLError( CE_Failure, CPLE_OpenFailed, "Layer '%s' is not exist",
pszLayername );
return CE_Failure;
}
CPLDebug("GNM", "Layer '%s' loaded", poLayer->GetName());
GNMGenericLayer* pGNMLayer = new GNMGenericLayer(poLayer, this);
m_apoLayers.push_back(pGNMLayer);
m_mpLayerDatasetMap[pGNMLayer] = poDS;
return CE_None;
}
示例6: OGRPointToLatLon
bool OGRPointToLatLon(double &x, double &y, OGRDataSourceH hDS,
const char *datum) {
char *pszPrj = NULL;
OGRSpatialReference *poSrcSRS;
OGRSpatialReference oSourceSRS, oTargetSRS;
OGRCoordinateTransformation *poCT;
if (hDS == NULL) {
return false;
}
OGRLayer *poLayer;
poLayer = (OGRLayer *)OGR_DS_GetLayer(hDS, 0);
poLayer->ResetReading();
poSrcSRS = poLayer->GetSpatialRef();
if (poSrcSRS == NULL) {
return false;
}
oTargetSRS.SetWellKnownGeogCS(datum);
poCT = OGRCreateCoordinateTransformation(poSrcSRS, &oTargetSRS);
if (poCT == NULL) {
return false;
}
if (!poCT->Transform(1, &x, &y)) {
OGRCoordinateTransformation::DestroyCT(poCT);
return false;
}
OGRCoordinateTransformation::DestroyCT(poCT);
return true;
}
示例7: GetLayer
OGRErr GNMFileNetwork::DeleteLayer(int nIndex)
{
OGRLayer* pLayer = GetLayer(nIndex);
GDALDataset* poDS = m_mpLayerDatasetMap[pLayer];
if(NULL == poDS)
{
return OGRERR_FAILURE;
}
CPLDebug("GNM", "Delete network layer '%s'", pLayer->GetName());
if(poDS->DeleteLayer(0) != OGRERR_NONE)
{
return OGRERR_FAILURE;
}
GDALClose(poDS);
// remove pointer from map
m_mpLayerDatasetMap.erase(pLayer);
return GNMGenericNetwork::DeleteLayer(nIndex);
}
示例8: LoadNetworkLayer
CPLErr GNMDatabaseNetwork::LoadNetworkLayer(const char *pszLayername)
{
// check if not loaded
for(size_t i = 0; i < m_apoLayers.size(); ++i)
{
if(EQUAL(m_apoLayers[i]->GetName(), pszLayername))
return CE_None;
}
OGRLayer* poLayer = m_poDS->GetLayerByName(pszLayername);
if(NULL == poLayer)
{
CPLError( CE_Failure, CPLE_OpenFailed, "Layer '%s' is not exist",
pszLayername );
return CE_Failure;
}
CPLDebug("GNM", "Layer '%s' loaded", poLayer->GetName());
GNMGenericLayer* pGNMLayer = new GNMGenericLayer(poLayer, this);
m_apoLayers.push_back(pGNMLayer);
return CE_None;
}
示例9: CPLErrorReset
// *************************************************************
// LoadStyle()
// *************************************************************
CStringW OgrStyleHelper::LoadStyle(GDALDataset* dataset, CStringW styleTableName, CStringW layerName, CStringW styleName)
{
USES_CONVERSION;
CStringW sql;
sql.Format(L"SELECT style FROM %s WHERE layername = '%s' AND stylename = '%s'", styleTableName, layerName, styleName);
CStringW xml = L"";
bool found = false;
CPLErrorReset();
OGRLayer* layer = dataset->ExecuteSQL(OgrHelper::String2OgrString(sql), NULL, NULL);
if (layer) {
OGRFeature* ft = layer->GetNextFeature();
if (ft) {
const char* s = ft->GetFieldAsString(0);
if (s) {
xml = OgrHelper::OgrString2Unicode(s);
}
OGRFeature::DestroyFeature(ft);
}
dataset->ReleaseResultSet(layer);
}
return xml;
}
示例10: transcoder
ogr_featureset::ogr_featureset(OGRDataSource & dataset,
OGRLayer & layer,
OGRGeometry & extent,
const std::string& encoding,
const bool multiple_geometries)
: dataset_(dataset),
layer_(layer),
layerdef_(layer.GetLayerDefn()),
tr_(new transcoder(encoding)),
fidcolumn_(layer_.GetFIDColumn ()),
multiple_geometries_(multiple_geometries),
count_(0)
{
layer_.SetSpatialFilter (&extent);
}
示例11: MyOGRHandler
MyOGRHandler(const std::string& filename) :
m_data_source(NULL),
m_layer_point(NULL),
m_filter(true),
m_tohstore() {
OGRRegisterAll();
OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("PostgreSQL");
if (driver == NULL) {
std::cerr << "PostgreSQL OGR driver not available.\n";
exit(1);
}
// using COPY is much faster than INSERT
CPLSetConfigOption("PG_USE_COPY", "YES");
const char* options[] = { NULL };
m_data_source = driver->CreateDataSource(filename.c_str(), const_cast<char**>(options));
if (m_data_source == NULL) {
std::cerr << "Database open failed.\n";
exit(1);
}
// OGR can't create a table with hstore column, so we do it ourselves here
OGRLayer* dummy = m_data_source->ExecuteSQL("CREATE TABLE nodes (id VARCHAR, tags hstore);", NULL, NULL);
if (dummy) {
m_data_source->ReleaseResultSet(dummy);
}
dummy = m_data_source->ExecuteSQL("SELECT AddGeometryColumn('nodes', 'geom', 4326, 'POINT', 2);", NULL, NULL);
if (dummy) {
m_data_source->ReleaseResultSet(dummy);
}
m_layer_point = m_data_source->GetLayerByName("nodes");
if (!m_layer_point) {
std::cerr << "Something went wrong setting up the 'nodes' layer.\n";
exit(1);
}
// using transactions makes this much faster than without
m_layer_point->StartTransaction();
m_filter.add(false, "created_by");
m_filter.add(false, "odbl");
}
示例12: OGRRegisterAll
bool ShpReader::Open(std::wstring fullPath, StudyControllerPtr studyController,
VectorMapControllerPtr vectorMapController, ProgressDlgPtr progressDlg)
{
// Registers all format drivers built into GDAL/OGR.
OGRRegisterAll();
OGRDataSource *OGRDataset;
// Open vector file path
std::string tempStr( fullPath.begin(), fullPath.end() );
OGRDataset = OGRSFDriverRegistrar::Open( tempStr.c_str(), FALSE );
// Return if no vector files are found
if( OGRDataset == NULL )
{
Log::Inst().Warning("(Warning) Failed to open file at " + tempStr + ".");
return false;
}
if ( App::Inst().GetLayerTreeController()->GetNumMapLayers() >0 )
MapControllerPtr mapController= App::Inst().GetLayerTreeController()->GetLayerTreeModel()->GetStudy(0)->GetMapLayer(0)->GetMapController();
// It appears that shapefiles (*.SHP) only support up to one layer per file
// This will need to be further investigated for other vector filetypes (e.g., KML)
// For now just grab layer at position 0
OGRLayer *poLayer = OGRDataset->GetLayer( 0 );
// Determine the XY boundaries for the entire vector dataset
OGREnvelope psEnvelope;
VectorMapModelPtr vectorMapModel = vectorMapController->GetVectorMapModel();
poLayer->GetExtent( &psEnvelope );
vectorMapModel->SetVectorBoundary(psEnvelope);
if(!SetupVectorProjection(OGRDataset,studyController,poLayer,vectorMapController ))
{
OGRDataset->DestroyDataSource(OGRDataset);
return false;
}
if(progressDlg)
{
if(!progressDlg->Update(0, _T("Reading Vector Map Information...")))
{
OGRDataset->DestroyDataSource(OGRDataset);
return false;
}
}
GLdouble minX, minY, maxX, maxY;
minX = minY = std::numeric_limits<float>::max();
maxX = maxY = -std::numeric_limits<float>::max();
// Retrieve features from the dataset
OGRFeature *poFeature;
poLayer->ResetReading();
int numFeatures = poLayer->GetFeatureCount();
int count=0;
//Log::Inst().Write("Loading shapefile with the following meta data:");
while ( ( poFeature = poLayer->GetNextFeature() ) != NULL )
{
/////////////////////////////////////////////////
// PHASE 1: Retrieve METADATA from the dataset //
/////////////////////////////////////////////////
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
int iField;
for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );
//if( poFieldDefn->GetType() == OFTInteger )
// printf( "%d,", poFeature->GetFieldAsInteger( iField ) );
//else if( poFieldDefn->GetType() == OFTReal )
// printf( "%.3f,", poFeature->GetFieldAsDouble(iField) );
//else if( poFieldDefn->GetType() == OFTString )
// printf( "%s,", poFeature->GetFieldAsString(iField) );
//else
// printf( "%s,", poFeature->GetFieldAsString(iField) );
//ofs << poFeature->GetFieldAsString(iField) << ",";
std::string metaData = poFeature->GetFieldAsString(iField);
// do something with the meta data...
//Log::Inst().Write(metaData);
}
count++;
if(progressDlg)
{
if(!progressDlg->Update(int(50 + (float(count)/numFeatures)*50)))
return false;
}
///////////////////////////////////////////////////
// PHASE 2: Retrieve GEOMETRIES from the dataset //
///////////////////////////////////////////////////
OGRGeometry *poGeometry;
poGeometry = poFeature->GetGeometryRef();
//.........这里部分代码省略.........
示例13: ofieldDefn
int ILI2Reader::AddFeature(DOMElement *elem) {
bool newLayer = true;
OGRLayer *curLayer = 0;
char *pszName = XMLString::transcode(elem->getTagName());
// test if this layer exist
for (list<OGRLayer *>::reverse_iterator layerIt = m_listLayer.rbegin();
layerIt != m_listLayer.rend();
++layerIt) {
OGRFeatureDefn *fDef = (*layerIt)->GetLayerDefn();
if (cmpStr(fDef->GetName(), pszName) == 0) {
newLayer = false;
curLayer = *layerIt;
break;
}
}
// add a layer
if (newLayer) { // FIXME in Layer: SRS Writer Type datasource
CPLDebug( "OGR_ILI", "Adding layer: %s", pszName );
// new layer data
OGRSpatialReference *poSRSIn = NULL; // FIXME fix values for initial layer
int bWriterIn = 0;
OGRwkbGeometryType eReqType = wkbUnknown;
OGRILI2DataSource *poDSIn = NULL;
curLayer = new OGRILI2Layer(pszName, poSRSIn, bWriterIn, eReqType, poDSIn);
m_listLayer.push_back(curLayer);
}
// the feature and field definition
OGRFeatureDefn *featureDef = curLayer->GetLayerDefn();
if (newLayer) {
// add TID field
OGRFieldDefn ofieldDefn (ILI2_TID, OFTString);
featureDef->AddFieldDefn(&ofieldDefn);
setFieldDefn(featureDef, elem);
}
// add the features
OGRFeature *feature = new OGRFeature(featureDef);
// assign TID
int fIndex = feature->GetFieldIndex(ILI2_TID);
if (fIndex != -1) {
XMLCh *pszIli2_tid = XMLString::transcode(ILI2_TID);
char *fChVal = XMLString::transcode(elem->getAttribute(pszIli2_tid));
feature->SetField(fIndex, fChVal);
XMLString::release (&pszIli2_tid);
XMLString::release (&fChVal);
} else {
CPLDebug( "OGR_ILI","'%s' not found", ILI2_TID);
}
SetFieldValues(feature, elem);
curLayer->SetFeature(feature);
XMLString::release (&pszName);
return 0;
}
示例14: CPLAssert
//.........这里部分代码省略.........
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot open file %s", pszFilename);
return FALSE;
}
char** argv = GetArgv(bExplicitFeatures, bWaypoints, bRoutes,
bTracks, pszGPSBabelDriverName, "-");
VSILFILE* tmpfp = VSIFOpenL(osTmpFileName.c_str(), "wb");
CPLPushErrorHandler(CPLQuietErrorHandler);
bRet = (CPLSpawn(argv, fp, tmpfp, TRUE) == 0);
CPLPopErrorHandler();
CSLDestroy(argv);
argv = NULL;
CPLErr nLastErrorType = CPLGetLastErrorType();
CPLErrorNum nLastErrorNo = CPLGetLastErrorNo();
CPLString osLastErrorMsg = CPLGetLastErrorMsg();
VSIFCloseL(tmpfp);
tmpfp = NULL;
VSIFCloseL(fp);
fp = NULL;
if (!bRet)
{
if ( strstr(osLastErrorMsg.c_str(),
"This format cannot be used in piped commands") == NULL)
{
CPLError( nLastErrorType, nLastErrorNo, "%s",
osLastErrorMsg.c_str());
}
else
{
VSIStatBuf sStatBuf;
if (VSIStat(pszFilename, &sStatBuf) != 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"Driver %s only supports real (non virtual) "
"files",
pszGPSBabelDriverName );
return FALSE;
}
/* Try without piping in */
argv = GetArgv(bExplicitFeatures, bWaypoints, bRoutes,
bTracks, pszGPSBabelDriverName, pszFilename);
tmpfp = VSIFOpenL(osTmpFileName.c_str(), "wb");
bRet = (CPLSpawn(argv, NULL, tmpfp, TRUE) == 0);
VSIFCloseL(tmpfp);
tmpfp = NULL;
CSLDestroy(argv);
argv = NULL;
}
}
}
if (bRet)
{
poGPXDS = static_cast<GDALDataset *>(
GDALOpenEx( osTmpFileName.c_str(),
GDAL_OF_VECTOR, NULL, NULL, NULL ) );
if (poGPXDS)
{
if (bWaypoints)
{
OGRLayer* poLayer = poGPXDS->GetLayerByName("waypoints");
if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
apoLayers[nLayers++] = poLayer;
}
if (bRoutes)
{
OGRLayer* poLayer = poGPXDS->GetLayerByName("routes");
if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
apoLayers[nLayers++] = poLayer;
poLayer = poGPXDS->GetLayerByName("route_points");
if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
apoLayers[nLayers++] = poLayer;
}
if (bTracks)
{
OGRLayer* poLayer = poGPXDS->GetLayerByName("tracks");
if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
apoLayers[nLayers++] = poLayer;
poLayer = poGPXDS->GetLayerByName("track_points");
if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
apoLayers[nLayers++] = poLayer;
}
}
}
return nLayers > 0;
}
示例15: OGRRegisterAll
void ogr_datasource::bind() const
{
if (is_bound_) return;
// initialize ogr formats
OGRRegisterAll();
std::string driver = *params_.get<std::string>("driver","");
if (! driver.empty())
{
OGRSFDriver * ogr_driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driver.c_str());
if (ogr_driver && ogr_driver != NULL)
{
dataset_ = ogr_driver->Open((dataset_name_).c_str(), FALSE);
}
}
else
{
// open ogr driver
dataset_ = OGRSFDriverRegistrar::Open((dataset_name_).c_str(), FALSE);
}
if (! dataset_)
{
const std::string err = CPLGetLastErrorMsg();
if (err.size() == 0)
{
throw datasource_exception("OGR Plugin: connection failed: " + dataset_name_ + " was not found or is not a supported format");
}
else
{
throw datasource_exception("OGR Plugin: " + err);
}
}
// initialize layer
boost::optional<std::string> layer_by_name = params_.get<std::string>("layer");
boost::optional<unsigned> layer_by_index = params_.get<unsigned>("layer_by_index");
boost::optional<std::string> layer_by_sql = params_.get<std::string>("layer_by_sql");
int passed_parameters = 0;
passed_parameters += layer_by_name ? 1 : 0;
passed_parameters += layer_by_index ? 1 : 0;
passed_parameters += layer_by_sql ? 1 : 0;
if (passed_parameters > 1)
{
throw datasource_exception("OGR Plugin: you can only select an ogr layer by name "
"('layer' parameter), by number ('layer_by_index' parameter), "
"or by sql ('layer_by_sql' parameter), "
"do not supply 2 or more of them at the same time" );
}
if (layer_by_name)
{
layer_name_ = *layer_by_name;
layer_.layer_by_name(dataset_, layer_name_);
}
else if (layer_by_index)
{
const unsigned num_layers = dataset_->GetLayerCount();
if (*layer_by_index >= num_layers)
{
std::ostringstream s;
s << "OGR Plugin: only ";
s << num_layers;
s << " layer(s) exist, cannot find layer by index '" << *layer_by_index << "'";
throw datasource_exception(s.str());
}
layer_.layer_by_index(dataset_, *layer_by_index);
layer_name_ = layer_.layer_name();
}
else if (layer_by_sql)
{
layer_.layer_by_sql(dataset_, *layer_by_sql);
layer_name_ = layer_.layer_name();
}
else
{
std::ostringstream s;
s << "OGR Plugin: missing <layer> or <layer_by_index> or <layer_by_sql> "
<< "parameter, available layers are: ";
unsigned num_layers = dataset_->GetLayerCount();
bool layer_found = false;
for (unsigned i = 0; i < num_layers; ++i )
{
OGRLayer* ogr_layer = dataset_->GetLayer(i);
OGRFeatureDefn* ogr_layer_def = ogr_layer->GetLayerDefn();
if (ogr_layer_def != 0)
{
layer_found = true;
s << " '" << ogr_layer_def->GetName() << "' ";
}
}
//.........这里部分代码省略.........