コード例 #1
0
    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
コード例 #2
0
ファイル: views.py プロジェクト: boubafanta/lampadaires
def geodata(request):
	if request.method=='GET':
		try:
        		x=float(request.GET['x'])
        		y=float(request.GET['y'])
        		p=float(request.GET['p'])
        		pt= Point(x,y,srid=4326)
        		pt.transform(32628)
		except Exception:
        		pass
		geojson = Serializer().serialize(
		#Lampadaire.objects.all()[:100],
		Lampadaire.objects.filter(geom__dwithin=(pt,D(m=p) ) ) )
		return HttpResponse(
			geojson,
        		content_type="application/json"
    		)
	elif request.method == 'POST':
		#s=request.POST.get['statut']
		s=request.POST['statut']
		id_lampe=float(request.POST['id'])
		sama_lampe=get_object_or_404(Lampadaire, gid=id_lampe)
		sama_lampe.states=s
		sama_lampe.save()
		geojson = Serializer().serialize(Lampadaire.objects.filter(gid=id_lampe))
		return HttpResponse(
			geojson,
        		content_type="application/json"
    		)
コード例 #3
0
ファイル: views.py プロジェクト: zdimon/fbr
    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
コード例 #4
0
    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
コード例 #5
0
ファイル: views.py プロジェクト: Chedi/france_geo_queries
    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))
コード例 #6
0
ファイル: geojson_tags.py プロジェクト: ozzmos/django-geojson
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
コード例 #7
0
ファイル: admin.py プロジェクト: zdimon/forestry
    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
コード例 #8
0
ファイル: admin.py プロジェクト: zdimon/forestry
    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
コード例 #9
0
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
コード例 #10
0
ファイル: views.py プロジェクト: boubafanta/lampadaires
def denthialma(request):
		#s=request.POST.get['statut']
		s=request.GET['statut']
		id_lampe=float(request.GET['id'])
		sama_lampe=get_object_or_404(Lampadaire, gid=id_lampe)
		sama_lampe.states=s
		sama_lampe.save()
		geojson = Serializer().serialize(Lampadaire.objects.filter(gid=id_lampe))
		return HttpResponse(
			geojson,
        		content_type="application/json"
    		)
コード例 #11
0
    datamodel = descriptor.dymodel

    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):