Exemple #1
0
def tile(x, y, z):

  # start = time()
  # TODO Add z limit -> 204 No Content
  c = Coordinate(y, x, z)
  nw = OSM.coordinateLocation(c)
  se = OSM.coordinateLocation(c.down().right())
  box = as_bbox(se, nw, 4326)
  query = Commune.query.filter(Commune.centroid.intersects(box))
  features = []
  for f in query:
    feature = {
      'type': 'Feature',
      'id': f.id,
      'properties': f.properties,
      'geometry': f.shape.__geo_interface__
    }
    features.append(feature)
  # data_time = time() - start
  response = jsonify({
    'type': 'FeatureCollection',
    'features': features
  })
  # serialize_time = time() - start - data_time
  # print (x,y,z), "Data:", data_time, "Serialize:", serialize_time
  return response
Exemple #2
0
def tile(key, x, y, z):

    dbo = resolve_dbo(key)
    if key is None:
        return abort(404)

    start = time()
    # TODO Add z limit -> 204 No Content
    c = Coordinate(y, x, z)
    nw = OSM.coordinateLocation(c)
    se = OSM.coordinateLocation(c.down().right())
    box = as_bbox(se, nw, 4326)
    query = dbo.Feature.query.filter(Feature.geom.intersects(box))
    features = []
    for f in query:
        feature = {
            'type': 'Feature',
            'id': f.id,
            'properties': f.properties,
            'geometry': f.shape.__geo_interface__
        }
        features.append(feature)
    data_time = time() - start
    response = jsonify({'type': 'FeatureCollection', 'features': features})
    serialize_time = time() - start - data_time
    # print (x,y,z), "Data:", data_time, "Serialize:", serialize_time
    return response
Exemple #3
0
def tile(key, x, y, z):

    dbo = resolve_dbo(key)
    if key is None:
        return abort(404)

    start = time()
    # TODO Add z limit -> 204 No Content
    c = Coordinate(y, x, z)
    nw = OSM.coordinateLocation(c)
    se = OSM.coordinateLocation(c.down().right())
    box = as_bbox(se, nw, 4326)
    query = dbo.Feature.query.filter(Feature.geom.intersects(box))
    features = []
    for f in query:
        feature = {
            'type': 'Feature',
            'id': f.id,
            'properties': f.properties,
            'geometry': f.shape.__geo_interface__
        }
        features.append(feature)
    data_time = time() - start
    response = jsonify({
            'type': 'FeatureCollection',
            'features': features
        })
    serialize_time = time() - start - data_time
    # print (x,y,z), "Data:", data_time, "Serialize:", serialize_time
    return response
Exemple #4
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
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 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
Exemple #7
0
def tile(x, y, z):

    # start = time()
    # TODO Add z limit -> 204 No Content
    c = Coordinate(y, x, z)
    nw = OSM.coordinateLocation(c)
    se = OSM.coordinateLocation(c.down().right())
    box = as_bbox(se, nw, 4326)
    query = Commune.query.filter(Commune.centroid.intersects(box))
    features = []
    for f in query:
        feature = {
            'type': 'Feature',
            'id': f.id,
            'properties': f.properties,
            'geometry': f.shape.__geo_interface__
        }
        features.append(feature)
    # data_time = time() - start
    response = jsonify({'type': 'FeatureCollection', 'features': features})
    # serialize_time = time() - start - data_time
    # print (x,y,z), "Data:", data_time, "Serialize:", serialize_time
    return response
Exemple #8
0
         'http://c.tile.openstreetmap.org/6/15/28.png']

paths = [urlparse(href).path for href in hrefs]
tiles = [splitext(path)[0].lstrip('/') for path in paths]
values = [map(int, tile.split('/', 2)) for tile in tiles]
rows, cols = zip(*[(y, x) for (z, x, y) in values])

rows_cols = []

for row in range(min(rows), max(rows) + 1):
    for col in range(min(cols), max(cols) + 1):
        rows_cols.append((row, col))

for (index, (row, col)) in enumerate(rows_cols):
    coord = Coordinate(row, col, zoom)

    filename = '%(output_dir)s/%(zoom)d-%(col)d-%(row)d.tif' % locals()
    print 'echo', '-' * 80, index, 'of', len(rows_cols), filename

    ll = mercator.coordinateProj(coord.down())
    ur = mercator.coordinateProj(coord.right())
    
    print 'gdalwarp',
    print '-t_srs "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"',
    print '-te', ll.x, ll.y, ur.x, ur.y,
    print '-tr', scale, scale,
    print '-tps -r cubicspline',
    print '-co COMPRESS=JPEG',
    print 'landcover-1km-to-merc.vrt',
    print filename
Exemple #9
0
values = [map(int, tile.split('/', 2)) for tile in tiles]
rows, cols = zip(*[(y, x) for (z, x, y) in values])

rows_cols = []

for row in range(min(rows), max(rows) + 1):
    for col in range(min(cols), max(cols) + 1):
        rows_cols.append((row, col))

for (index, (row, col)) in enumerate(rows_cols):
    coord = Coordinate(row, col, zoom)

    filename = '%(output_dir)s/%(zoom)d-%(col)d-%(row)d.tif' % locals()
    print 'echo', '-' * 80, index, 'of', len(rows_cols), filename

    ll = mercator.coordinateProj(coord.down())
    ur = mercator.coordinateProj(coord.right())

    print 'gdalwarp',
    print '-t_srs "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"',
    print '-te', ll.x, ll.y, ur.x, ur.y,
    print '-tr', scale, scale,
    print '-tps -r cubicspline',
    print '-co COMPRESS=JPEG',
    print 'landcover-1km-to-merc.vrt',
    print filename

########NEW FILE########
__FILENAME__ = mapping
from imposm.mapping import Options, Polygons, LineStrings, PseudoArea, GeneralizedTable, meter_to_mapunit