def __str__(self):
     """This is where the magic happens."""
     buf = []
     for var, val in self._kml.items():
         if val is not None:  # Exclude all variables that are None
             if var.endswith("_"):
                 buf.append(
                     "{0}".format(val))  # Use the variable's __str__ as is
             else:
                 if var in [
                         'name', 'description', 'text'
                 ] and Kmlable._parse:  # Parse value for HTML and convert
                     val = Kmlable._chrconvert(val)
                 elif (var == 'href' and os.path.exists(val) and Kmlable._kmz == True)\
                         or (var == 'targetHref' and os.path.exists(val) and Kmlable._kmz == True): # Check for images
                     Kmlable._addimage(val)
                     val = os.path.join('files',
                                        os.path.split(val)[1]).replace(
                                            '\\', '/')
                 buf.append(u("<{0}>{1}</{0}>").format(
                     var,
                     val))  # Enclose the variable's __str__ with its name
                 # Add namespaces
                 if var.startswith(
                         "atom:"
                 ) and 'xmlns:atom="http://www.w3.org/2005/Atom"' not in Kmlable._namespaces:
                     Kmlable._namespaces.append(
                         'xmlns:atom="http://www.w3.org/2005/Atom"')
                 elif var.startswith(
                         "xal:"
                 ) and 'xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"' not in Kmlable._namespaces:
                     Kmlable._namespaces.append(
                         'xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"'
                     )
     return "".join(buf)
Example #2
0
 def _genkml(self, format=True):
     """Returns the kml as a string or "prettyprinted" if format = True."""
     Kmlable._compiling = True
     self._processedstyles = []
     kml_str = ""
     if self._feature is not None:
         kml_str = self._feature.__str__()
     networklinkcontrol_str = ""
     if self._networklinkcontrol is not None:
         networklinkcontrol_str = self._networklinkcontrol.__str__()
     if self._hint is not None:
         hint = ' hint="{0}"'.format(self._hint)
     else:
         hint = ''
     xml_str = u("<kml {0}{2}>{1}{3}</kml>").format(self._getnamespaces(),
                                                    kml_str, hint,
                                                    networklinkcontrol_str)
     if format:
         KmlElement.patch()
         kml_str = xml.dom.minidom.parseString(xml_str.encode("utf-8"))
         KmlElement.unpatch()
         Kmlable._compiling = False
         return kml_str.toprettyxml(indent="    ",
                                    newl="\n",
                                    encoding="UTF-8").decode("utf-8")
     else:
         Kmlable._compiling = False
         return xml_str
Example #3
0
 def _genkml(self, format=True):
     """Returns the kml as a string or "prettyprinted" if format = True."""
     kml_str = self._feature.__str__()
     xml_str = u("<kml {0}>{1}</kml>").format(Kmlable._getnamespaces(), kml_str)
     if format:
        KmlElement.patch()
        kml_str = xml.dom.minidom.parseString(xml_str.encode("utf-8"))
        KmlElement.unpatch()
        return kml_str.toprettyxml(indent="    ", newl="\n", encoding="UTF-8").decode("utf-8")
     else:
         return xml_str
Example #4
0
 def _genkml(self, format=True):
     """Returns the kml as a string or "prettyprinted" if format = True."""
     kml_str = self._feature.__str__()
     xml_str = u("<kml {0}>{1}</kml>").format(Kmlable._getnamespaces(), kml_str)
     if format:
        KmlElement.patch()
        kml_str = xml.dom.minidom.parseString(xml_str.encode("utf-8"))
        KmlElement.unpatch()
        return kml_str.toprettyxml(indent="    ", newl="\n", encoding="UTF-8").decode("utf-8")
     else:
         return xml_str
Example #5
0
 def __str__(self):
     str = ""
     for var, val in self._kml.items():
         if val is not None:  # Exclude all variables that are None
             if var.endswith("_"):
                 str += "{0}".format(val)  # Use the variable's __str__ as is
             else:
                 if var in ['name', 'description', 'text'] and Kmlable._parse: # Parse value for HTML and convert
                     val = Kmlable._chrconvert(val)
                 elif (var == 'href' and os.path.exists(val) and Kmlable._kmz == True)\
                         or (var == 'targetHref' and os.path.exists(val) and Kmlable._kmz == True): # Check for local images
                     Kmlable._addimage(val)
                     val = os.path.join('files', os.path.split(val)[1])
                 str += u("<{0}>{1}</{0}>").format(var, val)  # Enclose the variable's __str__ with the variables name
     return str
Example #6
0
    def _genkml(self, format=True):
        """
        Returns the kml as a string or as a single line or formatted.

        Keyword arguments:
        format (bool) -- format the resulting kml "prettyprint" (default True)

        """
        kml_tag = 'xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"'
        xmlstr = u("<kml {0}>{1}</kml>").format(kml_tag, self._feature.__str__())
        if format:
           KmlElement.patch()
           kmlstr = xml.dom.minidom.parseString(xmlstr.encode("utf-8"))
           KmlElement.unpatch()
           return kmlstr.toprettyxml(indent="    ", newl="\n", encoding="UTF-8").decode("utf-8")
        else:
            return xmlstr
Example #7
0
 def __str__(self):
     """This is where the magic happens."""
     buf = []
     for var, val in self._kml.items():
         if val is not None:  # Exclude all variables that are None
             if var.endswith("_"):
                 buf.append(u"{0}".format(val))  # Use the variable's __str__ as is
             else:
                 if (
                     var
                     in [
                         "name",
                         "description",
                         "text",
                         "linkname",
                         "linkdescription",
                         "message",
                         "change",
                         "create",
                         "delete",
                     ]
                     and Kmlable._parse
                 ):  # Parse value for HTML and convert
                     val = Kmlable._chrconvert(val)
                 elif (var == "href" and os.path.exists(val) and Kmlable._kmz == True) or (
                     var == "targetHref" and os.path.exists(val) and Kmlable._kmz == True
                 ):  # Check for images
                     Kmlable._addimage(val)
                     val = os.path.join("files", os.path.split(val)[1]).replace("\\", "/")
                 buf.append(u("<{0}>{1}</{0}>").format(var, val))  # Enclose the variable's __str__ with its name
                 # Add namespaces
                 if (
                     var.startswith("atom:")
                     and 'xmlns:atom="http://www.w3.org/2005/Atom"' not in Kmlable._namespaces
                 ):
                     Kmlable._namespaces.append('xmlns:atom="http://www.w3.org/2005/Atom"')
                 elif (
                     var.startswith("xal:")
                     and 'xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"' not in Kmlable._namespaces
                 ):
                     Kmlable._namespaces.append('xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"')
     return "".join(buf)
Example #8
0
 def _genkml(self, format=True):
     """Returns the kml as a string or "prettyprinted" if format = True."""
     kml_str = ""
     if self._feature is not None:
         kml_str = self._feature.__str__()
     networklinkcontrol_str = ""
     if self._networklinkcontrol is not None:
         networklinkcontrol_str = self._networklinkcontrol.__str__()
     if self._hint is not None:
         hint = ' hint="{0}"'.format(self._hint)
     else:
         hint = ''
     xml_str = u("<kml {0}{2}>{1}{3}</kml>").format(Kmlable._getnamespaces(), kml_str, hint, networklinkcontrol_str)
     if format:
        KmlElement.patch()
        kml_str = xml.dom.minidom.parseString(xml_str.encode("utf-8"))
        KmlElement.unpatch()
        return kml_str.toprettyxml(indent="    ", newl="\n", encoding="UTF-8").decode("utf-8")
     else:
         return xml_str
Example #9
0
    def _genkml(self, format=True):
        """
        Returns the kml as a string or as a single line or formatted.

        Keyword arguments:
        format (bool) -- format the resulting kml "prettyprint" (default True)

        """
        kml_tag = 'xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"'
        xmlstr = u("<kml {0}>{1}</kml>").format(kml_tag,
                                                self._feature.__str__())
        if format:
            KmlElement.patch()
            kmlstr = xml.dom.minidom.parseString(xmlstr.encode("utf-8"))
            KmlElement.unpatch()
            return kmlstr.toprettyxml(indent="    ",
                                      newl="\n",
                                      encoding="UTF-8").decode("utf-8")
        else:
            return xmlstr
Example #10
0
 def __str__(self):
     str = ""
     for var, val in self._kml.items():
         if val is not None:  # Exclude all variables that are None
             if var.endswith("_"):
                 str += "{0}".format(
                     val)  # Use the variable's __str__ as is
             else:
                 if var in [
                         'name', 'description', 'text'
                 ] and Kmlable._parse:  # Parse value for HTML and convert
                     val = Kmlable._chrconvert(val)
                 elif (var == 'href' and os.path.exists(val) and Kmlable._kmz == True)\
                         or (var == 'targetHref' and os.path.exists(val) and Kmlable._kmz == True): # Check for local images
                     Kmlable._addimage(val)
                     val = os.path.join('files', os.path.split(val)[1])
                 str += u("<{0}>{1}</{0}>").format(
                     var, val
                 )  # Enclose the variable's __str__ with the variables name
     return str
Example #11
0
 def __str__(self):
     """This is where the magic happens."""
     buf = []
     for var, val in self._kml.items():
         if val is not None:  # Exclude all variables that are None
             if var.endswith("_"):
                 buf.append("{0}".format(val))  # Use the variable's __str__ as is
             else:
                 if var in ['name', 'description', 'text'] and Kmlable._parse: # Parse value for HTML and convert
                     val = Kmlable._chrconvert(val)
                 elif (var == 'href' and os.path.exists(val) and Kmlable._kmz == True)\
                         or (var == 'targetHref' and os.path.exists(val) and Kmlable._kmz == True): # Check for local images
                     Kmlable._addimage(val)
                     val = os.path.join('files', os.path.split(val)[1])
                 buf.append(u("<{0}>{1}</{0}>").format(var, val))  # Enclose the variable's __str__ with the variables name
                 # Add namespaces
                 if var.startswith("atom:") and 'xmlns:atom="http://www.w3.org/2005/Atom"' not in Kmlable._namespaces:
                     Kmlable._namespaces.append('xmlns:atom="http://www.w3.org/2005/Atom"')
                 elif var.startswith("xal:") and 'xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"' not in Kmlable._namespaces:
                     Kmlable._namespaces.append('xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"')
     return "".join(buf)
 def __str__(self):
     """This is where the magic happens."""
     parsetext = True
     outputkmz = False
     
     if Kmlable._compiling:
         parsetext = Kmlable._currentroot._parsetext
         outputkmz = Kmlable._currentroot._outputkmz            
     
     buf = []
     for var, val in self._kml.items():
         if val is not None:  # Exclude all variables that are None
             if var.endswith("_"):
                 buf.append(u"{0}".format(val))  # Use the variable's __str__ as is
             else:
                 if var in ['name', 'description', 'text', 'linkname', 'linkdescription', 'message', 'change', 'create', 'delete', 'link'] and parsetext: # Parse value for HTML and convert
                     val = Kmlable._chrconvert(val)
                 elif (var == 'href' and os.path.exists(val) and outputkmz == True)\
                         or (var == 'targetHref' and os.path.exists(val) and outputkmz == True): # Check for images
                     Kmlable._currentroot._foundimages.append(val)
                     val = os.path.join('files', os.path.split(val)[1]).replace('\\', '/')
                     val = Kmlable._chrconvert(val)
                 elif (var in ['href', 'targetHref']):
                     val = Kmlable._chrconvert(val)
                 buf.append(u("<{0}>{1}</{0}>").format(var, val))  # Enclose the variable's __str__ with its name
                 # Add namespaces
                 if Kmlable._compiling:
                     if var.startswith("atom:") and 'xmlns:atom="http://www.w3.org/2005/Atom"' not in Kmlable._currentroot._namespaces:
                         Kmlable._currentroot._namespaces.append('xmlns:atom="http://www.w3.org/2005/Atom"')
                     elif var.startswith("xal:") and 'xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"' not in Kmlable._currentroot._namespaces:
                         Kmlable._currentroot._namespaces.append('xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"')
                 else:
                     if var.startswith("atom:") and 'xmlns:atom="http://www.w3.org/2005/Atom"' not in Kmlable._namespaces:
                         Kmlable._currentroot.append('xmlns:atom="http://www.w3.org/2005/Atom"')
                     elif var.startswith("xal:") and 'xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"' not in Kmlable._namespaces:
                         Kmlable._currentroot.append('xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"')
                 
     return "".join(buf)
Example #13
0
    def __str__(self):
        """This is where the magic happens."""
        parsetext = True
        outputkmz = False

        if Kmlable._compiling:
            parsetext = Kmlable._currentroot._parsetext
            outputkmz = Kmlable._currentroot._outputkmz

        buf = []
        for var, val in self._kml.items():
            if val is not None:  # Exclude all variables that are None
                if var.endswith("_"):
                    buf.append(
                        u"{0}".format(val))  # Use the variable's __str__ as is
                else:
                    if var in [
                            'name', 'description', 'text', 'linkname',
                            'linkdescription', 'message', 'change', 'create',
                            'delete', 'link'
                    ] and parsetext:  # Parse value for HTML and convert
                        val = str(
                            val
                        )  # _chrconvert() barfs with inscrutable error when not passed a string, e.g. a NaN value.
                        val = Kmlable._chrconvert(val)
                    elif (var == 'href' and os.path.exists(val) and outputkmz == True)\
                            or (var == 'targetHref' and os.path.exists(val) and outputkmz == True): # Check for images
                        Kmlable._currentroot._foundimages.append(val)
                        val = os.path.join('files',
                                           os.path.split(val)[1]).replace(
                                               '\\', '/')
                        val = Kmlable._chrconvert(val)
                    elif (var in ['href', 'targetHref']):
                        val = Kmlable._chrconvert(val)
                    buf.append(u("<{0}>{1}</{0}>").format(
                        var,
                        val))  # Enclose the variable's __str__ with its name
                    # Add namespaces
                    if Kmlable._compiling:
                        if var.startswith(
                                "atom:"
                        ) and 'xmlns:atom="http://www.w3.org/2005/Atom"' not in Kmlable._currentroot._namespaces:
                            Kmlable._currentroot._namespaces.append(
                                'xmlns:atom="http://www.w3.org/2005/Atom"')
                        elif var.startswith(
                                "xal:"
                        ) and 'xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"' not in Kmlable._currentroot._namespaces:
                            Kmlable._currentroot._namespaces.append(
                                'xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"'
                            )
                    else:
                        if var.startswith(
                                "atom:"
                        ) and 'xmlns:atom="http://www.w3.org/2005/Atom"' not in Kmlable._namespaces:
                            Kmlable._currentroot.append(
                                'xmlns:atom="http://www.w3.org/2005/Atom"')
                        elif var.startswith(
                                "xal:"
                        ) and 'xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"' not in Kmlable._namespaces:
                            Kmlable._currentroot.append(
                                'xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"'
                            )

        return "".join(buf)