求教啊-boost C++library 如何将需要的坐标全部加入到polygon内

问题描述

boost C++library 如何将需要的坐标全部加入到polygon内
 #include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/assign/list_of.hpp>
#include <string>
namespace bg = boost::geometry;

int main()
{
      std::string a = "(0, 0)(0, 3)(3, 3)(0, 0)";
    typedef bg::model::d2::point_xy<double> point;
    typedef bg::model::box<point> box;
    typedef bg::model::polygon<point> polygon;

//    // box
//    {
//        const box x(point(0, 0), point(3, 3));
//
//        const double result = bg::area(x);
//        std::cout << result << std::endl;
//    }
    // polygon

        polygon x;
        bg::exterior_ring(x) = boost::assign::list_of<point>a;

        const double result = bg::area(x);
        std::cout << result << std::endl;

}

解决方案

include <iostream>
#include <vector>
#include <boost/assign/std/vector.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/algorithms/area.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/io/dsv/write.hpp>

int main()
{
    using namespace boost::assign;
    typedef boost::geometry::model::d2::point_xy<double> point_xy;

    // Create points to represent a 5x5 closed polygon.
    std::vector<point_xy> points;
    points +=
      point_xy(0,0),
      point_xy(0,5),
      point_xy(5,5),
      point_xy(5,0),
      point_xy(0,0)
      ;

    // Create a polygon object and assign the points to it.
    boost::geometry::model::polygon<point_xy> polygon;
    boost::geometry::assign_points(polygon, points);

    std::cout << "Polygon " << boost::geometry::dsv(polygon) <<
      " has an area of " << boost::geometry::area(polygon) << std::endl;
}

时间: 2024-07-28 13:54:14

求教啊-boost C++library 如何将需要的坐标全部加入到polygon内的相关文章

Boost Graph Library一个通用图库用于C++开发人员

关于计算的公理表达通常颇具争论.然而,现代计算最重要的理论支柱之一的图论并不是这些公理表达之一.无数工程领域(从设计路由器和网络到设计构成移动设备核心的芯片)都是图论的应用. 作为 C++++ 应用程序软件http://www.aliyun.com/zixun/aggregation/7155.html">开发人员,我们通常需要直接将实际工程问题转化成一个等价的图论问题.如果有一个可靠的基于 C++ 的通用图库,就可以帮助我们实现这个转换,这样的图库显然非常受欢迎:Boost Graph

yum-configure: error: Boost.System library not found

问题描述 configure: error: Boost.System library not found Checking for boost libraries: checking for boostlib >= 1.36... configure: We could not detect the boost libraries (version 1.36 or higher). If you have a staged boost library (still not installed)

Visulalization Boost Voronoi in OpenSceneGraph

Visulalization Boost Voronoi in OpenSceneGraph eryar@163.com Abstract. One of the important features of the boost polygon library is the implementation of the generic sweepline algorithm to construct Voronoi diagrams of points and linear segments in

iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)

图像: 1.图片浏览控件MWPhotoBrowser        实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等操作.       下载:https://github.com/mwaterfall/MWPhotoBrowser   目前比较活跃的社区仍旧是Github,除此以外也有一些不错的库散落在Google Code.SourceForge等地方.由于Github社区太过主流,这里主要介绍一下Gith

常用iOS的第三方框架

图像:1.图片浏览控件MWPhotoBrowser       实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等操作.      下载:https://github.com/mwaterfall/MWPhotoBrowser 目前比较活跃的社区仍旧是Github,除此以外也有一些不错的库散落在Google Code.SourceForge等地方.由于Github社区太过主流,这里主要介绍一下Github里面流

Pregel: A System for Large-Scale Graph Processing

作者Grzegorz Malewicz, Matthew H. Austern .etc.Google Inc 2010-6 原文http://people.apache.org/~edwardyoon/documents/pregel.pdf 译者phylips@bmy 2012-09-14 译文http://duanple.blog.163.com/blog/static/70971767201281610126277/ [说明Pregel这篇是发表在2010年的SIGMOD上Pregel这

一个游戏程序员的学习资料

转自:http://software.intel.com/zh-cn/blogs/2012/03/20/400010004/?cid=sw:prccsdn2194 想起写这篇文章是在看侯杰先生的<深入浅出MFC>时, 突然觉得自己在大学这几年关于游戏编程方面还算是有些心得,因此写出这篇小文,介绍我眼中的游戏程序 员的书单与源代码参考.一则是作为自己今后两年学习目标的备忘录,二来没准对别人也有点参考价值.我的原则是只写自己研究过或准备研究的资料,所以内容无 疑会带上强烈的个人喜好色彩, 比如对网

大数据应用日志采集之Scribe 安装配置指南

1.概述 Scribe是Facebook开源的日志收集系统,在Facebook内部已经得到大量的应用.它能从各种日志源收集日志,存储到一个中央存储系统上,便于进行集中统计分析处理.它为日志的"分布式收集,统一处理"提供了一个可扩展的,高容错的方案.scribe代码很简单,但是安装配置却很复杂,本文记录了作者实际的一次安装的过程,感觉真是不一般的琐碎,另外Scribe开源社区的版本已经是几年前的版本了,最新的维护信息一致没有看到,HDFS和Thrift的版本使用的都是比较旧的版本,考虑另

基于Solr的空间搜索

如果需要对带经纬度的数据进行检索,比如查找当前所在位置附近1000米的酒店,一种简单的方法就是:获取数据库中的所有酒店数据,按经纬度计算距离,返回距离小于1000米的数据. 这种方式在数据量小的时候比较有效,但是当数据量大的时候,检索的效率是很低的,本文介绍使用Solr的Spatial Query进行空间搜索. 空间搜索原理 空间搜索,又名Spatial Search(Spatial Query),基于空间搜索技术,可以做到: 1)对Point(经纬度)和其他的几何图形建索引 2)根据距离排序