Last active
September 11, 2016 10:26
-
-
Save shoorick/66f7b473086c43eacc66 to your computer and use it in GitHub Desktop.
Mark in PostGIS buildings which belongs to South Ural State University
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
=head1 DESCRIPTION | |
Marks academic buildings which belongs to SUSU relation in PostGIS: | |
set type='academic'. This mark-up used for map coloring. | |
=head1 SEE ALSO | |
L<http://shoorick.ru/category/software/tilemill/> | |
=head1 AUTHOR | |
Alexander Sapozhnikov | |
L<E<lt>shoorick@cpan.orgE<gt>> | |
L<http://shoorick.ru/> | |
=cut | |
use LWP::Simple; | |
use XML::Simple; | |
use Getopt::Long; | |
my $yes = ''; | |
my $quiet = ''; | |
my $help = ''; | |
GetOptions( | |
'yes' => \$yes, | |
'quiet' => \$quiet, | |
'help|?' => \$help, | |
); | |
my $ids = join ",", get_academic_buildings_from_relation(1473514); | |
my $query = qq{UPDATE osm_buildings SET type='academic' WHERE osm_id IN ($ids)}; | |
$yes = 1 if $quiet; | |
unless ( $yes ) { | |
print qq{Query is\n$query\n\nExecute [Y/n]?}; | |
my $line = <>; | |
chomp($line); | |
if ($line !~ /^y(es)?/i && $line ne '') { | |
die "Canceled\n"; | |
} | |
} | |
# else | |
my $result = qx(psql -U username -d database-name -c "$query"); | |
print $result unless $quiet; | |
sub get_academic_buildings_from_relation { | |
my $osm_id = 0 + shift or return; | |
my $xml = get("http://www.openstreetmap.org/api/0.6/relation/$osm_id") | |
or die "Could not get XML: $!"; | |
my $object = XMLin $xml; | |
my @ways; | |
foreach my $member ( @{ $object->{'relation'}->{'member'} } ) { | |
push @ways, $member->{'ref'} | |
if $member->{'role'} eq 'academic' | |
} | |
return @ways; | |
} # sub get_academic_buildings_from_relation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
=head1 DESCRIPTION | |
Marks ways which belongs to SUSU relation in PostGIS: set flag belongs_to_susu=1 | |
=head1 SEE ALSO | |
L<http://shoorick.ru/category/software/tilemill/> | |
=head1 AUTHOR | |
Alexander Sapozhnikov | |
L<E<lt>shoorick@cpan.orgE<gt>> | |
L<http://shoorick.ru/> | |
=cut | |
use LWP::Simple; | |
use XML::Simple; | |
use Getopt::Long; | |
my $yes = ''; | |
my $quiet = ''; | |
my $help = ''; | |
GetOptions( | |
'yes' => \$yes, | |
'quiet' => \$quiet, | |
'help|?' => \$help, | |
); | |
my $ids = join ",", get_ways_of_relation(1473514); | |
my $query = qq{UPDATE osm_buildings SET belongs_to_susu=1 WHERE osm_id IN ($ids)}; | |
$yes = 1 if $quiet; | |
unless ( $yes ) { | |
print qq{Query is\n$query\n\nExecute [Y/n]?}; | |
my $line = <>; | |
chomp($line); | |
if ($line !~ /^y(es)?/i && $line ne '') { | |
die "Canceled\n"; | |
} | |
} | |
# else | |
my $result = qx(psql -U username -d database-name -c '$query'); | |
print $result unless $quiet; | |
sub get_ways_of_relation { | |
my $osm_id = 0 + shift or return; | |
my $xml = get("http://www.openstreetmap.org/api/0.6/relation/$osm_id") | |
or die "Could not get XML: $!"; | |
my $object = XMLin $xml; | |
my @ways; | |
foreach my $member ( @{ $object->{'relation'}->{'member'} } ) { | |
push @ways, $member->{'ref'} | |
} | |
return @ways; | |
} # sub get_ways_of_relation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment