Skip to content

Commit

Permalink
- Improvements for gnip #2211
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Sep 23, 2015
1 parent c855b07 commit d7a4706
Show file tree
Hide file tree
Showing 31 changed files with 1,059 additions and 55 deletions.
2 changes: 1 addition & 1 deletion geonode/base/templates/base/resourcebase_info_panel.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load i18n %}

<article itemscope itemtype="http://schema.org/Dataset" class="description tab-pane active" id="info">
<article itemscope itemtype="http://schema.org/Dataset" class="description tab-pane {% if not tab or tab == 'info' %}active{% endif %}" id="info">
<dl class="dl-horizontal">
{% if resource.title %}
<dt>{% trans "Title" %}</dt>
Expand Down
8 changes: 8 additions & 0 deletions geonode/geoserver/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,13 @@ def geoserver_urls(request):
dict()).get(
'TIME_ENABLED',
False),
MOSAIC_ENABLED=getattr(
settings,
'UPLOADER',
dict()).get(
'OPTIONS',
dict()).get(
'MOSAIC_ENABLED',
False),
)
return defaults
33 changes: 33 additions & 0 deletions geonode/geoserver/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,3 +1651,36 @@ def _fixup_ows_url(thumb_spec):
gspath = '"' + ogc_server_settings.public_url # this should be in img src attributes
repl = '"' + ogc_server_settings.LOCATION
return re.sub(gspath, repl, thumb_spec)

def mosaic_delete_first_granule(cat, layer):
# - since GeoNode will uploade the first granule again through the Importer, we need to /
# delete the one created by the gs_config
cat._cache.clear()
store = cat.get_store(layer)
coverages = cat.mosaic_coverages(store)

granule_id = layer + ".1"

cat.mosaic_delete_granule(coverages['coverages']['coverage'][0]['name'], store, granule_id)

def set_time_dimension(cat, layer, time_presentation, time_presentation_res, time_presentation_default_value, time_presentation_reference_value):
# configure the layer time dimension as LIST
cat._cache.clear()

presentation = time_presentation
if not presentation:
presentation = "LIST"

resolution = None
if time_presentation == 'DISCRETE_INTERVAL':
resolution = time_presentation_res

strategy = None
if time_presentation_default_value and not time_presentation_default_value == "":
strategy = time_presentation_default_value

timeInfo = DimensionInfo("time", "true", presentation, resolution, "ISO8601", None, attribute="time", strategy=strategy, reference_value=time_presentation_reference_value)

resource = cat.get_layer(layer).resource
resource.metadata = {'time':timeInfo}
cat.save(resource)
1 change: 1 addition & 0 deletions geonode/geoserver/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def setUp(self):
'BACKEND': 'geonode.rest',
'OPTIONS': {
'TIME_ENABLED': False,
'MOSAIC_ENABLED': False,
'GEOGIG_ENABLED': False}}

self.DATABASE_DEFAULT_SETTINGS = {
Expand Down
17 changes: 17 additions & 0 deletions geonode/layers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@

cov_exts = ['.tif', '.tiff', '.geotiff', '.geotif']

TIME_REGEX = (
('[0-9]{8}', _('YYYYMMDD')),
('[0-9]{8}T[0-9]{6}', _("YYYYMMDD'T'hhmmss")),
('[0-9]{8}T[0-9]{6}Z', _("YYYYMMDD'T'hhmmss'Z'")),
)

TIME_REGEX_FORMAT = {
'[0-9]{8}': '%Y%m%d',
'[0-9]{8}T[0-9]{6}': '%Y%m%dT%H%M%S',
'[0-9]{8}T[0-9]{6}Z': '%Y%m%dT%H%M%SZ'
}

class Style(models.Model):

Expand Down Expand Up @@ -85,6 +96,12 @@ class Layer(ResourceBase):
name = models.CharField(max_length=128)
typename = models.CharField(max_length=128, null=True, blank=True)

is_mosaic = models.BooleanField(default=False)
has_time = models.BooleanField(default=False)
has_elevation = models.BooleanField(default=False)
time_regex = models.CharField(max_length=128, null=True, blank=True, choices=TIME_REGEX)
elevation_regex = models.CharField(max_length=128, null=True, blank=True)

default_style = models.ForeignKey(
Style,
related_name='layer_default_style',
Expand Down
111 changes: 105 additions & 6 deletions geonode/layers/templates/layers/layer_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% load dialogos_tags %}
{% load agon_ratings_tags %}
{% load bootstrap_tags %}
{% load pagination_tags %}
{% load url from future %}
{% load base_tags %}
{% load guardian_tags %}
Expand Down Expand Up @@ -50,7 +51,106 @@ <h2 class="page-title">{{ resource.title|default:resource.typename }}</h2>

{% include "base/resourcebase_info_panel.html" %}

{% if resource.is_mosaic %}
<article id="granules" class="description tab-pane {% if tab and tab == 'granules' %}active{% endif %}">
<div class="paginate-contents">

<form method="GET" action="{% url "layer_detail" resource.layer.service_typename %}">
{% csrf_token %}
<input type="text" id="filter" name="filter" style="witdh:400px"/>&nbsp;<input type="submit" value='{% trans "Filter Granules" %}'/>
</br>
{% if filter %}
<strong>{% trans "Active Filter:" %}</strong> <em>{{ filter }}</em>
{% endif %}
</form>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<!-- th>{% trans "Granule ID" %}</th -->
<th>{% trans "Bounding Box" %} (minX,minY,maxX,maxY)</th>
<th>{% trans "Time" %}</th>
<!-- th>{% trans "Elevation" %}</th -->
<th>{% trans "Actions" %}</th>
</tr>
</thead>
<tbody>
{% autopaginate all_granules.features 10 %}
{% for feature in granules.features %}
<tr>
<!-- td>{{ feature.id }}</td -->
<td><script language="Javascript">var bbox = JSON.parse('{{ feature.geometry.coordinates }}'); document.write('{{ granules.crs.properties.name }};' + bbox[0][0][0] + ',' + bbox[0][0][1] + ',' + bbox[0][2][0] + ',' + bbox[0][2][1]);</script></td>
<td>{% if feature.properties.time %}{{ feature.properties.time }}{% endif %}</td>
<!-- td>{% if feature.properties.elevation %}{{ feature.properties.elevation }}{% endif %}</td -->
<td>
<a class="btn btn-xs" href="#" onclick="doPreview('{{ resource.service_typename }}', '{{ feature.id }}', '{{ granules.crs.properties.name }}', '{{ feature.geometry.coordinates }}', {% if feature.properties.time %}'{{ feature.properties.time }}'{% else %}null{% endif %});"><img alt="Granule Preview" title="Granule Preview" src="/static/lib/img/map_go.png"/></a>
<a class="btn btn-xs" href="{% url "layer_granule_remove" feature.id resource.service_typename %}"><img alt="Granule Remove" title="Granule Remove" src="/static/lib/img/cancel-on.png"/></a>
<script language="Javascript">
function doPreview(layer_name, feature_id, srs, the_geom, time) {
var map = app.mapPanel.map;
for (var ll = 0; ll < app.map.layers.length; ll++) {
var layer = app.map.layers[ll];
if (layer.name == layer_name) {
if (time) {
var re = new RegExp("(\\+[0-9]{4})", "gm");
var timePosition = time;
if (re.test(time)) timePosition = time.replace(re, 'Z');
map.layers[ll].mergeNewParams({"TIME" : timePosition, "CQL_FILTER" : "IN ('" + feature_id + "')"});
}
else {
map.layers[ll].mergeNewParams({"CQL_FILTER" : "IN ('" + feature_id + "')"});
}

map.layers[ll].addOptions({
singleTile: true
});

bbox = JSON.parse(the_geom);
bbox = new OpenLayers.Bounds(bbox[0][0][0],bbox[0][0][1],bbox[0][2][0],bbox[0][2][1]).transform(srs, map.projection);

//map.maxExtent = bbox;
//map.restrictedExtent = bbox;
map.maxExtent = new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34);
map.restrictedExtent = map.maxExtent;

map.zoomToExtent(bbox);
}
}
}
</script>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% paginate %}
</article>
{% endif %}

<article id="attributes" class="tab-pane">
{% if resource.is_mosaic %}
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>{% trans "Dimension" %}</th>
<th>{% trans "Enabled" %}</th>
<th>{% trans "Regex" %}</th>
</tr>
</thead>
<tbody>
<tr>
<td title="TIME">{% trans "TIME" %}</td>
<td>{% if resource.has_time %}{% trans "True" %}{% else %}{% trans "False" %}{% endif %}</td>
<td>{% if resource.time_regex %}{{ resource.time_regex }}{% else %}&nbsp;{% endif %}</td>
</tr>
<!-- tr>
<td title="ELEVATION">{% trans "ELEVATION" %}</td>
<td>{% if resource.has_elevation %}{% trans "True" %}{% else %}{% trans "False" %}{% endif %}</td>
<td>{% if resource.elevation_regex %}{{ resource.elevation_regex }}{% else %}&nbsp;{% endif %}</td>
</tr -->
</tbody>
</table>
{% endif %}
{% if resource.attribute_set.all %}
<table class="table table-striped table-bordered table-condensed">
<thead>
Expand Down Expand Up @@ -148,7 +248,6 @@ <h4>{% trans 'Average Rating' %}</h4>
{% endif %}
</li>
{% endif %}
</ul>
<div class="modal fade" id="download-layer" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
Expand Down Expand Up @@ -176,7 +275,7 @@ <h4 class="modal-title" id="myModalLabel">{% trans "Download Layer" %}</h4>
{% get_obj_perms request.user for resource.layer as "layer_perms" %}
{% endif %}
{% if "change_resourcebase_metadata" in perms_list or "change_resourcebase" in perms_list or "delete_resourcebase" in perms_list or "change_layer_style" in layer_perms %}
<li class="list-group-item">
<li class="list-group-item">
<button class="btn btn-primary btn-md btn-block" data-toggle="modal" data-target="#edit-layer">{% trans "Edit Layer" %}</button>
</li>
<div class="modal fade" id="edit-layer" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
Expand Down Expand Up @@ -299,7 +398,7 @@ <h4>{% trans "Create a map using this layer" %}</h4>
<h4>{% trans "Documents related to this layer" %}</h4>
<p>{% trans "List of documents related to this layer:" %}</p>
<ul class="list-unstyled">
{% for document in documents %}
{% for document in documents %}
<li><a href="{{ document.get_absolute_url }}">{{ document.title }}</a></li>
{% endfor %}
</ul>
Expand Down Expand Up @@ -346,11 +445,11 @@ <h4>{% trans "External service layer" %}</h4>
</li>
{% endif %}

{% include "base/_resourcebase_contact_snippet.html" %}
{% include "base/_resourcebase_contact_snippet.html" %}
</ul>


{% if GEONODE_SECURITY_ENABLED %}
{% if GEONODE_SECURITY_ENABLED %}
{% include "_permissions_form.html" %}
{% endif %}

Expand Down Expand Up @@ -381,7 +480,7 @@ <h4>{% trans "External service layer" %}</h4>
data: $("#form_post_comment").serialize(),
success: function() {
$('#form_post_comment_div').modal('hide');
$('#comments_section').load(window.location.pathname + ' #comments_section',
$('#comments_section').load(window.location.pathname + ' #comments_section',
function(){$(this).children().unwrap()})
}
});
Expand Down
47 changes: 47 additions & 0 deletions geonode/layers/templates/layers/layer_geoext_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,53 @@
};

config = Ext.apply(config, {{ viewer|safe }});

//
// Extrapolating the granules times
//
var is_mosaic = "{{resource.is_mosaic}}" == "True" ? true : false;
if(is_mosaic){
var resource_name = "{{resource.name}}";

var granules_features = {% if all_granules %} {{all_granules.features}} {% else %} [] {% endif %};

var time_list = [];
for(var i=0; i<granules_features.length; i++){
var feature = granules_features[i];

if(feature.properties.time){
var date = new Date(feature.properties.time);
var time = date.toISOString();

if(time){
time_list.push(time);
}
}
}

//
// Setting the time dimension accordingly to the granule time list
//
var layers = config.map.layers;
for(var layer in layers){
l = layers[layer];
if(!l.background && l.name && l.name.indexOf(resource_name) != -1){
l.dimensions = {
time:{
"name":"time",
"units":"ISO8601",
"unitsymbol":null,
"nearestVal":false,
"multipleVal":false,
"current":false,
"default":"current",
"values": time_list // granule time list
}
}
}
}
}

app = new GeoExplorer.Viewer(config);

for (var key in app.tools) {
Expand Down
40 changes: 40 additions & 0 deletions geonode/layers/templates/layers/layer_granule_remove.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends "layers/layer_base.html" %}
{% load i18n %}

{% block title %}{{ layer.typename }} — {{ block.super }}{% endblock %}

{% block body %}
<div class="page-header">
<a href="{% url "layer_browse" %}" class="btn btn-primary pull-right">{% trans "Explore Layers" %}</a>
<h2 class="page-title">{% trans "Remove Mosaic Granules" %}</h2>
</div>
<div class="row">
<div class="col-md-8">
<p class="lead">
{% blocktrans with layer.typename as layer_title %}
Are you sure you want to remove Granule {{ granule_id }} of the Mosaic <a href="{{ layer.get_absolute_url }}">{{ layer_title }}</a>?
{% endblocktrans %}
</p>
<form action="{% url "layer_granule_remove" granule_id layer.service_typename %}" method="POST">
{% csrf_token %}
<input type="hidden" value="{{ layer.service_typename }}" />
<div class="form-actions">
<input type="submit" value="{% trans "Yes, I am sure" %}" class="btn btn-danger" />
<a href="{{ layer.get_absolute_url }}" class="btn btn-default">{% trans "No, don't remove it" %}</a>
</div>
</form>
</div>
{% if layer.maps %}
<div class="col-md-4">
<ul class="nav nav-list">
<li class="nav-header">{% trans "This action affects the following maps:" %}</li>
{% for map_layer in layer.maps %}
<li><a href="{{ map_layer.map.get_absolute_url }}">{{ map_layer.map.title }}</a></li>
{% empty %}
<li>{% trans "No maps are using this layer" %}</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
{% endblock %}
1 change: 1 addition & 0 deletions geonode/layers/templates/layers/layer_replace.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ <h3>{% trans "Permissions" %}</h3>
form_target = "{% url "layer_replace" layer.service_typename %}",
geogig_enabled = {{ GEOGIG_ENABLED|lower }},
time_enabled = {{ TIME_ENABLED|lower }},
mosaic_enabled = {{ MOSAIC_ENABLED|lower }},
userLookup = "{% url "geonode.views.ajax_lookup" %}"

{% endautoescape %}
Expand Down
17 changes: 17 additions & 0 deletions geonode/layers/templates/upload/layer_upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
<div class="page-header">
<a href="{% url "layer_browse" %}" class="btn btn-primary pull-right">{% trans "Explore Layers" %}</a>
<h2 class="page-title">{% trans "Upload Layers" %}</h2>

<script language="javascript">
var json_mosaics = [
{% for mosaic in mosaics %}
{
"name" : "{{mosaic.name}}",
"workspace" : "{{mosaic.workspace}}",
"is_mosaic" : "{{mosaic.is_mosaic}}",
"has_time" : "{{mosaic.has_time}}",
"has_elevation" : "{{mosaic.has_elevation}}",
"time_regex" : "{{mosaic.time_regex}}",
"elevation_regex" : "{{mosaic.elevation_regex}}"
},
{% endfor %}
]
</script>
</div>
<div class="row">
<div class="col-md-8">
Expand Down Expand Up @@ -112,6 +128,7 @@ <h3>{% trans "Permissions" %}</h3>
form_target = "{{ UPLOADER_URL }}",
geogig_enabled = {{ GEOGIG_ENABLED|lower }},
time_enabled = {{ TIME_ENABLED|lower }},
mosaic_enabled = {{ MOSAIC_ENABLED|lower }},
userLookup = "{% url "geonode.views.ajax_lookup" %}"

{% endautoescape %}
Expand Down
Loading

0 comments on commit d7a4706

Please sign in to comment.