add explicit cast, else postgresql 9.5 will break (9.3 works fine)
[osmrrze.git] / scripts / osmbuildings-json-generator.pl
index 5cd216f370c7e975a1c6f5dde7c327a9ca8dd965..3a39357550c2fe6aadb9e8acbf1ae7b01af0cd65 100755 (executable)
@@ -177,7 +177,8 @@ foreach $xtable ('planet_osm_polygon1', 'planet_osm_polygon2', 'planet_osm_line'
     exit(1);
   }
   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");
+                         . " from (select ST_astext((ST_dumppoints(ST_transform(geometry(?), 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(*)"
@@ -224,17 +225,33 @@ foreach $xtable ('planet_osm_polygon1', 'planet_osm_polygon2', 'planet_osm_line'
     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;
@@ -277,8 +294,8 @@ foreach $xtable ('planet_osm_polygon1', 'planet_osm_polygon2', 'planet_osm_line'
     # Now dump it all.
     print($crappyjsonoo->encode($jso));
   }
-  $sth2->finish();
-  undef($sth2);
+  $sth4->finish();
+  undef($sth4);
   $sth->finish();
   undef($sth);
 }
This page took 0.071157 seconds and 4 git commands to generate.