2011-08-18 17:14:56 +00:00
|
|
|
import csv
|
|
|
|
from settings import DATA_DIR
|
|
|
|
from os.path import join
|
2011-08-19 13:05:24 +00:00
|
|
|
from places.models import Feature, FeatureType
|
2011-08-18 17:14:56 +00:00
|
|
|
from django.contrib.gis.geos import Point
|
|
|
|
|
2011-08-19 13:05:24 +00:00
|
|
|
def import_ftypes(f):
|
2011-08-18 17:14:56 +00:00
|
|
|
t = csv.reader(f, delimiter="\t")
|
|
|
|
for row in t:
|
2011-08-19 13:05:24 +00:00
|
|
|
ft = FeatureType()
|
|
|
|
ft.feature_class = row[0]
|
|
|
|
ft.code = row[1]
|
|
|
|
ft.name = row[2]
|
|
|
|
try:
|
|
|
|
ft.description = row[3]
|
|
|
|
except:
|
|
|
|
ft.description = ''
|
|
|
|
ft.save()
|
|
|
|
print "saved " + ft.name
|
|
|
|
|
|
|
|
|
|
|
|
def import_gazetteer(f, limit):
|
|
|
|
t = csv.reader(f, delimiter="\t")
|
|
|
|
i = 0
|
|
|
|
for row in t:
|
|
|
|
ft = Feature()
|
|
|
|
if Feature.objects.filter(url=row[0]).count() > 0:
|
2011-08-18 17:14:56 +00:00
|
|
|
print "duplicate row " + row[0]
|
|
|
|
else:
|
2011-08-19 13:05:24 +00:00
|
|
|
ft.url = row[0]
|
|
|
|
ft.preferred_name = row[1]
|
|
|
|
|
2011-08-18 17:14:56 +00:00
|
|
|
try:
|
2011-08-19 13:05:24 +00:00
|
|
|
fcode = FeatureType.objects.get(code=row[2])
|
2011-08-18 17:14:56 +00:00
|
|
|
except:
|
2011-08-19 13:05:24 +00:00
|
|
|
fcode = None
|
2011-08-18 17:14:56 +00:00
|
|
|
|
2011-08-19 13:05:24 +00:00
|
|
|
ft.feature_type = fcode
|
2011-08-27 21:31:36 +00:00
|
|
|
ft.admin1 = row[4]
|
|
|
|
ft.admin2 = row[5]
|
|
|
|
ft.geometry = Point(float(row[7]), float(row[6]))
|
2011-08-19 13:05:24 +00:00
|
|
|
ft.save()
|
|
|
|
print "saved " + ft.preferred_name
|
|
|
|
i += 1
|
|
|
|
if i > limit:
|
|
|
|
break
|
2011-08-18 17:14:56 +00:00
|
|
|
|