コード例 #1
0
 def setUp(self):
     self.stub = StubDistrictsImporter()
     test_council = Council(pk="X01000000")
     test_council.area = GEOSGeometry(
         "MULTIPOLYGON(((-1.8821953907294073 52.702871360302076,-0.37706843760440734 52.702871360302076,-0.37706843760440734 51.9237934761779,-1.8821953907294073 51.9237934761779,-1.8821953907294073 52.702871360302076)))",
         srid=4326,
     )
     self.stub.council = test_council
     self.stub.logger = MockLogger()
コード例 #2
0
    def pre_process_councils(self, councils):
        """
        if the new councils for 2019 don't already
        exist in the input file we need to:
        - build the boundaries as a union of
          the old authorities that they replace
        - delete the old ones out of the councils array so
          we don't have >1 polygons covering the same area
        """

        new_council_objects = {}
        for code in settings.NEW_COUNCILS:
            # only attempt to build the new areas if they don't already exist
            if code not in [c.council_id for c in councils]:
                new_council_objects[code] = Council(council_id=code, area=None)

        self.stdout.write(
            "building new areas: {}".format(str(list(new_council_objects.keys())))
        )

        # ids of any councils we're going to delete
        deleteme = []

        for council in councils:
            if not council.council_id in settings.OLD_TO_NEW_MAP:
                continue
            code = settings.OLD_TO_NEW_MAP[council.council_id]
            if code in new_council_objects:
                new_council_objects[code].area = union_areas(
                    new_council_objects[code].area, council.area
                )
                self.stdout.write("{} --> {}".format(council.council_id, code))
                deleteme.append(council.council_id)

        councils = [c for c in councils if c.council_id not in deleteme]

        for code, council in new_council_objects.items():
            councils.append(council)

        return councils