def post_import(self):
        # iterate self.missing_stations + insert
        # points are missing and we have no postcodes to geocode
        self.stations = StationSet()
        for record in self.missing_stations:
            address_parts = self.split_address(record[2])
            self.add_polling_station({
                'internal_council_id': record[1],
                'postcode': address_parts['postcode'],
                'address': address_parts['address'],
                'location': None,
                'council': self.council
            })
        self.stations.save()
        """
        This data isn't great – the polygons seem to be corrupt in some way.

        PostGIS can fix them though!
        """
        print("running fixup SQL")
        table_name = PollingDistrict()._meta.db_table

        cursor = connection.cursor()
        cursor.execute("""
        UPDATE {0}
         SET area=ST_Multi(ST_CollectionExtract(ST_MakeValid(area), 3))
         WHERE NOT ST_IsValid(area);
        """.format(table_name))
Ejemplo n.º 2
0
    def post_import(self):
        # fix self-intersecting polygon
        print("running fixup SQL")
        table_name = PollingDistrict()._meta.db_table

        cursor = connection.cursor()
        cursor.execute("""
        UPDATE {0}
         SET area=ST_Multi(ST_CollectionExtract(ST_MakeValid(area), 3))
         WHERE NOT ST_IsValid(area);
        """.format(table_name))
Ejemplo n.º 3
0
 def save(self):
     districts_db = []
     for district in self.elements:
         record = PollingDistrict(
             name=district.name,
             council=district.council,
             internal_council_id=district.internal_council_id,
             extra_id=district.extra_id,
             area=district.area,
             polling_station_id=district.polling_station_id,
         )
         districts_db.append(record)
     PollingDistrict.objects.bulk_create(districts_db)
    def post_import(self):
        """
        This data isn't great – the polygons seem to be corrupt in some way.

        PostGIS can fix them though!
        """
        print("running fixup SQL")
        table_name = PollingDistrict()._meta.db_table

        cursor = connection.cursor()
        cursor.execute("""
        UPDATE {0}
         SET area=ST_Multi(ST_CollectionExtract(ST_MakeValid(area), 3))
         WHERE NOT ST_IsValid(area);
        """.format(table_name))