}
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(*)"
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;
# Now dump it all.
print($crappyjsonoo->encode($jso));
}
- $sth2->finish();
- undef($sth2);
+ $sth4->finish();
+ undef($sth4);
$sth->finish();
undef($sth);
}