Boost logo

Geometry :

Subject: [ggl] centroid strategies and transform to 3D
From: Barend Gehrels (Barend.Gehrels)
Date: 2010-04-01 03:20:39


Hi Fausto,

> I've a couple of further questions, that might be helpful for other
> users too.
>
> How can one calculate the centroid of a multipolygon made of lat/long
> coordinates (for ex. country).
There is currently no explicit strategy for centroids for geometries in
latlong coordinates. You might use the default strategy (for Cartesian),
which is what most packages do.
>
> Is there a way to transform polygons from lat/long coordinates to xyz
> (eventually defiing which plane to use, the default being xy).

You mean to geocentric coordinates? Yes, there is, the strategy
"from_spherical_2_to_cartesian_3". It will be automatically called if
the source coordinate system is spherical, the target is cartesian3d.
However, if the source is geographic, you must specify the strategy
explicitly (currently).

> If it doesn't exist:
> is it possible to implement a custom transform and use an external 3d
> point type?
> OR
> is there a way to get() the outer and inners points of the polygon, so
> that I can implement the xyz transform externally?
So it exist, but these two suggestions are also possible. To get outer
and inner points, you can use a construct like:

        foo(exterior_ring(poly));

        for (typename boost::range_iterator
                <
                    typename interior_type<Polygon>::type const
>::type it = boost::begin(interior_rings(poly));
             it != boost::end(interior_rings(poly));
             ++it)
        {
            foo(*it);
        }

where foo would be a function which takes a ring (Boost.Range, usually a
std::vector) of points.

Regards, Barend


Geometry list run by mateusz at loskot.net