Exemplo n.º 1
0
def genSummaryStub(Ddeploy):
    # Start off with some background info
    root = K.kml(
        K.Document(
            ATOM.author(ATOM.name(KMLauthor)),
            ATOM.link(href=homepage),
            K.name(Ddeploy['name']),
            K.description(Ddeploy['purpose']),
        ))
    root.insert(
        0,
        etree.Comment(
            '\nKML generated automatically by drifterSummaryKML.py\n'))
    doc = root.xpath('//default:Document', \
               namespaces={'gx': 'http://www.google.com/kml/ext/2.2',\
                           'atom': 'http://www.w3.org/2005/Atom',\
                           'default': 'http://www.opengis.net/kml/2.2'})

    # create and add the pieces of the stub
    doc[0].append(
        etree.Comment("\nStyle definition for drifter's positions\n"))
    doc[0].append(K.styleUrl('#drifter_info'))
    doc[0].append(genKMLstub.SurfaceStyle())
    doc[0].append(
        etree.Comment("\nStyle definition for drifter's trackline\n"))
    doc[0].append(genKMLstub.TrackStyle(Ddeploy))
    return root
Exemplo n.º 2
0
def genFinalStub():
    # using information in the dictionary of deployment qualities, make KML

    # Start off with some background info
    root = K.kml(
        K.Document(
            ATOM.author(ATOM.name(KMLauthor)),
            ATOM.link(href=homepage),
            K.name(final_title),
            K.description(
                'To track the ultimate fate of all released drifters'),
        ))
    root.insert(
        0,
        etree.Comment(
            '\nKML generated automatically by drifterSummaryKML.py\n'))
    doc = root.xpath('//default:Document', \
               namespaces={'gx': 'http://www.google.com/kml/ext/2.2',\
                           'atom': 'http://www.w3.org/2005/Atom',\
                           'default': 'http://www.opengis.net/kml/2.2'})

    # create and add the pieces of the stub
    doc[0].append(
        etree.Comment("\nStyle definition for drifter's positions\n"))
    doc[0].append(K.styleUrl('#drifter_info'))
    doc[0].append(genKMLstub.SurfaceStyle())
    return root
Exemplo n.º 3
0
    def test_write_python_script_for_kml_document(self):
        """Tests the creation of a trivial OGC KML document."""
        from pykml.factory import write_python_script_for_kml_document

        doc = KML.kml(
            KML.Document(
                ATOM.author(ATOM.name("J. K. Rowling")),
                ATOM.link(href="http://www.harrypotter.com"),
                KML.Placemark(KML.name("Hogwarts"),
                              KML.Point(KML.coordinates("1,1")))))
        script = write_python_script_for_kml_document(doc)
        self.assertEqual(
            script, 'from lxml import etree\n'
            'from pykml.factory import KML_ElementMaker as KML\n'
            'from pykml.factory import ATOM_ElementMaker as ATOM\n'
            'from pykml.factory import GX_ElementMaker as GX\n'
            '\n'
            'doc = KML.kml(\n'
            '  KML.Document(\n'
            '    ATOM.author(\n'
            '      ATOM.name(\'J. K. Rowling\'),\n'
            '    ),\n'
            '    ATOM.link(  href="http://www.harrypotter.com",\n'
            '),\n'
            '    KML.Placemark(\n'
            '      KML.name(\'Hogwarts\'),\n'
            '      KML.Point(\n'
            '        KML.coordinates(\'1,1\'),\n'
            '      ),\n'
            '    ),\n'
            '  ),\n'
            ')\n'
            'print(etree.tostring(etree.ElementTree(doc),pretty_print=True).decode())\n'
        )
Exemplo n.º 4
0
    def test_kml_document_with_atom_element(self):
        """Tests the creation of a KML document with an ATOM element."""
        doc = KML.kml(
            KML.Document(
                ATOM.author(ATOM.name("J. K. Rowling")),
                ATOM.link(href="http://www.harrypotter.com"),
                KML.Placemark(KML.name("Hogwarts"),
                              KML.Point(KML.coordinates("1,1")))))
        self.assertTrue(Schema("kml22gx.xsd").validate(doc))

        target = etree.fromstring(
            '<kml '
            'xmlns:atom="http://www.w3.org/2005/Atom" '
            'xmlns:gx="http://www.google.com/kml/ext/2.2" '
            'xmlns="http://www.opengis.net/kml/2.2">'
            '<Document>'
            '<atom:author>'
            '<atom:name>J. K. Rowling</atom:name>'
            '</atom:author>'
            '<atom:link href="http://www.harrypotter.com"/>'
            '<Placemark>'
            '<name>Hogwarts</name>'
            '<Point>'
            '<coordinates>1,1</coordinates>'
            '</Point>'
            '</Placemark>'
            '</Document>'
            '</kml>')
        self.assertTrue(compare_xml(target, doc))
Exemplo n.º 5
0
    def test_write_python_script_for_kml_document(self):
        """Tests the creation of a trivial OGC KML document."""
        doc = KML.kml(
            KML.Document(
                ATOM.author(
                    ATOM.name('J. K. Rowling')
                ),
                ATOM.link(href='http://www.harrypotter.com'),
                KML.Placemark(
                    KML.name('Hogwarts'),
                    KML.Point(
                        KML.coordinates('1,1')
                    )
                )
            )
        )
        script = write_python_script_for_kml_document(doc)
        expected = \
            'from lxml import etree\n' \
            'from pykml.factory import KML_ElementMaker as KML\n' \
            'from pykml.factory import ATOM_ElementMaker as ATOM\n' \
            'from pykml.factory import GX_ElementMaker as GX\n' \
            '\n' \
            'doc = KML.kml(\n' \
            '  KML.Document(\n' \
            '    ATOM.author(\n' \
            '      ATOM.name(\'J. K. Rowling\'),\n' \
            '    ),\n' \
            '    ATOM.link(href=\'http://www.harrypotter.com\',\n' \
            '),\n' \
            '    KML.Placemark(\n' \
            '      KML.name(\'Hogwarts\'),\n' \
            '      KML.Point(\n' \
            '        KML.coordinates(\'1,1\'),\n' \
            '      ),\n' \
            '    ),\n' \
            '  ),\n' \
            ')\n' \
            'print(etree.tostring(etree.ElementTree(doc), \n' \
            '                     encoding=\'utf-8\', \n' \
            '                     xml_declaration=True, \n' \
            '                     pretty_print=True).decode(\'utf-8\'))\n'

        self.assertEqual(script, expected)
Exemplo n.º 6
0
 def test_write_python_script_for_kml_document(self):
     """Tests the creation of a trivial OGC KML document."""
     from pykml.factory import write_python_script_for_kml_document
     
     doc = KML.kml(
         KML.Document(
             ATOM.author(
                 ATOM.name("J. K. Rowling")
             ),
             ATOM.link(href="http://www.harrypotter.com"),
             KML.Placemark(
                 KML.name("Hogwarts"),
                 KML.Point(
                     KML.coordinates("1,1")
                 )
             )
         )
     )
     script = write_python_script_for_kml_document(doc)
     self.assertEquals(
         script,
         'from lxml import etree\n'
         'from pykml.factory import KML_ElementMaker as KML\n'
         'from pykml.factory import ATOM_ElementMaker as ATOM\n'
         'from pykml.factory import GX_ElementMaker as GX\n'
         '\n'
         'doc = KML.kml(\n'
         '  KML.Document(\n'
         '    ATOM.author(\n'
         '      ATOM.name(\'J. K. Rowling\'),\n'
         '    ),\n'
         '    ATOM.link(  href="http://www.harrypotter.com",\n'
         '),\n'
         '    KML.Placemark(\n'
         '      KML.name(\'Hogwarts\'),\n'
         '      KML.Point(\n'
         '        KML.coordinates(\'1,1\'),\n'
         '      ),\n'
         '    ),\n'
         '  ),\n'
         ')\n'
         'print etree.tostring(etree.ElementTree(doc),pretty_print=True)\n'
     )
Exemplo n.º 7
0
def genStub(Ddeploy):
    # using information in the dictionary of deployment qualities, make KML

    timestamp = time.strptime(Ddeploy['startstr'], '%Y-%m-%d %H:%M:%S')
    date = time.strftime('%b. %Y', timestamp)
    description = 'The trackline for the %s deployment of %s' % (
        Ddeploy['area'], Ddeploy['name'])
    #print description

    # Start off with some background info
    root = K.kml(
        K.Document(
            ATOM.author(ATOM.name(KMLauthor)),
            ATOM.link(href=homepage),
            K.name(Ddeploy['name']),
            K.description(description),
        ))
    root.insert(
        0, etree.Comment('\nKML generated automatically by genKMLstub.py\n'))
    doc = root.xpath('//default:Document', \
               namespaces={'gx': 'http://www.google.com/kml/ext/2.2',\
                           'atom': 'http://www.w3.org/2005/Atom',\
                           'default': 'http://www.opengis.net/kml/2.2'})

    # create and add the pieces of the stub
    doc[0].append(
        etree.Comment("\nStyle definition for drifter's positions\n"))
    doc[0].append(K.styleUrl('#drifter_info'))
    doc[0].append(SurfaceStyle())
    doc[0].append(
        etree.Comment("\nStyle definition for drifter's trackline\n"))
    doc[0].append(TrackStyle(Ddeploy))
    doc[0].append(
        etree.Comment(
            "\nEach drifter position has data associated with it.  To display that\n\
data, need separate placemarks for each.  Contain in a Folder for\n\
cleanliness.\n"))
    doc[0].append(Folder(Ddeploy))
    return root
Exemplo n.º 8
0
    def test_kml_document_with_atom_element(self):
        """Tests the creation of a KML document with an ATOM element."""
        doc = KML.kml(
            KML.Document(
                ATOM.author(
                    ATOM.name('J. K. Rowling')
                ),
                ATOM.link(href='http://www.harrypotter.com'),
                KML.Placemark(
                    KML.name('Hogwarts'),
                    KML.Point(
                        KML.coordinates('1,1')
                    )
                )
            )
        )
        self.assertTrue(Schema('kml22gx.xsd').validate(doc))

        data = etree.tostring(doc, encoding='ascii')
        expected = \
            b'<kml xmlns:gx="http://www.google.com/kml/ext/2.2" ' \
            b'xmlns:atom="http://www.w3.org/2005/Atom" ' \
            b'xmlns="http://www.opengis.net/kml/2.2">' \
            b'<Document>' \
            b'<atom:author>' \
            b'<atom:name>J. K. Rowling</atom:name>' \
            b'</atom:author>' \
            b'<atom:link href="http://www.harrypotter.com"/>' \
            b'<Placemark>' \
            b'<name>Hogwarts</name>' \
            b'<Point>' \
            b'<coordinates>1,1</coordinates>' \
            b'</Point>' \
            b'</Placemark>' \
            b'</Document>' \
            b'</kml>'
        self.assertXmlEquivalentOutputs(data, expected)
Exemplo n.º 9
0
 def test_kml_document_with_atom_element(self):
     """Tests the creation of a KML document with an ATOM element."""
     doc = KML.kml(
         KML.Document(
             ATOM.author(
                 ATOM.name("J. K. Rowling")
             ),
             ATOM.link(href="http://www.harrypotter.com"),
             KML.Placemark(
                 KML.name("Hogwarts"),
                 KML.Point(
                     KML.coordinates("1,1")
                 )
             )
         )
     )
     self.assertTrue(Schema("kml22gx.xsd").validate(doc))
     self.assertEquals(
         etree.tostring(doc),
         '<kml xmlns:gx="http://www.google.com/kml/ext/2.2" '
              'xmlns:atom="http://www.w3.org/2005/Atom" '
              'xmlns="http://www.opengis.net/kml/2.2">'
           '<Document>'
             '<atom:author>'
               '<atom:name>J. K. Rowling</atom:name>'
             '</atom:author>'
             '<atom:link href="http://www.harrypotter.com"/>'
             '<Placemark>'
               '<name>Hogwarts</name>'
               '<Point>'
                 '<coordinates>1,1</coordinates>'
               '</Point>'
             '</Placemark>'
           '</Document>'
         '</kml>'
     )