Message boards : Number crunching : Country, state/province/region, city from lat, long
Author | Message |
---|---|
See http://stackoverflow.com/questions/4013606/google-maps-how-to-get-country-state-province-region-city-given-a-lat-long-va. | |
ID: 806 | Rating: 0 | rate: / Reply Quote | |
Here's a Python script to associate country, state and city info to detector IDs using the Google reverse geocoding service mentioned in the previous post. The script gets the detector ID numbers and lat/long coordinates in a crude way from the sample data provided in the "Raw data" thread. It would be better if the script had direct access to the database but I created the script to test and evaluate Google's reverse geocoding service and demo how it could work, not how it should work. The script stops short of moving the raw sample data into compressed country files but it does sort the existing detector IDs into country files. Moving the sample data itself is a trivial step. | |
ID: 821 | Rating: 0 | rate: / Reply Quote | |
I have the raw data sorting now into files by country, state and city. The directory tree is below. The country named "lost" is the directory for detectors that have no latitude and longitude. Each filename consists of the detector_ID (host_ID) followed by the latitude and longitude. Detectors that are not in a city are stored in a folder named for its state/province. There are 75 files therefore 75 detectors reporting data though 8 of those are "lost". I will make the script send a PM to the owners of detectors that do not have coordinates for more than 7 days, 1 PM only. Since I have their country info I can probably use that to guess which language they speak, get a translation of the message into their language from Google and send it to them.
hi_dat
├── canada
│ └── alberta
│ └── lethbridge
│ └── 1016_49.663364_-112.798454.txt
├── germany
│ ├── baden-wurttemberg
│ │ ├── neulingen
│ │ │ └── 497_48.968441_8.728466.txt
│ │ ├── reutlingen
│ │ │ └── 628_48.564335_9.231973.txt
│ │ ├── rheinfelden
│ │ │ └── 880_47.582821_7.805476.txt
│ │ ├── rosenfeld
│ │ │ └── 954_48.265369_8.693833.txt
│ │ └── sindelfingen
│ │ ├── 646_48.695747_9.015518.txt
│ │ └── 647_48.726219_9.067961.txt
│ ├── bayern
│ │ ├── emmering
│ │ │ └── 481_48.189411_11.280191.txt
│ │ ├── hemau
│ │ │ └── 480_49.055630_11.788689.txt
│ │ ├── maxhütte-haidhof
│ │ │ └── 1464_49.197693_12.090973.txt
│ │ └── schongau
│ │ └── 505_47.804909_10.886885.txt
│ ├── bremen
│ │ └── bremen
│ │ └── 91_53.064697_8.812038.txt
│ ├── hessen
│ │ ├── buseck
│ │ │ └── 990_50.630737_8.826141.txt
│ │ ├── darmstadt
│ │ │ └── 1182_49.882027_8.658943.txt
│ │ └── rüsselsheim
│ │ └── 881_49.994568_8.412435.txt
│ ├── mecklenburg-vorpommern
│ │ └── stavenhagen
│ │ └── 935_53.703400_12.910266.txt
│ ├── niedersachsen
│ │ ├── goslar
│ │ │ └── 478_51.916584_10.470486.txt
│ │ └── osnabrück
│ │ └── 859_52.255898_8.005659.txt
│ ├── nordrhein-westfalen
│ │ ├── lübbecke
│ │ │ └── 694_52.306618_8.625813.txt
│ │ └── rheinbach
│ │ └── 499_50.588699_6.897968.txt
│ └── sachsen-anhalt
│ ├── dessau-roßlau
│ │ └── 905_51.798672_12.245851.txt
│ └── kalbe
│ └── 1276_52.683613_11.422345.txt
├── ireland
│ └── county_limerick
│ └── limerick
│ ├── 1488_52.660892_-8.620791.txt
│ └── 930_52.662342_-8.619976.txt
├── japan
│ └── saitama_prefecture
│ └── yoshikawa
│ └── 374_35.871613_139.845444.txt
├── lost
│ ├── 1252_0.000000_0.000000.txt
│ ├── 1567_0.000000_0.000000.txt
│ ├── 1608_0.000000_0.000000.txt
│ ├── 1613_0.000000_0.000000.txt
│ ├── 1650_0.000000_0.000000.txt
│ ├── 1651_0.000000_0.000000.txt
│ ├── 1655_0.000000_0.000000.txt
│ └── 311_0.000000_0.000000.txt
├── poland
│ ├── dolnoslaskie
│ │ ├── gmina_jelcz-laskowice
│ │ │ └── 1478_51.075649_17.283297.txt
│ │ ├── kudowa-zdrój
│ │ │ └── 2_50.443192_16.256702.txt
│ │ ├── legnica
│ │ │ └── 645_51.226318_16.165159.txt
│ │ └── wroclaw
│ │ ├── 1658_51.091232_16.986752.txt
│ │ └── 470_51.074856_17.043335.txt
│ ├── kujawsko-pomorskie
│ │ └── ciechocinek
│ │ └── 650_52.874920_18.791599.txt
│ ├── lodzkie
│ │ └── brzeziny
│ │ ├── 506_51.802658_19.751944.txt
│ │ └── 6_51.803467_19.753675.txt
│ ├── lubelskie
│ │ ├── łubki-kolonia
│ │ │ └── 495_51.241779_22.299938.txt
│ │ └── lublin
│ │ └── 1649_51.233978_22.535191.txt
│ ├── malopolskie
│ │ ├── gmina_brzeszcze
│ │ │ └── 635_49.975899_19.129429.txt
│ │ ├── kęty
│ │ │ └── 1486_49.882607_19.207621.txt
│ │ └── krakow
│ │ └── 642_50.064583_19.919947.txt
│ ├── mazowieckie
│ │ ├── siedlce
│ │ │ └── 1391_52.175282_22.285666.txt
│ │ ├── strzała
│ │ │ └── 5_52.196087_22.290573.txt
│ │ └── warsaw
│ │ ├── 1602_52.150356_21.042059.txt
│ │ ├── 1657_52.220558_21.097420.txt
│ │ └── 634_52.272110_21.015102.txt
│ ├── opolskie
│ │ └── opole
│ │ └── 1408_50.682198_17.937155.txt
│ ├── podkarpackie
│ │ └── krasne
│ │ └── 1332_50.051186_22.086365.txt
│ ├── podlaskie
│ │ └── gmina_michałowo
│ │ └── 516_53.029148_23.607838.txt
│ ├── pomorskie
│ │ └── gdynia
│ │ ├── 1218_54.506954_18.546532.txt
│ │ ├── 755_54.505760_18.549086.txt
│ │ └── 798_54.506855_18.545845.txt
│ ├── śląskie
│ │ ├── czechowice-dziedzice
│ │ │ └── 51_49.919102_18.998129.txt
│ │ ├── czestochowa
│ │ │ └── 689_50.785103_19.145651.txt
│ │ └── tychy
│ │ └── 633_50.126183_18.977777.txt
│ ├── wielkopolskie
│ │ └── poznan
│ │ └── 584_52.393932_16.905457.txt
│ └── zachodniopomorskie
│ ├── kolobrzeg
│ │ ├── 1094_54.177757_15.577068.txt
│ │ └── 1584_54.175571_15.548658.txt
│ └── szczecin
│ ├── 200_53.461983_14.567497.txt
│ ├── 821_53.461933_14.567298.txt
│ └── 875_53.463108_14.577853.txt
├── spain
│ └── andalucía
│ └── granada
│ └── 663_37.206364_-3.619376.txt
├── ukraine
│ └── zhytomyrs'ka
│ └── berdychiv
│ └── 1503_49.877823_28.588829.txt
├── united_kingdom
│ └── england
│ ├── 324_51.405174_-0.512280.txt
│ ├── church_warsop
│ │ └── 1635_53.214565_-1.164980.txt
│ ├── shireoaks
│ │ └── 7_53.322926_-1.158328.txt
│ └── worksop
│ └── 619_53.305107_-1.135454.txt
├── united_states
│ ├── california
│ │ └── dublin
│ │ └── 1077_37.705959_-121.957085.txt
│ └── idaho
│ └── twin_falls
│ └── 1103_42.568031_-114.426903.txt
└── valid_ids.txt
93 directories, 75 files
____________ | |
ID: 833 | Rating: 0 | rate: / Reply Quote | |
I'll be implementing this on the server in the near future (not sure when yet, because there are lots of high priority things to do), however it has to be changed a bit. | |
ID: 834 | Rating: 0 | rate: / Reply Quote | |
I am aware that each data sample has its own coordinates and that those coordinates can change but since your detectors don't have GPS at this time the script assumes the coordinates in the last data sample are its current location and stores the samples accordingly. | |
ID: 843 | Rating: 0 | rate: / Reply Quote | |
Message boards :
Number crunching :
Country, state/province/region, city from lat, long