Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow for settings to override GEONAMES_DUMPS_URL and GEONAMES_DATA #5

Open
wants to merge 39 commits into from

4 participants

@pix0r

Not sure if this is the appropriate way to override an app-specific setting.. I'd like to use your download_geonames but not keep my data in my virtualenv dir.

originell and others added some commits
@originell originell Added package_data for sql folder c55cf9e
@originell originell forgot file specimen f5aff05
@originell originell added download command. 5078644
@originell originell moved Alternate.Meta down a bit c36ef6f
@originell originell Added OSX zcat fix c801623
@originell originell mixed up (un)equalness - getting tired 9d3fb6d
@originell originell updated README 9e458a9
@originell originell fixed indents and spacing in README ed83849
@originell originell no comment d6682a9
@originell originell added the time it took me to load the db 2467489
Adam Coddington Set up Geonames using a geography field and a spatial index. 43abb2d
Adam Coddington Changing index type. 332256a
@EspadaV8 EspadaV8 Merge branch 'originell-master' 006cf05
@EspadaV8 EspadaV8 Merge branch 'latestrevision-master' 964d219
@EspadaV8 EspadaV8 Correctly compare the existing filesize and the remote file size. If …
…they match then correctly close existing file and also close the web file. Print a message to inform the user too.
36ffbff
@EspadaV8 EspadaV8 Change the download function so that it prints out the amount of the …
…file downloaded so far. Ideally this should be on a single line but \r just seems to delay output until all the file has downloaded.
01b96bb
@EspadaV8 EspadaV8 Updated the progress tracker so that it works on a single line now. T…
…he progress it printed, X backspace chars are printed and then flushed. Without this either the output would be buffered until the download was finished or new lines would appear from somewhere.
f0d159c
@EspadaV8 EspadaV8 After the download has finished print a new line so that things aren'…
…t so... compact.
fa34e44
@EspadaV8 EspadaV8 Add in the ability to download the postal code data as well as the ot…
…her files. Only the main 'allCountries' file is downloaded since it's only 8.8MB which should be small enough as it is. Also include an option to disable the postalcodes.
c70f120
@EspadaV8 EspadaV8 Add in a function to compress the postal code data file into a gzip f…
…ormat. All the data from the postal code dump is kept.
744ec09
@EspadaV8 EspadaV8 Created a model for the postal code table from Geonames. Includes all
the columns that are mentioned in
http://www.geonames.org/export/zip/readme.txt
675b394
@EspadaV8 EspadaV8 Create a way to import the postal code data into the GeoDjango database.
All fields should be imported from the original file.
6d818ee
@EspadaV8 EspadaV8 Add in a missing ';' from the end of the CREATE INDEX 948a88f
@EspadaV8 EspadaV8 Some of the postalcode data doen't include long/lat figures and/or ac…
…curacy figures. If the long or lat are missing then ignore the row. If accuracy is missing then assume that it's 0 (zero)
ff930d7
@EspadaV8 EspadaV8 We need to import the postal code data into the correct table, not th…
…e Alternate names table.
194fae4
@EspadaV8 EspadaV8 Rather than redefine the GEONAMES_DATA path in the load file, import …
…the values from the compress file like the download command does.
20f71b3
@jezdez jezdez Use `gunzip -c` for uncompressing the alternateNames.gz file instead …
…of zcat which doesn't work in POSIX mode correctly (appending a .Z to the filename by default).
0e79345
@jezdez jezdez Merge remote-tracking branch 'EspadaV8/master'
Conflicts:
	geonames/management/commands/load_geonames.py
	setup.py
e55233d
@jezdez jezdez Nitpicking a few things (PEP8 and general code cleanup).
Removed the custom BigIntegerField since Django >= 1.2 has its own.
654490f
@pix0r pix0r Allow for settings to override GEONAMES_DUMPS_URL and GEONAMES_DATA 297a252
@pix0r pix0r Store PGPASSWORD in environment before running psql commands db7dbce
@pix0r pix0r Ignore *.pyc fb413ed
@jezdez jezdez Added cities convenience method and ordered Geonames by name and coun…
…try.
05198a1
@jezdez jezdez Extended admin interface of Geonames. fcad785
@jezdez jezdez Added initial migration. be3c2f4
@jezdez jezdez Disabled local names of geonames. a130fd0
@pix0r pix0r Merge remote-tracking branch 'jezdez/master'
Conflicts:
	.gitignore
	geonames/management/commands/compress_geonames.py
	geonames/management/commands/download_geonames.py
	geonames/management/commands/load_geonames.py
0fc1a43
Dan Fairs Add missing import 31bb17d
@pix0r pix0r Merge pull request #1 from danfairs/master
Missing import
2205fb7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 6, 2011
  1. @originell
  2. @originell

    forgot file specimen

    originell authored
  3. @originell

    added download command.

    originell authored
  4. @originell
  5. @originell

    Added OSX zcat fix

    originell authored
  6. @originell
  7. @originell

    updated README

    originell authored
  8. @originell
  9. @originell

    no comment

    originell authored
Commits on May 7, 2011
  1. @originell
Commits on Jul 28, 2011
  1. Set up Geonames using a geography field and a spatial index.

    Adam Coddington authored
Commits on Nov 2, 2011
  1. Changing index type.

    Adam Coddington authored
Commits on Nov 7, 2011
  1. @EspadaV8
  2. @EspadaV8
Commits on Nov 15, 2011
  1. @EspadaV8

    Correctly compare the existing filesize and the remote file size. If …

    EspadaV8 authored
    …they match then correctly close existing file and also close the web file. Print a message to inform the user too.
  2. @EspadaV8

    Change the download function so that it prints out the amount of the …

    EspadaV8 authored
    …file downloaded so far. Ideally this should be on a single line but \r just seems to delay output until all the file has downloaded.
  3. @EspadaV8

    Updated the progress tracker so that it works on a single line now. T…

    EspadaV8 authored
    …he progress it printed, X backspace chars are printed and then flushed. Without this either the output would be buffered until the download was finished or new lines would appear from somewhere.
  4. @EspadaV8
  5. @EspadaV8

    Add in the ability to download the postal code data as well as the ot…

    EspadaV8 authored
    …her files. Only the main 'allCountries' file is downloaded since it's only 8.8MB which should be small enough as it is. Also include an option to disable the postalcodes.
  6. @EspadaV8

    Add in a function to compress the postal code data file into a gzip f…

    EspadaV8 authored
    …ormat. All the data from the postal code dump is kept.
  7. @EspadaV8
  8. @EspadaV8

    Create a way to import the postal code data into the GeoDjango database.

    EspadaV8 authored
    All fields should be imported from the original file.
Commits on Nov 16, 2011
  1. @EspadaV8
  2. @EspadaV8

    Some of the postalcode data doen't include long/lat figures and/or ac…

    EspadaV8 authored
    …curacy figures. If the long or lat are missing then ignore the row. If accuracy is missing then assume that it's 0 (zero)
  3. @EspadaV8
  4. @EspadaV8

    Rather than redefine the GEONAMES_DATA path in the load file, import …

    EspadaV8 authored
    …the values from the compress file like the download command does.
Commits on Jan 27, 2012
  1. @jezdez

    Use `gunzip -c` for uncompressing the alternateNames.gz file instead …

    jezdez authored
    …of zcat which doesn't work in POSIX mode correctly (appending a .Z to the filename by default).
  2. @jezdez

    Merge remote-tracking branch 'EspadaV8/master'

    jezdez authored
    Conflicts:
    	geonames/management/commands/load_geonames.py
    	setup.py
  3. @jezdez

    Nitpicking a few things (PEP8 and general code cleanup).

    jezdez authored
    Removed the custom BigIntegerField since Django >= 1.2 has its own.
Commits on Mar 20, 2012
  1. @pix0r
  2. @pix0r
  3. @pix0r

    Ignore *.pyc

    pix0r authored
Commits on May 3, 2012
  1. @jezdez
  2. @jezdez
  3. @jezdez

    Added initial migration.

    jezdez authored
  4. @jezdez
Commits on May 7, 2012
  1. @pix0r

    Merge remote-tracking branch 'jezdez/master'

    pix0r authored
    Conflicts:
    	.gitignore
    	geonames/management/commands/compress_geonames.py
    	geonames/management/commands/download_geonames.py
    	geonames/management/commands/load_geonames.py
Commits on Jun 12, 2012
  1. Add missing import

    Dan Fairs authored
Commits on Jun 14, 2012
  1. @pix0r

    Merge pull request #1 from danfairs/master

    pix0r authored
    Missing import
This page is out of date. Refresh to see the latest.
View
4 .gitignore
@@ -1 +1,5 @@
+build/
+dist/
geonames/data
+*.pyc
+*.egg-info
View
12 DOWNLOAD
@@ -1,12 +0,0 @@
-Geonames data may be downloaded from:
-
- http://download.geonames.org/export/dump/
-
-The management commands are written assuming that the following data
-files are downloaded:
-
- allCountries.zip
- alternateNames.zip
-
-Other data files, as they are supported, should also be placed in
-here.
View
2  MANIFEST.in
@@ -0,0 +1,2 @@
+include README.md
+recursive-include geonames/sql *.sql
View
8 README
@@ -1,8 +0,0 @@
-This is an experimental application for using Geonames data within
-GeoDjango. To get started download the necessary data (read
-`DOWNLOAD` in `data` subdirectory), add `geonames` to your
-`INSTALLED_APPS`, and run the following management commands.
-These commands will take a while to run.
-
- $ ./manage.py compress_geonames
- $ ./manage.py load_geonames
View
44 README.md
@@ -0,0 +1,44 @@
+===============
+django-geonames
+===============
+
+This is an experimental application for using Geonames data within
+GeoDjango.
+
+Furthermore this is a fork of
+[ramusus django-geonames](https://github.com/lazerscience/django-geonames),
+containing some (osx specific) fixes:
+
+* setup.py includes geonames/sql/* as package_data
+* load_geonames checks to see if its run on OSX <= 10.6.7,
+ because `zcat` has a bug there, so we use `gzcat` instead.
+ Hopefully this gets fixed with 10.7
+
+I also encounter some weird error: `syncdb` wouldnt create the tables
+specified by `geonames/models.py`. I didnt find the reason why this
+happens. However heres a workaround in case you encounter this too:
+
+* add `geonames` to your `INSTALLED_APPS` (as you would anyway)
+* now do `python manage.py sqlall geonames` and copy the sql from the output
+* run `python manage.py dbshell`, paste the copied sql and execute it
+* now that we have our tables created, you can follow the installation
+ instructions
+
+Installation
+============
+
+Note that running all this can take some serious time. The database is
+pretty huge (~200mb WITHOUT alternateNames, which itself weights in
+at ~94mb). So you might want to do `load_geonames` over night, it did
+take my macbook 18h28min to complete with a default 5200rpm drive,
+you might find it a hell lot faster with a 7200rpm drive or some
+SSD.
+
+1. Add `geonames` to your `INSTALLED_APPS`
+2. `python manage.py syncdb` so it creates the tables
+3. `python manage.py download_geonames` will download all the data
+ you might need (and more)
+4. `python manage.py compress_geonames` -- This will gzip the downloaded
+ data, to minimize disk I/O during sql read.
+5. `python manage.py load_geonames` -- Load the data.
+6. Hours later: have fun ;-)
View
43 geonames/admin.py
@@ -1,7 +1,44 @@
from django.contrib.gis import admin
-from models import Geoname
-class GeonameAdmin(admin.OSMGeoAdmin):
+from geonames.models import Geoname, Alternate
+
+from django.utils.translation import ugettext_lazy as _
+from django.contrib.admin import SimpleListFilter
+
+
+class CityListFilter(SimpleListFilter):
+ # Human-readable title which will be displayed in the
+ # right admin sidebar just above the filter options.
+ title = _('is topographically')
+ # Parameter for the filter that will be used in the URL query.
+ parameter_name = 'topo'
+
+ def lookups(self, request, model_admin):
+ return (
+ ('city', _('city or town')),
+ ('country', _('country')),
+ ('continent', _('continent')),
+ )
+
+ def queryset(self, request, queryset):
+ selected = self.value()
+ if selected == 'city':
+ queryset = queryset.filter(fcode='PPL')
+ elif selected == 'country':
+ queryset = queryset.filter(fcode='PCLI')
+ elif selected == 'continent':
+ queryset = queryset.filter(fcode='CONT')
+ return queryset
+
+
+class AlternateInline(admin.TabularInline):
+ model = Alternate
+
+
+class GeonameAdmin(admin.GeoModelAdmin):
search_fields = ('name',)
-
+ list_display = ('name', 'country', 'timezone')
+ list_filter = (CityListFilter, 'country', 'timezone')
+ inlines = (AlternateInline,)
+
admin.site.register(Geoname, GeonameAdmin)
View
22 geonames/load.py
@@ -1,11 +1,12 @@
-import bz2, gzip, os, zipfile
-from datetime import datetime
+import os
from django.db import transaction
-from models import Admin1Code, Admin2Code, TimeZone, Geoname, Alternate
+from geonames.models import Admin1Code, Admin2Code, TimeZone
+
+GEONAMES_DATA = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), 'data'))
-GEONAMES_DATA = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data'))
def txt_lengths(txt_file):
fh = open(os.path.join(GEONAMES_DATA, txt_file))
@@ -18,15 +19,17 @@ def txt_lengths(txt_file):
lengths[i] = [n]
else:
lengths[i].append(n)
-
+
cols = lengths.keys()
cols.sort()
for col in cols:
print '%d: %d' % (col, max(lengths[col]))
+
def clean(sarr):
return [s.strip().decode('utf8') for s in sarr]
+
@transaction.commit_on_success
def run():
# Loading the Admin1Code models
@@ -35,7 +38,7 @@ def run():
for line in fh:
splits = line.split('\t')
kwargs = dict(zip(fields, clean(splits)))
- admin1 = Admin1Code.objects.create(**kwargs)
+ Admin1Code.objects.create(**kwargs)
# Loading the Admin2Code models
fh = open(os.path.join(GEONAMES_DATA, 'admin2Codes.txt'))
@@ -43,8 +46,9 @@ def run():
for line in fh:
splits = line.split('\t')
kwargs = dict(zip(fields, clean(splits)))
- for key in ('ascii', 'geonameid'): kwargs.pop(key)
- admin2 = Admin2Code.objects.create(**kwargs)
+ for key in ('ascii', 'geonameid'):
+ kwargs.pop(key)
+ Admin2Code.objects.create(**kwargs)
# Loading the TimeZone models.
fh = open(os.path.join(GEONAMES_DATA, 'timeZones.txt'))
@@ -53,4 +57,4 @@ def run():
for line in fh:
splits = line.split('\t')
kwargs = dict(zip(fields, clean(splits)))
- tz = TimeZone.objects.create(**kwargs)
+ TimeZone.objects.create(**kwargs)
View
99 geonames/management/commands/compress_geonames.py
@@ -1,13 +1,25 @@
-import datetime, gzip, os, sys, zipfile
+import datetime
+import gzip
+import os
+import sys
+import zipfile
from optparse import make_option
from django.core.management.base import NoArgsCommand
+from django.conf import settings
from geonames import models
-GEONAMES_DATA = os.path.abspath(os.path.join(os.path.dirname(models.__file__), 'data'))
+
+GEONAMES_DATA = getattr(settings,
+ 'GEONAMES_DATA',
+ os.path.abspath(os.path.join(os.path.dirname(models.__file__), 'data'))
+ )
+GEONAMES_DATA_PC = getattr(settings,
+ 'GEONAMES_DATA_PC',
+ os.path.join(GEONAMES_DATA, 'pc'),
+ )
class Command(NoArgsCommand):
-
option_list = NoArgsCommand.option_list + (
make_option('-t', '--time', action='store_true', dest='time', default=False,
help='Print the total time in running this command'),
@@ -17,8 +29,9 @@ class Command(NoArgsCommand):
help='Do not perform compression on allCountries.zip'),
make_option('--no-alternates', action='store_true', dest='no_alternates', default=False,
help='Do not perform compression on alternateNames.zip'),
- )
-
+ make_option('--no-postalcodes', action='store_true', dest='no_postalcodes', default=False,
+ help='Do not perform compression on postalcodes allCountries.zip'),
+ )
clear_line = chr(27) + '[2K' + chr(27) +'[G'
def allCountries(self, **options):
@@ -26,13 +39,14 @@ def allCountries(self, **options):
gzf = gzip.GzipFile(os.path.join(GEONAMES_DATA, 'allCountries.gz'), 'w')
in_fields = ['geonameid', 'name', 'asciiname', 'alternates', 'latitude', 'longitude',
- 'fclass', 'fcode', 'country_code', 'cc2',
+ 'fclass', 'fcode', 'country_code', 'cc2',
'admin1', 'admin2', 'admin3', 'admin4',
'population', 'elevation', 'topo', 'timezone', 'mod_date']
out_fields = [f for f in in_fields if not f in ('latitude', 'longitude', 'asciiname')]
len_fields = ['name', 'asciiname', 'alternates', 'fclass', 'fcode', 'country_code',
'cc2', 'admin1', 'admin2', 'admin3', 'admin4', 'timezone']
- if options['lengths']: lengths = dict([(f, 0) for f in len_fields])
+ if options['lengths']:
+ lengths = dict([(f, 0) for f in len_fields])
contents = zf.read('allCountries.txt').split('\n')
num_lines = len(contents)
@@ -40,20 +54,22 @@ def allCountries(self, **options):
if line:
row = dict(zip(in_fields, map(str.strip, line.split('\t'))))
if options['lengths']:
- for k in len_fields: lengths[k] = max(len(row[k]), lengths[k])
-
+ for k in len_fields:
+ lengths[k] = max(len(row[k]), lengths[k])
+
# fixing trailing slash problem in geonames data
try:
if row['name'][-1:] == "\\":
row['name'] = row['name'][0:-1]
except:
pass
-
+
try:
# Setting integers to 0 so they won't have to be NULL.
for key in ('population', 'elevation', 'topo'):
- if not row[key]: row[key] = '0'
-
+ if not row[key]:
+ row[key] = '0'
+
# Getting the EWKT for the point -- has to be EWKT or else
# the insertion of the point will raise a constraint error for
# for a non-matching ID.
@@ -68,7 +84,8 @@ def allCountries(self, **options):
if i % 10000 == 0:
sys.stdout.write(self.clear_line)
- sys.stdout.write('Compressing allCountries.txt: %.2f%% (%d/%d)' % ( (100. * i) / num_lines, i, num_lines))
+ sys.stdout.write('Compressing allCountries.txt: %.2f%% (%d/%d)' %
+ ((100. * i) / num_lines, i, num_lines))
sys.stdout.flush()
gzf.close()
@@ -87,7 +104,8 @@ def alternateNames(self, **options):
bool_fields = ['preferred', 'short']
len_fields = ['isolanguage', 'variant']
out_fields = in_fields
- if options['lengths']: lengths = dict([(f, 0) for f in len_fields])
+ if options['lengths']:
+ lengths = dict([(f, 0) for f in len_fields])
contents = zf.read('alternateNames.txt').split('\n')
num_lines = len(contents)
@@ -100,14 +118,16 @@ def alternateNames(self, **options):
else:
row[bool_field] = '0'
if options['lengths']:
- for k in len_fields: lengths[k] = max(len(row[k]), lengths[k])
+ for k in len_fields:
+ lengths[k] = max(len(row[k]), lengths[k])
new_line = '\t'.join([row[k] for k in out_fields])
new_line += '\n'
gzf.write(new_line)
if i % 10000 == 0:
sys.stdout.write(self.clear_line)
- sys.stdout.write('Compressing alternateNames.txt: %.2f%% (%d/%d)' % ( (100. * i) / num_lines, i, num_lines))
+ sys.stdout.write('Compressing alternateNames.txt: %.2f%% (%d/%d)' %
+ ((100. * i) / num_lines, i, num_lines))
sys.stdout.flush()
gzf.close()
@@ -118,6 +138,48 @@ def alternateNames(self, **options):
for fld in len_fields:
sys.stdout.write('%s:\t%d\n' % (fld, lengths[fld]))
+ def postalCodes(self, **options):
+ zf = zipfile.ZipFile(os.path.join(GEONAMES_DATA_PC, 'allCountries.zip'))
+ gzf = gzip.GzipFile(os.path.join(GEONAMES_DATA_PC, 'allCountries.gz'), 'w')
+
+ in_fields = ['countrycode', 'postalcode', 'placename', 'admin1name', 'admin1code', 'admin2name', 'admin2code', 'admin3name', 'admin3code', 'latitude', 'longitude', 'accuracy']
+ len_fields = ['countrycode', 'postalcode', 'placename', 'admin1name', 'admin1code', 'admin2name', 'admin2code', 'admin3name', 'admin3code']
+ out_fields = in_fields
+ if options['lengths']:
+ lengths = dict([(f, 0) for f in len_fields])
+
+ contents = zf.read('allCountries.txt').split('\n')
+ num_lines = len(contents)
+ for i, line in enumerate(contents):
+ if line:
+ row = dict(zip(in_fields, map(str.strip, line.split('\t'))))
+ if options['lengths']:
+ for k in len_fields:
+ lengths[k] = max(len(row[k]), lengths[k])
+
+ if row['latitude'] == '' or row['longitude'] == '':
+ continue
+
+ if row['accuracy'] == '':
+ row['accuracy'] = '0'
+
+ new_line = '\t'.join([row[k] for k in out_fields])
+ new_line += '\n'
+ gzf.write(new_line)
+
+ if i % 10000 == 0:
+ sys.stdout.write(self.clear_line)
+ sys.stdout.write('Compressing allCountries.txt: %.2f%% (%d/%d)' %
+ ((100. * i) / num_lines, i, num_lines))
+ sys.stdout.flush()
+
+ gzf.close()
+
+ sys.stdout.write('\n')
+
+ if options['lengths']:
+ for fld in len_fields:
+ sys.stdout.write('%s:\t%d\n' % (fld, lengths[fld]))
def handle_noargs(self, **options):
if options['time']:
@@ -129,5 +191,8 @@ def handle_noargs(self, **options):
if not options['no_alternates']:
self.alternateNames(**options)
- if options['time']:
+ if not options['no_postalcodes']:
+ self.postalCodes(**options)
+
+ if options['time']:
sys.stdout.write('\nCompleted in %s\n' % (datetime.datetime.now() - start_time))
View
72 geonames/management/commands/download_geonames.py
@@ -1,15 +1,25 @@
-from optparse import make_option
-import datetime, os, sys
-import urllib, urllib2, urlparse
+import datetime
+import os
import re
+import sys
+import urllib
+import urllib2
+import urlparse
+from optparse import make_option
-from django.db import connection, models
-from django.core.management import call_command, sql, color
-from django.core.management.base import NoArgsCommand
from django.conf import settings
-from compress_geonames import GEONAMES_DATA
+from django.core.management.base import NoArgsCommand
-GEONAMES_DUMPS_URL = 'http://download.geonames.org/export/dump/'
+from .compress_geonames import GEONAMES_DATA, GEONAMES_DATA_PC
+
+GEONAMES_DUMPS_URL = getattr(settings,
+ 'GEONAMES_DUMPS_URL',
+ 'http://download.geonames.org/export/dump/',
+ )
+GEONAMES_PC_DUMPS_URL = getattr(settings,
+ 'GEONAMES_PC_DUMPS_URL',
+ 'http://download.geonames.org/export/zip/',
+ )
def download(url, filepath=False):
"""
@@ -25,19 +35,38 @@ def download(url, filepath=False):
# check size of files
web_file_size = web_file.info().getheaders("Content-Length")[0]
+ web_file_size = int(web_file_size)
if os.path.isfile(filepath):
existing_file = open(filepath, "r")
existing_file_size = len(existing_file.read())
print existing_file_size, web_file_size
if existing_file_size == web_file_size:
- existing_file_size.close()
+ existing_file.close()
+ web_file.close()
+ print 'Skiping. File sizes match.'
return
local_file = open(filepath, 'w')
- local_file.write(web_file.read())
+ readSize = 102400
+ bytesRead = 0
+ while True:
+ read = web_file.read(readSize)
+ bytesRead += len(read)
+ if not read:
+ break
+
+ local_file.write(read)
+
+ progress = 'Downloaded %s of %s' % (bytesRead, web_file_size)
+ sys.stdout.write(progress)
+ sys.stdout.write('\b' * len(progress))
+ sys.stdout.flush()
+
+ sys.stdout.write('\n')
web_file.close()
local_file.close()
+
class Command(NoArgsCommand):
help = 'Download all data files from geonames to data dir.'
@@ -50,7 +79,9 @@ class Command(NoArgsCommand):
help='Disable loading of the Geonames alternate names data.'),
make_option('--no-geonames', action='store_true', dest='no_geonames', default=False,
help='Disable loading of the Geonames data.'),
- )
+ make_option('--no-postalcodes', action='store_true', dest='no_postalcodes', default=False,
+ help='Disable loading of the postal codes data.'),
+ )
def handle_noargs(self, **options):
if options['time']:
@@ -67,7 +98,22 @@ def handle_noargs(self, **options):
continue
print '\nStart download "%s" file' % file
- download(urlparse.urljoin(GEONAMES_DUMPS_URL, file), os.path.join(GEONAMES_DATA, file))
+ download(urlparse.urljoin(GEONAMES_DUMPS_URL, file),
+ os.path.join(GEONAMES_DATA, file))
+
+ if options['no_postalcodes'] == False:
+ print '\nLooking for postalcode data to download'
+ req = urllib2.Request(url=GEONAMES_PC_DUMPS_URL)
+ postalcodeResponse = urllib2.urlopen(req)
+ postalcodeFiles = re.findall(r'\<a href="(.+\.(?:txt|zip))"\>',
+ postalcodeResponse.read())
+ for file in postalcodeFiles:
+ if file != 'allCountries.zip':
+ continue
+
+ print '\nStart download "%s" file' % file
+ download(urlparse.urljoin(GEONAMES_PC_DUMPS_URL, file),
+ os.path.join(GEONAMES_DATA_PC, file))
if options['time']:
- print '\nCompleted in %s' % (datetime.datetime.now() - start_time)
+ print '\nCompleted in %s' % (datetime.datetime.now() - start_time)
View
92 geonames/management/commands/load_geonames.py
@@ -1,16 +1,20 @@
-import datetime, os, sys
+import datetime
+import os
from optparse import make_option
-from django.db import connection, models
-from django.core.management import call_command, sql, color
+from django.core.management import call_command
from django.core.management.base import NoArgsCommand
from django.conf import settings
+from compress_geonames import GEONAMES_DATA, GEONAMES_DATA_PC
from geonames import models as m
+
Alternate = m.Alternate
Geoname = m.Geoname
-GEONAMES_DATA = os.path.abspath(os.path.join(os.path.dirname(m.__file__), 'data'))
-GEONAMES_SQL = os.path.abspath(os.path.join(os.path.dirname(m.__file__), 'sql'))
+PostalCode = m.PostalCode
+
+GEONAMES_SQL = os.path.abspath(
+ os.path.join(os.path.dirname(m.__file__), 'sql'))
def get_cmd_options():
"Obtains the command-line PostgreSQL connection options for shell commands."
@@ -25,10 +29,13 @@ def get_cmd_options():
options += '-h %s ' % db_settings['HOST']
if db_settings['PORT']:
options += '-p %s ' % db_settings['PORT']
+ if db_settings['PASSWORD']:
+ os.environ['PGPASSWORD'] = db_settings['PASSWORD']
+
return options
-class Command(NoArgsCommand):
+class Command(NoArgsCommand):
option_list = NoArgsCommand.option_list + (
make_option('-t', '--time', action='store_true', dest='time', default=False,
help='Print the total time in running this command'),
@@ -36,10 +43,13 @@ class Command(NoArgsCommand):
help='Disable loading of the Geonames alternate names data.'),
make_option('--no-geonames', action='store_true', dest='no_geonames', default=False,
help='Disable loading of the Geonames data.'),
- )
+ make_option('--no-postalcodes', action='store_true', dest='no_postalcodes', default=False,
+ help='Disable loading of the postal code data.'),
+ )
def handle_noargs(self, **options):
- if options['time']: start_time = datetime.datetime.now()
+ if options['time']:
+ start_time = datetime.datetime.now()
# Making sure the db tables exist.
call_command('syncdb')
@@ -48,8 +58,9 @@ def handle_noargs(self, **options):
db_opts = get_cmd_options()
fromfile_cmd = 'psql %(db_opts)s -f %(sql_file)s'
- fromfile_args = {'db_opts' : db_opts,
- }
+ fromfile_args = {
+ 'db_opts': db_opts,
+ }
### COPY'ing into the Geonames table ###
@@ -60,10 +71,11 @@ def handle_noargs(self, **options):
# reduces disk I/O.
copy_sql = "COPY %s (geonameid,name,alternates,fclass,fcode,country,cc2,admin1,admin2,admin3,admin4,population,elevation,topo,timezone,moddate,point) FROM STDIN;" % db_table
copy_cmd = 'gunzip -c %(gz_file)s | psql %(db_opts)s -c "%(copy_sql)s"'
- copy_args = {'gz_file' : os.path.join(GEONAMES_DATA, 'allCountries.gz'),
- 'db_opts' : db_opts,
- 'copy_sql' : copy_sql
- }
+ copy_args = {
+ 'gz_file': os.path.join(GEONAMES_DATA, 'allCountries.gz'),
+ 'db_opts': db_opts,
+ 'copy_sql': copy_sql,
+ }
# Printing the copy command and executing it.
if not options['no_geonames']:
@@ -81,11 +93,12 @@ def handle_noargs(self, **options):
db_table = Alternate._meta.db_table
copy_sql = "COPY %s (alternateid,geoname_id,isolanguage,variant,preferred,short) FROM STDIN;" % db_table
- copy_cmd = 'zcat %(gz_file)s | psql %(db_opts)s -c "%(copy_sql)s"'
- copy_args = {'gz_file' : os.path.join(GEONAMES_DATA, 'alternateNames.gz'),
- 'db_opts' : get_cmd_options(),
- 'copy_sql' : copy_sql
- }
+ copy_cmd = 'gunzip -c %(gz_file)s | psql %(db_opts)s -c "%(copy_sql)s"'
+ copy_args = {
+ 'gz_file': os.path.join(GEONAMES_DATA, 'alternateNames.gz'),
+ 'db_opts': get_cmd_options(),
+ 'copy_sql': copy_sql,
+ }
if not options['no_alternates']:
fromfile_args['sql_file'] = os.path.join(GEONAMES_SQL, 'drop_alternate_indexes.sql')
@@ -98,5 +111,44 @@ def handle_noargs(self, **options):
print(fromfile_cmd % fromfile_args)
os.system(fromfile_cmd % fromfile_args)
+ # cursor = connection.cursor()
+ # list_sql = []
+ # insert_sql = []
+ # for language in settings.LANGUAGES:
+ # insert_sql.append('name_%s' % language[0])
+ # for language in settings.LANGUAGES:
+ # list_sql.append("(SELECT variant FROM geonames_alternate "
+ # "WHERE geoname_id=geonameid AND isolanguage='%s' "
+ # "ORDER BY preferred DESC LIMIT 1) AS name_%s" %
+ # (language[0], language[0]))
+ # denorm_sql = (
+ # "INSERT INTO geonames_localname (geoname_id, %s) "
+ # "SELECT geonameid, %s FROM geonames_geoname" %
+ # (", ".join(insert_sql), ", ".join(list_sql)))
+ # cursor.execute(denorm_sql)
+
+
+ ### COPY'ing into the Geonames alternate table ###
+ db_table = PostalCode._meta.db_table
+ copy_sql = "COPY %s (countrycode, postalcode, placename, admin1name, admin1code, admin2name, admin2code, admin3name, admin3code, latitude, longitude, accuracy) FROM STDIN;" % db_table
+ copy_cmd = 'gunzip -c %(gz_file)s | psql %(db_opts)s -c "%(copy_sql)s"'
+ copy_args = {
+ 'gz_file': os.path.join(GEONAMES_DATA_PC, 'allCountries.gz'),
+ 'db_opts': get_cmd_options(),
+ 'copy_sql': copy_sql,
+ }
+
+ if not options['no_postalcodes']:
+ fromfile_args['sql_file'] = os.path.join(GEONAMES_SQL, 'drop_postalcode_indexes.sql')
+ print(fromfile_cmd % fromfile_args)
+ os.system(fromfile_cmd % fromfile_args)
+ print(copy_cmd % copy_args)
+ os.system(copy_cmd % copy_args)
+ print('Finished PostgreSQL `COPY` from Geonames postal code data file.')
+ fromfile_args['sql_file'] = os.path.join(GEONAMES_SQL, 'create_postalcode_indexes.sql')
+ print(fromfile_cmd % fromfile_args)
+ os.system(fromfile_cmd % fromfile_args)
+
# Done
- if options['time']: print('\nCompleted in %s' % (datetime.datetime.now() - start_time))
+ if options['time']:
+ print('\nCompleted in %s' % (datetime.datetime.now() - start_time))
View
173 geonames/migrations/0001_initial.py
@@ -0,0 +1,173 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'Admin1Code'
+ db.create_table('geonames_admin1code', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('code', self.gf('django.db.models.fields.CharField')(max_length=6)),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=58)),
+ ))
+ db.send_create_signal('geonames', ['Admin1Code'])
+
+ # Adding model 'Admin2Code'
+ db.create_table('geonames_admin2code', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('code', self.gf('django.db.models.fields.CharField')(max_length=32)),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=46)),
+ ))
+ db.send_create_signal('geonames', ['Admin2Code'])
+
+ # Adding model 'TimeZone'
+ db.create_table('geonames_timezone', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('tzid', self.gf('django.db.models.fields.CharField')(max_length=30)),
+ ('gmt_offset', self.gf('django.db.models.fields.FloatField')()),
+ ('dst_offset', self.gf('django.db.models.fields.FloatField')()),
+ ))
+ db.send_create_signal('geonames', ['TimeZone'])
+
+ # Adding model 'Geoname'
+ db.create_table('geonames_geoname', (
+ ('geonameid', self.gf('django.db.models.fields.PositiveIntegerField')(unique=True, primary_key=True)),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=200, db_index=True)),
+ ('alternates', self.gf('django.db.models.fields.TextField')(blank=True)),
+ ('fclass', self.gf('django.db.models.fields.CharField')(max_length=1, db_index=True)),
+ ('fcode', self.gf('django.db.models.fields.CharField')(max_length=10, db_index=True)),
+ ('country', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=2, blank=True)),
+ ('cc2', self.gf('django.db.models.fields.CharField')(max_length=60, blank=True)),
+ ('admin1', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=20, blank=True)),
+ ('admin2', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=80, blank=True)),
+ ('admin3', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=20, blank=True)),
+ ('admin4', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=20, blank=True)),
+ ('population', self.gf('django.db.models.fields.BigIntegerField')(db_index=True)),
+ ('elevation', self.gf('django.db.models.fields.IntegerField')(db_index=True)),
+ ('topo', self.gf('django.db.models.fields.IntegerField')(db_index=True)),
+ ('timezone', self.gf('django.db.models.fields.CharField')(max_length=30, blank=True)),
+ ('moddate', self.gf('django.db.models.fields.DateField')()),
+ ('point', self.gf('django.contrib.gis.db.models.fields.PointField')(null=True, geography=True)),
+ ))
+ db.send_create_signal('geonames', ['Geoname'])
+
+ # Adding model 'Alternate'
+ db.create_table('geonames_alternate', (
+ ('alternateid', self.gf('django.db.models.fields.PositiveIntegerField')(unique=True, primary_key=True)),
+ ('geoname', self.gf('django.db.models.fields.related.ForeignKey')(related_name='alternate_names', to=orm['geonames.Geoname'])),
+ ('isolanguage', self.gf('django.db.models.fields.CharField')(max_length=7)),
+ ('variant', self.gf('django.db.models.fields.CharField')(max_length=200, db_index=True)),
+ ('preferred', self.gf('django.db.models.fields.BooleanField')(default=False, db_index=True)),
+ ('short', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ))
+ db.send_create_signal('geonames', ['Alternate'])
+
+ # Adding model 'PostalCode'
+ db.create_table('geonames_postalcode', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('countrycode', self.gf('django.db.models.fields.CharField')(max_length=2)),
+ ('postalcode', self.gf('django.db.models.fields.CharField')(max_length=20)),
+ ('placename', self.gf('django.db.models.fields.CharField')(max_length=180)),
+ ('admin1name', self.gf('django.db.models.fields.CharField')(max_length=100)),
+ ('admin1code', self.gf('django.db.models.fields.CharField')(max_length=20)),
+ ('admin2name', self.gf('django.db.models.fields.CharField')(max_length=100)),
+ ('admin2code', self.gf('django.db.models.fields.CharField')(max_length=20)),
+ ('admin3name', self.gf('django.db.models.fields.CharField')(max_length=100)),
+ ('admin3code', self.gf('django.db.models.fields.CharField')(max_length=20)),
+ ('latitude', self.gf('django.db.models.fields.FloatField')()),
+ ('longitude', self.gf('django.db.models.fields.FloatField')()),
+ ('accuracy', self.gf('django.db.models.fields.SmallIntegerField')()),
+ ))
+ db.send_create_signal('geonames', ['PostalCode'])
+
+ def backwards(self, orm):
+ # Deleting model 'Admin1Code'
+ db.delete_table('geonames_admin1code')
+
+ # Deleting model 'Admin2Code'
+ db.delete_table('geonames_admin2code')
+
+ # Deleting model 'TimeZone'
+ db.delete_table('geonames_timezone')
+
+ # Deleting model 'Geoname'
+ db.delete_table('geonames_geoname')
+
+ # Deleting model 'Alternate'
+ db.delete_table('geonames_alternate')
+
+ # Deleting model 'PostalCode'
+ db.delete_table('geonames_postalcode')
+
+ models = {
+ 'geonames.admin1code': {
+ 'Meta': {'object_name': 'Admin1Code'},
+ 'code': ('django.db.models.fields.CharField', [], {'max_length': '6'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '58'})
+ },
+ 'geonames.admin2code': {
+ 'Meta': {'object_name': 'Admin2Code'},
+ 'code': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '46'})
+ },
+ 'geonames.alternate': {
+ 'Meta': {'ordering': "('-preferred',)", 'object_name': 'Alternate'},
+ 'alternateid': ('django.db.models.fields.PositiveIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
+ 'geoname': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'alternate_names'", 'to': "orm['geonames.Geoname']"}),
+ 'isolanguage': ('django.db.models.fields.CharField', [], {'max_length': '7'}),
+ 'preferred': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
+ 'short': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'variant': ('django.db.models.fields.CharField', [], {'max_length': '200', 'db_index': 'True'})
+ },
+ 'geonames.geoname': {
+ 'Meta': {'object_name': 'Geoname'},
+ 'admin1': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '20', 'blank': 'True'}),
+ 'admin2': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '80', 'blank': 'True'}),
+ 'admin3': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '20', 'blank': 'True'}),
+ 'admin4': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '20', 'blank': 'True'}),
+ 'alternates': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'cc2': ('django.db.models.fields.CharField', [], {'max_length': '60', 'blank': 'True'}),
+ 'country': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '2', 'blank': 'True'}),
+ 'elevation': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
+ 'fclass': ('django.db.models.fields.CharField', [], {'max_length': '1', 'db_index': 'True'}),
+ 'fcode': ('django.db.models.fields.CharField', [], {'max_length': '10', 'db_index': 'True'}),
+ 'geonameid': ('django.db.models.fields.PositiveIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
+ 'moddate': ('django.db.models.fields.DateField', [], {}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'db_index': 'True'}),
+ 'point': ('django.contrib.gis.db.models.fields.PointField', [], {'null': 'True', 'geography': 'True'}),
+ 'population': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True'}),
+ 'timezone': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'topo': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'})
+ },
+ 'geonames.postalcode': {
+ 'Meta': {'object_name': 'PostalCode'},
+ 'accuracy': ('django.db.models.fields.SmallIntegerField', [], {}),
+ 'admin1code': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
+ 'admin1name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'admin2code': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
+ 'admin2name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'admin3code': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
+ 'admin3name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'countrycode': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'latitude': ('django.db.models.fields.FloatField', [], {}),
+ 'longitude': ('django.db.models.fields.FloatField', [], {}),
+ 'placename': ('django.db.models.fields.CharField', [], {'max_length': '180'}),
+ 'postalcode': ('django.db.models.fields.CharField', [], {'max_length': '20'})
+ },
+ 'geonames.timezone': {
+ 'Meta': {'object_name': 'TimeZone'},
+ 'dst_offset': ('django.db.models.fields.FloatField', [], {}),
+ 'gmt_offset': ('django.db.models.fields.FloatField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'tzid': ('django.db.models.fields.CharField', [], {'max_length': '30'})
+ }
+ }
+
+ complete_apps = ['geonames']
View
0  geonames/migrations/__init__.py
No changes.
View
83 geonames/models.py 100755 → 100644
@@ -1,15 +1,5 @@
from django.contrib.gis.db import models
-from django.conf import settings
-class BigIntegerField(models.PositiveIntegerField):
- def db_type(self, connection):
- return 'bigint'
-
-if 'south' in settings.INSTALLED_APPS:
- from south.modelsinspector import add_introspection_rules
- add_introspection_rules([], ["^geonames\.models\.BigIntegerField"])
-
-### Geonames.org Models ###
class Admin1Code(models.Model):
code = models.CharField(max_length=6)
@@ -18,7 +8,8 @@ class Admin1Code(models.Model):
objects = models.GeoManager()
def __unicode__(self):
- return u': '.join([self.code, self.name])
+ return u': '.join([unicode(self.code), unicode(self.name)])
+
class Admin2Code(models.Model):
code = models.CharField(max_length=32)
@@ -27,7 +18,8 @@ class Admin2Code(models.Model):
objects = models.GeoManager()
def __unicode__(self):
- return u': '.join([self.code, self.name])
+ return u': '.join([unicode(self.code), unicode(self.name)])
+
class TimeZone(models.Model):
tzid = models.CharField(max_length=30)
@@ -39,18 +31,26 @@ class TimeZone(models.Model):
def __unicode__(self):
return self.tzid
+
class GeonameManager(models.GeoManager):
def countries(self, *args, **kwargs):
- '''
+ """
Filter returns only countries
- '''
- return super(GeonameManager, self).filter(fcode__in=['PCLI']).filter(*args, **kwargs)
+ """
+ return self.filter(fcode__in=['PCLI']).filter(*args, **kwargs)
def continents(self, *args, **kwargs):
- '''
+ """
Filter returns only continents
- '''
- return super(GeonameManager, self).filter(fcode__in=['CONT']).filter(*args, **kwargs)
+ """
+ return self.filter(fcode__in=['CONT']).filter(*args, **kwargs)
+
+ def cities(self, *args, **kwargs):
+ """
+ Filter returns only cities and other populated places
+ """
+ return self.filter(fcode__in=['PPL']).filter(*args, **kwargs)
+
class Geoname(models.Model):
geonameid = models.PositiveIntegerField(primary_key=True, unique=True)
@@ -64,12 +64,12 @@ class Geoname(models.Model):
admin2 = models.CharField(max_length=80, blank=True, db_index=True)
admin3 = models.CharField(max_length=20, blank=True, db_index=True)
admin4 = models.CharField(max_length=20, blank=True, db_index=True)
- population = BigIntegerField(db_index=True)
+ population = models.BigIntegerField(db_index=True)
elevation = models.IntegerField(db_index=True)
topo = models.IntegerField(db_index=True)
timezone = models.CharField(max_length=30, blank=True)
moddate = models.DateField('Date of Last Modification')
- point = models.PointField(null=True)
+ point = models.PointField(null=True, geography=True, spatial_index=True)
objects = GeonameManager()
@@ -82,19 +82,33 @@ def is_country(self):
def is_continent(self):
return self.fcode == 'CONT'
+ def is_populated(self):
+ return self.fcode == 'PPL'
+
def get_country(self):
if not self.is_country():
try:
- return self.__class__.objects.get(fcode='PCLI', country=self.country)
+ return self.__class__.objects.get(
+ fcode='PCLI', country=self.country)
except self.__class__.DoesNotExist:
return None
else:
return self
-class Alternate(models.Model):
class Meta:
- ordering = ('-preferred',)
+ ordering = ('name', 'country')
+
+# class LocalName(models.Model):
+# uuid = UUIDField(auto=True)
+# language = models.CharField(max_length=20, db_index=True)
+# name = models.CharField(max_length=255)
+# value = models.TextField()
+#
+# def __unicode__(self):
+# return self.name
+
+class Alternate(models.Model):
alternateid = models.PositiveIntegerField(primary_key=True, unique=True)
geoname = models.ForeignKey(Geoname, related_name='alternate_names')
isolanguage = models.CharField(max_length=7)
@@ -104,5 +118,28 @@ class Meta:
objects = models.GeoManager()
+ class Meta:
+ ordering = ('-preferred',)
+
def __unicode__(self):
return self.geoname.name
+
+
+class PostalCode(models.Model):
+ countrycode = models.CharField(max_length=2)
+ postalcode = models.CharField(max_length=20)
+ placename = models.CharField(max_length=180)
+ admin1name = models.CharField(max_length=100)
+ admin1code = models.CharField(max_length=20)
+ admin2name = models.CharField(max_length=100)
+ admin2code = models.CharField(max_length=20)
+ admin3name = models.CharField(max_length=100)
+ admin3code = models.CharField(max_length=20)
+ latitude = models.FloatField()
+ longitude = models.FloatField()
+ accuracy = models.SmallIntegerField()
+
+ objects = models.GeoManager()
+
+ def __unicode__(self):
+ return self.placename
View
4 geonames/sql/create_geoname_indexes.sql
@@ -1,4 +1,4 @@
-CREATE INDEX "geonames_geoname_point_id" ON "geonames_geoname" USING GIST ( "point" GIST_GEOMETRY_OPS );
+CREATE INDEX "geonames_geoname_point_id" ON "geonames_geoname" USING GIST ("point");
CREATE INDEX "geonames_geoname_name" ON "geonames_geoname" ("name");
CREATE INDEX "geonames_geoname_fclass" ON "geonames_geoname" ("fclass");
CREATE INDEX "geonames_geoname_fcode" ON "geonames_geoname" ("fcode");
@@ -9,4 +9,4 @@ CREATE INDEX "geonames_geoname_admin3" ON "geonames_geoname" ("admin3");
CREATE INDEX "geonames_geoname_admin4" ON "geonames_geoname" ("admin4");
CREATE INDEX "geonames_geoname_population" ON "geonames_geoname" ("population");
CREATE INDEX "geonames_geoname_elevation" ON "geonames_geoname" ("elevation");
-CREATE INDEX "geonames_geoname_topo" ON "geonames_geoname" ("topo");
+CREATE INDEX "geonames_geoname_topo" ON "geonames_geoname" ("topo");
View
2  geonames/sql/create_postalcode_indexes.sql
@@ -0,0 +1,2 @@
+CREATE INDEX "geonames_postalcode_countrycode" ON "geonames_postalcode" ("countrycode");
+CREATE INDEX "geonames_postalcode_postalcode" ON "geonames_postalcode" ("postalcode");
View
6 geonames/sql/drop_geoname_indexes.sql
@@ -1,8 +1,8 @@
-DROP INDEX "geonames_geoname_point_id";
-DROP INDEX "geonames_geoname_name";
+DROP INDEX "geonames_geoname_point_id";
+DROP INDEX "geonames_geoname_name";
DROP INDEX "geonames_geoname_fclass";
DROP INDEX "geonames_geoname_fcode";
-DROP INDEX "geonames_geoname_country";
+DROP INDEX "geonames_geoname_country";
DROP INDEX "geonames_geoname_admin1";
DROP INDEX "geonames_geoname_admin2";
DROP INDEX "geonames_geoname_admin3";
View
2  geonames/sql/drop_postalcode_indexes.sql
@@ -0,0 +1,2 @@
+DROP INDEX "geonames_postalcode_countrycode";
+DROP INDEX "geonames_postalcode_postalcode";
View
4 setup.py 100644 → 100755
@@ -9,9 +9,7 @@
author_email='jbronn@geodjango.org',
url='https://github.com/ramusus/django-geonames/',
packages = find_packages(),
- include_package_data = True,
package_data = {
'geonames' : ['sql/*.sql']
- }
+ },
)
-
Something went wrong with that request. Please try again.