C++ boost::geometry模块 linestring使用案例

以下是一些个人使用的C++ boost::geometry模块中的linestring 向量测试案例
包括了boost::geometry中的函数、linestring的函数以及部分STL函数

#pragma once
#include <iostream>
#include <string>
#include <boost/geometry.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>

#include <boost/assign.hpp>
#include <boost/foreach.hpp>

#include <vector>

namespace bg = boost::geometry;
namespace bga = boost::assign;

using namespace std;
using namespace bga;

typedef bg::model::d2::point_xy<int> BGPoint;
typedef bg::model::linestring<BGPoint> BGVector;


// linestring 测试使用
namespace linestringTest {

	void test_init();
	void test_point();
	void test_append();
	void test_add();
	void test_size();
	void test_distance();
	void test_output_vector();
	void test_foreach();
	void test_namespace_assign();
	void test_reverse();
	void test_length();
	void test_delete_insert();
	void test_simplify();
	void test_foreach_point();
	void test_intersects();
	void test_output_as_json();



	void test_init() {

		BGVector vector{ {0, 1}, {2, 1} };

		int len = bg::length(vector);
		cout << "length: " << len << endl;
	}

	void test_point() {
		BGPoint point(1, 2);

		cout << point.x() << " " << point.y() << endl;
	}

	void test_append() {

		BGVector vector;

		// 一条经过三个点的折线
		bg::append(vector, BGPoint(0, 0));
		bg::append(vector, BGPoint(1, 1));
		bg::append(vector, BGPoint(2, 0));

		double len = bg::length(vector);
		cout << "长度为: " << len << endl;
	}

	void test_add() {
		BGVector vector;

		// namespace boost::assign 中包含的运算符 +=
		vector += BGPoint(1, 1);
		vector += BGPoint(1, 3), BGPoint(3, 3);

		double len = bg::length(vector);
		// dsv()
		cout << "add--长度为: " << len << endl;
		cout << "dsv(输出所有点): " << bg::dsv(vector) << endl;
	}

	void test_size() {
		BGVector vector;

		bg::append(vector, BGPoint(1, 1));
		bg::append(vector, BGPoint(2, 2));
		bg::append(vector, BGPoint(2, 3));
		bg::append(vector, BGPoint(3, 4));

		// linestring.size : 输出点(BGPoint)的个数
		cout << "linestring.size : " << vector.size() << endl;
		cout << "boost::size : " << boost::size(
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值