Пример #1
0
    def create_signage(self, geometry, name, infra, condition, structure,
                       description, year):
        infra_type, created = InfrastructureType.objects.get_or_create(
            label=infra, type='S')

        if created:
            self.stdout.write(
                u"- InfrastructureType '{}' created".format(infra_type))

        condition_type, created = InfrastructureCondition.objects.get_or_create(
            label=condition)

        if created:
            self.stdout.write(
                u"- Condition Type '{}' created".format(condition_type))

        structure, created = Structure.objects.get_or_create(name=structure)

        if created:
            self.stdout.write(u"- Structure '{}' created".format(structure))

        infra = Signage.objects.create(type=infra_type,
                                       name=name,
                                       condition=condition_type,
                                       structure=structure,
                                       description=description,
                                       implantation_year=year)
        serialized = '{"lng": %s, "lat": %s}' % (geometry.x, geometry.y)
        topology = TopologyHelper.deserialize(serialized)
        infra.mutate(topology)

        self.counter += 1

        return infra
Пример #2
0
    def create_infrastructure(self, geometry, name, type, category,
                              use_structure, condition, structure, description,
                              year, verbosity, eid):

        infra_type, created = InfrastructureType.objects.get_or_create(
            label=type,
            type=category,
            structure=structure if use_structure else None)
        if created and verbosity:
            self.stdout.write(
                "- InfrastructureType '{}' created".format(infra_type))

        if condition:
            condition_type, created = InfrastructureCondition.objects.get_or_create(
                label=condition,
                structure=structure if use_structure else None)
            if created and verbosity:
                self.stdout.write(
                    "- Condition Type '{}' created".format(condition_type))
        else:
            condition_type = None

        with transaction.atomic():
            fields_without_eid = {
                'type': infra_type,
                'name': name,
                'condition': condition_type,
                'structure': structure,
                'description': description,
                'implantation_year': year
            }
            if eid:
                infra, created = Infrastructure.objects.update_or_create(
                    eid=eid, defaults=fields_without_eid)
                if verbosity > 0 and not created:
                    self.stdout.write("Update : %s with eid %s" % (name, eid))
            else:
                infra = Infrastructure.objects.create(**fields_without_eid)
        if settings.TREKKING_TOPOLOGY_ENABLED:
            try:
                geometry.coord_dim = 2
                geometry = geometry.transform(settings.API_SRID, clone=True)
                serialized = '{"lng": %s, "lat": %s}' % (geometry.x,
                                                         geometry.y)
                topology = TopologyHelper.deserialize(serialized)
                infra.mutate(topology)
            except IndexError:
                raise GEOSException('Invalid Geometry type. You need 1 path')
        else:
            if geometry.geom_type != 'Point':
                raise GEOSException('Invalid Geometry type.')
            geometry = geometry.transform(settings.SRID, clone=True)
            infra.geom = Point(geometry.x, geometry.y)
            infra.save()
        self.counter += 1

        return infra
Пример #3
0
 def create_poi(self, geometry, name, poitype):
     poitype, created = POIType.objects.get_or_create(label=poitype)
     poi = POI.objects.create(name=name, type=poitype)
     # Use existing topology helpers to transform a Point(x, y)
     # to a path aggregation (topology)
     serialized = '{"lng": %s, "lat": %s}' % (geometry.x, geometry.y)
     topology = TopologyHelper.deserialize(serialized)
     # Move deserialization aggregations to the POI
     poi.mutate(topology)
     return poi
Пример #4
0
 def create_poi(self, geometry, name, poitype):
     poitype, created = POIType.objects.get_or_create(label=poitype)
     poi = POI.objects.create(name=name, type=poitype)
     if settings.TREKKING_TOPOLOGY_ENABLED:
         # Use existing topology helpers to transform a Point(x, y)
         # to a path aggregation (topology)
         serialized = '{"lng": %s, "lat": %s}' % (geometry.x, geometry.y)
         topology = TopologyHelper.deserialize(serialized)
         # Move deserialization aggregations to the POI
         poi.mutate(topology)
     else:
         if geometry.geom_type != 'Point':
             raise TypeError
         poi.geom = Point(geometry.x, geometry.y, srid=settings.SRID)
         poi.save()
     return poi
Пример #5
0
    def create_infrastructure(self, geometry, name, type, condition, structure,
                              description, year, model, verbosity, eid):

        infra_type, created = InfrastructureType.objects.get_or_create(
            label=type, type=model, structure=None)

        if created and verbosity:
            self.stdout.write(
                u"- InfrastructureType '{}' created".format(infra_type))

        if condition:
            condition_type, created = InfrastructureCondition.objects.get_or_create(
                label=condition, structure=None)
            if created and verbosity:
                self.stdout.write(
                    u"- Condition Type '{}' created".format(condition_type))
        else:
            condition_type = None

        with transaction.atomic():
            Model = Signage if model == 'S' else Infrastructure
            fields_without_eid = {
                'type': infra_type,
                'name': name,
                'condition': condition_type,
                'structure': structure,
                'description': description,
                'implantation_year': year
            }
            if eid:
                infra, created = Model.objects.update_or_create(
                    eid=eid, defaults=fields_without_eid)
                if verbosity > 0 and not created:
                    self.stdout.write(u"Update : %s with eid %s" % (name, eid))
            else:
                infra = Model.objects.create(**fields_without_eid)

        serialized = '{"lng": %s, "lat": %s}' % (geometry.x, geometry.y)
        topology = TopologyHelper.deserialize(serialized)
        infra.mutate(topology)

        self.counter += 1

        return infra
Пример #6
0
    def create_infrastructure(self, geometry, name, type,
                              condition, structure, description, year, verbosity, eid):

        infra_type, created = SignageType.objects.get_or_create(label=type, structure=None)
        if created and verbosity:
            self.stdout.write(u"- SignageType '{}' created".format(infra_type))

        if condition:
            condition_type, created = InfrastructureCondition.objects.get_or_create(label=condition,
                                                                                    structure=None)
            if created and verbosity:
                self.stdout.write(u"- Condition Type '{}' created".format(condition_type))
        else:
            condition_type = None

        with transaction.atomic():
            fields_without_eid = {
                'type': infra_type,
                'name': name,
                'condition': condition_type,
                'structure': structure,
                'description': description,
                'implantation_year': year
            }
            if eid:
                infra, created = Signage.objects.update_or_create(
                    eid=eid,
                    defaults=fields_without_eid
                )
                if verbosity > 0 and not created:
                    self.stdout.write(u"Update : %s with eid %s" % (name, eid))
            else:
                infra = Signage.objects.create(**fields_without_eid)

        serialized = '{"lng": %s, "lat": %s}' % (geometry.x, geometry.y)
        topology = TopologyHelper.deserialize(serialized)
        infra.mutate(topology)

        self.counter += 1

        return infra
    def create_infrastructure(self, geometry, name, type, condition, structure,
                              description, year, model, verbosity):

        infra_type, created = InfrastructureType.objects.get_or_create(
            label=type, type=model)

        if created and verbosity:
            self.stdout.write(
                u"- InfrastructureType '{}' created".format(infra_type))

        condition_type, created = InfrastructureCondition.objects.get_or_create(
            label=condition)

        if created and verbosity:
            self.stdout.write(
                u"- Condition Type '{}' created".format(condition_type))

        structure, created = Structure.objects.get_or_create(name=structure)

        if created and verbosity:
            self.stdout.write(u"- Structure '{}' created".format(structure))
        with transaction.atomic():
            Model = Signage if model == 'S' else Infrastructure
            infra = Model.objects.create(type=infra_type,
                                         name=name,
                                         condition=condition_type,
                                         structure=structure,
                                         description=description,
                                         implantation_year=year)
        serialized = '{"lng": %s, "lat": %s}' % (geometry.x, geometry.y)
        topology = TopologyHelper.deserialize(serialized)
        infra.mutate(topology)

        self.counter += 1

        return infra