[OSM-dev] osm2pgsql way_area is 0 for small areas

Sven Geggus lists at fuchsschwanzdomain.de
Fri Mar 22 13:57:55 UTC 2013


Michael Kussmaul <kussmaul.list at nix.ch> wrote:

> I'm using osm2pgsql in hstore+latlon configuration and experienced a
> problem with the calculated way_area. For small areas (parks, buildings)
> the value stored in the database is always 0. Looking at the code
> output_pgsql.c (line 931, 1162, 1215), I saw we simply use "%f" to format
> the calculated area - obviously this results in a rounded 0.000000 for
> very small areas.

I consider this to be a bug.

> I was wondering if there would be any side-effects in OSM toolchains if we
> change this to an "%g" formatter?

I don't think so because psql is the only software affected by this change.

> This would enable exponential notation for very small numbers (e.g.
> "1e-10") - do you think this will break existing software? I changed
> osm2pgsql localy to use the %g formatter for my usecase - but I would be
> grateful if such a change could be incorporated into mainstream, so I do
> not need to patch the file for every update. What do you think?

I would just commit the change to svn.

> My other question would be: How could I disable way_area calculation in a
> hstore configuration? I understand I can add "way_area" in a normal
> default.style config file, but when using a hstore.style, I was not
> capable of disabling the calculation of the way_area.

This will arise from the fact, that way_area is an artificial tag. Normal
tags can be disabled easily by style-file options.

The way this works is that the key/value combination will be ignored right
away, when data is read from the osm/pbf file. As this can not work this way
with an artificial tag I would suggest something like the following patch:

Index: output-pgsql.c
===================================================================
--- output-pgsql.c	(revision 29383)
+++ output-pgsql.c	(working copy)
@@ -44,6 +44,8 @@
     t_point, t_line, t_poly, t_roads
 };
 
+static int enable_way_area=1;
+
 static const struct output_options *Options;
 
 /* Tables to output */
@@ -193,6 +195,10 @@
         exit_nicely();
     }
     
+    if ((0==strcmp(temp.name,"way_area")) && (temp.flags==FLAG_DELETE)) {
+        enable_way_area=0;
+    }
+
     temp.count = 0;
     /*    printf("%s %s %d %d\n", temp.name, temp.type, temp.polygon, offset ); */
     
@@ -925,7 +931,7 @@
             if (!strncmp(wkt, "POLYGON", strlen("POLYGON")) || !strncmp(wkt, "MULTIPOLYGON", strlen("MULTIPOLYGON"))) {
                 expire_tiles_from_nodes_poly(nodes, count, id);
                 area = get_area(i);
-                if (area > 0.0) {
+                if ((area > 0.0) && enable_way_area) {
                     char tmp[32];
                     snprintf(tmp, sizeof(tmp), "%f", area);
                     addItem(tags, "way_area", tmp, 0);
@@ -1156,7 +1162,7 @@
             /* FIXME: there should be a better way to detect polygons */
             if (!strncmp(wkt, "POLYGON", strlen("POLYGON")) || !strncmp(wkt, "MULTIPOLYGON", strlen("MULTIPOLYGON"))) {
                 double area = get_area(i);
-                if (area > 0.0) {
+                if ((area > 0.0) && enable_way_area) {
                     char tmp[32];
                     snprintf(tmp, sizeof(tmp), "%f", area);
                     addItem(&tags, "way_area", tmp, 0);
@@ -1209,7 +1215,7 @@
                 /* FIXME: there should be a better way to detect polygons */
                 if (!strncmp(wkt, "POLYGON", strlen("POLYGON")) || !strncmp(wkt, "MULTIPOLYGON", strlen("MULTIPOLYGON"))) {
                     double area = get_area(i);
-                    if (area > 0.0) {
+                    if ((area > 0.0) && enable_way_area) {
                         char tmp[32];
                         snprintf(tmp, sizeof(tmp), "%f", area);
                         addItem(&tags, "way_area", tmp, 0);

Sven

-- 
Unix is simple and coherent, but it takes a genius – or at any rate a
programmer – to understand and appreciate the simplicity
(Dennis M. Ritchie)
/me is giggls at ircnet, http://sven.gegg.us/ on the Web




More information about the dev mailing list