add a geojson export of visualization data (fixes #15180)
This commit is contained in:
parent
62d181a384
commit
6d3f6c7716
|
@ -27,6 +27,19 @@ psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
|
|||
psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
|
||||
|
||||
|
||||
def cast_point(value, cur):
|
||||
if value is None:
|
||||
return None
|
||||
return schemas.Point._make(map(float, value[1:-1].split(',')))
|
||||
|
||||
|
||||
POINT = psycopg2.extensions.new_type((600,), "POINT", cast_point)
|
||||
psycopg2.extensions.register_type(POINT)
|
||||
|
||||
POINT_ARRAY = psycopg2.extensions.new_array_type((1017,), "POINT[]", POINT)
|
||||
psycopg2.extensions.register_type(POINT_ARRAY)
|
||||
|
||||
|
||||
def to_tuple(cur, values):
|
||||
return cur.mogrify(', '.join(['%s'] * len(values)), values)
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import collections
|
|||
|
||||
from .relative_time import RelativeDate
|
||||
|
||||
Point = collections.namedtuple('Point', ['x', 'y'])
|
||||
|
||||
TYPE_MAP = {
|
||||
'duration': datetime.timedelta,
|
||||
|
@ -29,6 +30,7 @@ TYPE_MAP = {
|
|||
'integer': int,
|
||||
'decimal': decimal.Decimal,
|
||||
'percent': float,
|
||||
'point': Point,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ INSTALLED_APPS = (
|
|||
'xstatic.pkg.chartnew_js',
|
||||
'django_select2',
|
||||
'gadjo',
|
||||
'rest_framework',
|
||||
'bijoe',
|
||||
'bijoe.visualization',
|
||||
)
|
||||
|
|
|
@ -192,7 +192,8 @@ class CubeForm(forms.Form):
|
|||
required=False)
|
||||
|
||||
# measures
|
||||
choices = [(measure.name, measure.label) for measure in cube.measures]
|
||||
choices = [(measure.name, measure.label)
|
||||
for measure in cube.measures if measure.type != 'point']
|
||||
self.base_fields['measure'] = forms.ChoiceField(
|
||||
label=_('Measure'), choices=choices)
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ urlpatterns = patterns(
|
|||
url(r'warehouse/(?P<warehouse>[^/]*)/(?P<cube>[^/]*)/save/$',
|
||||
views.create_visualization, name='create-visualization'),
|
||||
url(r'(?P<pk>\d+)/$', views.visualization, name='visualization'),
|
||||
url(r'(?P<pk>\d+)/geojson/$', views.visualization_geojson, name='visualization-geojson'),
|
||||
url(r'(?P<pk>\d+)/iframe/$', views.visualization_iframe, name='visualization-iframe'),
|
||||
url(r'(?P<pk>\d+)/rename/$', views.rename_visualization, name='rename-visualization'),
|
||||
url(r'(?P<pk>\d+)/delete/$', views.visualization, name='delete-visualization'),
|
||||
|
|
|
@ -27,6 +27,9 @@ from django.http import HttpResponse, Http404
|
|||
from django.core.exceptions import PermissionDenied
|
||||
from django.views.decorators.clickjacking import xframe_options_exempt
|
||||
|
||||
from rest_framework import generics
|
||||
from rest_framework.response import Response
|
||||
|
||||
from ..utils import get_warehouses
|
||||
from ..engine import Engine
|
||||
from . import models, forms, signature
|
||||
|
@ -230,6 +233,32 @@ class VisualizationsJSONView(MultipleObjectMixin, View):
|
|||
class CubeIframeView(CubeView):
|
||||
template_name = 'bijoe/cube_raw.html'
|
||||
|
||||
|
||||
class VisualizationGeoJSONView(generics.GenericAPIView):
|
||||
permission_classes = ()
|
||||
queryset = models.Visualization.objects.all()
|
||||
|
||||
def get(self, request, pk, format=None):
|
||||
instance = self.get_object()
|
||||
visualization = Visualization.from_json(instance.parameters, request=request)
|
||||
visualization.measure = visualization.cube.measures['geolocation']
|
||||
drilldown = visualization.drilldown
|
||||
geojson = []
|
||||
for row in visualization.data():
|
||||
properties = {}
|
||||
for dim in row[:len(drilldown)]:
|
||||
properties[dim['label']] = dim['value']
|
||||
geojson.append({
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'Multipoint',
|
||||
'coordinates': row[len(drilldown)]['value'] or [],
|
||||
},
|
||||
'properties': properties,
|
||||
})
|
||||
return Response(geojson)
|
||||
|
||||
|
||||
warehouse = WarehouseView.as_view()
|
||||
cube = CubeView.as_view()
|
||||
cube_iframe = xframe_options_exempt(CubeIframeView.as_view())
|
||||
|
@ -240,6 +269,7 @@ delete_visualization = DeleteVisualizationView.as_view()
|
|||
rename_visualization = RenameVisualization.as_view()
|
||||
visualization = VisualizationView.as_view()
|
||||
visualization_iframe = xframe_options_exempt(VisualizationIframeView.as_view())
|
||||
visualization_geojson = VisualizationGeoJSONView.as_view()
|
||||
|
||||
cube_iframe.mellon_no_passive = True
|
||||
visualization_iframe.mellon_no_passive = True
|
||||
|
|
2
setup.py
2
setup.py
|
@ -94,7 +94,7 @@ setup(name="bijoe",
|
|||
include_package_data=True,
|
||||
install_requires=['requests', 'django', 'psycopg2', 'isodate', 'Django-Select2<5',
|
||||
'XStatic-ChartNew.js', 'gadjo', 'django-jsonfield<1.0.0',
|
||||
'python-dateutil'],
|
||||
'python-dateutil', 'djangorestframework<3.4'],
|
||||
scripts=['bijoe-ctl'],
|
||||
cmdclass={
|
||||
'sdist': eo_sdist,
|
||||
|
|
Loading…
Reference in New Issue