http://download.geonames.org/export/dump/countryInfo.txt?app=drupal currently returns the following fields

#ISO ISO3 ISO-Numeric fips Country Capital Area(in sq km) Population Continent tld CurrencyCode CurrencyName Phone Postal Code Format Postal Code Regex Languages geonameid neighbours EquivalentFipsCode

Which doesn't match our cache table, or the method that loads this table.

CommentFileSizeAuthor
#19 geonames_countryinfo.sql_.gz15.94 KBjmary
#10 geonames-countryinfo-schema.patch2.82 KBAnonymous (not verified)
#7 geonames-countryinfo-schema.patch3.04 KBAnonymous (not verified)

Comments

gagarine’s picture

http://drupal.org/node/353619 marked as duplicate.

I can perhaps work on this bug...

Some poeple have already know the best way to implement this?
What do you think, is a hard job? I can start this project in one month.

My first opinion is to have exactly the same field of geoname http://download.geonames.org/export/dump/readme.txt

The main 'geoname' table has the following fields :
---------------------------------------------------
geonameid         : integer id of record in geonames database
name              : name of geographical point (utf8) varchar(200)
asciiname         : name of geographical point in plain ascii characters, varchar(200)
alternatenames    : alternatenames, comma separated varchar(4000) (varchar(5000) for SQL Server)
latitude          : latitude in decimal degrees (wgs84)
longitude         : longitude in decimal degrees (wgs84)
feature class     : see http://www.geonames.org/export/codes.html, char(1)
feature code      : see http://www.geonames.org/export/codes.html, varchar(10)
country code      : ISO-3166 2-letter country code, 2 characters
cc2               : alternate country codes, comma separated, ISO-3166 2-letter country code, 60 characters
admin1 code       : fipscode (subject to change to iso code), isocode for the us and ch, see file admin1Codes.txt for display names of this code; varchar(20)
admin2 code       : code for the second administrative division, a county in the US, see file admin2Codes.txt; varchar(80) 
admin3 code       : code for third level administrative division, varchar(20)
admin4 code       : code for fourth level administrative division, varchar(20)
population        : integer 
elevation         : in meters, integer
gtopo30           : average elevation of 30'x30' (ca 900mx900m) area in meters, integer
timezone          : the timezone id (see file timeZone.txt)
modification date : date of last modification in yyyy-MM-dd format



The table 'alternate names' :
-----------------------------
alternateNameId   : the id of this alternate name, int
geonameid         : geonameId referring to id in table 'geoname', int
isolanguage       : iso 639 language code 2- or 3-characters; 4-characters 'post' for postal codes and 'iata' or 'icao' for airport codes, fr-1793 for French Revolution names, varchar(7)
alternate name    : alternate name or name variant, varchar(200)
isPreferredName   : '1', if this alternate name is an official/preferred name
isShortName       : '1', if this is a short name like 'California' for 'State of California'
lyricnz’s picture

Yes, of course we should have same format as the source data (but the issue above refers to the countryInfo format, while your posting is about the main geoname format).

gagarine’s picture

I have understand geoname use the same table for all geo data and one table for the alternate name. cityInfo is a dump with only the city but the structure is the same if you have city, place, country or anything else. The end of this page explain all thing about dump http://download.geonames.org/export/dump/

Correct me if I'm wrong...

lyricnz’s picture

Just open http://download.geonames.org/export/dump/countryInfo.txt in your browser, and look at the column names. These are not the same as the "main" geonames format.

gagarine’s picture

Thank, Ok I understand... sorry. So i work first on this bug. After that what do you think about caching city and at the best all tables?

Here how import all tables on MySQL: http://forum.geonames.org/gforum/posts/list/732.page

I don't found graphical schema for the geoname database :/.

I assign this bug to me after I'm sure I can done this job.

lyricnz’s picture

We've thought about this, of course. These are two facets to this;

- making it possible to load the data-dumps from geonames, and then query/search within this dataset (which will work very different to the existing web-services)

- using this data as a "local cache" for some parts of some queries.

Anonymous’s picture

StatusFileSize
new3.04 KB

This patch updates the schema and fixes the REPLACE statements.

Anonymous’s picture

Status: Active » Needs review
lyricnz’s picture

Status: Needs review » Needs work

Can you reroll, post code-style cleanups just committed?

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new2.82 KB

Sure thing! Thanks.

lyricnz’s picture

Status: Needs review » Fixed

Applied, thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

lyricnz’s picture

Assigned: Unassigned » 2xe
Status: Closed (fixed) » Needs work

hook_update_n required

jmary’s picture

Priority: Normal » Critical
lyricnz’s picture

jmary: why is this critical? just disable and uninstall the module, then reinstall it - and the table will be created correctly. The outstanding issue is just around the fact that the module doesn't update cleanly.

jmary’s picture

lyricnz : It is critical because the module just doesn't install correctly : the table geonames_countryinfo keeps empty.

lyricnz’s picture

Priority: Critical » Normal

jmary: did you actually _try this_? (using 6.x-1.x-dev)

It works fine. Here is a log of my session: I downloaded geonames into a default drupal6 site, unpacked and enabled it (which creates the table). I then downloaded countryInfo.txt straight from geonames.org, removed the leading comments, then use mysqlimport to load the file into the database table (checking number of records loaded against the number of lines in the file). I then queried the DB to verify that the data looked okay.

simonmac:~ simonroberts$ cd htdocs/drupal6/sites/all/modules/
simonmac:modules simonroberts$ curl http://ftp.drupal.org/files/projects/geonames-6.x-1.x-dev.tar.gz | tar xvz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 28407  100 28407    0     0  16070      0  0:00:01  0:00:01 --:--:-- 19496
geonames/
geonames/LICENSE.txt
geonames/CHANGELOG.txt
geonames/GeoNames_API.txt
geonames/README.txt
geonames/geonames.info
geonames/geonames.install
geonames/geonames.module
geonames/geonames_config.inc
geonames/geonames_search_API.txt
geonames/geonames_tools.info
geonames/geonames_tools.module
simonmac:modules simonroberts$ drush enable geonames
Initialized Drupal 6.13 root directory at /Users/simonroberts/htdocs/drupal6                                                                                                                                              Initialized Drupal site default at sites/default                                                                                                                                                                          The following modules will be enabled: geonames
Do you really want to continue? (y/n): y
GeoNames API was enabled successfully.                                                                                                                                                                                 Command dispatch complete                                                                                                                                                                                                 simonmac:modules simonroberts$ curl -O http://download.geonames.org/export/dump/countryInfo.txt 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 29667  100 29667    0     0  14904      0  0:00:01  0:00:01 --:--:-- 18681
simonmac:modules simonroberts$ grep -v '^#' countryInfo.txt > geonames_countryinfo.txt
simonmac:modules simonroberts$ mysqlimport -u drupal6 -p drupal6 -v $(pwd)/geonames_countryinfo.txt 
Enter password: 
Connecting to localhost
Selecting database drupal6
Loading data from SERVER file: /Users/simonroberts/htdocs/drupal6/sites/all/modules/geonames_countryinfo.txt into geonames_countryinfo
drupal6.geonames_countryinfo: Records: 247  Deleted: 0  Skipped: 0  Warnings: 405
Disconnecting from localhost
simonmac:modules simonroberts$ wc -l geonames_countryinfo.txt
     247 geonames_countryinfo.txt
simonmac:modules simonroberts$ drush sql query 'select iso_alpha2, name, geonameid from geonames_countryinfo limit 10'
iso_alpha2	name	geonameid
AD	Andorra	3041565
AE	United Arab Emirates	290557
AF	Afghanistan	1149361
AG	Antigua and Barbuda	3576396
AI	Anguilla	3573511
AL	Albania	783754
AM	Armenia	174982
AN	Netherlands Antilles	3513447
AO	Angola	3351879
AQ	Antarctica	6697173
simonmac:modules simonroberts$ 
jmary’s picture

I needed to copy geonames_countryinfo.txt in /tmp to ensure that the file was in a directory which is readable by the user the MySql server is running as.

Using mysqlimport is really what does the trick. And it is fault tolerant comparing to import through phpmyadmin.

Without doing that I was getting an error 13. I'm running a Debian server.

Some remarks.

- So this is a tricky to install the module as it should work out of the box also for peoples who are not having an ssh access to their server.
- also the monthly updates to this db should also not work as the invoking of geonames_metadata_update() will fail as well.
- this way to import the data is not documented (now it is, through this topic)
- the module gmaps which is having geonames as dependancy is broken because of that problem in geonames.
- the import using directly phpmyadmin doesn't work as well as it is answering that there is a wrong number of columns.

What can be done to save others :

1- Providing the table geonames_countryinfo in the module.
or
2- updating the structure of the table geonames_countryinfo and ensure that peoples who don't have shell access can still have benefit of the module.

I have urgent things to finish this week, after that I'll provide my support to help you in that as soon as you have defined which plan you want we work on : 1 or 2.

jmary’s picture

StatusFileSize
new15.94 KB

In attachement the table geonames_countryinfo

lyricnz’s picture

1) It is not possible to include the actual data from geonames with the module, as it is licensed under Creative Commons Attribution, which is incompatible with GPL, which Drupal+Contrib is released under.

2) The format of the table created by this module matches the current format of http://download.geonames.org/export/dump/countryInfo.txt - any problems with tools like phpMyAdmin etc are not the problem of the module, as such.

3) Likewise other contributed modules (you mention gmaps) aren't our responsibility. We updated the table structure to match geonames.org - they should use our API functions, or update their queries to match the new structure

4) Agree that geonames_metadata_update() is broken. It should be updated, along with a new hook_update_nn() to allow the module to be upgraded cleanly.

jmary’s picture

1- is crystal clear

2- I disagree (but not strongly) with that.
Many webmasters have only phpmyadmin to do such operations. And as the filling of the table at enabling module is broken this is leaving the module unusable and justifying the critical level of the bug.

3- Gmaps is definitely using the module API. The fact that geonames_countryinfo table is empty at enabling geonames prevents modules which are using correctly the geonames API to work.

4- It seems you persist to think that the module isn't broken at installing but only at updating. I wouldn't say so. As long as the table geonames_countryinfo is not filled at enabling the module and that is necessary to have shell access to proceed.

lyricnz’s picture

4. This module never claimed to fill in the geonames_countryinfo table at install time, and there is currently no code that would do that. However, if geonames_metadata_update() was working it would load this table on the first cron call (and every month thereafter). Arguably, there should be a more human-friendly way to trigger this refresh. Feel free to file that as a feature request.

lyricnz’s picture

Added hook_update support to 6.x-1.x-dev

lyricnz’s picture

Status: Needs work » Fixed

Updated geonames_metadata_update() to handle new columns, and use schema API. Committed to 6.x-1.x-dev.

jmary: If you want an easier way to refresh this metadata (than deleting the variable that keeps track of the interval, and re-executing cron), please don't hijack this issue - file a separate feature request.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.