def bound(self): """Generates bounds""" for sn in range(1, self.n_source_nodes+1): for tn in range(1, self.n_transit_nodes+1): for dn in range(1, self.n_destination_nodes+1): bound = Bound() bound.create_constraint_flow(sn, tn, dn) self.add_line(bound) bound = Bound() bound.create_constraint_min() self.add_line(bound)
def calc_bounds(self, domain, scale): """ Calculate the set of xyz tiles to render for the domain, expressed as boundary objects in terms of xyz tile numbers. """ denom = self.scale_denominator(scale) tiles = Bound(north=self.lat_to_xyz(domain.north, denom), south=self.lat_to_xyz(domain.south, denom), east=self.lon_to_xyz(domain.east, denom), west=self.lon_to_xyz(domain.west, denom)) return tiles
def inner_tiles(self, meta_bounds, scale): mw, mn, me, ms = meta_bounds meta = Bound(north=mn * 256, south=ms * 256, east=me * 256, west=mw * 256) for bound in meta.tiles_for(256): loc = Bound.from_tuple(bound).sub(meta).int().tuple() yield (loc, self.namer.name_for(scale, int(bound[1] / 256), int(bound[0] / 256)))
def search_nearest(request): data = request.GET.dict() latitude = float(data.get('latitude')) longtitude = float(data.get('longtitude')) LC = Bound(latitude, longtitude) result = AED.objects.filter( Q(langt__range=[LC['langt_min'], LC['langt_max']]) & Q(longt__range=[LC['longt_min'], LC['longt_max']])) data = result.values() distance_result = [] for datum in data: point1 = (latitude, longtitude) point2 = (datum['langt'], datum['longt']) distance = haversine(point1, point2) if len(distance_result) >= 3: distance_result.sort() if distance < distance_result[-1][0]: distance_result.pop() distance_result += [(distance, datum['id'])] else: distance_result += [(distance, datum['id'])] len_d = len(distance_result) if len_d == 0: final = None elif len_d == 1: final = AED.objects.filter(Q(id=distance_result[0][1])) elif len_d == 2: final = AED.objects.filter( Q(id=distance_result[0][1]) | Q(id=distance_result[1][1])) elif len_d == 3: final = AED.objects.filter( Q(id=distance_result[0][1]) | Q(id=distance_result[1][1]) | Q(id=distance_result[2][1])) serializer = AEDSerializer(final, many=True) final = json.dumps(serializer.data, ensure_ascii=False) return HttpResponse(final)
def meta_tiles(self, domain, scale, base_dir): """ Create a generator for a list of (meta_extent, meta_pixels, meta_filename, [(tile_offset, tile_name)]) tuples. That can be used to generate tiles at 'scale' from 'domain'. meta_extent - the real-world unit extent to render into the metatile meta_pixels - the pixel width/height of the metatile (they're always square) meta_filename - the file name to store the metatile in tile_offset - the pixel offset of this tile within the meta tile tile_name - the file name to store this tile in """ tiles = self.calc_bounds(domain, scale) tiles.east = tiles.east + 1 tiles.south = tiles.south + 1 meta_width = self.appropriate_meta_width(tiles) meta_bounds = tiles.tiles_for(meta_width) north_max = self.max_bounds.north west_max = self.max_bounds.west scale_denom = self.scale_denominator(scale) for boundaries in meta_bounds: bw, bn, be, bs = boundaries meta_filename = "%s-%s-%s.%s" % (scale, bw, bn, self.file_type) meta_loc = os.path.join(base_dir, "meta_panels", meta_filename) extent = Bound(north=north_max - float(bn * scale_denom), south=north_max - float(bs * scale_denom), east=west_max + float(be * scale_denom), west=west_max + float(bw * scale_denom)) scale_filename = scale yield (extent, meta_width * 256, meta_loc, self.inner_tiles(boundaries, scale_filename))
def search_nearest(request): data = request.GET.dict() latitude = float(data.get('latitude')) longtitude = float(data.get('longtitude')) LC = Bound(latitude, longtitude) curday = data.get('curday') curtime = data.get('curtime') if curday == '1': result = Nerve.objects.filter( Q(langt__range=[LC['langt_min'], LC['langt_max']]) & Q(longt__range=[LC['longt_min'], LC['longt_max']]) & Q(duty1=1) & Q(duty1_close__gte=curtime) & Q(duty1_open__lte=curtime)) elif curday == '2': result = Nerve.objects.filter( Q(langt__range=[LC['langt_min'], LC['langt_max']]) & Q(longt__range=[LC['longt_min'], LC['longt_max']]) & Q(duty2=1) & Q(duty2_close__gte=curtime) & Q(duty2_open__lte=curtime)) elif curday == '3': result = Nerve.objects.filter( Q(langt__range=[LC['langt_min'], LC['langt_max']]) & Q(longt__range=[LC['longt_min'], LC['longt_max']]) & Q(duty3=1) & Q(duty3_close__gte=curtime) & Q(duty3_open__lte=curtime)) elif curday == '4': result = Nerve.objects.filter( Q(langt__range=[LC['langt_min'], LC['langt_max']]) & Q(longt__range=[LC['longt_min'], LC['longt_max']]) & Q(duty4=1) & Q(duty4_close__gte=curtime) & Q(duty4_open__lte=curtime)) elif curday == '5': result = Nerve.objects.filter( Q(langt__range=[LC['langt_min'], LC['langt_max']]) & Q(longt__range=[LC['longt_min'], LC['longt_max']]) & Q(duty5=1) & Q(duty5_close__gte=curtime) & Q(duty5_open__lte=curtime)) elif curday == '6': result = Nerve.objects.filter( Q(langt__range=[LC['langt_min'], LC['langt_max']]) & Q(longt__range=[LC['longt_min'], LC['longt_max']]) & Q(duty6=1) & Q(duty6_close__gte=curtime) & Q(duty6_open__lte=curtime)) elif curday == '7': result = Nerve.objects.filter( Q(langt__range=[LC['langt_min'], LC['langt_max']]) & Q(longt__range=[LC['longt_min'], LC['longt_max']]) & Q(duty7=1) & Q(duty7_close__gte=curtime) & Q(duty7_open__lte=curtime)) data = result.values() distance_result = [] for datum in data: point1 = (latitude, longtitude) point2 = (datum['langt'], datum['longt']) distance = haversine(point1, point2) if len(distance_result) >= 3: distance_result.sort() if distance < distance_result[-1][0]: distance_result.pop() distance_result += [(distance, datum['id'])] else: distance_result += [(distance, datum['id'])] len_d = len(distance_result) if len_d == 0: final = None elif len_d == 1: final = Nerve.objects.filter(Q(id=distance_result[0][1])) elif len_d == 2: final = Nerve.objects.filter( Q(id=distance_result[0][1]) | Q(id=distance_result[1][1])) elif len_d == 3: final = Nerve.objects.filter( Q(id=distance_result[0][1]) | Q(id=distance_result[1][1]) | Q(id=distance_result[2][1])) serializer = NerveSerializer(final, many=True) final = json.dumps(serializer.data, ensure_ascii=False) return HttpResponse(final)