Example #1
0
 def get_bound(self):
     
     v2 = self.vertexs[2]
     
     bound = Bound(list(v2), list(v2))
     
     for j in range(3):
         
         v0 = self.vertexs[0][j]
         v1 = self.vertexs[1][j]
         
         if v0 < v1:
             if v0 < bound.lower[j]:
                 bound.lower[j] = v0
             if v1 > bound.upper[j]:
                 bound.upper[j] = v1
         else:
             if v1 < bound.lower[j]:
                 bound.lower[j] = v1
             if v0 > bound.upper[j]:
                 bound.upper[j] = v0
         
         bound.lower[j] -= (abs(bound.lower[j]) + 1.0) * TOLERANCE
         bound.upper[j] += (abs(bound.upper[j]) + 1.0) * TOLERANCE
     
     return bound
Example #2
0
    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)))
Example #3
0
    def __init__(self, dpi, meta_size, file_type, spherical_mercator, verbose=False):
        self.dpi = dpi
        self.meta_size = meta_size
        self.file_type = file_type
        self.spherical_mercator = spherical_mercator
        self.namer = XYZNamingScheme(file_type)
        self.verbose = verbose

        if self.spherical_mercator:
            self.max_bounds = Bound.spherical_mercator_max_extent()
            pass
        else:
            self.max_bounds = Bound.geographic_max_extent()
Example #4
0
    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)))
Example #5
0
 def __init__(self, eye_position, items):
     
     bound = Bound(list(eye_position), list(eye_position))
     
     item_bounds = []
     
     for item in items:
         item_bound = item.get_bound()
         item_bounds.append((item, item_bound))
         bound.expand_to_fit(item_bound)
     
     bound.clamp()
     
     self.root = SpatialNode(bound, item_bounds, 0)
     self.deepest_level = self.root.deepest_level
Example #6
0
    def __init__(self, bound, item_bounds, level):

        self.bound = bound
        self.deepest_level = level

        self.is_branch = (
            len(item_bounds) > MAX_ITEMS and
            level < MAX_LEVELS - 1)

        if self.is_branch:
            q1 = 0
            self.children = [None] * 8

            for sub_cell in range(8):
                sub_bound = Bound([], [])

                for m in range(3):
                    if (sub_cell >> m) % 2 == 1:
                        sub_bound.lower.append((self.bound.lower[m] + self.bound.upper[m]) * 0.5)
                        sub_bound.upper.append(self.bound.upper[m])
                    else:
                        sub_bound.lower.append(self.bound.lower[m])
                        sub_bound.upper.append((self.bound.lower[m] + self.bound.upper[m]) * 0.5)

                sub_item_bounds = []

                for item, item_bound in item_bounds:
                    if sub_bound.encloses(item_bound):
                        sub_item_bounds.append((item, item_bound))

                q1 += 1 if len(sub_item_bounds) == len(item_bounds) else 0
                q2 = (sub_bound.upper[0] - sub_bound.lower[0]) < (TOLERANCE * 4.0)

                if len(sub_item_bounds) > 0:
                    if q1 > 1 or q2:
                        next_level = MAX_LEVELS
                    else:
                        next_level = level + 1

                    self.children[sub_cell] = SpatialNode(
                        sub_bound, sub_item_bounds, next_level)
                    if self.children[sub_cell].deepest_level > self.deepest_level:
                        self.deepest_level = self.children[sub_cell].deepest_level

        else:
            self.items = [item for item, item_bound in item_bounds]
Example #7
0
    def __init__(self,
                 dpi,
                 meta_size,
                 file_type,
                 spherical_mercator,
                 verbose=False):
        self.dpi = dpi
        self.meta_size = meta_size
        self.file_type = file_type
        self.spherical_mercator = spherical_mercator
        self.namer = XYZNamingScheme(file_type)
        self.verbose = verbose

        if self.spherical_mercator:
            self.max_bounds = Bound.spherical_mercator_max_extent()
            pass
        else:
            self.max_bounds = Bound.geographic_max_extent()
Example #8
0
 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)
Example #9
0
 def __init__(self):
     Scene.__init__(self)
     self.bird = Bird(*BIRD_INITPOS)
     self.bounds = Bound.getUpperLowerBounds()
     # TODO: background image
     self.obstacles = []
     self.add(self.bird)
     self.add(self.bounds[0])
     self.add(self.bounds[1])
     self.plannedObsGen = []
Example #10
0
    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
Example #11
0
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)
Example #12
0
    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))
Example #13
0
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)