def render_to_response(self, context, **response_kwargs): from fbr.settings import BASE_DIR import os.path cpath = BASE_DIR + '/map_cache/burning_' + self.request.GET[ 'time'] + '.txt' if (os.path.exists(cpath)): from django.http import HttpResponse f = open(cpath, 'r') out = f.read() f.close() return HttpResponse(out, content_type="application/json") """ Returns a JSON response, transforming 'context' to make the payload. """ serializer = GeoJSONSerializer() response = self.response_class(**response_kwargs) options = dict(properties=self.properties, srid=self.srid, geometry_field=self.geometry_field, force2d=self.force2d) serializer.serialize(self.get_queryset(), stream=response, ensure_ascii=False, **options) #import pdb; pdb.set_trace() #f = open(cpath,'w') #f.write(response.content) #f.close() return response
def render_to_response(self, context, **response_kwargs): from fbr.settings import BASE_DIR import os.path cpath = BASE_DIR+'/map_cache/cotter.txt' if(os.path.exists(cpath)): from django.http import HttpResponse f = open(cpath,'r') out = f.read() f.close() return HttpResponse(out, content_type="application/json") """ Returns a JSON response, transforming 'context' to make the payload. """ serializer = GeoJSONSerializer() response = self.response_class(**response_kwargs) options = dict(properties=self.properties, precision=self.precision, simplify=self.simplify, srid=self.srid, geometry_field=self.geometry_field, force2d=self.force2d) serializer.serialize(self.get_queryset(), stream=response, ensure_ascii=False, **options) #import pdb; pdb.set_trace() f = open(cpath,'w') f.write(response.content) f.close() return response
def render_to_response(self, context, **response_kwargs): """ Returns a JSON response, transforming 'context' to make the payload. """ serializer = GeoJSONSerializer() response = self.response_class(**response_kwargs) queryset = self.get_queryset() options = dict(properties=self.properties, precision=self.precision, simplify=self.simplify, srid=self.srid, geometry_field=self.geometry_field, force2d=self.force2d, bbox=self.bbox, bbox_auto=self.bbox_auto, use_natural_keys=self.use_natural_keys) serializer.serialize( queryset, stream=response, ensure_ascii=False, crs=self. crs, # in geoJSON crs is deprecated, raises error 36 in ol.source **options) return response
def render_to_response(self, context, **response_kwargs): """ Returns a JSON response, transforming 'context' to make the payload. """ serializer = GeoJSONSerializer() response = self.response_class(**response_kwargs) options = dict(properties=self.properties, precision=self.precision, simplify=self.simplify, srid=self.srid, geometry_field=self.geometry_field, force2d=self.force2d) serializer.serialize(self.get_queryset(), stream=response, ensure_ascii=False, **options) return response
def get(self, request, id=None): source = [] serializer = Serializer() properties = ['id', 'nom'] if id is not None: source = Commune.objects.filter(canton__arrondissement__departement=id) properties.append('zip') else: source = Departement.objects.all() return Response(serializer.serialize(source, properties=properties, geometry_field='geom', srid=4326))
def geojsonfeature(obj, srid=None): if obj is None or isinstance(obj, basestring): return 'null' if srid is None: # Try to guess SRID from potential settings srid = getattr(settings, 'API_SRID', getattr(settings, 'MAP_SRID', getattr(settings, 'SRID', 4326))) geojsonvalue = '' if isinstance(obj, (GEOSGeometry, GeometryField)): if obj.srid != srid: obj.transform(srid) feature = geojson.Feature(geometry=simplejson.loads(obj.geojson)) geojsonvalue = geojson.dumps(feature) elif hasattr(obj, '__iter__'): serializer = Serializer() geojsonvalue = serializer.serialize(obj, fields=[], srid=srid) else: serializer = Serializer() geojsonvalue = serializer.serialize([obj], fields=[], srid=srid) return geojsonvalue
def geojsonfeature(obj, srid=None): if obj is None or isinstance(obj, basestring): return 'null' if srid is None: # Try to guess SRID from potential settings srid = getattr(settings, 'API_SRID', getattr(settings, 'MAP_SRID', getattr(settings, 'SRID', 4326))) geojsonvalue = '' if isinstance(obj, (GEOSGeometry, GeometryField)): if obj.srid != srid: obj.transform(srid) feature = geojson.Feature(geometry=simplejson.loads(obj.geojson)) geojsonvalue = geojson.dumps(feature) else: serializer = Serializer() geojsonvalue = serializer.serialize([obj], fields=[], srid=srid) return geojsonvalue
out = {} objs = datamodel.Dataset.objects.all() #.geojson() limit = request.GET.get('limit', None) offset = request.GET.get('offset', None) #out_objs = collect_queryset_rows(objs, offset, limit) #vectorformats #djf = Django.Django(geodjango='geom') #geoj = GeoJSON.GeoJSON() #out_objs = geoj.encode(djf.decode(objs)) serializer = GeoJSONSerializer() out_objs = serializer.serialize(objs, fields=datamodel.non_geo_fields) out = {} out['rows'] = out_objs out['descriptor'] = instance_dict(descriptor, recursive=True, related_names=['items'], properties=['metadata']) response.result = out return response.as_http_response() def dataset_geodata_ajax_chunks(request, descriptor_id): response = AjaxResponse()