int main() { // Create spherical polygon bg::model::polygon<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly; bg::read_wkt("POLYGON((0 0,0 1,1 0,0 0))", sph_poly); // Create spherical strategy with mean Earth radius in meters bg::strategy::area::spherical<> sph_strategy(6371008.8); // Calculate the area of a spherical polygon double area = bg::area(sph_poly, sph_strategy); std::cout << "Area: " << area << std::endl; // Create geographic polygon bg::model::polygon<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > > geo_poly; bg::read_wkt("POLYGON((0 0,0 1,1 0,0 0))", geo_poly); // Create geographic strategy with WGS84 spheroid bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793); bg::strategy::area::geographic<> geo_strategy(spheroid); // Calculate the area of a geographic polygon area = bg::area(geo_poly, geo_strategy); std::cout << "Area: " << area << std::endl; return 0; }
int main() { namespace bg = boost::geometry; typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > point_type; typedef bg::model::linestring<point_type> linestring_type; linestring_type ls1, ls2; bg::read_wkt("LINESTRING(0 0,1 1,1 2,2 1,2 2)", ls1); bg::read_wkt("LINESTRING(1 0,0 1,1 1,2 1,3 1)", ls2); bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793); bg::strategy::distance::geographic<> strategy(spheroid); double res = bg::discrete_frechet_distance(ls1, ls2, strategy); std::cout << "Discrete Frechet Distance: " << res << std::endl; return 0; }
CT test_vrt_lon_geo(CT lon1r, CT lat1r, CT lon2r, CT lat2r) { // WGS84 bg::srs::spheroid<CT> spheroid(6378137.0, 6356752.3142451793); typedef FormulaPolicy<CT, false, true, false, false, false> formula; CT a1 = formula::apply(lon1r, lat1r, lon2r, lat2r, spheroid).azimuth; typedef bg::model::point<CT, 2, bg::cs::geographic<bg::radian> > geo_point; bg::model::segment<geo_point> segment(geo_point(lon1r, lat1r), geo_point(lon2r, lat2r)); bg::model::box<geo_point> box; bg::envelope(segment, box); CT vertex_lat; CT lat_sum = lat1r + lat2r; if (lat_sum > CT(0)) { vertex_lat = bg::get_as_radian<bg::max_corner, 1>(box); } else { vertex_lat = bg::get_as_radian<bg::min_corner, 1>(box); } bg::strategy::azimuth::geographic<> azimuth_geographic; return bg::formula::vertex_longitude <CT, bg::geographic_tag>::apply(lon1r, lat1r, lon2r, lat2r, vertex_lat, a1, azimuth_geographic); }