예제 #1
0
    def projCoordinate(self, point):
        """ Convert from Point object in EPSG:900913 to a Coordinate object
        """
        # the zoom at which we're dealing with meters on the ground
        diameter = 2 * _pi * 6378137
        zoom = _log(diameter) / _log(2)

        # global offsets
        coord = Coordinate(point.y, point.x, zoom)
        coord.column = coord.column + diameter/2
        coord.row = diameter/2 - coord.row
        
        return coord
예제 #2
0
    def projCoordinate(self, point):
        """ Convert from Point object in EPSG:3857 to a Coordinate object
        """
        # the zoom at which we're dealing with meters on the ground
        diameter = 2 * _pi * 6378137
        zoom = _log(diameter) / _log(2)

        # global offsets
        coord = Coordinate(point.y, point.x, zoom)
        coord.column = coord.column + diameter/2
        coord.row = diameter/2 - coord.row
        
        return coord
예제 #3
0
def generatePyramid(projection, top_tile, zooms):
    """ Generate a stream of (offset, count, coordinate) tuples for seeding.
    """

    print('Projection', projection)

    if (projection.__class__.__name__ == 'WGS84'):
        print('Skip')
    else:
        bounds_ul = projection.coordinateProj(top_tile)
        bounds_lr = projection.coordinateProj(top_tile.down().right())
        print('Pyramid top tile bounds in projection units', bounds_ul,
              bounds_lr)

        print bounds_ul.__class__

        pyramid_start = projection.projCoordinate(bounds_ul, zooms[-1])
        pyramid_end = projection.projCoordinate(bounds_lr, zooms[-1])
        print('Tile grid extent of bottom of pyramid', pyramid_start,
              pyramid_end)

    # start with a simple total of all the coordinates we will need.
    count = 0

    for zoom in zooms:
        if (projection.__class__.__name__ == 'WGS84'):
            pyramid_start = Coordinate(0, 0, zoom)
            pyramid_end = Coordinate(2**zoom - 1, 2 * 2**zoom - 1, zoom)
        else:
            pyramid_start = projection.projCoordinate(bounds_ul, zoom)
            pyramid_end = projection.projCoordinate(bounds_lr, zoom)
            pyramid_end.row = pyramid_end.row - 1
            pyramid_end.column = pyramid_end.column - 1

        columns = pyramid_end.column - pyramid_start.column
        rows = pyramid_end.row - pyramid_start.row

        count += columns * rows

    # now generate the actual coordinates.
    # offset starts at zero
    offset = 0

    for zoom in zooms:
        print projection.__class__.__name__
        if (projection.__class__.__name__ == 'WGS84'):
            pyramid_start = Coordinate(0, 0, zoom)
            pyramid_end = Coordinate(2**zoom - 1, 2 * 2**zoom - 1, zoom)
        else:
            pyramid_start = projection.projCoordinate(bounds_ul, zoom)
            pyramid_end = projection.projCoordinate(bounds_lr, zoom)
            pyramid_end.row = pyramid_end.row - 1
            pyramid_end.column = pyramid_end.column - 1

        print('Tile grid extent at zoom ' + str(zoom), pyramid_start,
              pyramid_end)

        for column in xrange(pyramid_start.column, pyramid_end.column + 1):
            for row in xrange(pyramid_start.row, pyramid_end.row + 1):
                coord = Coordinate(row, column, zoom)

                yield (offset, count, coord)

                offset += 1