示例#1
0
    def update(self):
        country = Country.objects.get(iso2=self.iso2_code)
        items = get_json_data('/../data_backup/township_nl.json').get(
            'features')
        for item in items:
            properties = item.get('properties')
            name = properties.get('name').lower()
            city, created = City.objects.get_or_create(
                name=name,
                country=country,
                polygons=json.dumps(item.get('geometry')),
                language=self.language)
            if created:
                Geolocation(content_object=city, tag=name, type='city').save()

            print(item.get('properties').get('name').lower())
示例#2
0
    def update(self):
        items = get_json_data('/../data_backup/cities.json').get('features')
        for item in items:
            name = item['properties']['NAME'].lower()
            the_country = None
            latitude = item['properties']['LATITUDE']
            longitude = item['properties']['LONGITUDE']
            ascii_name = item['properties']['NAMEASCII']
            country_iso2 = item['properties']['ISO_A2']
            polygons = json.dumps(item.get('geometry'))
            point_loc_str = 'POINT(' + str(longitude) + ' ' + str(
                latitude) + ')'
            longlat = fromstr(point_loc_str, srid=4326)

            country = None
            if Country.objects.filter(iso2=country_iso2).exists():
                country = Country.objects.get(code=country_iso2)

            try:
                city = City.objects.get(name=name)
            except City.DoesNotExist:
                city = City(name=name,
                            country=country,
                            ascii_name=ascii_name,
                            polygons=polygons,
                            center_longlat=longlat,
                            language=self.language)
                city.save()

                try:
                    Geolocation.objects.get(tag=name)
                except Geolocation.DoesNotExist:
                    Geolocation(content_object=city,
                                tag=name,
                                type='city',
                                polygons=polygons,
                                center_longlat=longlat).save()

            if item['properties']['FEATURECLA'] == "Admin-0 capital":
                if the_country:
                    the_country.capital_city = city
                    the_country.save()

            print(city.name)
示例#3
0
    def update_pc2(self):
        country = Country.objects.get(iso2=self.iso2_code)
        items = get_json_data('/../data_backup/PC2.geo.json').get('features')
        for item in items:
            properties = item.get('properties')
            code = properties.get('postalcode').lower()
            polygons = json.dumps(item.get('geometry'))
            post_code, created = PostCode.objects.get_or_create(
                code=code,
                country=country,
                polygons=polygons,
                language=self.language)
            if created:
                Geolocation(content_object=post_code,
                            tag=code,
                            type='postcode',
                            polygons=polygons).save()

            print(code)
示例#4
0
 def _updated_pc_centers(self, file):
     centers = get_json_data(file)
     for center in centers:
         try:
             pc = PostCode.objects.get(code=center.lower())
             point_string = ''.join([
                 'POINT(',
                 str(centers[center]["longitude"]), ' ',
                 str(centers[center]["latitude"]), ')'
             ])
             long_lat = fromstr(point_string, srid=4326)
             pc.center_longlat = long_lat
             pc.save()
             try:
                 geolocation = Geolocation.objects.get(tag=pc.code)
                 geolocation.save()
                 print("Updated {code}".format(code=pc.code))
             except Geolocation.DoesNotExist:
                 pass
         except PostCode.DoesNotExist:
             print("Not found {code}:".format(code=center.lower()))