Ejemplo n.º 1
0
    def testBoundsExpand(self):
        b1 = geom.Bounds(0, 0, 5, 5)
        b2 = geom.Bounds(5, 5, 10, 10)
        b1.expand(b2)

        assert 0 == b1.west and 0 == b1.south
        assert 10 == b1.east and 10 == b1.north
Ejemplo n.º 2
0
    def render(self, format=None, bounds=None, size=None, **options):
        if not bounds:
            # calulate bounds for layers, merge all bounds together
            bounds = reduce(lambda x, y: x + y,
                            map(lambda x: x.bounds(), self.layers))
        else:
            # bounds may be a "raw" envelope
            if not isinstance(bounds, geom.Bounds):
                bounds = geom.Bounds(env=bounds)

        # handle the case of a 0 width/height bounds, might happen if rendering
        # a single point, or a single verticle/horizontal line
        if bounds.width == 0 or bounds.height == 0:
            if bounds.height > 0:
                h = bounds.height / 2.0
                bounds = geom.Bounds(bounds.west - h, bounds.south,
                                     bounds.east + h, bounds.north,
                                     bounds.proj)
            elif bounds.width > 0:
                w = bounds.width / 2.0
                bounds = geom.Bounds(bounds.west, bounds.south - w,
                                     bounds.east, bounds.south + w,
                                     bounds.proj)
            else:
                e = geom.Point(bounds.west,
                               bounds.south).buffer(0.1).getEnvelopeInternal()
                bounds = geom.Bounds(env=e, prj=bounds.proj)

        # try to ensure the bounds has a projection
        if not bounds.proj and self.layers[0].proj:
            # use the layer projection
            bounds = geom.Bounds(env=bounds, prj=self.layers[0].proj)

        if not size:
            size = (500, int(500 * bounds.height / bounds.width))

        format = format if format else 'window'

        # look up the render based on format
        renderer = _renderers[format]
        if not renderer:
            raise Exception("Unrecognized format '%s'" % format)

        # instantiate it
        renderer = renderer()

        # set some options
        if self.title and not options.has_key('title'):
            options['title'] = self.title

        obj = renderer.render(self.layers, self.styles, bounds, size,
                              **options)

        self.renderer = renderer
        return obj if obj else renderer
Ejemplo n.º 3
0
 def testBoundsReproject(self):
     b = geom.Bounds(-111, 44.7, -110, 44.9, 'epsg:4326')
     b1 = b.reproject('epsg:26912')
     assertClose(self, 499999, int(b1.west))
     assertClose(self, 4949624, int(b1.south))
     assertClose(self, 579224, int(b1.east))
     assertClose(self, 4972327, int(b1.north))
Ejemplo n.º 4
0
    def bounds(self, filter=None):
        """
    The :class:`Bounds <geoscript.geom.Bounds>` of the layer.

    *filter* is an optional :class:`Filter <geoscript.filter.Filter>` to constrains the returned bounds.

    >>> l = Layer()
    >>> from geoscript import geom 
    >>> l.add([geom.Point(1.0, 2.0)])
    >>> l.add([geom.Point(3.0, 4.0)])

    >>> l.bounds()
    (1.0, 2.0, 3.0, 4.0, EPSG:4326)

    >>> l.bounds('INTERSECTS(geom,POINT(3 4))')
    (3.0, 4.0, 3.0, 4.0, EPSG:4326)
    """

        f = Filter(filter) if filter else Filter.PASS
        q = DefaultQuery(self.name, f._filter)
        e = self._source.getBounds(q)

        if not e:
            # try through feature collection
            fc = self._source.getFeatures(q)
            e = fc.getBounds()
        if e:
            if e.crs():
                return geom.Bounds(env=e)
            else:
                return geom.Bounds(env=e, prj=self.proj)
        else:
            # calculate manually
            fit = self._source.getFeatures(q).features()
            try:
                bounds = geom.Bounds(prj=self.proj)
                if fit.hasNext():
                    bounds.init(fit.next().getBounds())
                    while fit.hasNext():
                        bounds.expland(fit.next().getBounds())
                return bounds
            finally:
                fit.close()
Ejemplo n.º 5
0
    def testBoundsScale(self):
        b = geom.Bounds(5, 5, 10, 10)

        b1 = b.scale(2)
        assert 2.5 == b1.west
        assert 2.5 == b1.south
        assert 12.5 == b1.east
        assert 12.5 == b1.north

        b1 = b.scale(0.5)
        assert 6.25 == b1.west
        assert 6.25 == b1.south
        assert 8.75 == b1.east
        assert 8.75 == b1.north
Ejemplo n.º 6
0
    def bounds(self, filter=None):
        """
    The :class:`Bounds <geoscript.geom.Bounds>` of the layer.

    *filter* is an optional :class:`Filter <geoscript.filter.Filter>` to constrains the returned bounds.

    >>> l = Layer()
    >>> from geoscript import geom 
    >>> l.add([geom.Point(1.0, 2.0)])
    >>> l.add([geom.Point(3.0, 4.0)])

    >>> l.bounds()
    (1.0, 2.0, 3.0, 4.0)

    >>> l.bounds('INTERSECTS(geom,POINT(3 4))')
    (3.0, 4.0, 3.0, 4.0)
    """

        f = Filter(filter) if filter else Filter.PASS
        e = self._source.getBounds(DefaultQuery(self.name, f._filter))
        if e:
            return geom.Bounds(env=e)
Ejemplo n.º 7
0
 def testBoundsAspect(self):
     assert 1.0 == float(geom.Bounds(0, 0, 5, 5).aspect)
     assert 0.5 == float(geom.Bounds(0, 0, 5, 10).aspect)
Ejemplo n.º 8
0
    def testBounds(self):
        b = geom.Bounds(1.0, 2.0, 3.0, 4.0)
        self.assertEqual('(1.0, 2.0, 3.0, 4.0)', str(b))

        b = geom.Bounds(1.0, 2.0, 3.0, 4.0, 'epsg:4326')
        self.assertEqual('(1.0, 2.0, 3.0, 4.0, EPSG:4326)', str(b))
Ejemplo n.º 9
0
 def getbounds(self):
     if self.geom:
         return geom.Bounds(prj=self.schema.proj,
                            env=self.geom.getEnvelopeInternal())
Ejemplo n.º 10
0
 def getbounds(self):
     env = self._feature.getBounds()
     if env is not None and not env.isNull():
         return geom.Bounds(env=env)