コード例 #1
0
    def testCreate(self):
        l = self.ws.create('widgets', [('geom', geom.Point), ('name', str)])
        assert l

        l.add({'geom': geom.Point(1, 1), 'name': 'one'})
        l.add({'geom': geom.Point(2, 2), 'name': 'two'})
        l.add({'geom': geom.Point(3, 3), 'name': 'three'})

        assert 3 == l.count()
コード例 #2
0
    def testGetSet(self):
        self.ws['widgets2'] = [('geom', geom.Point), ('name', str)]
        l = self.ws['widgets2']
        assert l

        l.add([geom.Point(1, 1), 'one'])
        l.add([geom.Point(2, 2), 'two'])
        l.add([geom.Point(3, 3), 'three'])

        assert 3 == l.count()
コード例 #3
0
ファイル: test_feature.py プロジェクト: ecor/geoscript-py
 def testBasic(self):
     id = 'fid'
     g = geom.Point(-125, 50)
     a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
     f = feature.Feature(a, 'fid')
     assert id == f.id
     assert g == f.geom
コード例 #4
0
ファイル: test_feature.py プロジェクト: ecor/geoscript-py
 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
コード例 #5
0
    def testReadWKB(self):
        p = geom.Point(1, 2)
        wkb = geom.writeWKB(p)

        assert str(p) == str(geom.readWKB(wkb))
        assert str(p) == str(geom.readWKB(bytes.encode(wkb, 2), 2))
        assert str(p) == str(geom.readWKB(bytes.encode(wkb, 8), 8))
        assert str(p) == str(geom.readWKB(bytes.encode(wkb, 16), 16))
コード例 #6
0
 def testPlacePoint(self):
     line = geom.LineString((1137466.548141059, 650434.9943107369),
                            (1175272.4129268457, 648011.541439853),
                            (1185935.6055587344, 632986.1336403737))
     point1 = geom.Point(1153461.34, 649950.30)
     point2 = line.placePoint(point1)
     assert "POINT (1153426.8271476042 649411.899502625)" == str(point2)
     point3 = line.placePoint(1153461.34, 649950.30)
     assert "POINT (1153426.8271476042 649411.899502625)" == str(point3)
コード例 #7
0
 def testLocatePoint(self):
     line = geom.LineString((1137466.548141059, 650434.9943107369),
                            (1175272.4129268457, 648011.541439853),
                            (1185935.6055587344, 632986.1336403737))
     point = geom.Point(1153461.34, 649950.30)
     position = line.locatePoint(point)
     self.assertAlmostEqual(0.284, position, places=3)
     position = line.locatePoint(1153461.34, 649950.30)
     self.assertAlmostEqual(0.284, position, places=3)
コード例 #8
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
コード例 #9
0
    def testWriteGML(self):
        gml = geom.writeGML(geom.Point(1, 2))
        p = geom.readGML(gml)
        assert 1.0 == p.x and 2.0 == p.y

        line = geom.LineString([1, 2], [3, 4])
        assert str(line) == str(geom.readGML(geom.writeGML(line, ver=3),
                                             ver=3))

        poly = geom.Polygon([[1, 2], [3, 4], [5, 6], [1, 2]])
        assert str(poly) == str(
            geom.readGML(geom.writeGML(poly, ver=3.2), ver=3.2))
コード例 #10
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)
コード例 #11
0
ファイル: test_feature.py プロジェクト: ecor/geoscript-py
    def testWriteJSON(self):
        g = geom.Point(-125, 50)
        a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
        f1 = feature.Feature(a, 'fid')
        st = feature.writeJSON(f1)
        assert st

        obj = json.loads(st)
        assert obj['type'] == 'Feature'
        assert obj['properties']['x'] == 1
        assert obj['properties']['y'] == 1.1
        assert obj['geometry']['type'] == 'Point'
        assert obj['geometry']['coordinates'] == [-125, 50]
コード例 #12
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))
コード例 #13
0
ファイル: test_feature.py プロジェクト: ecor/geoscript-py
    def testAsContainer(self):
        id = 'fid'
        g = geom.Point(-125, 50)
        a = {'x': 1, 'y': 1.1, 'z': 'one', 'geom': g}
        f = feature.Feature(a, 'fid')

        assert 1 == f['x']
        try:
            f['foo']
            assert False
        except KeyError:
            pass

        assert [x for x in f.schema] == [y for y in f]
        expected = [(x, y) for x, y in f.attributes.iteritems()]
        assert [(x, y) for x, y in f.iteritems()] == expected

        assert sorted(f.attributes.keys()) == sorted(f.keys())
        assert sorted(f.attributes.values()) == sorted(f.values())
コード例 #14
0
 def testTransform(self):
     p = geom.Point(-125, 50)
     rp = proj.transform(p, 'epsg:4326', 'epsg:3005')
     self.assertEqual(1071693, int(rp.x))
     self.assertEqual(554289, int(rp.y))
コード例 #15
0
 def testPointFromJTS(self):
     p = geom.Point(self.gf.createPoint(Coordinate(1, 2)))
     self.assertEqual('POINT (1 2)', str(p))
コード例 #16
0
 def testPoint(self):
     p = geom.Point(1, 2)
     self.assertEqual('POINT (1 2)', str(p))
コード例 #17
0
 def testTransform(self):
     p = geom.Point(-125, 50)
     rp = proj.transform(p, 'epsg:4326', 'epsg:3005')
     assertClose(self, 1071693, int(rp.x))
     assertClose(self, 554289, int(rp.y))