def get_electoral_wards(drupal_admin_id,local_ward_id):
url = SHELTER + 'electoral-ward-data/' + str(drupal_admin_id)
response = http.request('GET', url)
for n in json.loads(response.data)['nodes']:
coordinates = n['node']['shape'].split(',0')
lst_coordinates = []
for coordinate in coordinates[:-1]:
lst_coordinates.append(list(map(float, coordinate.split(','))))
lst_coordinates = [lst_coordinates]
key="Polygon"
pnt = GEOSGeometry('{ "type": "'+ key +'" , "coordinates": '+ str(lst_coordinates)+' }')
admin_data = AdministrativeWard.objects.get(id=local_ward_id)
obj, created = ElectoralWard.objects.update_or_create(name= n['node']['name'],administrative_ward = admin_data ,shape=pnt,extra_info=n['node']['description'], defaults={'name': n['node']['name']})
print created
评论列表
文章目录