How to use the fastkml.kml.Schema 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
change in altitude]]>
            
           """
        s = kml.Schema(ns='', id='default')
        s.from_string(doc)
        self.assertEqual(len(list(s.simple_fields)), 3)
        self.assertEqual(list(s.simple_fields)[0]['type'], 'string')
        self.assertEqual(list(s.simple_fields)[1]['type'], 'double')
        self.assertEqual(list(s.simple_fields)[2]['type'], 'int')
        self.assertEqual(list(s.simple_fields)[0]['name'], 'TrailHeadName')
        self.assertEqual(list(s.simple_fields)[1]['name'], 'TrailLength')
        self.assertEqual(list(s.simple_fields)[2]['name'], 'ElevationGain')
        self.assertEqual(list(s.simple_fields)[0]['displayName'], '<b>Trail Head Name</b>')
        self.assertEqual(list(s.simple_fields)[1]['displayName'], '<i>The length in miles</i>')
        self.assertEqual(list(s.simple_fields)[2]['displayName'], '<i>change in altitude</i>')
        s1 = kml.Schema(ns='', id='default')
        s1.from_string(s.to_string())
        self.assertEqual(len(list(s1.simple_fields)), 3)
        self.assertEqual(list(s1.simple_fields)[0]['type'], 'string')
        self.assertEqual(list(s1.simple_fields)[1]['name'], 'TrailLength')
        self.assertEqual(list(s1.simple_fields)[2]['displayName'], '<i>change in altitude</i>')
        self.assertEqual(s.to_string(), s1.to_string())
        doc1 = """
            
            %s
        
        """ % doc
        k = kml.KML()
        k.from_string(doc1)
        d = list(k.features())[0]
        s2 = list(d.schemata())[0]
        s.ns = config.NS
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_schema(self):
        ns = '{http://www.opengis.net/kml/2.2}'
        self.assertRaises(ValueError, kml.Schema, ns)
        s = kml.Schema(ns, 'some_id')
        self.assertEqual(len(list(s.simple_fields)), 0)
        s.append('int', 'Integer', 'An Integer')
        self.assertEqual(list(s.simple_fields)[0]['type'], 'int')
        self.assertEqual(list(s.simple_fields)[0]['name'], 'Integer')
        self.assertEqual(list(s.simple_fields)[0]['displayName'], 'An Integer')
        s.simple_fields = None
        self.assertEqual(len(list(s.simple_fields)), 0)
        self.assertRaises(TypeError, s.append, ('none', 'Integer', 'An Integer'))
        self.assertRaises(TypeError, s.simple_fields, [('none', 'Integer', 'An Integer')])
        self.assertRaises(TypeError, s.simple_fields, ('int', 'Integer', 'An Integer'))
        fields = {'type': 'int', 'name': 'Integer', 'displayName': 'An Integer'}
        s.simple_fields = fields
        self.assertEqual(list(s.simple_fields)[0]['type'], 'int')
        self.assertEqual(list(s.simple_fields)[0]['name'], 'Integer')
        self.assertEqual(list(s.simple_fields)[0]['displayName'], 'An Integer')
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_schema(self):
        ns = '{http://www.opengis.net/kml/2.2}'
        self.assertRaises(ValueError, kml.Schema, ns)
        s = kml.Schema(ns, 'some_id')
        self.assertEqual(len(list(s.simple_fields)), 0)
        s.append('int', 'Integer', 'An Integer')
        self.assertEqual(list(s.simple_fields)[0]['type'], 'int')
        self.assertEqual(list(s.simple_fields)[0]['name'], 'Integer')
        self.assertEqual(list(s.simple_fields)[0]['displayName'], 'An Integer')
        s.simple_fields = None
        self.assertEqual(len(list(s.simple_fields)), 0)
        self.assertRaises(TypeError, s.append, ('none', 'Integer', 'An Integer'))
        self.assertRaises(TypeError, s.simple_fields, [('none', 'Integer', 'An Integer')])
        self.assertRaises(TypeError, s.simple_fields, ('int', 'Integer', 'An Integer'))
        fields = {'type': 'int', 'name': 'Integer', 'displayName': 'An Integer'}
        s.simple_fields = fields
        self.assertEqual(list(s.simple_fields)[0]['type'], 'int')
        self.assertEqual(list(s.simple_fields)[0]['name'], 'Integer')
        self.assertEqual(list(s.simple_fields)[0]['displayName'], 'An Integer')
        s.simple_fields = [['float', 'Float'], fields]
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_schema(self):
        doc = """
            
              Trail Head Name]]&gt;
            
            
              The length in miles]]&gt;
            
            
              change in altitude]]&gt;
            
           """
        s = kml.Schema(ns='', id='default')
        s.from_string(doc)
        self.assertEqual(len(list(s.simple_fields)), 3)
        self.assertEqual(list(s.simple_fields)[0]['type'], 'string')
        self.assertEqual(list(s.simple_fields)[1]['type'], 'double')
        self.assertEqual(list(s.simple_fields)[2]['type'], 'int')
        self.assertEqual(list(s.simple_fields)[0]['name'], 'TrailHeadName')
        self.assertEqual(list(s.simple_fields)[1]['name'], 'TrailLength')
        self.assertEqual(list(s.simple_fields)[2]['name'], 'ElevationGain')
        self.assertEqual(list(s.simple_fields)[0]['displayName'], '<b>Trail Head Name</b>')
        self.assertEqual(list(s.simple_fields)[1]['displayName'], '<i>The length in miles</i>')
        self.assertEqual(list(s.simple_fields)[2]['displayName'], '<i>change in altitude</i>')
        s1 = kml.Schema(ns='', id='default')
        s1.from_string(s.to_string())
        self.assertEqual(len(list(s1.simple_fields)), 3)
        self.assertEqual(list(s1.simple_fields)[0]['type'], 'string')
        self.assertEqual(list(s1.simple_fields)[1]['name'], 'TrailLength')
github cleder / fastkml / fastkml / kml.py View on Github external
def from_element(self, element):
        super(Document, self).from_element(element)
        folders = element.findall('%sFolder' % self.ns)
        for folder in folders:
            feature = Folder(self.ns)
            feature.from_element(folder)
            self.append(feature)
        placemarks = element.findall('%sPlacemark' % self.ns)
        for placemark in placemarks:
            feature = Placemark(self.ns)
            feature.from_element(placemark)
            self.append(feature)
        schemata = element.findall('%sSchema' % self.ns)
        for schema in schemata:
            s = Schema(self.ns, id='default')
            s.from_element(schema)
            self.append_schema(s)
github cleder / fastkml / fastkml / kml.py View on Github external
def append_schema(self, schema):
        if self._schemata is None:
            self._schemata = []
        if isinstance(schema, Schema):
            self._schemata.append(schema)
        else:
            s = Schema(schema)
            self._schemata.append(s)
github cleder / fastkml / fastkml / kml.py View on Github external
def append_schema(self, schema):
        if self._schemata is None:
            self._schemata = []
        if isinstance(schema, Schema):
            self._schemata.append(schema)
        else:
            s = Schema(schema)
            self._schemata.append(s)
github cleder / fastkml / fastkml / kml.py View on Github external
def from_element(self, element):
        super(Schema, self).from_element(element)
        self.name = element.get('name')
        simple_fields = element.findall('%sSimpleField' % self.ns)
        self.simple_fields = None
        for simple_field in simple_fields:
            sfname = simple_field.get('name')
            sftype = simple_field.get('type')
            display_name = simple_field.find('%sdisplayName' % self.ns)
            if display_name is not None:
                sfdisplay_name = display_name.text
            else:
                sfdisplay_name = None
            self.append(sftype, sfname, sfdisplay_name)