本文整理汇总了Python中mapit.models.Area.id方法的典型用法代码示例。如果您正苦于以下问题:Python Area.id方法的具体用法?Python Area.id怎么用?Python Area.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapit.models.Area
的用法示例。
在下文中一共展示了Area.id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_label
# 需要导入模块: from mapit.models import Area [as 别名]
# 或者: from mapit.models.Area import id [as 别名]
def handle_label(self, filename, **options):
missing_options = []
for k in ['generation_id', 'area_type_code', 'name_type_code', 'country_code']:
if options[k]:
continue
else:
missing_options.append(k)
if missing_options:
message_start = "Missing arguments " if len(missing_options) > 1 else "Missing argument "
message = message_start + " ".join('--{0}'.format(k) for k in missing_options)
raise CommandError(message)
generation_id = options['generation_id']
area_type_code = options['area_type_code']
name_type_code = options['name_type_code']
country_code = options['country_code']
override_name = options['override_name']
name_field = options['name_field']
if not (override_name or name_field):
name_field = 'Name'
override_code = options['override_code']
code_field = options['code_field']
code_type_code = options['code_type']
encoding = options['encoding'] or 'utf-8'
if len(area_type_code) > 3:
raise CommandError("Area type code must be 3 letters or fewer, sorry")
if name_field and override_name:
raise CommandError("You must not specify both --name_field and --override_name")
if code_field and override_code:
raise CommandError("You must not specify both --code_field and --override_code")
using_code = (code_field or override_code)
if (using_code and not code_type_code) or (not using_code and code_type_code):
raise CommandError(
"If you want to save a code, specify --code_type and either --code_field or --override_code")
try:
area_type = Type.objects.get(code=area_type_code)
except:
type_desc = input('Please give a description for area type code %s: ' % area_type_code)
area_type = Type(code=area_type_code, description=type_desc)
if options['commit']:
area_type.save()
try:
name_type = NameType.objects.get(code=name_type_code)
except:
name_desc = input('Please give a description for name type code %s: ' % name_type_code)
name_type = NameType(code=name_type_code, description=name_desc)
if options['commit']:
name_type.save()
try:
country = Country.objects.get(code=country_code)
except:
country_name = input('Please give the name for country code %s: ' % country_code)
country = Country(code=country_code, name=country_name)
if options['commit']:
country.save()
if code_type_code:
try:
code_type = CodeType.objects.get(code=code_type_code)
except:
code_desc = input('Please give a description for code type %s: ' % code_type_code)
code_type = CodeType(code=code_type_code, description=code_desc)
if options['commit']:
code_type.save()
self.stdout.write("Importing from %s" % filename)
if not options['commit']:
self.stdout.write('(will not save to db as --commit not specified)')
current_generation = Generation.objects.current()
new_generation = Generation.objects.get(id=generation_id)
def verbose(*args):
if int(options['verbosity']) > 1:
self.stdout.write(" ".join(str(a) for a in args))
ds = DataSource(filename)
layer = ds[0]
if (override_name or override_code) and len(layer) > 1:
message = (
"Warning: you have specified an override %s and this file contains more than one feature; "
"multiple areas with the same %s will be created")
if override_name:
self.stdout.write(message % ('name', 'name'))
if override_code:
self.stdout.write(message % ('code', 'code'))
for feat in layer:
if override_name:
name = override_name
else:
try:
#.........这里部分代码省略.........
示例2: handle_label
# 需要导入模块: from mapit.models import Area [as 别名]
# 或者: from mapit.models.Area import id [as 别名]
def handle_label(self, filename, **options):
err = False
for k in ['generation_id','area_type_code','name_type_code','country_code']:
if options[k]: continue
print "Missing argument '--%s'" % k
err = True
if err:
sys.exit(1)
generation_id = options['generation_id']
area_type_code = options['area_type_code']
name_type_code = options['name_type_code']
country_code = options['country_code']
name_field = options['name_field'] or 'Name'
code_field = options['code_field']
code_type_code = options['code_type']
encoding = options['encoding'] or 'utf-8'
if len(area_type_code)>3:
print "Area type code must be 3 letters or fewer, sorry"
sys.exit(1)
if (code_field and not code_type_code) or (not code_field and code_type_code):
print "You must specify both code_field and code_type, or neither."
sys.exit(1)
try:
area_type = Type.objects.get(code=area_type_code)
except:
type_desc = raw_input('Please give a description for area type code %s: ' % area_type_code)
area_type = Type(code=area_type_code, description=type_desc)
if options['commit']: area_type.save()
try:
name_type = NameType.objects.get(code=name_type_code)
except:
name_desc = raw_input('Please give a description for name type code %s: ' % name_type_code)
name_type = NameType(code=name_type_code, description=name_desc)
if options['commit']: name_type.save()
try:
country = Country.objects.get(code=country_code)
except:
country_name = raw_input('Please give the name for country code %s: ' % country_code)
country = Country(code=country_code, name=country_name)
if options['commit']: country.save()
if code_type_code:
try:
code_type = CodeType.objects.get(code=code_type_code)
except:
code_desc = raw_input('Please give a description for code type %s: ' % code_type_code)
code_type = CodeType(code=code_type_code, description=code_desc)
if options['commit']: code_type.save()
print "Importing from %s" % filename
if not options['commit']:
print '(will not save to db as --commit not specified)'
current_generation = Generation.objects.current()
new_generation = Generation.objects.get( id=generation_id )
def verbose(*args):
if options['verbose']:
print " ".join(str(a) for a in args)
ds = DataSource(filename)
layer = ds[0]
for feat in layer:
try:
name = feat[name_field].value
except:
choices = ', '.join(layer.fields)
print "Could not find name using name field '%s' - should it be something else? It will be one of these: %s. Specify which with --name_field" % (name_field, choices)
sys.exit(1)
try:
name = name.decode(encoding)
except:
print "Could not decode name using encoding '%s' - is it in another encoding? Specify one with --encoding" % encoding
sys.exit(1)
name = re.sub('\s+', ' ', name)
if not name:
raise Exception( "Could not find a name to use for area" )
code = None
if code_field:
try:
code = feat[code_field].value
except:
choices = ', '.join(layer.fields)
print "Could not find code using code field '%s' - should it be something else? It will be one of these: %s. Specify which with --code_field" % (code_field, choices)
sys.exit(1)
print " looking at '%s'%s" % ( name.encode('utf-8'), (' (%s)' % code) if code else '' )
g = feat.geom.transform(4326, clone=True)
#.........这里部分代码省略.........
示例3: handle_label
# 需要导入模块: from mapit.models import Area [as 别名]
# 或者: from mapit.models.Area import id [as 别名]
def handle_label(self, filename, **options):
err = False
for k in ['generation_id','area_type_code','name_type_code','country_code']:
if options[k]: continue
print "Missing argument '--%s'" % k
err = True
if err:
sys.exit(1)
generation_id = options['generation_id']
area_type_code = options['area_type_code']
name_type_code = options['name_type_code']
country_code = options['country_code']
name_field = options['name_field'] or 'Name'
code_field = options['code_field']
code_type_code = options['code_type']
encoding = options['encoding'] or 'utf-8'
if len(area_type_code)>3:
print "Area type code must be 3 letters or fewer, sorry"
sys.exit(1)
if (code_field and not code_type_code) or (not code_field and code_type_code):
print "You must specify both code_field and code_type, or neither."
sys.exit(1)
try:
area_type = Type.objects.get(code=area_type_code)
except:
type_desc = raw_input('Please give a description for area type code %s: ' % area_type_code)
area_type = Type(code=area_type_code, description=type_desc)
if options['commit']: area_type.save()
try:
name_type = NameType.objects.get(code=name_type_code)
except:
name_desc = raw_input('Please give a description for name type code %s: ' % name_type_code)
name_type = NameType(code=name_type_code, description=name_desc)
if options['commit']: name_type.save()
try:
country = Country.objects.get(code=country_code)
except:
country_name = raw_input('Please give the name for country code %s: ' % country_code)
country = Country(code=country_code, name=country_name)
if options['commit']: country.save()
if code_type_code:
try:
code_type = CodeType.objects.get(code=code_type_code)
except:
code_desc = raw_input('Please give a description for code type %s: ' % code_type_code)
code_type = CodeType(code=code_type_code, description=code_desc)
if options['commit']: code_type.save()
print "Importing from %s" % filename
if not options['commit']:
print '(will not save to db as --commit not specified)'
current_generation = Generation.objects.current()
new_generation = Generation.objects.get( id=generation_id )
ds = DataSource(filename)
layer = ds[0]
for feat in layer:
try:
name = feat[name_field].value
except:
choices = ', '.join(layer.fields)
print "Could not find name using name field '%s' - should it be something else? It will be one of these: %s. Specify which with --name_field" % (name_field, choices)
sys.exit(1)
try:
name = name.decode(encoding)
except:
print "Could not decode name using encoding '%s' - is it in another encoding? Specify one with --encoding" % encoding
sys.exit(1)
name = re.sub('\s+', ' ', name)
if not name:
raise Exception( "Could not find a name to use for area" )
code = None
if code_field:
try:
code = feat[code_field].value
except:
choices = ', '.join(layer.fields)
print "Could not find code using code field '%s' - should it be something else? It will be one of these: %s. Specify which with --code_field" % (code_field, choices)
sys.exit(1)
print " looking at '%s'%s" % ( name.encode('utf-8'), (' (%s)' % code) if code else '' )
try:
if code:
m = Area.objects.get(codes__code=code, codes__type=code_type)
else:
# Assumes unique names if no code column used
m = Area.objects.get(name=name, type=area_type)
#.........这里部分代码省略.........