mirror of
https://github.com/HaitiData/haitidata.git
synced 2026-11-03 05:25:47 +00:00
enable layer filtering by region bbox
This commit is contained in:
1 parent
a5fb0c8a6f
commit
89f1de552c
11 files changed
+146
-2
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '24_to_26'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='RegionBBox',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('bbox_x0', models.DecimalField(null=True, max_digits=19, decimal_places=10, blank=True)),
|
||||
('bbox_x1', models.DecimalField(null=True, max_digits=19, decimal_places=10, blank=True)),
|
||||
('bbox_y0', models.DecimalField(null=True, max_digits=19, decimal_places=10, blank=True)),
|
||||
('bbox_y1', models.DecimalField(null=True, max_digits=19, decimal_places=10, blank=True)),
|
||||
('region', models.OneToOneField(to='base.Region')),
|
||||
],
|
||||
),
|
||||
]
|
||||
Whitespace-only changes.
@@ -0,0 +1,11 @@
|
||||
from django.db import models
|
||||
|
||||
from geonode.base.models import Region
|
||||
|
||||
|
||||
class RegionBBox(models.Model):
|
||||
region = models.OneToOneField(Region, on_delete=models.CASCADE)
|
||||
bbox_x0 = models.DecimalField(max_digits=19, decimal_places=10, blank=True, null=True)
|
||||
bbox_x1 = models.DecimalField(max_digits=19, decimal_places=10, blank=True, null=True)
|
||||
bbox_y0 = models.DecimalField(max_digits=19, decimal_places=10, blank=True, null=True)
|
||||
bbox_y1 = models.DecimalField(max_digits=19, decimal_places=10, blank=True, null=True)
|
||||
@@ -0,0 +1,86 @@
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from geonode.api.resourcebase_api import CommonModelApi, CommonMetaApi
|
||||
from geonode.layers.models import Layer
|
||||
from geonode.base.models import Region
|
||||
|
||||
|
||||
class CommonModelApiExt(CommonModelApi):
|
||||
def apply_filters(self, request, applicable_filters):
|
||||
types = applicable_filters.pop('type', None)
|
||||
extent = applicable_filters.pop('extent', None)
|
||||
keywords = applicable_filters.pop('keywords__slug__in', None)
|
||||
region = applicable_filters.get('regions__name__in', None)
|
||||
region_bbox = None
|
||||
if region:
|
||||
print('region is ', region)
|
||||
try:
|
||||
region_obj = Region.objects.get(name=region[0])
|
||||
except Region.DoesNotExist:
|
||||
print 'it does not exists'
|
||||
else:
|
||||
print('db record', region_obj.name_en)
|
||||
try:
|
||||
regionbbox_obj = region_obj.regionbbox
|
||||
except ObjectDoesNotExist:
|
||||
print 'regionbbox does not exist'
|
||||
else:
|
||||
print(str(regionbbox_obj.bbox_x0))
|
||||
bbox = [regionbbox_obj.bbox_x0, regionbbox_obj.bbox_y0, regionbbox_obj.bbox_x1, regionbbox_obj.bbox_y1]
|
||||
bbox_valid = not any(coo is None for coo in bbox)
|
||||
if bbox_valid:
|
||||
region_bbox = ','.join([str(coo) for coo in bbox])
|
||||
del applicable_filters['regions__name__in']
|
||||
extent = None
|
||||
print region_bbox
|
||||
else:
|
||||
print 'bbox not valid'
|
||||
|
||||
semi_filtered = super(
|
||||
CommonModelApi,
|
||||
self).apply_filters(
|
||||
request,
|
||||
applicable_filters)
|
||||
filtered = None
|
||||
if types:
|
||||
for the_type in types:
|
||||
if the_type in LAYER_SUBTYPES.keys():
|
||||
if filtered:
|
||||
filtered = filtered | semi_filtered.filter(
|
||||
Layer___storeType=LAYER_SUBTYPES[the_type])
|
||||
else:
|
||||
filtered = semi_filtered.filter(
|
||||
Layer___storeType=LAYER_SUBTYPES[the_type])
|
||||
else:
|
||||
if filtered:
|
||||
filtered = filtered | semi_filtered.instance_of(
|
||||
FILTER_TYPES[the_type])
|
||||
else:
|
||||
filtered = semi_filtered.instance_of(
|
||||
FILTER_TYPES[the_type])
|
||||
else:
|
||||
filtered = semi_filtered
|
||||
|
||||
if extent:
|
||||
filtered = self.filter_bbox(filtered, extent)
|
||||
|
||||
if keywords:
|
||||
filtered = self.filter_h_keywords(filtered, keywords)
|
||||
|
||||
if region_bbox:
|
||||
filtered = self.filter_bbox(filtered, region_bbox)
|
||||
print 'filtering by bbox: ', region_bbox
|
||||
|
||||
return filtered
|
||||
|
||||
|
||||
class LayerExtResource(CommonModelApiExt):
|
||||
"""Layer Ext API"""
|
||||
|
||||
class Meta(CommonMetaApi):
|
||||
queryset = Layer.objects.distinct().order_by('-date')
|
||||
if settings.RESOURCE_PUBLISHING:
|
||||
queryset = queryset.filter(is_published=True)
|
||||
resource_name = 'layers'
|
||||
excludes = ['csw_anytext', 'metadata_xml']
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -0,0 +1,9 @@
|
||||
from tastypie.api import Api
|
||||
|
||||
#from geonode.api.resourcebase_api import LayerResource
|
||||
from filter.resourcebase_api import LayerExtResource
|
||||
|
||||
|
||||
api_ext = Api(api_name='api')
|
||||
|
||||
api_ext.register(LayerExtResource())
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
@@ -62,7 +62,8 @@ INSTALLED_APPS = INSTALLED_APPS + (
|
||||
'geonode-client',
|
||||
'charts_app',
|
||||
'wfs_harvest',
|
||||
"clip-and-ship"
|
||||
"clip-and-ship",
|
||||
'filter'
|
||||
)
|
||||
|
||||
LAYER_PREVIEW_LIBRARY = 'react'
|
||||
|
||||
+4
-1
@@ -4,14 +4,17 @@ from osgeo_importer.urls import urlpatterns as importer_urlpatterns
|
||||
|
||||
from geonode.urls import *
|
||||
|
||||
from filter.urls import api_ext
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^/?$',
|
||||
TemplateView.as_view(template_name='site_index.html'),
|
||||
name='home'),
|
||||
url(r'', include(api_ext.urls))
|
||||
) + urlpatterns + [
|
||||
url(r'^chart/', include('charts_app.urls')),
|
||||
url(r'^table/', include('wfs_harvest.urls')),
|
||||
url(r'^clip/', include('clip-and-ship.urls'))
|
||||
url(r'^clip/', include('clip-and-ship.urls')),
|
||||
]
|
||||
|
||||
urlpatterns += patterns(
|
||||
|
||||
Reference in new issue
Block a user