当前位置: 首页>>代码示例>>C++>>正文


C++ OGRFeature::SetGeometry方法代码示例

本文整理汇总了C++中OGRFeature::SetGeometry方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFeature::SetGeometry方法的具体用法?C++ OGRFeature::SetGeometry怎么用?C++ OGRFeature::SetGeometry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OGRFeature的用法示例。


在下文中一共展示了OGRFeature::SetGeometry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: node

    void node(const osmium::Node& node) {
        const char* label = node.tags().get_value_by_key("label");
        if (label) {
            OGRFeature* feature = OGRFeature::CreateFeature(m_layer_labels->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("label", label);

            if (m_layer_labels->CreateFeature(feature) != OGRERR_NONE) {
                std::cerr << "Failed to create feature.\n";
                exit(1);
            }

            OGRFeature::DestroyFeature(feature);
        } else {
            OGRFeature* feature = OGRFeature::CreateFeature(m_layer_nodes->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()));

            if (m_layer_nodes->CreateFeature(feature) != OGRERR_NONE) {
                std::cerr << "Failed to create feature.\n";
                exit(1);
            }
            OGRFeature::DestroyFeature(feature);
        }
    }
开发者ID:7890,项目名称:osrm-backend,代码行数:28,代码来源:testdata-overview.cpp

示例2: run

void GDALMergeFaces::run()
{
	OGRGeometry * geo;
	leadingView.resetReading();

	OGRFeature * f;
	std::set<int> indizes;
	while (f = leadingView.getNextFeature()) {
		indizes.insert(f->GetFieldAsInteger(this->attriubteName.c_str()));
	}

	//int cluster_id = 1;
	int counter = 1;


	foreach (int cluster_id, indizes) {
	//while(geo = joinCluster(cluster_id)) {
		//cluster_id++;
		geo = joinCluster(cluster_id);

		if (counter % 100 == 0) {
		DM::Logger(DM::Standard) << "merged " << counter << "/" << indizes.size();
		}
		counter++;
		if (!geo)
			continue;



		if (wkbMultiPolygon == geo->getGeometryType()){
			geo = geo->UnionCascaded();
			OGRMultiPolygon * mgeo = (OGRMultiPolygon*) geo;
			if (mgeo->getNumGeometries() == 0) {
				continue;
			}
			geo = mgeo->getGeometryRef(0);

			int n = mgeo->getNumGeometries();
			for (int i = 0; i < n; i++) {
				OGRFeature * f = combinedView.createFeature();

				f->SetGeometry(mgeo->getGeometryRef(i));
				f->SetField("test_id", counter);
			}
			continue;
		}
		OGRFeature * f = combinedView.createFeature();
		f->SetGeometry(geo);
	}
开发者ID:iut-ibk,项目名称:DynaMind-ToolBox,代码行数:49,代码来源:gdalmergefaces.cpp

示例3: 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";
                }
            }
        }
    }
开发者ID:Rub21,项目名称:osmium,代码行数:27,代码来源:osmium_to_postgis.cpp

示例4: addToSystem

void GDALParceling::addToSystem(SFCGAL::Polygon & poly)
{

	std::string wkt = poly.asText(9).c_str();

	char * writable_wr = new char[wkt.size() + 1]; //Note not sure if memeory hole?
	std::copy(wkt.begin(), wkt.end(), writable_wr);
	writable_wr[wkt.size()] = '\0';

	OGRGeometry * ogr_poly;

	OGRErr err = OGRGeometryFactory::createFromWkt(&writable_wr, 0, &ogr_poly);

	if (!ogr_poly->IsValid()) {
		DM::Logger(DM::Warning) << "Geometry is not valid!";
		return;
	}
	if (ogr_poly->IsEmpty()) {
		DM::Logger(DM::Warning) << "Geometry is empty ";
		DM::Logger(DM::Warning) << "OGR Error " << err;
		DM::Logger(DM::Warning) << poly.asText(9);
		return;
	}
	//Create Feature
	OGRFeature * parcel = parcels.createFeature();
	parcel->SetGeometry(ogr_poly);
	OGRGeometryFactory::destroyGeometry(ogr_poly);

	counter_added++;
}
开发者ID:christianurich,项目名称:DynaMind-GDALModules,代码行数:30,代码来源:parceling.cpp

示例5: area

    void area(const osmium::Area& area) {
        const char* building = area.tags()["building"];
        if (building) {
            try {
                std::unique_ptr<OGRMultiPolygon> ogr_polygon = m_factory.create_multipolygon(area);
                OGRFeature* feature = OGRFeature::CreateFeature(m_layer_polygon->GetLayerDefn());
                feature->SetGeometry(ogr_polygon.get());
                feature->SetField("id", static_cast<int>(area.id()));
                feature->SetField("type", building);

                std::string type = "";
                if (area.from_way()) {
                    type += "w";
                } else {
                    type += "r";
                }
                feature->SetField("type", 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";
            }
        }
    }
开发者ID:ipaddr,项目名称:omim,代码行数:29,代码来源:osmium_toogr2_exp.cpp

示例6: 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);
            }
开发者ID:7890,项目名称:osrm-backend,代码行数:14,代码来源:problem_reporter_ogr.hpp

示例7: 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";
        }
    }
开发者ID:thomersch,项目名称:libosmium,代码行数:50,代码来源:testdata-multipolygon.cpp

示例8: run

void GDALAddComponentViewContainer::run()
{
	int counter = 0;
	for (int i = 0; i < elements; i++) {
		OGRFeature * f = this->components.createFeature();
		f->SetField("persons", "that is me");
		OGRPoint pt;
		pt.setX( i );
		pt.setY( i );

		f->SetGeometry(&pt);
		if (counter == 100000) {
			counter = 0;
		}
		counter++;
	}
}
开发者ID:christianurich,项目名称:DynaMind-ToolBox,代码行数:17,代码来源:gdaladdcomponentviewcontainer.cpp

示例9: 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);
        }
    }
开发者ID:ipaddr,项目名称:omim,代码行数:17,代码来源:osmium_toogr2_exp.cpp

示例10: SaveGeometry

void SaveGeometry(const CPLString &path, const OGRPolygon &polygon, const OGRSpatialReference &spaRef)
{
    const char *pszDriverName = "ESRI Shapefile";
    GDALDriver *poDriver = GetGDALDriverManager()->GetDriverByName(pszDriverName );
    if( poDriver == NULL )
    {
        printf( "%s driver not available.\n", pszDriverName );
        exit( 1 );
    }

    GDALDataset *poDS = poDriver->Create( path, 0, 0, 0, GDT_Unknown, NULL );
    if( poDS == NULL )
    {
        printf( "Creation of output file failed.\n" );
        exit( 1 );
    }

    const char* pszLayerName = CPLGetBasename(path);

    OGRLayer *poLayer = poDS->CreateLayer( pszLayerName, spaRef.Clone(), wkbPolygon, NULL );
    if( poLayer == NULL )
    {
        printf( "Layer creation failed.\n" );
        exit( 1 );
    }

    OGRFieldDefn oField( "Name", OFTString );
    oField.SetWidth(32);
    if( poLayer->CreateField( &oField ) != OGRERR_NONE )
    {
        printf( "Creating Name field failed.\n" );
        exit( 1 );
    }

    OGRFeature *poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
    //poFeature->SetField( "Name", szName );

    poFeature->SetGeometry( polygon.clone() );
    if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
    {
        printf( "Failed to create feature in shapefile.\n" );
        exit( 1 );
    }
    OGRFeature::DestroyFeature( poFeature );
    GDALClose( poDS );
}
开发者ID:BishopGIS,项目名称:gisconf2015,代码行数:46,代码来源:main.cpp

示例11: write_line

            void write_line(const char* problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location loc1, osmium::Location loc2) {
                std::unique_ptr<OGRPoint> ogr_point1 = m_ogr_factory.create_point(loc1);
                std::unique_ptr<OGRPoint> ogr_point2 = m_ogr_factory.create_point(loc2);
                std::unique_ptr<OGRLineString> ogr_linestring = std::unique_ptr<OGRLineString>(new OGRLineString());
                ogr_linestring->addPoint(ogr_point1.get());
                ogr_linestring->addPoint(ogr_point2.get());
                OGRFeature* feature = OGRFeature::CreateFeature(m_layer_lerror->GetLayerDefn());
                feature->SetGeometry(ogr_linestring.get());
                feature->SetField("id1", static_cast<double>(id1));
                feature->SetField("id2", static_cast<double>(id2));
                feature->SetField("problem_type", problem_type);

                if (m_layer_lerror->CreateFeature(feature) != OGRERR_NONE) {
                    std::runtime_error("Failed to create feature on layer 'lerrors'");
                }

                OGRFeature::DestroyFeature(feature);
            }
开发者ID:7890,项目名称:osrm-backend,代码行数:18,代码来源:problem_reporter_ogr.hpp

示例12: way

    void way(const osmium::Way& way) {
        try {
            std::unique_ptr<OGRLineString> ogr_linestring = m_ogr_factory.create_linestring(way);
            OGRFeature* feature = OGRFeature::CreateFeature(m_layer_linestring->GetLayerDefn());
            feature->SetGeometry(ogr_linestring.get());
            feature->SetField("id", static_cast<double>(way.id()));
            feature->SetField("type", way.tags().get_value_by_key("type"));

            if (m_layer_linestring->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 way " << way.id() << ".\n";
        }
    }
开发者ID:thomersch,项目名称:libosmium,代码行数:18,代码来源:testdata-multipolygon.cpp

示例13: feed_way

	void feed_way(const osmium::Way& way) {
		try {
			const char* building = way.tags().get_value_by_key("building");

			if (building && way.is_closed()) {
				std::unique_ptr<OGRLineString> ogr_linestring = m_factory.create_linestring(way);
				OGRFeature* feature = OGRFeature::CreateFeature(m_layer->GetLayerDefn());
				OGRPolygon polygon;
				polygon.addRing(static_cast<OGRLinearRing*>(ogr_linestring.get()));
				feature->SetGeometry(static_cast<OGRGeometry*>(&polygon));

				feature->SetField("way_id", static_cast<double>(way.id())); //TODO: node.id() is of type int64_t. is this ok?
				feature->SetField("lastchange", way.timestamp().to_iso().c_str());

				create_feature(feature);
			}

		} catch (osmium::geom::geometry_error& e) {
			catch_geometry_error(e, way);
		}
	}
开发者ID:gravitystorm,项目名称:osmi-addresses,代码行数:21,代码来源:BuildingsWriter.hpp

示例14: feed_way

	void feed_way(const osmium::Way& way) {
		try {
			const char* building = way.tags().get_value_by_key("building");
			if (building && way.is_closed()) {
				const char* street   = way.tags().get_value_by_key("addr:street");
				const char* houseno  = way.tags().get_value_by_key("addr:housenumber");
				
				if (street || houseno) {
					std::unique_ptr<OGRLineString> ogr_linestring = m_factory.create_linestring(way);
					OGRFeature* feature = OGRFeature::CreateFeature(m_layer->GetLayerDefn());
					OGRPolygon polygon;
					polygon.addRing(static_cast<OGRLinearRing*>(ogr_linestring.get()));
					feature->SetGeometry(static_cast<OGRGeometry*>(&polygon));
					feature->SetField("way_id", static_cast<double>(way.id())); //TODO: node.id() is of type int64_t. is this ok?
					feature->SetField("lastchange", way.timestamp().to_iso().c_str());

					const char* postcode = way.tags().get_value_by_key("addr:postcode");
					const char* city     = way.tags().get_value_by_key("addr:city");
					const char* country  = way.tags().get_value_by_key("addr:country");
					const char* fulladdr = way.tags().get_value_by_key("addr:full");
					const char* place    = way.tags().get_value_by_key("addr:place");

					if (street)   { feature->SetField("street"  , street);   }
					if (houseno)  { feature->SetField("houseno" , houseno);  }
					if (postcode) { feature->SetField("postcode", postcode); }
					if (city)     { feature->SetField("city",     city);     }
					if (country)  { feature->SetField("country",  country);  }
					if (fulladdr) { feature->SetField("fulladdr", fulladdr); }
					if (place)    { feature->SetField("place",    place);    }

					create_feature(feature);

				}
			}
		}
		catch (osmium::geometry_error& e) {
			catch_geometry_error(e, way);
		}
	}
开发者ID:Nathanael-L,项目名称:osmi-addresses,代码行数:39,代码来源:WaysWithAddressesWriter.hpp

示例15: addToSystem

void GDALParcelSplit::addToSystem(QString poly)
{
	QMutexLocker ml(&mMutex);

	std::string wkt = poly.toStdString();

	char * writable_wr = new char[wkt.size() + 1]; //Note not sure if memeory hole?
	std::copy(wkt.begin(), wkt.end(), writable_wr);
	writable_wr[wkt.size()] = '\0';

	OGRGeometry * ogr_poly;

	OGRErr err = OGRGeometryFactory::createFromWkt(&writable_wr, 0, &ogr_poly);
	//delete writable_wr;
	if (err != OGRERR_NONE) {
		DM::Logger(DM::Warning) << "Geometry is not valid!";
		return;
	}


	//delete writable_wr;
	if (!ogr_poly->IsValid()) {
		DM::Logger(DM::Warning) << "Geometry is not valid!";
		return;
	}
	if (ogr_poly->IsEmpty()) {
		DM::Logger(DM::Warning) << "Geometry is empty ";
		DM::Logger(DM::Warning) << "OGR Error " << err;
		DM::Logger(DM::Warning) << poly.toStdString();
		return;
	}
	//Create Feature
	OGRFeature * parcel = parcels.createFeature();
	parcel->SetGeometry(ogr_poly);
	OGRGeometryFactory::destroyGeometry(ogr_poly);

	counter_added++;
}
开发者ID:iut-ibk,项目名称:DynaMind-ToolBox,代码行数:38,代码来源:gdalparcelsplit.cpp


注:本文中的OGRFeature::SetGeometry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。