sym_difference(linestring,polygon,vector <linestring>)是否可以正常工作?

时间:2018-07-20 19:03:57

标签: c++ boost-geometry

here开始,线性/区域应该起作用。但是下面的代码会导致编译错误?

#include <iostream>
#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/c_array.hpp>
BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
typedef boost::geometry::model::d2::point_xy<double> geo2dpoint;
typedef boost::geometry::model::polygon<geo2dpoint> polygon;
typedef boost::geometry::model::linestring<geo2dpoint> linestr;

int main()
{
    double points[][2] = {{2.0, 1.3}, {4.1, 3.0}, {5.3, 2.6}, {2.9, 0.7}, {2.0, 1.3}};
    polygon poly;
    boost::geometry::append(poly, points);
    std::cout << boost::geometry::dsv(poly) << std::endl;
    linestr line1;
    boost::geometry::append(line1, std::vector<geo2dpoint>{{2., 1.f}, {5.f, 3.f}});
    std::cout << boost::geometry::dsv(line1) << std::endl;
    std::vector<linestr> intlines;
    boost::geometry::sym_difference(line1, poly, intlines);
    return 0;
}
error: no matching function for call to 'assertion_failed'
    BOOST_MPL_ASSERT_MSG

1 个答案:

答案 0 :(得分:1)

我不确定,但是我认为线串的 collection 适用于@Test @NeedsEmptyTestTables public void testSOKricket() { // Register the coder defaultPipeline .getCoderRegistry() .registerCoderForClass(HCatRecord.class, WritableCoder.of(DefaultHCatRecord.class)); defaultPipeline .apply(TextIO.read().from("/tmp/words.txt")) .apply(ParDo.of(new PukeHive())) .apply( HCatalogIO.write() .withConfigProperties(getConfigPropertiesAsMap(service.getHiveConf())) .withDatabase(TEST_DATABASE) .withTable(TEST_TABLE) .withPartition(new java.util.HashMap<>()) .withBatchSize(1L)); defaultPipeline.run(); } static class PukeHive extends DoFn<String, HCatRecord> { @ProcessElement public void processElement(ProcessContext c) throws Exception { // our test schema is (mycol1 string, mycol2 int) DefaultHCatRecord rec = new DefaultHCatRecord(2); rec.set(0, c.element()); rec.set(1, 1); c.output(rec); } } multi_linestring输入的情况。

以下内容会编译:

Live On Coliru

multi_polygon

打印

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/algorithms/sym_difference.hpp>
#include <iostream>
#include <vector>

namespace bg = boost::geometry;

typedef bg::model::d2::point_xy<double>      geo2dpoint;
typedef bg::model::polygon<geo2dpoint>       polygon;
typedef bg::model::linestring<geo2dpoint>    linestr;
typedef bg::model::multi_linestring<linestr> multi_linestr;

int main() {
    polygon poly { { { 2.0, 1.3 }, { 4.1, 3.0 }, { 5.3, 2.6 }, { 2.9, 0.7 }, { 2.0, 1.3 } } };
    multi_linestr line1 { { { 2., 1. }, { 5., 3. } } };

    multi_linestr out;
    bg::sym_difference(line1, poly, out);

    std::cout << bg::dsv(poly) << std::endl;
    std::cout << bg::dsv(line1) << std::endl;
    std::cout << bg::dsv(out) << std::endl;
}