Skip to content

Commit

Permalink
Merge pull request #1496 from pierotofy/mapapi
Browse files Browse the repository at this point in the history
Imperial units support, improvements, fixes, plugins API expansion
  • Loading branch information
pierotofy committed May 13, 2024
2 parents dd6b46a + 7272ca5 commit 32ba4ed
Show file tree
Hide file tree
Showing 38 changed files with 908 additions and 223 deletions.
12 changes: 6 additions & 6 deletions app/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ def upload(self, request, pk=None, project_pk=None):
raise exceptions.NotFound()

files = flatten_files(request.FILES)

if len(files) == 0:
raise exceptions.ValidationError(detail=_("No files uploaded"))

Expand Down Expand Up @@ -366,19 +365,20 @@ def get(self, request, pk=None, project_pk=None, asset=""):

# Check and download
try:
asset_fs, is_zipstream = task.get_asset_file_or_zipstream(asset)
asset_fs = task.get_asset_file_or_stream(asset)
except FileNotFoundError:
raise exceptions.NotFound(_("Asset does not exist"))

if not is_zipstream and not os.path.isfile(asset_fs):
is_stream = not isinstance(asset_fs, str)
if not is_stream and not os.path.isfile(asset_fs):
raise exceptions.NotFound(_("Asset does not exist"))

download_filename = request.GET.get('filename', get_asset_download_filename(task, asset))

if not is_zipstream:
return download_file_response(request, asset_fs, 'attachment', download_filename=download_filename)
else:
if is_stream:
return download_file_stream(request, asset_fs, 'attachment', download_filename=download_filename)
else:
return download_file_response(request, asset_fs, 'attachment', download_filename=download_filename)

"""
Raw access to the task's asset folder resources
Expand Down
16 changes: 8 additions & 8 deletions app/api/tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def get(self, request, pk=None, project_pk=None, tile_type="", z="", x="", y="",
# Hillshading is not a local tile operation and
# requires neighbor tiles to be rendered seamlessly
if hillshade is not None:
tile_buffer = tilesize
tile_buffer = 16

try:
if expr is not None:
Expand Down Expand Up @@ -471,17 +471,17 @@ def get(self, request, pk=None, project_pk=None, tile_type="", z="", x="", y="",
# Remove elevation data from edge buffer tiles
# (to keep intensity uniform across tiles)
elevation = tile.data[0]
elevation[0:tilesize, 0:tilesize] = nodata
elevation[tilesize*2:tilesize*3, 0:tilesize] = nodata
elevation[0:tilesize, tilesize*2:tilesize*3] = nodata
elevation[tilesize*2:tilesize*3, tilesize*2:tilesize*3] = nodata
elevation[0:tile_buffer, 0:tile_buffer] = nodata
elevation[tile_buffer+tilesize:tile_buffer*2+tilesize, 0:tile_buffer] = nodata
elevation[0:tile_buffer, tile_buffer+tilesize:tile_buffer*2+tilesize] = nodata
elevation[tile_buffer+tilesize:tile_buffer*2+tilesize, tile_buffer+tilesize:tile_buffer*2+tilesize] = nodata

intensity = ls.hillshade(elevation, dx=dx, dy=dy, vert_exag=hillshade)
intensity = intensity[tilesize:tilesize * 2, tilesize:tilesize * 2]
intensity = intensity[tile_buffer:tile_buffer+tilesize, tile_buffer:tile_buffer+tilesize]

if intensity is not None:
rgb = tile.post_process(in_range=(rescale_arr,))
rgb_data = rgb.data[:,tilesize:tilesize * 2, tilesize:tilesize * 2]
rgb_data = rgb.data[:,tile_buffer:tilesize+tile_buffer, tile_buffer:tilesize+tile_buffer]
if colormap:
rgb, _discard_ = apply_cmap(rgb_data, colormap.get(color_map))
if rgb.data.shape[0] != 3:
Expand All @@ -490,7 +490,7 @@ def get(self, request, pk=None, project_pk=None, tile_type="", z="", x="", y="",
intensity = intensity * 255.0
rgb = hsv_blend(rgb, intensity)
if rgb is not None:
mask = tile.mask[tilesize:tilesize * 2, tilesize:tilesize * 2]
mask = tile.mask[tile_buffer:tilesize+tile_buffer, tile_buffer:tilesize+tile_buffer]
return HttpResponse(
render(rgb, mask, img_format=driver, **options),
content_type="image/{}".format(ext)
Expand Down
8 changes: 4 additions & 4 deletions app/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,16 @@ def duplicate(self, set_new_name=True):

return False

def get_asset_file_or_zipstream(self, asset):
def get_asset_file_or_stream(self, asset):
"""
Get a stream to an asset
:param asset: one of ASSETS_MAP keys
:return: (path|stream, is_zipstream:bool)
:return: (path|stream)
"""
if asset in self.ASSETS_MAP:
value = self.ASSETS_MAP[asset]
if isinstance(value, str):
return self.assets_path(value), False
return self.assets_path(value)

elif isinstance(value, dict):
if 'deferred_path' in value and 'deferred_compress_dir' in value:
Expand All @@ -469,7 +469,7 @@ def get_asset_file_or_zipstream(self, asset):
paths = [p for p in paths if os.path.basename(p['fs']) not in value['deferred_exclude_files']]
if len(paths) == 0:
raise FileNotFoundError("No files available for download")
return zipfly.ZipStream(paths), True
return zipfly.ZipStream(paths)
else:
raise FileNotFoundError("{} is not a valid asset (invalid dict values)".format(asset))
else:
Expand Down
23 changes: 22 additions & 1 deletion app/static/app/js/ModelView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PropTypes from 'prop-types';
import * as THREE from 'THREE';
import $ from 'jquery';
import { _, interpolate } from './classes/gettext';
import { getUnitSystem, setUnitSystem } from './classes/Units';

require('./vendor/OBJLoader');
require('./vendor/MTLLoader');
Expand Down Expand Up @@ -301,6 +302,20 @@ class ModelView extends React.Component {
viewer.setPointBudget(10*1000*1000);
viewer.setEDLEnabled(true);
viewer.loadSettingsFromURL();

const currentUnit = getUnitSystem();
const origSetUnit = viewer.setLengthUnitAndDisplayUnit;
viewer.setLengthUnitAndDisplayUnit = (lengthUnit, displayUnit) => {
if (displayUnit === 'm') setUnitSystem('metric');
else if (displayUnit === 'ft'){
// Potree doesn't have US/international imperial, so
// we default to international unless the user has previously
// selected US
if (currentUnit === 'metric') setUnitSystem("imperial");
else setUnitSystem(currentUnit);
}
origSetUnit.call(viewer, lengthUnit, displayUnit);
};

viewer.loadGUI(() => {
viewer.setLanguage('en');
Expand Down Expand Up @@ -335,7 +350,7 @@ class ModelView extends React.Component {
directional.position.z = 99999999999;
viewer.scene.scene.add( directional );

this.pointCloudFilePath(pointCloudPath => {
this.pointCloudFilePath(pointCloudPath =>{
Potree.loadPointCloud(pointCloudPath, "Point Cloud", e => {
if (e.type == "loading_failed"){
this.setState({error: "Could not load point cloud. This task doesn't seem to have one. Try processing the task again."});
Expand All @@ -351,6 +366,12 @@ class ModelView extends React.Component {

viewer.fitToScreen();

if (getUnitSystem() === 'metric'){
viewer.setLengthUnitAndDisplayUnit('m', 'm');
}else{
viewer.setLengthUnitAndDisplayUnit('m', 'ft');
}

// Load saved scene (if any)
$.ajax({
type: "GET",
Expand Down
8 changes: 8 additions & 0 deletions app/static/app/js/classes/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class Storage{
console.warn("Failed to call setItem " + key, e);
}
}

static removeItem(key){
try{
localStorage.removeItem(key);
}catch(e){
console.warn("Failed to call removeItem " + key, e);
}
}
}

export default Storage;
Loading

0 comments on commit 32ba4ed

Please sign in to comment.