Exemple #1
0
    def to_node(self,
                doc,
                tag,
                ns_key=None,
                parent=None,
                check_validity=False,
                strict=DEFAULT_STRICT,
                exclude=()):
        if parent is None:
            parent = doc.getroot()
        if ns_key is None:
            node = _create_new_node(doc, tag, parent=parent)
        else:
            node = _create_new_node(doc,
                                    '{}:{}'.format(ns_key, tag),
                                    parent=parent)

        if 'RemapLUT' in self._child_xml_ns_key:
            rtag = '{}:RemapLUT'.format(self._child_xml_ns_key['RemapLUT'])
        elif ns_key is not None:
            rtag = '{}:RemapLUT'.format(ns_key)
        else:
            rtag = 'RemapLUT'

        if self._remap_lut is not None:
            value = ' '.join('{0:d},{1:d},{2:d}'.format(*entry)
                             for entry in self._remap_lut)
            entry = _create_text_node(doc, rtag, value, parent=node)
            entry.attrib['size'] = str(self.size)
        return node
Exemple #2
0
    def to_node(self, doc, tag, ns_key=None, parent=None, check_validity=False, strict=DEFAULT_STRICT, exclude=()):
        if parent is None:
            parent = doc.getroot()
        if ns_key is None:
            node = _create_new_node(doc, tag, parent=parent)
        else:
            node = _create_new_node(doc, '{}:{}'.format(ns_key, tag), parent=parent)
        typ = self.GeometryType
        if typ is None:
            return node

        coords = getattr(self, typ).get_coordinates_list()
        if typ == 'Point':
            self._serialize_point(coords, doc, 'sfa:Point', node)
        elif typ == 'Line':
            self._serialize_line(coords, doc, 'sfa:Line', node)
        elif typ == 'LinearRing':
            self._serialize_line(coords, doc, 'sfa:LinearRing', node)
        elif typ == 'Polygon':
            self._serialize_polygon(coords, doc, 'sfa:Polygon', node)
        elif typ == 'MultiPoint':
            self._serialize_line(coords, doc, 'sfa:MultiPoint', node)
        elif typ == 'MultiLineString':
            self._serialize_multilinestring(coords, doc, 'sfa:MultiLineString', node)
        elif typ == 'MultiPolygon':
            self._serialize_multipolygon(coords, doc, 'sfa:MultiPolygon', node)
        else:
            raise ValueError('Unsupported serialization type {}'.format(typ))
        return node
Exemple #3
0
 def _serialize_point(coords, doc, tag, parent):
     if len(coords) < 2:
         raise ValueError('coords must have at least two elements')
     fmt_func = '{0:0.16G}'.format
     node = _create_new_node(doc, tag, parent=parent)
     _create_text_node(doc, 'sfa:X', fmt_func(coords[0]), parent=node)
     _create_text_node(doc, 'sfa:Y', fmt_func(coords[1]), parent=node)
     if len(coords) > 2:
         _create_text_node(doc, 'sfa:Z', fmt_func(coords[2]), parent=node)
     if len(coords) > 3:
         _create_text_node(doc, 'sfa:M', fmt_func(coords[3]), parent=node)
Exemple #4
0
    def to_node(self,
                doc,
                tag,
                ns_key=None,
                parent=None,
                check_validity=False,
                strict=DEFAULT_STRICT,
                exclude=()):
        def make_entry(arr):
            value = ' '.join(str(el) for el in arr)
            entry = _create_text_node(doc, ltag, value, parent=node)
            entry.attrib['lut'] = str(arr.size)

        if parent is None:
            parent = doc.getroot()

        if ns_key is None:
            node = _create_new_node(doc, tag, parent=parent)
        else:
            node = _create_new_node(doc,
                                    '{}:{}'.format(ns_key, tag),
                                    parent=parent)

        if 'LUTValues' in self._child_xml_ns_key:
            ltag = '{}:LUTValues'.format(self._child_xml_ns_key['LUTValues'])
        elif ns_key is not None:
            ltag = '{}:LUTValues'.format(ns_key)
        else:
            ltag = 'LUTValues'

        if self._lut_values is not None:
            node.attrib['numLuts'] = str(self.numLUTs)
            node.attrib['size'] = str(self.size)
            if self._lut_values.ndim == 1:
                make_entry(self._lut_values)
            else:
                for j in range(self._lut_values.shape[1]):
                    make_entry(self._lut_values[:, j])
        return node
Exemple #5
0
    def to_node(self,
                doc,
                tag,
                ns_key=None,
                parent=None,
                check_validity=False,
                strict=DEFAULT_STRICT,
                exclude=()):
        if parent is None:
            parent = doc.getroot()
        if ns_key is None:
            node = _create_new_node(doc, tag, parent=parent)
        else:
            node = _create_new_node(doc,
                                    '{}:{}'.format(ns_key, tag),
                                    parent=parent)

        if 'Coefs' in self._child_xml_ns_key:
            ctag = '{}:Coef'.format(self._child_xml_ns_key['Coefs'])
        elif ns_key is not None:
            ctag = '{}:Coef'.format(ns_key)
        else:
            ctag = 'Coef'

        node.attrib['numPhasings'] = str(self.numPhasings)
        node.attrib['numPoints'] = str(self.numPoints)
        fmt_func = self._get_formatter('Coefs')
        for i, val1 in enumerate(self._coefs):
            for j, val in enumerate(val1):
                # if val != 0.0:  # should we serialize it sparsely?
                cnode = _create_text_node(doc,
                                          ctag,
                                          fmt_func(val),
                                          parent=node)
                cnode.attrib['phasing'] = str(i)
                cnode.attrib['point'] = str(j)
        return node
Exemple #6
0
 def _serialize_multipolygon(self, coords, doc, tag, parent):
     node = _create_new_node(doc, tag, parent=parent)
     for entry in coords:
         self._serialize_polygon(entry, doc, 'sfa:Element', node)
Exemple #7
0
 def _serialize_multilinestring(self, coords, doc, tag, parent):
     node = _create_new_node(doc, tag, parent=parent)
     for entry in coords:
         self._serialize_line(entry, doc, 'sfa:Element', node)
Exemple #8
0
 def _serialize_polygon(self, coords, doc, tag, parent):
     node = _create_new_node(doc, tag, parent=parent)
     for entry in coords:
         self._serialize_line(entry, doc, 'sfa:Ring', node)
Exemple #9
0
 def _serialize_line(self, coords, doc, tag, parent):
     node = _create_new_node(doc, tag, parent=parent)
     for entry in coords:
         self._serialize_point(entry, doc, 'sfa:Vertex', node)