Commit f03ce510 authored by Emmanuel René Huchim Puc's avatar Emmanuel René Huchim Puc
parents 75b668f3 ced6890c
import imp
class APISentinel():
# area example:
# POLYGON((-89.62543487548828 21.068482340502072,-89.51351165771484 20.918472761430806,
# -89.72705841064453 20.9203969139719,-89.62543487548828 21.068482340502072))
# dates example:
# '2018-01-01'
# cloudPercentage example:
# "[0 TO 10]" or 95
def getProducts(this, area, initDate, endDate, cloudPercentage):
GeoSentinel_path = "/home/geointdev/sidt-env/GeoSentinel/geosentinel/APISentinel.py"
# GeoSentinel_path = "/home/emmanuelhp/Documentos/GeoSentinel/geosentinel/APISentinel.py"
api = imp.load_source('geosentinel', GeoSentinel_path)
sentinel = api.APISentinel('emmhp', 'geoemm29')
products = sentinel.getProducts(area, ("".join(initDate.split('-')), "".join(endDate.split('-'))),
{"platformname":"Sentinel-2", "cloudcoverpercentage":cloudPercentage})
return products
...@@ -213,6 +213,19 @@ $(document).ready(function () { ...@@ -213,6 +213,19 @@ $(document).ready(function () {
data.catalog.forEach(function (data) { data.catalog.forEach(function (data) {
console.log("DD: ", data); console.log("DD: ", data);
$.ajax({
type: "POST",
url: img_req_url,
data: {
'csrfmiddlewaretoken': document.getElementsByName('csrfmiddlewaretoken')[0].value,
'value': data.product.link_icon
},
dataType: 'text',
success: function (response) {
// console.log("from img response: ", response);
}
});
var product_html = '<li id="' + data.id + ' class="hover-me">'+ var product_html = '<li id="' + data.id + ' class="hover-me">'+
'<a href="javascript:void(0)">'+ '<a href="javascript:void(0)">'+
'<i class="menu-icon glyphicon glyphicon-bookmark bg-red"></i>'+ '<i class="menu-icon glyphicon glyphicon-bookmark bg-red"></i>'+
......
...@@ -271,5 +271,6 @@ ...@@ -271,5 +271,6 @@
osmap.addInteraction(); osmap.addInteraction();
var req_url = "{% url 'search-submit' %}"; // url for requesting polygon data var req_url = "{% url 'search-submit' %}"; // url for requesting polygon data
var prod_req_url = "{% url 'productList' %}" // url for requesting product data var prod_req_url = "{% url 'productList' %}" // url for requesting product data
var img_req_url = "{% url 'img-rqst' %}" // url for requestim preview image
</script> </script>
{% endblock %} {% endblock %}
...@@ -7,6 +7,7 @@ urlpatterns = [ ...@@ -7,6 +7,7 @@ urlpatterns = [
url(r'^$', views.map, name='map'), url(r'^$', views.map, name='map'),
url(r'^productlist/$', views.productList, name='productList'), url(r'^productlist/$', views.productList, name='productList'),
url(r'^regionsearched/$', views.regionSearched, name='regionSearched'), url(r'^regionsearched/$', views.regionSearched, name='regionSearched'),
url(r'^searchsubmit/$', views.SearchSubmitView.as_view(), name='search-submit') url(r'^searchsubmit/$', views.SearchSubmitView.as_view(), name='search-submit'),
url(r'^imgrequest/$', views.requestToImage, name='img-rqst')
] ]
...@@ -10,8 +10,12 @@ from django.views.generic.base import View ...@@ -10,8 +10,12 @@ from django.views.generic.base import View
from django.template import loader from django.template import loader
from urllib import urlencode from urllib import urlencode
import requests, json, unicodedata import requests, json, unicodedata
from apis.sentinel import APISentinel import random, sys, imp
import random
sys.path.append('../')
from geosentinel import APISentinel
sentinel = APISentinel.APISentinel('emmhp', 'geoemm29')
# Create your views here. # Create your views here.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
...@@ -33,6 +37,16 @@ def map(request): ...@@ -33,6 +37,16 @@ def map(request):
# Render the HTML template index.html with the data in the context variable # Render the HTML template index.html with the data in the context variable
return render(request, 'map.html', { "searchForm": form }) return render(request, 'map.html', { "searchForm": form })
#-------------------------------------------------------------------------------
def requestToImage(request):
# print("REQUEST: ", request.POST['value'])
img_link = request.POST['value']
# img_link = img_link[:img_link.find("/") + 2] + "emmhp:geoemm29@" + img_link[img_link.find("/") + 2:]
r = requests.get(img_link, auth=("emmhp", "geoemm29"))
return JsonResponse({'img': r.content})
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def productList(request): def productList(request):
""" """
...@@ -45,13 +59,13 @@ def productList(request): ...@@ -45,13 +59,13 @@ def productList(request):
area = req['polygon'][0] area = req['polygon'][0]
init_date = req['start'][0][:10] init_date = req['start'][0][:10]
end_date = req['end'][0][:10] end_date = req['end'][0][:10]
cloud_percentage = req['cloudPercentage'][0] cloud_percentage = "[0 TO " + req['cloudPercentage'][0] + "]"
## ----- aqui llamada a api sentinel ## ----- aqui llamada a api sentinel
## ----- antes consultar en DB si no se tiene ya el producto ## ----- antes consultar en DB si no se tiene ya el producto
sentinel = APISentinel() products = sentinel.getProducts(area, ("".join(init_date.split('-')), "".join(end_date.split('-'))),
products = sentinel.getProducts(area, init_date, end_date, cloud_percentage) {"platformname": "Sentinel-2", "cloudcoverpercentage": cloud_percentage})
## simulation of 6-digit random id, this will be obtain from sentinel(?) ## simulation of 6-digit random id, this will be obtain from sentinel(?)
# random_id = ''.join(["%s" % random.randint(0, 9) for i in range(0, 6)]) # random_id = ''.join(["%s" % random.randint(0, 9) for i in range(0, 6)])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment