from rasterio import Affine from ..catalogs import SpatialiteCatalog from ..colormap import COLORMAP from ..formats import GeoJSON logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) logging.getLogger("botocore.credentials").setLevel(logging.WARNING) logging.getLogger("marblecutter.mosaic").setLevel(logging.WARNING) logging.getLogger("rasterio._base").setLevel(logging.WARNING) CATALOG = PostGISCatalog(table="land_cover") COLORMAP_TRANSFORMATION = Colormap(COLORMAP) GEOTIFF_FORMAT = GeoTIFF(colormap=COLORMAP) PNG_FORMAT = PNG(paletted=True) S3 = boto3.client("s3") def build_catalog(tile, min_zoom, max_zoom): catalog = SpatialiteCatalog() for source in upstream_sources_for_tile(tile, CATALOG, min_zoom=min_zoom, max_zoom=max_zoom): catalog.add_source(source) return catalog
from marblecutter import NoCatalogAvailable, tiling from marblecutter.catalogs.postgis import PostGISCatalog from marblecutter.formats.geotiff import GeoTIFF from marblecutter.formats.png import PNG from marblecutter.transformations import Colormap, Image, Transformation from marblecutter.web import bp, url_for from mercantile import Tile from .colormap import COLORMAP from .formats import GeoJSON LOG = logging.getLogger(__name__) CATALOG = PostGISCatalog(table="land_cover") COLORMAP_TRANSFORMATION = Colormap(COLORMAP) IMAGE_TRANSFORMATION = Image() IMAGE_FORMAT = PNG(paletted=True) GEOTIFF_FORMAT = GeoTIFF(colormap=COLORMAP) # configure logging logging.basicConfig(level=logging.INFO) logging.getLogger("rasterio._base").setLevel(logging.WARNING) logging.getLogger("botocore.credentials").setLevel(logging.WARNING) app = Flask("marblecutter-land-cover") app.register_blueprint(bp) app.url_map.strict_slashes = False @app.route("/") def meta():
from cachetools.func import lru_cache from flask import jsonify, render_template, request, url_for from marblecutter import NoCatalogAvailable, tiling from marblecutter.catalogs.remote import RemoteCatalog from marblecutter.formats.optimal import Optimal from marblecutter.formats.png import PNG from marblecutter.transformations import Image from marblecutter.web import app from mercantile import Tile from .catalogs import OAMSceneCatalog, OINMetaCatalog LOG = logging.getLogger(__name__) IMAGE_TRANSFORMATION = Image() PNG_FORMAT = PNG() OPTIMAL_FORMAT = Optimal() REMOTE_CATALOG_BASE_URL = os.getenv("REMOTE_CATALOG_BASE_URL", "https://api.openaerialmap.org") S3_BUCKET = os.getenv("S3_BUCKET") S3_PREFIX = os.getenv("S3_PREFIX", "") # normalize prefix if S3_PREFIX == "/": S3_PREFIX = "" if not S3_PREFIX.endswith("/"): S3_PREFIX += "/" if S3_PREFIX.startswith("/"):
from mercantile import Tile from marblecutter import tiling from marblecutter.catalogs.postgis import PostGISCatalog from marblecutter.formats.png import PNG from tilezen.transformations import Normal logging.basicConfig(level=logging.INFO) if __name__ == "__main__": zoom = 2 tile = Tile(0, 0, zoom) (headers, data) = tiling.render_tile(tile, PostGISCatalog(), format=PNG(), transformation=Normal(collar=2), scale=2) print("Headers: ", headers) with open( "tmp/{}_{}_{}_buffered_normal.png".format(tile.z, tile.x, tile.y), "w") as f: f.write(data) tile = Tile(0, 2**zoom - 1, zoom) (headers, data) = tiling.render_tile(tile, PostGISCatalog(), format=PNG(), transformation=Normal(collar=2),
ELEVATION_CATALOG = PostGISCatalog(table="dems") GEOTIFF_FORMAT = GeoTIFF(area_or_point="Point") HILLSHADE_GEOTIFF_FORMAT = GeoTIFF() HILLSHADE_TRANSFORMATION = Hillshade(resample=True, add_slopeshade=True) IMAGERY_CATALOG = PostGISCatalog(table="imagery") CATALOGS = { "buffered_normal": ELEVATION_CATALOG, "hillshade": ELEVATION_CATALOG, "imagery": IMAGERY_CATALOG, "normal": ELEVATION_CATALOG, "terrarium": ELEVATION_CATALOG, } DATA_BAND_COUNTS = {"imagery": 3} FORMATS = { "buffered_normal": PNG(), "hillshade": ColorRamp(), "imagery": PNG(), "normal": PNG(), "terrarium": PNG(), } RENDERERS = ["hillshade", "imagery", "buffered_normal", "normal", "terrarium"] TRANSFORMATIONS = { "buffered_normal": Normal(collar=2), "hillshade": HILLSHADE_TRANSFORMATION, "imagery": Image(), "normal": Normal(), "terrarium": Terrarium(), } logging.getLogger("botocore.credentials").setLevel(logging.WARNING)