From: Michael 'PoempelFox' Meier Date: Thu, 6 Aug 2015 13:13:38 +0000 (+0200) Subject: fix handling of buildings with inner holes by breaking up polygons into their rings X-Git-Url: http://git.rrze.uni-erlangen.de/gitweb/?a=commitdiff_plain;ds=inline;h=d25e5b4e4f74dd966426b0cba59deb3a1c81a5c4;p=osmrrze.git fix handling of buildings with inner holes by breaking up polygons into their rings --- diff --git a/scripts/osmbuildings-json-generator.pl b/scripts/osmbuildings-json-generator.pl index 5cd216f..a9b28f4 100755 --- a/scripts/osmbuildings-json-generator.pl +++ b/scripts/osmbuildings-json-generator.pl @@ -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 $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); }