forked from zerebubuth/openstreetmap-license-change
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script to populate the tracker database with an ordered list of…
… regions.
- Loading branch information
1 parent
f33da4d
commit 89cda57
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- add as many bounds as you see fit --> | ||
<!-- bounding boxes will be expanded into 1 degree squares --> | ||
<!-- descriptions are ignored, but are here just to help coordination --> | ||
<list> | ||
<bounds minlat="51.2" minlon="-12.2524800" maxlat="55.5" maxlon="-5.29" description="Ireland" /> | ||
<bounds minlat="43.71" minlon="7.40" maxlat="43.76" maxlon="7.45" description="Monaco" /> | ||
</list> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env ruby | ||
# Generates the ordered region list in the tracker database | ||
|
||
require 'pg' | ||
require 'yaml' | ||
require 'xml/libxml' | ||
|
||
# Lat+lon are for the Bottom Left of the cell | ||
|
||
@regions = {} | ||
|
||
parser = XML::Reader.io(File.open('bounds.xml', "r")) | ||
|
||
dbauth = YAML.load(File.open('auth.yaml'))['tracker'] | ||
|
||
@conn = PGconn.open( :dbname => dbauth['dbname'] ) | ||
|
||
@conn.exec("create table if not exists regions (id serial, lat integer, lon integer, status region_status, bot_id integer)") | ||
@conn.exec("truncate table regions") | ||
|
||
def add_region(lat, lon) | ||
@conn.exec("insert into regions (lat, lon) values ($1, $2)", [lat, lon]) | ||
@regions[[lat, lon]] = true | ||
end | ||
|
||
@conn.transaction do | ||
while parser.read do | ||
next unless ["bounds"].include? parser.name | ||
|
||
# you want to floor the maxes too, or do (ceil - 1) | ||
min_lat = parser["minlat"].to_f.floor | ||
max_lat = parser["maxlat"].to_f.floor | ||
min_lon = parser["minlon"].to_f.floor | ||
max_lon = parser["maxlon"].to_f.floor | ||
|
||
(min_lat..max_lat).each do |lat| | ||
(min_lon..max_lon).each do |lon| | ||
add_region(lat, lon) | ||
end | ||
end | ||
end | ||
|
||
# Add remaining regions that weren't covered by the bounds | ||
(-180..179).each do |lon| | ||
(-90..89).each do |lat| | ||
unless @regions.key?([lat, lon]) | ||
add_region(lat, lon) | ||
end | ||
end | ||
end | ||
end | ||
|