示例#1
0
    def get_2d_dataset(self, **kwargs):
        # TODO apply filtering.  Should start supporting CQL soon.
        layers, srs, bbox, width, height, styles, bgcolor, transparent, time, elevation, v, filter = [kwargs[k] if k in kwargs else None for k in ['layers', 'srs', 'bbox', 'width', 'height', 'styles', 'bgcolor', 'transparent', 'time', 'elevation', 'v', 'filter']]
        ds = self.dataset.Clone()
        minx,miny,maxx,maxy = bbox
        if filter is None:
            filter = {}

        if self.requires_time and not time:
            raise Exception("this service requires a time parameter")
        if self.requires_elevation and not elevation:
            raise Exception('this service requires an elevation')

        ss = None
        if type(self.styles) is dict:
            if not styles and 'default' in self.styles:
                ss = self.styles['default']
            elif styles:
                ss = self.styles[styles]
        else:
            ss = self.styles

        ctx = RenderingContext(ss, minx, miny, maxx, maxy, width, height)

        t_srs = osr.SpatialReference()
        t_srs.ImportFromEPSG(int(srs))
        l0 = self.dataset.GetLayer(0)
        s_srs = l0.GetSpatialRef()

        s_mins = Point(minx, miny, srid=t_srs.wkt)
        s_maxs = Point(maxx, maxy, srid=t_srs.wkt)
        s_mins.transform(s_srs.wkt)
        s_maxs.transform(s_srs.wkt)

        ls = {}
        crx = osr.CoordinateTransformation(s_srs, t_srs)

        def xform(f):
            f.SetGeometry(f.geometry().Transform(crx))

        for query_layer in layers:
            ls[query_layer] = ds.GetLayerByName(query_layer)
            ls[query_layer].ResetReading()
            ls[query_layer].SetSpatialFilterRect(s_mins.x, s_mins.y, s_maxs.x, s_maxs.y)

        for query_layer in layers:
            mysrs = self.nativesrs(query_layer)
            if mysrs == srs:
                ctx.render(ls[query_layer], lambda k: k[query_layer])
            else:
                ctx.render(ls[query_layer], lambda k: xform(k[query_layer]))

        return ctx.surface
示例#2
0
文件: wms.py 项目: gijs/ga_ows
    def get_2d_dataset(self, bbox, width, height, query_layers, styles=None, **args):
        minx,miny,maxx,maxy = bbox
        if self.requires_time and 'time' not in args:
            raise Exception("this service requires a time parameter")
        if self.requires_elevation and 'elevation' not in args:
            raise Exception('this service requires an elevation')

        ss = None
        if type(self.styles) is dict:
            if not styles and 'default' in self.styles:
                ss = self.styles['default']
            elif styles:
                ss = self.styles[styles]
       
        ctx = RenderingContext(ss, minx, miny, maxx, maxy, width, height)
       
        default_srid=srid=self.cls.__dict__[query_layers[0]]._field.srid
        if 'srs' in args:
            if args['srs'].upper().startswith('EPSG'):
                srid = int(args['srs'][5:])
            else:
                srid = int(args['srs'])

        geom = GEOSGeometry('SRID={srid};POLYGON(({minx} {miny}, {maxx} {miny}, {maxx} {maxy}, {minx} {maxy}, {minx} {miny}))'.format(srid=srid,minx=minx,miny=miny,maxx=maxx,maxy=maxy))

        flt = dict([(query_layer + "__bboverlaps" , geom) for query_layer in query_layers])
        for k,v in args.items():
            if k[0] == '_':
                flt[k[1:]] = v
            if k == 'time':
                flt[self.time_property] = v
            if k == 'elevation':
                flt[self.elevation_property] = v

        for layer in query_layers:
            if default_srid != srid:
                ctx.render(self.cls.objects.transform(srid).filter(**flt), lambda k: k.__getattribute__(layer))
            else:
                ctx.render(self.cls.objects.filter(**flt), lambda k: k.__getattribute__(layer))

        return ctx.surface
示例#3
0
文件: ogr.py 项目: kob-aha/hydroshare
    def get_2d_dataset(self, **kwargs):
        # TODO apply filtering.  Should start supporting CQL soon.
        layers, srs, bbox, width, height, styles, bgcolor, transparent, time, elevation, v, filter = [
            kwargs[k] if k in kwargs else None for k in [
                'layers', 'srs', 'bbox', 'width', 'height', 'styles',
                'bgcolor', 'transparent', 'time', 'elevation', 'v', 'filter'
            ]
        ]
        ds = self.dataset.Clone()
        minx, miny, maxx, maxy = bbox
        if filter is None:
            filter = {}

        if self.requires_time and not time:
            raise Exception("this service requires a time parameter")
        if self.requires_elevation and not elevation:
            raise Exception('this service requires an elevation')

        ss = None
        if type(self.styles) is dict:
            if not styles and 'default' in self.styles:
                ss = self.styles['default']
            elif styles:
                ss = self.styles[styles]
        else:
            ss = self.styles

        ctx = RenderingContext(ss, minx, miny, maxx, maxy, width, height)

        t_srs = osr.SpatialReference()
        t_srs.ImportFromEPSG(int(srs))
        l0 = self.dataset.GetLayer(0)
        s_srs = l0.GetSpatialRef()

        s_mins = Point(minx, miny, srid=t_srs.wkt)
        s_maxs = Point(maxx, maxy, srid=t_srs.wkt)
        s_mins.transform(s_srs.wkt)
        s_maxs.transform(s_srs.wkt)

        ls = {}
        crx = osr.CoordinateTransformation(s_srs, t_srs)

        def xform(f):
            f.SetGeometry(f.geometry().Transform(crx))

        for query_layer in layers:
            ls[query_layer] = ds.GetLayerByName(query_layer)
            ls[query_layer].ResetReading()
            ls[query_layer].SetSpatialFilterRect(s_mins.x, s_mins.y, s_maxs.x,
                                                 s_maxs.y)

        for query_layer in layers:
            mysrs = self.nativesrs(query_layer)
            if mysrs == srs:
                ctx.render(ls[query_layer], lambda k: k[query_layer])
            else:
                ctx.render(ls[query_layer], lambda k: xform(k[query_layer]))

        return ctx.surface
示例#4
0
文件: wms.py 项目: jmwenda/ga_ows
    def get_2d_dataset(self, layers, srs, bbox, width, height, styles, bgcolor, transparent, time, elevation, v, filter):
        minx,miny,maxx,maxy = bbox
        if filter is None:
            filter = {}

        if self.requires_time and not time:
            raise Exception("this service requires a time parameter")
        if self.requires_elevation and not elevation:
            raise Exception('this service requires an elevation')

        ss = None
        required_fields = tuple()
        if type(self.styles) is dict:
            if not styles and 'default' in self.styles:
                ss = self.styles['default']
            elif styles:
                ss = self.styles[styles]
        else:
            ss = self.styles
            required_fields = ss.required_fields

        ctx = RenderingContext(ss, minx, miny, maxx, maxy, width, height)

        t_srs = djgdal.SpatialReference(srs)
        s_srs = djgdal.SpatialReference(self.nativesrs(layers[0]))

        s_mins = Point(minx, miny, srid=t_srs.wkt)
        s_maxs = Point(maxx, maxy, srid=t_srs.wkt)
        s_mins.transform(s_srs.wkt)
        s_maxs.transform(s_srs.wkt)

        geom = GEOSGeometry('POLYGON(({minx} {miny}, {maxx} {miny}, {maxx} {maxy}, {minx} {maxy}, {minx} {miny}))'.format(
            minx=s_mins.x,
            miny=s_mins.y,
            maxx=s_maxs.x,
            maxy=s_maxs.y
        ))

        for query_layer in layers:
            filter[query_layer + "__bboverlaps"] = geom


        def xform(g):
            if self.simplify:
                k = g.simplify((maxx-minx) / width)
                if k:
                    g = k
            g.transform(t_srs.wkt)
            return g

        for query_layer in layers:
            qs = self.cls.objects.filter(**filter)
            if required_fields:
                qs = qs.only(*required_fields).values(*required_fields)
            else:
                qs = qs.values()

            mysrs = self.nativesrs(query_layer)
            if mysrs == srs:
                ctx.render(qs, lambda k: k[query_layer])
            else:
                ctx.render(qs, lambda k: xform(k[query_layer]))

        return ctx.surface
示例#5
0
文件: wms.py 项目: demiurg/ga_ows
    def get_2d_dataset(self, layers, srs, bbox, width, height, styles, bgcolor, transparent, time, elevation, v, filter):
        minx,miny,maxx,maxy = bbox
        if filter is None:
            filter = {}

        if self.requires_time and not time:
            raise Exception("this service requires a time parameter")
        if self.requires_elevation and not elevation:
            raise Exception('this service requires an elevation')

        ss = None
        required_fields = tuple()
        if type(self.styles) is dict:
            if not styles and 'default' in self.styles:
                ss = self.styles['default']
            elif styles:
                ss = self.styles[styles]
        else:
            ss = self.styles
            required_fields = ss.required_fields

        ctx = RenderingContext(ss, minx, miny, maxx, maxy, width, height)

        t_srs = djgdal.SpatialReference(srs)
        s_srs = djgdal.SpatialReference(self.nativesrs(layers[0]))

        s_mins = Point(minx, miny, srid=t_srs.wkt)
        s_maxs = Point(maxx, maxy, srid=t_srs.wkt)
        s_mins.transform(s_srs.wkt)
        s_maxs.transform(s_srs.wkt)

        geom = GEOSGeometry('POLYGON(({minx} {miny}, {maxx} {miny}, {maxx} {maxy}, {minx} {maxy}, {minx} {miny}))'.format(
            minx=s_mins.x,
            miny=s_mins.y,
            maxx=s_maxs.x,
            maxy=s_maxs.y
        ))

        for query_layer in layers:
            filter[query_layer + "__bboverlaps"] = geom


        def xform(g):
            if self.simplify:
                k = g.simplify((maxx-minx) / width)
                if k:
                    g = k
            g.transform(t_srs.wkt)
            return g

        for query_layer in layers:
            qs = self.cls.objects.filter(**filter)
            if required_fields:
                qs = qs.only(*required_fields).values(*required_fields)
            else:
                qs = qs.values()

            mysrs = self.nativesrs(query_layer)
            if mysrs == srs:
                ctx.render(qs, lambda k: k[query_layer])
            else:
                ctx.render(qs, lambda k: xform(k[query_layer]))

        return ctx.surface