本文整理汇总了C++中OGRLayer::GetLayerDefn方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRLayer::GetLayerDefn方法的具体用法?C++ OGRLayer::GetLayerDefn怎么用?C++ OGRLayer::GetLayerDefn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRLayer
的用法示例。
在下文中一共展示了OGRLayer::GetLayerDefn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: node
void node(const shared_ptr<Osmium::OSM::Node const>& node) {
if (!node->tags().empty()) {
std::string tags = Osmium::filter_and_accumulate(node->tags(), m_filter, std::string(), m_tohstore);
if (!tags.empty()) {
try {
Osmium::Geometry::Point point(*node);
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_point->GetLayerDefn());
OGRPoint* ogrpoint = Osmium::Geometry::create_ogr_geometry(point);
feature->SetGeometry(ogrpoint);
feature->SetField("id", boost::lexical_cast<std::string>(node->id()).c_str());
feature->SetField("tags", tags.c_str());
if (m_layer_point->CreateFeature(feature) != OGRERR_NONE) {
std::cerr << "Failed to create feature.\n";
exit(1);
}
OGRFeature::DestroyFeature(feature);
delete ogrpoint;
} catch (Osmium::Geometry::IllegalGeometry) {
std::cerr << "Ignoring illegal geometry for node " << node->id() << ".\n";
}
}
}
}
示例2: transcoder
ogr_index_featureset<filterT>::ogr_index_featureset(mapnik::context_ptr const & ctx,
OGRDataSource & dataset,
OGRLayer & layer,
filterT const& filter,
std::string const& index_file,
std::string const& encoding)
: ctx_(ctx),
dataset_(dataset),
layer_(layer),
layerdef_(layer.GetLayerDefn()),
filter_(filter),
tr_(new transcoder(encoding)),
fidcolumn_(layer_.GetFIDColumn())
{
boost::optional<mapnik::mapped_region_ptr> memory = mapnik::mapped_memory_cache::find(index_file.c_str(),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_);
}
std::sort(ids_.begin(),ids_.end());
#ifdef MAPNIK_DEBUG
std::clog << "OGR Plugin: query size=" << ids_.size() << std::endl;
#endif
itr_ = ids_.begin();
// reset reading
layer_.ResetReading();
}
示例3:
//---------------------------------------------------------
CSG_Shapes * COGR_DataSource::Read_Shapes(int iLayer)
{
OGRLayer *pLayer = Get_Layer(iLayer);
//-----------------------------------------------------
if( pLayer && Get_Type(iLayer) != SHAPE_TYPE_Undefined )
{
int iField;
OGRFeature *pFeature;
OGRFeatureDefn *pDef = pLayer->GetLayerDefn();
CSG_Shapes *pShapes = SG_Create_Shapes(Get_Type(iLayer), CSG_String(pDef->GetName()));
for(iField=0; iField<pDef->GetFieldCount(); iField++)
{
OGRFieldDefn *pDefField = pDef->GetFieldDefn(iField);
pShapes->Add_Field(pDefField->GetNameRef(), COGR_Driver::Get_Type(pDefField->GetType()));
}
pLayer->ResetReading();
//-------------------------------------------------
while( (pFeature = pLayer->GetNextFeature()) != NULL && SG_UI_Process_Get_Okay(false) )
{
OGRGeometry *pGeometry = pFeature->GetGeometryRef();
if( pGeometry != NULL )
{
CSG_Shape *pShape = pShapes->Add_Shape();
for(iField=0; iField<pDef->GetFieldCount(); iField++)
{
OGRFieldDefn *pDefField = pDef->GetFieldDefn(iField);
switch( pDefField->GetType() )
{
default: pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField))); break;
case OFTString: pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField))); break;
case OFTInteger: pShape->Set_Value(iField, pFeature->GetFieldAsInteger(iField)); break;
case OFTReal: pShape->Set_Value(iField, pFeature->GetFieldAsDouble (iField)); break;
}
}
//-----------------------------------------
if( _Read_Geometry(pShape, pGeometry) == false )
{
pShapes->Del_Shape(pShape);
}
}
OGRFeature::DestroyFeature(pFeature);
}
return( pShapes );
}
//-----------------------------------------------------
return( NULL );
}
示例4: CreateFeature
OGRErr OGRGnmLayer::CreateFeature (OGRFeature *poFeature)
{
// Check for obligatory attributes' correct values.
int temp;
temp = poFeature->GetFieldAsInteger("is_blocked");
if (temp != GNM_FEATURE_BLOCKED &&
temp != GNM_FEATURE_UNBLOCKED)
{
// Set initial value if incoming value is incorrect.
poFeature->SetField("is_blocked", GNM_FEATURE_UNBLOCKED);
}
temp = poFeature->GetFieldAsInteger("direction");
if (temp != GNM_FEATURE_STRAIGHT_DIRECTION &&
temp != GNM_FEATURE_REVERSE_DIRECTION &&
temp != GNM_FEATURE_DOUBLE_DIRECTION)
{
// Set initial value if incoming value is incorrect.
poFeature->SetField("direction", GNM_FEATURE_DOUBLE_DIRECTION);
}
/*
// Set feature unique ID.
long id = parentDataSrc->getNextFeatureId();
OGRErr err = poFeature->SetFID(id);
poFeature->SetFID(id);
// Add feature's id and layer name to the id relation table.
OGRLayer *poLr = parentDataSrc->getInnerDataSource()->GetLayerByName("network_ids");
OGRFeature *poFt;
poFt = OGRFeature::CreateFeature(poLr->GetLayerDefn());
const char* layerName = this->GetName();
poFt->SetField("layer_name", layerName);
poFt->SetFID(id);
if(poLr->CreateFeature(poFt) != OGRERR_NONE) return OGRERR_FAILURE;
*/
// Create feature.
OGRErr err = geoLayer->CreateFeature(poFeature);
if (err != OGRERR_NONE)
return OGRERR_FAILURE;
// Add to relation table info about new feature.
const char* lrNm = this->GetName();
long ftGId = parentDataSrc->getNextFeatureId();
long ftLId = poFeature->GetFID();
OGRLayer *poLr = parentDataSrc->getInnerDataSource()->GetLayerByName("network_ids");
OGRFeature *poFt;
poFt = OGRFeature::CreateFeature(poLr->GetLayerDefn());
poFt->SetField("id_global", ftGId);
poFt->SetField("layer_name", lrNm);
poFt->SetField("id_local", ftLId);
if(poLr->CreateFeature(poFt) != OGRERR_NONE)
return OGRERR_FAILURE;
OGRFeature::DestroyFeature(poFt);
return OGRERR_NONE;
}
示例5: OGR2SQLITE_ogr_geocode_set_result
static
void OGR2SQLITE_ogr_geocode_set_result(sqlite3_context* pContext,
OGRLayerH hLayer,
const char* pszField)
{
if( hLayer == NULL )
sqlite3_result_null (pContext);
else
{
OGRLayer* poLayer = (OGRLayer*)hLayer;
OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
OGRFeature* poFeature = poLayer->GetNextFeature();
int nIdx = -1;
if( poFeature == NULL )
sqlite3_result_null (pContext);
else if( strcmp(pszField, "geometry") == 0 &&
poFeature->GetGeometryRef() != NULL )
{
GByte* pabyGeomBLOB = NULL;
int nGeomBLOBLen = 0;
if( OGRSQLiteLayer::ExportSpatiaLiteGeometry(
poFeature->GetGeometryRef(), 4326, wkbNDR, FALSE, FALSE, FALSE,
&pabyGeomBLOB,
&nGeomBLOBLen ) != CE_None )
{
sqlite3_result_null (pContext);
}
else
{
sqlite3_result_blob (pContext, pabyGeomBLOB, nGeomBLOBLen, CPLFree);
}
}
else if( (nIdx = poFDefn->GetFieldIndex(pszField)) >= 0 &&
poFeature->IsFieldSet(nIdx) )
{
OGRFieldType eType = poFDefn->GetFieldDefn(nIdx)->GetType();
if( eType == OFTInteger )
sqlite3_result_int(pContext,
poFeature->GetFieldAsInteger(nIdx));
else if( eType == OFTInteger64 )
sqlite3_result_int64(pContext,
poFeature->GetFieldAsInteger64(nIdx));
else if( eType == OFTReal )
sqlite3_result_double(pContext,
poFeature->GetFieldAsDouble(nIdx));
else
sqlite3_result_text(pContext,
poFeature->GetFieldAsString(nIdx),
-1, SQLITE_TRANSIENT);
}
else
sqlite3_result_null (pContext);
delete poFeature;
OGRGeocodeFreeResult(hLayer);
}
}
示例6: create_point_feature
OGRFeature* create_point_feature(const Osmium::OSM::Node* node) {
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_point->GetLayerDefn());
Osmium::Geometry::Point point(*node);
OGRPoint* ogrgeom = Osmium::Geometry::create_ogr_geometry(point);
ogrgeom->transform(m_transformation);
feature->SetGeometryDirectly(ogrgeom);
sprintf(longint, "%ld", node->id());
feature->SetField("osm_id", longint);
feature->SetField("z_order", calculate_z_order(node));
feature->SetField("way_area", 0);
return feature;
}
示例7: ofieldDefn
int ILI2Reader::AddFeature(DOMElement *elem) {
bool newLayer = true;
OGRLayer *curLayer = NULL;
char *pszName = tr_strdup(elem->getTagName());
//CPLDebug( "OGR_ILI", "Reading layer: %s", pszName );
// test if this layer exist
curLayer = GetLayer(pszName);
newLayer = (curLayer == NULL);
// add a layer
if (newLayer) {
CPLDebug( "OGR_ILI", "Adding layer: %s", pszName );
OGRFeatureDefn* poFeatureDefn = new OGRFeatureDefn(pszName);
poFeatureDefn->SetGeomType( wkbUnknown );
GeomFieldInfos oGeomFieldInfos;
curLayer = new OGRILI2Layer(poFeatureDefn, oGeomFieldInfos, NULL);
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 = tr_strdup(elem->getAttribute(pszIli2_tid));
feature->SetField(fIndex, fChVal);
XMLString::release(&pszIli2_tid);
CPLFree(fChVal);
} else {
CPLDebug( "OGR_ILI","'%s' not found", ILI2_TID);
}
SetFieldValues(feature, elem);
CPL_IGNORE_RET_VAL(curLayer->SetFeature(feature));
CPLFree(pszName);
return 0;
}
示例8: create_area_feature
OGRFeature* create_area_feature(const shared_ptr<Osmium::OSM::Area const>& area)
{
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_polygon->GetLayerDefn());
Osmium::Geometry::MultiPolygon mp(*area);
OGRMultiPolygon* ogrgeom = Osmium::Geometry::create_ogr_geometry(mp);
ogrgeom->transform(m_transformation);
feature->SetGeometryDirectly(ogrgeom);
sprintf(longint, "%ld", area->from_way() ? area->orig_id() : -area->orig_id());
feature->SetField("osm_id", longint);
feature->SetField("z_order", calculate_z_order(area.get()));
feature->SetField("way_area", ogrgeom->get_Area());
return feature;
}
示例9: write_point
void write_point(const char* problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location location) {
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_perror->GetLayerDefn());
std::unique_ptr<OGRPoint> ogr_point = m_ogr_factory.create_point(location);
feature->SetGeometry(ogr_point.get());
feature->SetField("id1", static_cast<double>(id1));
feature->SetField("id2", static_cast<double>(id2));
feature->SetField("problem_type", problem_type);
if (m_layer_perror->CreateFeature(feature) != OGRERR_NONE) {
std::runtime_error("Failed to create feature on layer 'perrors'");
}
OGRFeature::DestroyFeature(feature);
}
示例10: 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);
}
示例11: area
void area(const osmium::Area& area) {
if (m_first_out) {
m_out << "[\n";
m_first_out = false;
} else {
m_out << ",\n";
}
m_out << "{\n \"test_id\": " << (area.orig_id() / 1000) << ",\n \"area_id\": " << area.id() << ",\n \"from_id\": " << area.orig_id() << ",\n \"from_type\": \"" << (area.from_way() ? "way" : "relation") << "\",\n \"wkt\": \"";
try {
std::string wkt = m_wkt_factory.create_multipolygon(area);
m_out << wkt << "\",\n \"tags\": {";
auto tagmap = create_map(area.tags());
bool first = true;
for (auto& tag : tagmap) {
if (first) {
first = false;
} else {
m_out << ", ";
}
m_out << '"' << tag.first << "\": \"" << tag.second << '"';
}
m_out << "}\n}";
} catch (osmium::geometry_error&) {
m_out << "INVALID\"\n}";
}
try {
std::unique_ptr<OGRMultiPolygon> ogr_polygon = m_ogr_factory.create_multipolygon(area);
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_polygon->GetLayerDefn());
feature->SetGeometry(ogr_polygon.get());
feature->SetField("id", static_cast<int>(area.orig_id()));
std::string from_type;
if (area.from_way()) {
from_type = "w";
} else {
from_type = "r";
}
feature->SetField("from_type", from_type.c_str());
if (m_layer_polygon->CreateFeature(feature) != OGRERR_NONE) {
std::cerr << "Failed to create feature.\n";
exit(1);
}
OGRFeature::DestroyFeature(feature);
} catch (osmium::geometry_error&) {
std::cerr << "Ignoring illegal geometry for area " << area.id() << " created from " << (area.from_way() ? "way" : "relation") << " with id=" << area.orig_id() << ".\n";
}
}
示例12: node
void node(const osmium::Node& node) {
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_point->GetLayerDefn());
std::unique_ptr<OGRPoint> ogr_point = m_ogr_factory.create_point(node);
feature->SetGeometry(ogr_point.get());
feature->SetField("id", static_cast<double>(node.id()));
feature->SetField("type", node.tags().get_value_by_key("type"));
if (m_layer_point->CreateFeature(feature) != OGRERR_NONE) {
std::cerr << "Failed to create feature.\n";
exit(1);
}
OGRFeature::DestroyFeature(feature);
}
示例13: main
int main() {
// Read in raster data for night time lights
int band_number = 1; // only one band, starts with one
Raster* raster = import_raster("raster.tif", band_number);
// Read in shapefile data containing municipality administrative regions
int layer_number = 0; // only one layer, starts with zero
OGRLayer* shapelayer = import_shapefile("MEX_adm2.shp", layer_number);
shapelayer->SetAttributeFilter("ID_1 = 1834"); // Filter for Yucatan
const int idx_of_number_field = 5; // Column number of municipality number
const int idx_of_name_field = 6; // Column number of municipality name
OGRFeature* poFeature;
int feature_ctr = 0;
while( (poFeature = shapelayer->GetNextFeature()) != NULL ) {
cerr << "Feature: " << feature_ctr++ << "\t";
int feature_num = poFeature->GetFieldAsInteger(idx_of_number_field);
string feature_name = poFeature->GetFieldAsString(idx_of_name_field);
OGRFeatureDefn *poFDefn = shapelayer->GetLayerDefn();
for( int iField = 0; iField < poFDefn->GetFieldCount(); iField++ ) {
OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );
if( poFieldDefn->GetType() == OFTString ) cerr << poFeature->GetFieldAsString(iField) << ",";
}
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
if( poGeometry != NULL) {
// For contiguous regions
if ( wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon ) {
cerr << " polygon" << endl;
report_raster_data_within_polygon(raster, (OGRPolygon *) poGeometry, feature_num, feature_name);
// For disjoint regions
} else if ( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon ) {
cerr << " multipolygon" << endl;
OGRMultiPolygon *multipolygon = (OGRMultiPolygon *) poGeometry;
for (int i = 0; i<multipolygon->getNumGeometries(); i++) {
report_raster_data_within_polygon(raster, (OGRPolygon*) multipolygon->getGeometryRef(i), feature_num, feature_name);
}
// Is this really the right shapefile?
} else {
cerr << "No polygon or multipolygon geometry for this feature: " << poGeometry->getGeometryName() << endl;
}
} else {
cerr << "No geometry for this feature" << endl;
}
}
OGRFeature::DestroyFeature( poFeature );
}
示例14: 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);
}
示例15: node
void node(const osmium::Node& node) {
const char* amenity = node.tags()["amenity"];
if (amenity && !strcmp(amenity, "post_box")) {
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_point->GetLayerDefn());
std::unique_ptr<OGRPoint> ogr_point = m_factory.create_point(node);
feature->SetGeometry(ogr_point.get());
feature->SetField("id", static_cast<double>(node.id()));
feature->SetField("operator", node.tags()["operator"]);
if (m_layer_point->CreateFeature(feature) != OGRERR_NONE) {
std::cerr << "Failed to create feature.\n";
exit(1);
}
OGRFeature::DestroyFeature(feature);
}
}