From ee44283764fb4b727c9989d1be28958137023a69 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Wed, 20 Nov 2019 17:52:09 -0500 Subject: [PATCH] Metadata expression histogram working --- app/api/formulas.py | 3 --- app/api/tiler.py | 33 +-------------------------------- requirements.txt | 5 ++--- 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/app/api/formulas.py b/app/api/formulas.py index 5b573c4f..a63e5465 100644 --- a/app/api/formulas.py +++ b/app/api/formulas.py @@ -4,9 +4,6 @@ import re from functools import lru_cache -from rest_framework.permissions import AllowAny -from rest_framework.views import APIView -from rest_framework.response import Response algos = { 'VARI': { diff --git a/app/api/tiler.py b/app/api/tiler.py index 4b157ec1..fb76f279 100644 --- a/app/api/tiler.py +++ b/app/api/tiler.py @@ -1,7 +1,6 @@ import rasterio import urllib from django.http import HttpResponse -from rasterio import MemoryFile from rio_tiler.errors import TileOutsideBounds from rio_tiler.mercator import get_zooms from rio_tiler import main @@ -9,7 +8,6 @@ from rio_tiler.utils import array_to_image, get_colormap, expression, linear_res from rio_tiler.profiles import img_profiles import numpy as np -import mercantile from .hsvblend import hsv_blend from .hillshade import LightSource @@ -126,38 +124,9 @@ class Metadata(TaskNestedView): color_map = self.request.query_params.get('color_map') pmin, pmax = 2.0, 98.0 - raster_path = get_raster_path(task, tile_type) + info = main.metadata(raster_path, pmin=pmin, pmax=pmax, histogram_bins=64, expr=expr) - if expr is not None: - with rasterio.open(raster_path) as src: - minzoom, maxzoom = get_zooms(src) - centroid = get_extent(task, tile_type).centroid - coords = mercantile.tile(centroid.x, centroid.y, minzoom) - - tile, mask = expression( - raster_path, coords.x, coords.y, coords.z, expr=expr, tilesize=256, nodata=None - ) - - # Convert to uint - print(tile.min()) - print(tile.max()) - tile = (tile * 255.0).astype(np.uint8) - - with MemoryFile() as memfile: - profile = src.profile - profile['count'] = tile.shape[0] - profile.update() - - with memfile.open(**profile) as dataset: - dataset.write(tile) - dataset.write_mask(mask) - del tile - - with memfile.open() as dataset: # Reopen as DatasetReader - info = main.metadata(dataset, pmin=pmin, pmax=pmax, histogram_bins=64) - else: - info = main.metadata(raster_path, pmin=pmin, pmax=pmax, histogram_bins=64) if tile_type == 'plant': info['algorithms'] = get_algorithm_list(), diff --git a/requirements.txt b/requirements.txt index 7fd19620..7230382e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -54,6 +54,5 @@ uritemplate==3.0.0 vine==1.1.4 webcolors==1.5 rasterio==1.1.0 -rio-tiler==1.3.0 -rio-color==1.0.0 -mercantile==1.1.2 \ No newline at end of file +-e git://github.com/OpenDroneMap/rio-tiler.git#egg=rio-tiler +rio-color==1.0.0 \ No newline at end of file