Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for bugs #310 & #311 #325

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/promis/backend_api/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ def gen_selection():
# Intersection of search polygon and the orbit
isect = obj.session.geo_line.intersection(poly)

#django docs say that GEOSGeometry.dims returns -1 for empty GeometryCollection
if isect.dims == -1:
return

# Making sure isect is a collection of geolines, not a single one
if type(isect) is not MultiLineString:
isect = [ isect ]
Expand Down
19 changes: 12 additions & 7 deletions backend/promis/backend_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import datetime
from rest_framework.decorators import permission_classes
from django.contrib.gis.geos import GEOSGeometry

class PromisViewSet(viewsets.ReadOnlyModelViewSet):
'''Collects most commonly used View stuff'''
Expand Down Expand Up @@ -297,13 +298,17 @@ def get_queryset(self):
if space_project:
filter_opts['channel__device__space_project'] = int(space_project)

poly = self.request.query_params.get('polygon')

if poly:
try:
filter_opts['session__geo_line__intersects'] = poly
except ValueError:
raise NotFound("Invalid WKT for polygon selection")
# This code doesn't work because poly is a 3d polygon (geography),
# while geo_line is 2d (geometry)
# and it seems like it's not needed anyway,
# because this work is already done in DataSerializer.get_selection.
#
# poly = self.request.query_params.get('polygon')
# if poly:
# try:
# filter_opts['session__geo_line__intersects'] = poly
# except ValueError:
# raise NotFound("Invalid WKT for polygon selection")

# Applying the filter
return models.Measurement.objects.filter(**filter_opts)
1 change: 0 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dj-database-url==0.4.2
django-hvad==1.8.0
djangorestframework-gis==0.11
djangorestframework-filters==0.9.1
django-filters==0.2.1
pytz==2017.2 # for datetime conversions
django_loaddata_stdin==0.1.0 # for loading test data from the host
pytest-django==3.5.1
1 change: 1 addition & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ADD package.json /usr/src/promis/
# Install packages needed
RUN npm install
ADD webpack.config.js /usr/src/promis/
RUN npm i canvg

# Add the post install script
ADD postinstall.sh /usr/src/promis
Expand Down
23 changes: 15 additions & 8 deletions frontend/app/components/Quicklook.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { saveAs } from 'file-saver';
import { dataURLToBlob } from 'blob-util';
import Modal from './Modal';
import { strings } from "../localizations/localization";
import Canvg from 'canvg';

export default class Quicklook extends Component {
constructor(props) {
Expand All @@ -22,7 +23,7 @@ export default class Quicklook extends Component {
this.data = this.formatData(this.props.data, this.props.time);
}

componentDidUpdate() {
componentDidMount() {
/* get rendered SVG graph element */
if(this.el) {
this.svg = findDOMNode(this.el).querySelector('svg');
Expand Down Expand Up @@ -58,7 +59,6 @@ export default class Quicklook extends Component {
if(this.svg) {
var canvas = null, context = null;
var imageData = null, image = null;

/* setup offscreen canvas */
canvas = document.createElement('canvas');
canvas.width = this.props.graphWidth;
Expand All @@ -71,21 +71,28 @@ export default class Quicklook extends Component {

/* create new image from svg */
imageData = 'data:image/svg+xml,' + new XMLSerializer().serializeToString(this.svg);
image = new Image();
image = new Image()

/* draw image callback */
/* draw image callback */
image.onload = function() {
context.drawImage(image, 0, 0);

this.makeWatermark(canvas, context);

dataURLToBlob(canvas.toDataURL('image/png')).then(function(blob) {
saveAs(blob, this.makeFilename());
}.bind(this));
var dataURL = canvas.toDataURL('image/png');
var data = atob(dataURL.substring('data:image/png;base64,'.length)), asArray = new Uint8Array(data.length);

for (var i = 0, len = data.length; i < len; ++i)
{
asArray[i] = data.charCodeAt(i);
}

var blob = new Blob([asArray.buffer], {type: 'image/png'});
saveAs(blob, this.makeFilename());
}.bind(this);

/* set image data and trigger callback when done */
image.src = imageData;

} else window.alert(strings.alert);
}

Expand Down
15 changes: 12 additions & 3 deletions frontend/app/constants/Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,20 @@ export function selectionToPolygon(selection) {
case Types.Rect:
let bounds = Leaflet.latLngBounds(selection.data[0], selection.data[1]);
//let center = bounds.getCenter();

points.push(bounds.getSouthWest());
points.push(bounds.getSouthEast());
// had to add these two intermidiate points to overcome the bug
// "Antipodal (180 degrees long) edge detected!"
if (selection.data[0][0] == -90 && selection.data[1][0] == 90)
{
points.push({lat: 0, lng: bounds.getSouthEast().lng})
}
points.push(bounds.getNorthEast());
points.push(bounds.getNorthWest());
if (selection.data[0][0] == -90 && selection.data[1][0] == 90)
{
points.push({lat: 0, lng: bounds.getNorthWest().lng})
}
break;

case Types.Circle:
Expand All @@ -84,8 +93,8 @@ export function selectionToPolygon(selection) {
points.push(points[0]);

points.forEach(function(point) {
let lat = fixedPoint(point.lat ? point.lat : point[0]);
let lng = fixedPoint(point.lng ? point.lng : point[1]);
let lat = fixedPoint(selection.type == Types.Polygon ? point[0] : point.lat);
let lng = fixedPoint(selection.type == Types.Polygon ? point[1] : point.lng);

coords.push(new Array(lng, lat));
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"axios": "^0.19.0",
"blob-util": "^1.2.1",
"bootstrap": "^3.3.7",
"cesium": "^1.33.0",
"cesium": "1.33.0",
"d3": "^3.5.17",
"document-ready": "^2.0.1",
"es6-promise-promise": "^1.0.0",
Expand Down