[Tile-serving] [osm2pgsql] Add area reprojection facility (#454)

Sarah Hoffmann notifications at github.com
Sun Oct 18 08:06:37 UTC 2015


> + * \return the area in projected units, or in EPSG 3857 if area reprojection is enabled
> + */
> +double geometry_builder::getArea(const geos::geom::Geometry *geom) const
> +{
> +    // reprojection is not necessary, or has not been asked for.
> +    if (!reprojection) {
> +        return geom->getArea();
> +    }
> +
> +    // MultiPolygon - return sum of individual areas
> +    if (const geos::geom::MultiPolygon* multi = dynamic_cast<const geos::geom::MultiPolygon *>(geom)) {
> +        double area = 0.0;
> +        for (std::size_t i=0; i<multi->getNumGeometries(); i++) {
> +            area += getArea(multi->getGeometryN(i));
> +        }
> +        return area;

In this particular case, a loop would mean considerably less writing:

    for (auto g : multi) {
      area += getArea(g);
    }

Personally, I find that more readable. However, in general, using the standard library function and lambdas in place of hand-crafted for loops is a good thing. So sure, go ahead and use it.

(Also: please use auto inside the if condition.)

---
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/pull/454/files#r42318370
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20151018/ae45da3d/attachment-0001.html>


More information about the Tile-serving mailing list