How to use the fastkml.geometry.Polygon function in fastkml

To help you get started, we’ve selected a few fastkml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cleder / fastkml / fastkml / test_main.py View on Github external
def testMultiPolygon(self):
        # with holes
        p0 = Polygon(
            [(-1, -1), (2, -1), (2, 2), (-1, -1)],
            [[(0, 0), (1, 0), (1, 1), (0, 0)]]
        )
        # without holes
        p1 = Polygon([(3, 0), (4, 0), (4, 1), (3, 0)])
        g = Geometry(geometry=MultiPolygon([p0, p1]))
        self.assertTrue('MultiGeometry' in str(g.to_string()))
        self.assertTrue('Polygon' in str(g.to_string()))
        self.assertTrue('outerBoundaryIs' in str(g.to_string()))
        self.assertTrue('innerBoundaryIs' in str(g.to_string()))
        self.assertTrue('LinearRing' in str(g.to_string()))
        self.assertTrue(
            'coordinates>0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000-1.000000,-1.000000 2.000000,-1.000000 2.000000,2.000000 -1.000000,-1.000000
github cleder / fastkml / fastkml / test_main.py View on Github external
def testGeometryCollection(self):
        po = Polygon([(3, 0), (4, 0), (4, 1), (3, 0)])
        lr = LinearRing([(0, -1), (1, -1), (1, 1), (0, -1)])
        ls = LineString([(0, 0), (1, 1)])
        p = Point(0, 1)
        # geo_if = {'type': 'GeometryCollection', 'geometries': [
        #     po.__geo_interface__, p.__geo_interface__,
        #     ls.__geo_interface__, lr.__geo_interface__]}
        g = Geometry(geometry=GeometryCollection([po, p, ls, lr]))
        # g1 = Geometry(geometry=as_shape(geo_if))
        # self.assertEqual(g1.__geo_interface__, g.__geo_interface__)
        self.assertTrue('MultiGeometry' in str(g.to_string()))
        self.assertTrue('Polygon' in str(g.to_string()))
        self.assertTrue('outerBoundaryIs' in str(g.to_string()))
        self.assertFalse('innerBoundaryIs' in str(g.to_string()))
        self.assertTrue('LinearRing' in str(g.to_string()))
        self.assertTrue(
            'coordinates>3.000000,0.000000 4.000000,0.000000 4.000000,1.000000 3.000000,0.000000
github cleder / fastkml / fastkml / test_main.py View on Github external
28.291,-30.226,0
                    28.848,-30.07,0
                    29.018,-29.744,0
                    29.325,-29.257,0
                    28.978,-28.956,0
                  
                
              
            
          
        """
        k = kml.KML()
        k.from_string(doc)
        self.assertEqual(len(list(k.features())), 1)
        self.assertTrue(
            isinstance(list(k.features())[0].geometry, Polygon)
        )
        k2 = kml.KML()
        k2.from_string(k.to_string())
        self.assertEqual(k.to_string(), k2.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
def testPolygon(self):
        # without holes
        l = Polygon([(0, 0), (1, 0), (1, 1), (0, 0)])
        g = Geometry(geometry=l)
        self.assertEqual(g.geometry, l)
        self.assertTrue('Polygon' in str(g.to_string()))
        self.assertTrue('outerBoundaryIs' in str(g.to_string()))
        self.assertFalse('innerBoundaryIs' in str(g.to_string()))
        self.assertTrue('LinearRing' in str(g.to_string()))
        self.assertTrue(
            'coordinates>0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.0000000.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000-1.000000,-1.000000 2.000000,-1.000000 2.000000,2.000000 -1.000000,-1.000000
github cleder / fastkml / fastkml / test_main.py View on Github external
def testPolygon(self):
        # without holes
        l = Polygon([(0, 0), (1, 0), (1, 1), (0, 0)])
        g = Geometry(geometry=l)
        self.assertEqual(g.geometry, l)
        self.assertTrue('Polygon' in str(g.to_string()))
        self.assertTrue('outerBoundaryIs' in str(g.to_string()))
        self.assertFalse('innerBoundaryIs' in str(g.to_string()))
        self.assertTrue('LinearRing' in str(g.to_string()))
        self.assertTrue(
            'coordinates>0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_document(self):
        k = kml.KML()
        ns = '{http://www.opengis.net/kml/2.2}'
        d = kml.Document(ns, 'docid', 'doc name', 'doc description')
        f = kml.Folder(ns, 'fid', 'f name', 'f description')
        k.append(d)
        d.append(f)
        nf = kml.Folder(ns, 'nested-fid', 'nested f name', 'nested f description')
        f.append(nf)
        f2 = kml.Folder(ns, 'id2', 'name2', 'description2')
        d.append(f2)
        p = kml.Placemark(ns, 'id', 'name', 'description')
        p.geometry = Polygon([(0, 0, 0), (1, 1, 0), (1, 0, 1)])
        p2 = kml.Placemark(ns, 'id2', 'name2', 'description2')
        # p2 does not have a geometry!
        f2.append(p)
        nf.append(p2)
        self.assertEqual(len(list(k.features())), 1)
        self.assertEqual(len(list((list(k.features())[0].features()))), 2)
        k2 = kml.KML()
        k2.from_string(k.to_string())
        self.assertEqual(k.to_string(), k2.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
def testMultiPolygon(self):
        # with holes
        p0 = Polygon(
            [(-1, -1), (2, -1), (2, 2), (-1, -1)],
            [[(0, 0), (1, 0), (1, 1), (0, 0)]]
        )
        # without holes
        p1 = Polygon([(3, 0), (4, 0), (4, 1), (3, 0)])
        g = Geometry(geometry=MultiPolygon([p0, p1]))
        self.assertTrue('MultiGeometry' in str(g.to_string()))
        self.assertTrue('Polygon' in str(g.to_string()))
        self.assertTrue('outerBoundaryIs' in str(g.to_string()))
        self.assertTrue('innerBoundaryIs' in str(g.to_string()))
        self.assertTrue('LinearRing' in str(g.to_string()))
        self.assertTrue(
            'coordinates>0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000-1.000000,-1.000000 2.000000,-1.000000 2.000000,2.000000 -1.000000,-1.0000003.000000,0.000000 4.000000,0.000000 4.000000,1.000000 3.000000,0.000000
github cleder / fastkml / fastkml / test_main.py View on Github external
self.assertFalse('tessellate' in str(geom.to_string()))
        geom.altitude_mode = 'absolute'
        self.assertFalse('tessellate' in str(geom.to_string()))
        geom.tessellate = True
        geom.altitude_mode = None
        self.assertFalse('tessellate' in str(geom.to_string()))
        geom.altitude_mode = 'relativeToGround'
        self.assertFalse('tessellate' in str(geom.to_string()))
        geom.altitude_mode = 'absolute'
        self.assertFalse('tessellate' in str(geom.to_string()))
        geom.altitude_mode = 'clampToGround'
        self.assertTrue('tessellate>1
github cleder / fastkml / fastkml / test_main.py View on Github external
def test3d(self):
        ns = ''
        p2 = kml.Placemark(ns, 'id', 'name', 'description')
        p2.geometry = Polygon([(0, 0), (1, 1), (1, 0)])
        p3 = kml.Placemark(ns, 'id', 'name', 'description')
        p3.geometry = Polygon([(0, 0, 0), (1, 1, 0), (1, 0, 0)])
        config.FORCE3D = False
        # p3.altitudeMode = 'absolute'
        self.assertNotEqual(p2.to_string(), p3.to_string())
        config.FORCE3D = True
        self.assertEqual(p2.to_string(), p3.to_string())
        # altitudeMode clampToGround indicates to ignore an altitude specification.
        # p3.altitudeMode = 'clampToGround'
        # self.assertEqual(p2.to_string(), p3.to_string())
        # config.FORCE3D = False
        # self.assertNotEqual(p2.to_string(), p3.to_string())

        # Important: Set FORCE3D back to False!
        config.FORCE3D = False