Esempio n. 1
0
def update_geodata(point, category, value, url):
    lat = point.latitude
    lon = point.longitude
    area_id = get_area_id(lat, lon)
    geocode = Geocode.objects.filter(area_id=area_id)
    for g in geocode:
        if g.point_inside([lat, lon]):
            geodata = Geodata.objects.get(geocode=g.geocode)
            geodata.up_var(category.name, value)
            geodata.up_url()
            geodata.save()
def update_geodata(point, category, value, url):
  lat = point.latitude
  lon = point.longitude
  area_id = get_area_id(lat, lon)
  geocode = Geocode.objects.filter(area_id=area_id)
  for g in geocode:
    if g.point_inside([lat, lon]):
      geodata = Geodata.objects.get(geocode=g.geocode)
      geodata.up_var(category.name, value)
      geodata.up_url()
      geodata.save()
    def handle(self, *args, **options):
        point_id = options['point_id'][0]
        point = Point.objects.get(pk=point_id)
        area_id = get_area_id(point.latitude, point.longitude)
        #print(area_id)
        geos = Geocode.objects.filter(area_id=area_id)

        for g in geos:
            if g.point_inside([point.latitude, point.longitude]):
                point.geocode = g.geocode
                point.save()
                sys.exit()

        aux = area_id.split('_')
        p = 1.0 / 10**get_precision()
        neighbours = []
        neighbours.append([point.latitude + p, point.longitude])
        neighbours.append([point.latitude + p, point.longitude + p])
        neighbours.append([point.latitude, point.longitude + p])
        neighbours.append([point.latitude - p, point.longitude + p])
        neighbours.append([point.latitude - p, point.longitude])
        neighbours.append([point.latitude - p, point.longitude - p])
        neighbours.append([point.latitude, point.longitude - p])
        neighbours.append([point.latitude + p, point.longitude - p])

        neighbours = [get_area_id(n[0], n[1]) for n in neighbours]
        for n in neighbours:
            geos = Geocode.objects.filter(area_id=n)
            for g in geos:
                if g.point_inside([point.latitude, point.longitude]):
                    point.geocode = g.geocode
                    point.save()
                    sys.exit()

        neighbours = []
        neighbours.append([point.latitude + 2 * p, point.longitude])
        neighbours.append([point.latitude + 2 * p, point.longitude - 1 * p])
        neighbours.append([point.latitude + 2 * p, point.longitude - 2 * p])
        neighbours.append([point.latitude + p, point.longitude - 2 * p])
        neighbours.append([point.latitude, point.longitude - 2 * p])
        neighbours.append([point.latitude - p, point.longitude - 2 * p])
        neighbours.append([point.latitude - 2 * p, point.longitude - 2 * p])
        neighbours.append([point.latitude - 2 * p, point.longitude - p])
        neighbours.append([point.latitude - 2 * p, point.longitude])
        neighbours.append([point.latitude - 2 * p, point.longitude + p])
        neighbours.append([point.latitude - 2 * p, point.longitude + 2 * p])
        neighbours.append([point.latitude - p, point.longitude + 2 * p])
        neighbours.append([point.latitude, point.longitude + 2 * p])
        neighbours.append([point.latitude + p, point.longitude + 2 * p])
        neighbours.append([point.latitude + 2 * p, point.longitude + 2 * p])
        neighbours.append([point.latitude + 2 * p, point.longitude + p])

        #more neighbours??
        neighbours = [get_area_id(n[0], n[1]) for n in neighbours]
        for n in neighbours:
            geos = Geocode.objects.filter(area_id=n)
            for g in geos:
                if g.point_inside([point.latitude, point.longitude]):
                    point.geocode = g.geocode
                    point.save()
                    sys.exit()

        neighbours = []
        neighbours.append([point.latitude - 3 * p, point.longitude + 3 * p])
        neighbours.append([point.latitude - 2 * p, point.longitude + 3 * p])
        neighbours.append([point.latitude - p, point.longitude + 3 * p])
        neighbours.append([point.latitude, point.longitude + 3 * p])
        neighbours.append([point.latitude + p, point.longitude + 3 * p])
        neighbours.append([point.latitude + 2 * p, point.longitude + 3 * p])
        neighbours.append([point.latitude + 3 * p, point.longitude + 3 * p])

        neighbours.append([point.latitude + 3 * p, point.longitude + 2 * p])
        neighbours.append([point.latitude + 3 * p, point.longitude + p])
        neighbours.append([point.latitude + 3 * p, point.longitude])
        neighbours.append([point.latitude + 3 * p, point.longitude - p])
        neighbours.append([point.latitude + 3 * p, point.longitude - 2 * p])
        neighbours.append([point.latitude + 3 * p, point.longitude - 3 * p])

        neighbours.append([point.latitude + 2 * p, point.longitude - 3 * p])
        neighbours.append([point.latitude + p, point.longitude - 3 * p])
        neighbours.append([point.latitude, point.longitude - 3 * p])
        neighbours.append([point.latitude - p, point.longitude - 3 * p])
        neighbours.append([point.latitude - 2 * p, point.longitude - 3 * p])
        neighbours.append([point.latitude - 3 * p, point.longitude - 3 * p])

        neighbours.append([point.latitude - 3 * p, point.longitude - 3 * p])
        neighbours.append([point.latitude - 3 * p, point.longitude - 2 * p])
        neighbours.append([point.latitude - 3 * p, point.longitude - p])
        neighbours.append([point.latitude - 3 * p, point.longitude])
        neighbours.append([point.latitude - 3 * p, point.longitude + p])
        neighbours.append([point.latitude - 3 * p, point.longitude + 2 * p])

        #more neighbours??
        neighbours = [get_area_id(n[0], n[1]) for n in neighbours]
        for n in neighbours:
            geos = Geocode.objects.filter(area_id=n)
            for g in geos:
                if g.point_inside([point.latitude, point.longitude]):
                    point.geocode = g.geocode
                    point.save()
                    sys.exit()
  def handle(self, *args, **options):
    point_id = options['point_id'][0]
    point = Point.objects.get(pk=point_id)
    area_id = get_area_id(point.latitude, point.longitude)
    #print(area_id)
    geos = Geocode.objects.filter(area_id=area_id)

    for g in geos:
      if g.point_inside([point.latitude, point.longitude]):
        point.geocode = g.geocode
        point.save()
        sys.exit()

    aux = area_id.split('_')
    p = 1.0/10**get_precision()
    neighbours = []
    neighbours.append([point.latitude + p, point.longitude    ])
    neighbours.append([point.latitude + p, point.longitude + p])
    neighbours.append([point.latitude    , point.longitude + p])
    neighbours.append([point.latitude - p, point.longitude + p])
    neighbours.append([point.latitude - p, point.longitude    ])
    neighbours.append([point.latitude - p, point.longitude - p])
    neighbours.append([point.latitude    , point.longitude - p])
    neighbours.append([point.latitude + p, point.longitude - p])

    neighbours = [get_area_id(n[0], n[1]) for n in neighbours]
    for n in neighbours:
      geos = Geocode.objects.filter(area_id=n)
      for g in geos:
        if g.point_inside([point.latitude, point.longitude]):
          point.geocode = g.geocode
          point.save()
          sys.exit()

    neighbours = []
    neighbours.append([point.latitude + 2*p, point.longitude  ])
    neighbours.append([point.latitude + 2*p, point.longitude -1*p])
    neighbours.append([point.latitude + 2*p, point.longitude -2*p])
    neighbours.append([point.latitude +   p, point.longitude -2*p])
    neighbours.append([point.latitude      , point.longitude -2*p])
    neighbours.append([point.latitude -   p, point.longitude -2*p])
    neighbours.append([point.latitude - 2*p, point.longitude -2*p])
    neighbours.append([point.latitude - 2*p, point.longitude -  p])
    neighbours.append([point.latitude - 2*p, point.longitude     ])
    neighbours.append([point.latitude - 2*p, point.longitude +  p])
    neighbours.append([point.latitude - 2*p, point.longitude +2*p])
    neighbours.append([point.latitude -   p, point.longitude +2*p])
    neighbours.append([point.latitude      , point.longitude +2*p])
    neighbours.append([point.latitude +   p, point.longitude +2*p])
    neighbours.append([point.latitude + 2*p, point.longitude +2*p])
    neighbours.append([point.latitude + 2*p, point.longitude +  p])

    #more neighbours??
    neighbours = [get_area_id(n[0], n[1]) for n in neighbours]
    for n in neighbours:
      geos = Geocode.objects.filter(area_id=n)
      for g in geos:
        if g.point_inside([point.latitude, point.longitude]):
          point.geocode = g.geocode
          point.save()
          sys.exit()


    neighbours = []
    neighbours.append([point.latitude - 3*p, point.longitude + 3*p])
    neighbours.append([point.latitude - 2*p, point.longitude + 3*p])
    neighbours.append([point.latitude -   p, point.longitude + 3*p])
    neighbours.append([point.latitude      , point.longitude + 3*p])
    neighbours.append([point.latitude +   p, point.longitude + 3*p])
    neighbours.append([point.latitude + 2*p, point.longitude + 3*p])
    neighbours.append([point.latitude + 3*p, point.longitude + 3*p])

    neighbours.append([point.latitude + 3*p, point.longitude + 2*p])
    neighbours.append([point.latitude + 3*p, point.longitude +   p])
    neighbours.append([point.latitude + 3*p, point.longitude      ])
    neighbours.append([point.latitude + 3*p, point.longitude -   p])
    neighbours.append([point.latitude + 3*p, point.longitude - 2*p])
    neighbours.append([point.latitude + 3*p, point.longitude - 3*p])

    neighbours.append([point.latitude + 2*p, point.longitude - 3*p])
    neighbours.append([point.latitude +   p, point.longitude - 3*p])
    neighbours.append([point.latitude      , point.longitude - 3*p])
    neighbours.append([point.latitude -   p, point.longitude - 3*p])
    neighbours.append([point.latitude - 2*p, point.longitude - 3*p])
    neighbours.append([point.latitude - 3*p, point.longitude - 3*p])

    neighbours.append([point.latitude - 3*p, point.longitude - 3*p])
    neighbours.append([point.latitude - 3*p, point.longitude - 2*p])
    neighbours.append([point.latitude - 3*p, point.longitude -   p])
    neighbours.append([point.latitude - 3*p, point.longitude      ])
    neighbours.append([point.latitude - 3*p, point.longitude +   p])
    neighbours.append([point.latitude - 3*p, point.longitude + 2*p])

    #more neighbours??
    neighbours = [get_area_id(n[0], n[1]) for n in neighbours]
    for n in neighbours:
      geos = Geocode.objects.filter(area_id=n)
      for g in geos:
        if g.point_inside([point.latitude, point.longitude]):
          point.geocode = g.geocode
          point.save()
          sys.exit()