Permalink
Browse files

refactor directory structure, added setup.py

  • Loading branch information...
1 parent c7a227a commit a31294a473fd0aee95cd7ca0bcb5a6b981096f86 @ramusus committed Nov 15, 2010
View
12 DOWNLOAD
@@ -0,0 +1,12 @@
+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
0 management/commands/__init__.py → geonames/__init__.py 100644 → 100755
File renamed without changes.
View
0 admin.py → geonames/admin.py
File renamed without changes.
View
0 load.py → geonames/load.py
File renamed without changes.
View
0 management/__init__.py → geonames/management/__init__.py
File renamed without changes.
View
0 __init__.py → geonames/management/commands/__init__.py 100755 → 100644
File renamed without changes.
View
0 management/commands/compress_geonames.py → .../management/commands/compress_geonames.py
File renamed without changes.
View
19 management/commands/download_geonames.py → .../management/commands/download_geonames.py
@@ -44,10 +44,12 @@ 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'),
-# make_option('--no-alternates', action='store_true', dest='no_alternates', default=False,
-# 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('--country', action='store_value', dest='country', default=False,
+ help='Download only data for specified country.'),
+ make_option('--no-alternates', action='store_true', dest='no_alternates', default=False,
+ 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.'),
)
def handle_noargs(self, **options):
@@ -57,8 +59,13 @@ def handle_noargs(self, **options):
response = urllib2.urlopen(urllib2.Request(url=GEONAMES_DUMPS_URL))
files = re.findall(r'\<a href="(.+\.(?:txt|zip))"\>', response.read())
for file in files:
- if len(file) != 6:
- continue
+
+ if options['country'] and file != '%s.zip' % options['country'] \
+ or options['no_geonames'] and file == 'allCountries.zip' \
+ or options['no_alternates'] and file == 'alternateNames.zip' \
+ or not options['country'] and len(file) == 6:
+ continue
+
print '\nStart download "%s" file' % file
download(urlparse.urljoin(GEONAMES_DUMPS_URL, file), os.path.join(GEONAMES_DATA, file))
View
0 management/commands/load_geonames.py → ...ames/management/commands/load_geonames.py
File renamed without changes.
View
26 models.py → geonames/models.py
@@ -9,7 +9,7 @@ def db_type(self):
class Admin1Code(models.Model):
code = models.CharField(max_length=6)
name = models.CharField(max_length=58)
-
+
objects = models.GeoManager()
def __unicode__(self):
@@ -18,34 +18,34 @@ def __unicode__(self):
class Admin2Code(models.Model):
code = models.CharField(max_length=32)
name = models.CharField(max_length=46)
-
+
objects = models.GeoManager()
def __unicode__(self):
return u': '.join([self.code, self.name])
-
+
class TimeZone(models.Model):
tzid = models.CharField(max_length=30)
gmt_offset = models.FloatField()
dst_offset = models.FloatField()
-
+
objects = models.GeoManager()
-
+
def __unicode__(self):
return self.tzid
class Geoname(models.Model):
geonameid = models.PositiveIntegerField(primary_key=True, unique=True)
- name = models.CharField(max_length=154, db_index=True)
+ name = models.CharField(max_length=200, db_index=True)
alternates = models.TextField(blank=True)
fclass = models.CharField(max_length=1, db_index=True)
- fcode = models.CharField(max_length=5, db_index=True)
+ fcode = models.CharField(max_length=10, db_index=True)
country = models.CharField(max_length=2, blank=True, db_index=True)
- cc2 = models.CharField('Alternate Country Code', max_length=32, blank=True)
- admin1 = models.CharField(max_length=6, blank=True, db_index=True)
- admin2 = models.CharField(max_length=63, blank=True, db_index=True)
- admin3 = models.CharField(max_length=10, blank=True, db_index=True)
- admin4 = models.CharField(max_length=8, blank=True, db_index=True)
+ cc2 = models.CharField('Alternate Country Code', max_length=60, blank=True)
+ admin1 = models.CharField(max_length=20, blank=True, db_index=True)
+ 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)
elevation = models.IntegerField(db_index=True)
topo = models.IntegerField(db_index=True)
@@ -62,7 +62,7 @@ class Alternate(models.Model):
alternateid = models.PositiveIntegerField(primary_key=True, unique=True)
geoname = models.ForeignKey(Geoname)
isolanguage = models.CharField(max_length=7)
- variant = models.CharField(max_length=222, db_index=True)
+ variant = models.CharField(max_length=200, db_index=True)
preferred = models.BooleanField()
short = models.BooleanField()
View
2 geonames/sql/create_alternate_indexes.sql
@@ -0,0 +1,2 @@
+CREATE INDEX "geonames_alternate_geoname_id" ON "geonames_alternate" ("geoname_id");
+CREATE INDEX "geonames_alternate_variant" ON "geonames_alternate" ("variant");
View
12 geonames/sql/create_geoname_indexes.sql
@@ -0,0 +1,12 @@
+CREATE INDEX "geonames_geoname_point_id" ON "geonames_geoname" USING GIST ( "point" GIST_GEOMETRY_OPS );
+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");
+CREATE INDEX "geonames_geoname_country" ON "geonames_geoname" ("country");
+CREATE INDEX "geonames_geoname_admin1" ON "geonames_geoname" ("admin1");
+CREATE INDEX "geonames_geoname_admin2" ON "geonames_geoname" ("admin2");
+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");
View
2 geonames/sql/drop_alternate_indexes.sql
@@ -0,0 +1,2 @@
+DROP INDEX "geonames_alternate_geoname_id";
+DROP INDEX "geonames_alternate_variant";
View
12 geonames/sql/drop_geoname_indexes.sql
@@ -0,0 +1,12 @@
+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_admin1";
+DROP INDEX "geonames_geoname_admin2";
+DROP INDEX "geonames_geoname_admin3";
+DROP INDEX "geonames_geoname_admin4";
+DROP INDEX "geonames_geoname_population";
+DROP INDEX "geonames_geoname_elevation";
+DROP INDEX "geonames_geoname_topo";
View
13 setup.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+
+from distutils.core import setup
+
+setup(name='django-geonames',
+ version='1.0',
+ description='Fork of official GeoDjango geonames application refactored and adopted for Django 1.2.1',
+ author='Justin Bronn',
+ author_email='jbronn@geodjango.org',
+ url='https://github.com/ramusus/django-geonames/',
+ packages=['geonames', 'geonames.management', 'geonames.management.commands'],
+)
+
View
1 views.py
@@ -1 +0,0 @@
-# Create your views here.

0 comments on commit a31294a

Please sign in to comment.