Ejemplo n.º 1
0
def iterate_squares(ds, zoom):
    '''
    '''
    xoff, xstride, _, yoff, _, ystride = ds.GetGeoTransform()
    
    minlon, maxlat = xoff, yoff
    maxlon = xoff + ds.RasterXSize * xstride
    minlat = yoff + ds.RasterYSize * ystride
    
    if zoom > 11:
        maxlat = min(58, maxlat)
    
    osm = Provider()
    ul = osm.locationCoordinate(Location(maxlat, minlon)).zoomTo(zoom)
    lr = osm.locationCoordinate(Location(minlat, maxlon)).zoomTo(zoom)
    #lr = osm.locationCoordinate(Location(20, -60)).zoomTo(zoom)
    
    row = int(ul.row)
    while row < lr.row:
        lat = osm.coordinateLocation(Coordinate(row, 0, zoom)).lat
        print >> sys.stderr, 'lat:', round(lat, 2)
        col = int(ul.column)
        while col < lr.column:
            coord = Coordinate(row, col, zoom)
            sw = osm.coordinateLocation(coord.down())
            ne = osm.coordinateLocation(coord.right())
            
            west = max(minlon, sw.lon)
            north = min(maxlat, ne.lat)
            east = min(maxlon, ne.lon)
            south = max(minlat, sw.lat)
            
            left = round((west - xoff) / xstride)
            top = round((north - yoff) / ystride)
            width = round((east - xoff) / xstride) - left
            height = round((south - yoff) / ystride) - top
            
            yield (coord, south, north, int(left), int(top), int(width), int(height))
            
            col += 1
        row += 1
    
    return
    
    x = xmin
    while x < xmax:
        print >> sys.stderr, 'lon:', x
        y = ymin
        while y < ymax:
            left = round((x - xoff) / xstride)
            top = round((y + size - yoff) / ystride)
            width, height = round(size / xstride), round(size / -ystride)

            yield (round(x, 2), round(y, 2), int(left), int(top), int(width), int(height))
        
            y += size
        x += size
Ejemplo n.º 2
0
def coordinates(zoom):
    '''
    '''
    osm = Provider()

    for (col, row) in product(range(2**zoom), range(2**zoom)):
        coord = Coordinate(row, col, zoom)

        sw = osm.coordinateLocation(coord.down())
        ne = osm.coordinateLocation(coord.right())

        yield coord, sw, ne
Ejemplo n.º 3
0
def coordinates(zoom):
    """
    """
    osm = Provider()

    for (col, row) in product(range(2 ** zoom), range(2 ** zoom)):
        coord = Coordinate(row, col, zoom)

        sw = osm.coordinateLocation(coord.down())
        ne = osm.coordinateLocation(coord.right())

        yield coord, sw, ne
def search_tile(coord, buildings):
    ''' Search list of buildings for those within a tile coordinate.
    '''
    osm = Provider()
    
    sw = osm.coordinateLocation(coord.down())
    ne = osm.coordinateLocation(coord.right())
    
    found_buildings = [b for b in buildings
                       if sw.lon <= b['longitude'] < ne.lon
                       and sw.lat <= b['latitude'] < ne.lat]
    
    return found_buildings
Ejemplo n.º 5
0
def search_tile(coord, buildings):
    ''' Search list of buildings for those within a tile coordinate.
    '''
    osm = Provider()
    
    sw = osm.coordinateLocation(coord.down())
    ne = osm.coordinateLocation(coord.right())
    
    found_buildings = [b for b in buildings
                       if sw.lon <= b['longitude'] < ne.lon
                       and sw.lat <= b['latitude'] < ne.lat]
    
    return found_buildings
Ejemplo n.º 6
0
    print '-' * 80
    
    sw = map.pointLocation(Point(-100, map.dimensions.y + 100))
    ne = map.pointLocation(Point(map.dimensions.x + 100, -100))
    
    previewed_places = [place for place in visible_places
                        if (sw.lat < place.location.lat and place.location.lat < ne.lat
                        and sw.lon < place.location.lon and place.location.lon < ne.lon)]
    
    for place in previewed_places:
        box = place.label_bbox().envelope.exterior
        coord1 = Coordinate(box.coords[0][1], box.coords[0][0], zoom + 8)
        coord2 = Coordinate(box.coords[2][1], box.coords[2][0], zoom + 8)
        
        loc1, loc2 = osm.coordinateLocation(coord1), osm.coordinateLocation(coord2)
        point1, point2 = map.locationPoint(loc1), map.locationPoint(loc2)
        
        draw.rectangle((point1.x, point1.y, point2.x, point2.y), fill=(0xEE, 0xEE, 0xEE))
    
    i = 1
    for (cityA, cityB) in combinations(previewed_places, 2):
        if cityA.overlaps(cityB):
            print '%03d:' % i, cityA.name, 'x', cityB.name
            i += 1

    for place in previewed_places:
        if place.__class__ is Country:
            continue
    
        location = place.location