示例#1
0
    def testEvaluate(self):
        fil = filter.Filter('x = 12')
        f1 = feature.Feature({'x': 12})
        f2 = feature.Feature({'x': 13})

        assert fil.evaluate(f1) == True
        assert fil.evaluate(f2) == False
示例#2
0
 def testEquals(self):
     id = 'fid'
     g = geom.Point(-125, 50)
     a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
     f1 = feature.Feature(a, 'fid')
     f2 = feature.Feature(a, 'fid')
     assert f1 == f2
示例#3
0
    def testAdd(self):
        fil = filter.Filter('x = 12') + 'y < 10'
        print fil

        f1 = feature.Feature({'x': 12, 'y': 10})
        f2 = feature.Feature({'x': 12, 'y': 5})

        assert fil.evaluate(f1) == False
        assert fil.evaluate(f2) == True
示例#4
0
  def testWriteGML3(self):
    g = geom.Point(-125, 50)
    a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
    xml = feature.writeGML(feature.Feature(a,'fid'), ver=3)
    doc = dom.parseString(xml)
    assert "gsf:feature" == doc.documentElement.nodeName

    xp = Feature_Test.xpathctx
    assert u'1' in xp.findvalues('//gsf:x', doc) 
    assert u'1.1' in xp.findvalues('//gsf:y', doc) 
    assert u'one' in xp.findvalues('//gsf:z', doc) 
    assert u'-125.0 50.0' in xp.findvalues('//gsf:geom/gml:Point/gml:pos', doc)
示例#5
0
    def testWriteGML32(self):
        g = geom.Point(-125, 50)
        a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
        xml = feature.writeGML(feature.Feature(a, 'fid'), ver=3.2)
        doc = dom.parseString(xml)
        assert "gsf:feature" == doc.documentElement.nodeName

        xp = Feature_Test.xpathctx
        xp.namespaces['gml'] = 'http://www.opengis.net/gml/3.2'
        assert u'1' in xp.findvalues('//gsf:x', doc)
        assert u'1.1' in xp.findvalues('//gsf:y', doc)
        assert u'one' in xp.findvalues('//gsf:z', doc)
        self.assertIn(u'-125 50',
                      xp.findvalues('//gsf:geom/gml:Point/gml:pos', doc))
示例#6
0
    def reproject(self, prj, name=None):
        """
    Reprojects a layer.

    *prj* is the destination :class:`Projection <geoscript.proj.Projection>` 

    *name* is the optional name as a ``str`` to assign to the resulting reprojected layer.

    This method returns a newly reprojected layer. The new layer is create within the containing workspace of the original layer.

    >>> from geoscript import geom
    >>> l = Layer()
    >>> l.proj = 'epsg:4326'
    >>> l.add([geom.Point(-111, 45.7)])
    >>> 
    >>> l2 = l.reproject('epsg:26912')
    >>> l2.proj.id
    'EPSG:26912'

    >>> [f.geom for f in l2.features()]
    [POINT (499999.42501775385 5060716.092032814)]
    """

        prj = proj.Projection(prj)
        name = name or Layer._newname()

        # reproject the schema
        rschema = self.schema.reproject(prj, name)

        # create the reprojected layer
        rlayer = self.workspace.create(schema=rschema)

        # create a query specifying that feautres should be reproje`cted
        q = DefaultQuery(self.name, Filter.PASS._filter)
        if self.proj:
            q.coordinateSystem = self.proj._crs
        q.coordinateSystemReproject = prj._crs

        fc = self._source.getFeatures(q)
        i = fc.features()

        # loop through features and add to new reprojeced layer
        while i.hasNext():
            f = feature.Feature(schema=rschema, f=i.next())
            rlayer.add(f)

        fc.close(i)
        return rlayer
示例#7
0
    def filter(self, fil, name=None):
        """
    Filters the layer.

    *fil* is the :class:`Filter <geoscript.filter.Filter>` to apply.

    *name* is the optional name to assign to the new filtered layer.

    This method returns a newly filtered layer. The new layer is create within the containing workspace of the original layer.

    >>> from geoscript.feature import Schema
    >>> l = Layer(schema=Schema('original', [('name', str)]))
    >>> l.add(['foo'])
    >>> l.add(['bar'])
    >>> l.add(['baz'])
    >>> 
    >>> l2 = l.filter("name = 'foo'", "filtered")
    >>> l2.count()
    1
    >>> l3 = l.filter("name LIKE 'b%'", "filtered2")
    >>> l3.count()
    2
    """

        f = Filter(fil)
        name = name or Layer._newname()
        fschema = feature.Schema(name, self.schema.fields)

        # create the filtered layer
        flayer = self.workspace.create(schema=fschema)

        q = DefaultQuery(self.name, f._filter)

        # loop through features and add to new filtered layer
        fit = self._source.getFeatures(q).features()
        try:
            while fit.hasNext():
                f = feature.Feature(schema=fschema, f=fit.next())
                flayer.add(f)
        finally:
            fit.close()

        return flayer