fix handling of buildings with inner holes by breaking up polygons into their rings
authorMichael 'PoempelFox' Meier <git@mulder.franken.de>
Thu, 6 Aug 2015 13:13:38 +0000 (15:13 +0200)
committerMichael 'PoempelFox' Meier <git@mulder.franken.de>
Thu, 6 Aug 2015 13:13:38 +0000 (15:13 +0200)
scripts/osmbuildings-json-generator.pl

index 5cd216f370c7e975a1c6f5dde7c327a9ca8dd965..a9b28f42efcde8bc13c3f976b1b802cd80c12b37 100755 (executable)
@@ -178,6 +178,7 @@ foreach $xtable ('planet_osm_polygon1', 'planet_osm_polygon2', 'planet_osm_line'
   }
   my $sth2 = $dbh->prepare("select ST_X(points) as x, ST_Y(points) as y"
                          . " from (select ST_astext((ST_dumppoints(ST_transform(?, 4326))).geom) as points) as points");
   }
   my $sth2 = $dbh->prepare("select ST_X(points) as x, ST_Y(points) as y"
                          . " from (select ST_astext((ST_dumppoints(ST_transform(?, 4326))).geom) as points) as points");
+  my $sth4 = $dbh->prepare("select (ST_dumprings(?)).geom as rings");
   while ($row = $sth->fetchrow_hashref()) {
     if ($xtable eq 'planet_osm_polygon1') {
       my $hassubparts = $dbh->selectrow_array("select count(*)"
   while ($row = $sth->fetchrow_hashref()) {
     if ($xtable eq 'planet_osm_polygon1') {
       my $hassubparts = $dbh->selectrow_array("select count(*)"
@@ -224,17 +225,33 @@ foreach $xtable ('planet_osm_polygon1', 'planet_osm_polygon2', 'planet_osm_line'
     if (defined($row->{'name'})) {
       $jso->{'name'} = $row->{'name'};
     }
     if (defined($row->{'name'})) {
       $jso->{'name'} = $row->{'name'};
     }
-    unless ($sth2->execute($row->{'way'})) {
-      print(STDERR "Sorry, decoding the way data exploded.\n");
-      exit(1);
+    my @waystodecode = ();
+    {
+      local $sth4->{'PrintError'};  # We're fully aware that the execute can
+      local $sth4->{'PrintWarn'};   # fail, no need to spam about it.
+      if ($sth4->execute($row->{'way'})) {
+        while ((my $nxtway) = $sth4->fetchrow_array()) {
+          push(@waystodecode, $nxtway);
+        }
+      } else {
+        push(@waystodecode, $row->{'way'});
+      }
     }
     }
-    my ($onex, $oney);
-    my @geomarr1 = ();
-    while (($onex, $oney) = $sth2->fetchrow_array()) {
-      my @onecoord = ( sprintf("%.5f", $onex), sprintf("%.5f", $oney));
-      push (@geomarr1, \@onecoord);
+    my @geomarr2 = ();
+    foreach my $nxtway (@waystodecode) {
+      unless ($sth2->execute($nxtway)) {
+        print(STDERR "Sorry, decoding the way data exploded.\n");
+        exit(1);
+      }
+      my ($onex, $oney);
+      my @geomarr1 = ();
+      while (($onex, $oney) = $sth2->fetchrow_array()) {
+        my @onecoord = ( sprintf("%.5f", $onex), sprintf("%.5f", $oney));
+        push (@geomarr1, \@onecoord);
+      }
+      push(@geomarr2, \@geomarr1);
+      $sth2->finish();
     }
     }
-    my @geomarr2 = (\@geomarr1);
     my $geomhsh = { "type" => "Polygon",
                     "coordinates" => \@geomarr2 };
     $jso->{'geometry'} = $geomhsh;
     my $geomhsh = { "type" => "Polygon",
                     "coordinates" => \@geomarr2 };
     $jso->{'geometry'} = $geomhsh;
@@ -277,8 +294,8 @@ foreach $xtable ('planet_osm_polygon1', 'planet_osm_polygon2', 'planet_osm_line'
     # Now dump it all.
     print($crappyjsonoo->encode($jso));
   }
     # Now dump it all.
     print($crappyjsonoo->encode($jso));
   }
-  $sth2->finish();
-  undef($sth2);
+  $sth4->finish();
+  undef($sth4);
   $sth->finish();
   undef($sth);
 }
   $sth->finish();
   undef($sth);
 }
This page took 0.058436 seconds and 4 git commands to generate.