Skip to content

Commit

Permalink
#42 add Positional Accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi authored Feb 25, 2021
1 parent 77e8572 commit 439d943
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 38 deletions.
2 changes: 1 addition & 1 deletion rndt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = (0, 1, 11)
VERSION = (0, 1, 12)
__version__ = ".".join([str(i) for i in VERSION])
__author__ = "geosolutions-it"
__email__ = "[email protected]"
Expand Down
6 changes: 6 additions & 0 deletions rndt/layers/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class Meta:
widget=NumberInput(attrs={"class": "form-control"}),
)

accuracy = forms.FloatField(
label=_("accuracy"),
required=False,
widget=NumberInput(attrs={"class": "form-control"}),
)

def __init__(self, *args, **kwargs):
super(LayerRNDTForm, self).__init__(*args, *kwargs)
lang = get_language()
Expand Down
47 changes: 24 additions & 23 deletions rndt/layers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,30 @@ def layer_metadata(

# get cleaned form values
items = constraint_form.cleaned_data
if items["access_contraints"]:
# create the constraints_other required for RNDT
keyword = ThesaurusKeyword.objects.get(id=items['access_contraints'])
# get the layer available or create it
available = LayerRNDT.objects.filter(layer=layer)
# if the object does not exists, will save it for the first time
if not available.exists():
available = LayerRNDT(
layer=layer,
constraints_other=keyword.about,
resolution=items["resolution"],
)
# save the new value in the DB
available.save()
else:
# if the object exists and the constraing_other is changed
# the value will be updated
available = available.first()
if not available.is_equal(keyword.about):
available.constraints_other = keyword.about
available.resolution = items["resolution"]
# save the new value in the DB
available.save()
# create the constraints_other required for RNDT
keyword_id = items['access_contraints']
keyword = ThesaurusKeyword.objects.get(id=keyword_id) if keyword_id else None
# get the layer available or create it
available = LayerRNDT.objects.filter(layer=layer)
# if the object does not exists, will save it for the first time
if not available.exists():
available = LayerRNDT(
layer=layer,
constraints_other=keyword.about if keyword else None,
resolution=items["resolution"],
accuracy=items["accuracy"],
)
# save the new value in the DB
available.save()
else:
# if the object exists and the constraing_other is changed
# the value will be updated
available = available.first()
available.constraints_other = keyword.about
available.resolution = items["resolution"]
available.accuracy = items["accuracy"]
# save the new value in the DB
available.save()

# get the value to be saved in constraints_other
layer_constraint = (
Expand Down
18 changes: 18 additions & 0 deletions rndt/migrations/0005_layerrndt_accuracy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.16 on 2021-02-25 16:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('rndt', '0004_layerrndt_resolution'),
]

operations = [
migrations.AddField(
model_name='layerrndt',
name='accuracy',
field=models.FloatField(default=None, null=True),
),
]
2 changes: 1 addition & 1 deletion rndt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.db.models import signals
from django.db.models.signals import post_save
from django.dispatch import receiver

from geonode.base.models import Link, resourcebase_post_save
from geonode.groups.models import GroupProfile
from geonode.layers.models import Layer, ResourceBase
Expand Down Expand Up @@ -118,6 +117,7 @@ class LayerRNDT(models.Model):
layer = models.OneToOneField(Layer, on_delete=models.CASCADE)
constraints_other = models.TextField(default=None, null=True)
resolution = models.FloatField(default=None, null=True)
accuracy = models.FloatField(default=None, null=True)

def __str__(self):
return f"{self.layer.title}: {self.constraints_other}"
Expand Down
20 changes: 11 additions & 9 deletions rndt/templates/layouts/panels.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,19 @@
</div>
</div>
<div class="col-xs-12 col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">{% trans "Resolution" %}</div>
<div class="panel-body">
<span><label for="id_resolution" class="control-label required-field">{% trans "Resolution" %}</label></span><br>
<div class="input-group">
<div class="input-group-addon">mt</div>
{{ LayerRNDTForm.resolution|get_resolution_value:layer.id }}
</div>
</div>
<div class="">
<span><label for="id_resolution" class="control-label required-field">{% trans "Resolution" %}</label></span><br>
<div class="input-group">
<div class="input-group-addon">mt</div>
{{ LayerRNDTForm.resolution|get_resolution_value:layer.id }}
</div>
<span><label for="id_resolution" class="control-label required-field">{% trans "Positional Accuracy" %}</label></span><br>
<div class="input-group">
<div class="input-group-addon">mt</div>
{{ LayerRNDTForm.accuracy|get_accuracy_value:layer.id }}
</div>
</div>
</div>
</div>
</div>
{% endblock other_tab %}
5 changes: 2 additions & 3 deletions rndt/templates/xml/template-rndt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
{% if keyword.thesaurus.id == thesaurus_id %}
<gmd:keyword>
<gmx:Anchor
xlink:href="{{keyword.about}}">{{keyword|get_keyword_label}}</gmx:Anchor>
xlink:href="{{keyword.about}}">{{keyword.alt_label}}</gmx:Anchor>
</gmd:keyword>
{% endif %}
{% endfor %}
Expand Down Expand Up @@ -747,8 +747,7 @@
</gmd:valueUnit>
<gmd:value>
<gco:Record>
{# TODO #}
<gco:Real>1.0</gco:Real>
<gco:Real>{{layer.id|get_positional_accuracy}}</gco:Real>
</gco:Record>
</gmd:value>
</gmd:DQ_QuantitativeResult>
Expand Down
5 changes: 5 additions & 0 deletions rndt/templatetags/metadata_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ def is_url(item):
return True
except:
return False


@register.filter
def get_positional_accuracy(layer_id):
return LayerRNDT.objects.get(layer_id=layer_id).accuracy
11 changes: 10 additions & 1 deletion rndt/templatetags/rndt_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@ def get_other_constraint(constraint_id, layer_id):

@register.filter
def get_resolution_value(value, layer_id):
return get_numeric(value, layer_id, "resolution")


@register.filter
def get_accuracy_value(value, layer_id):
return get_numeric(value, layer_id, "accuracy")


def get_numeric(value, layer_id, category):
layer = LayerRNDT.objects.filter(layer=layer_id)
if layer.exists():
value.initial = layer.get().resolution
value.initial = getattr(layer.get(), category)
return value
return value

0 comments on commit 439d943

Please sign in to comment.