def generateWay (self, attr): featureMember = Element("gml:featureMember") feature = SubElement(featureMember, "way") FID = SubElement(feature, "FID") FID.text = str(attr["id"]) geometryProperty = SubElement(feature, "gml:geometryProperty") lineString = SubElement(geometryProperty, "gml:LineString") coordinates = SubElement(lineString, "gml:coordinates") coordinates.text = " ".join(map(lambda x: "%s,%s" % x, attr['segments'])) for k, v in attr.iteritems(): if k != "segments": SubElement(feature, "" + k).text = v ElementTree(featureMember).write(self.fh, "utf-8") self.fh.write("\n")
def test_writer(self): a = Element('a') b = SubElement(a, 'b') b.append(Comment('a comment')) c = SubElement(b, 'c', d = 'e') f = SubElement(c, 'f') f.text = 'g' h = SubElement(c, 'h') h.text = 'i << >> << &&' b.append(ProcessingInstruction('pdk', 'processing instruction')) tree = ElementTree(a) output = stringio() write_pretty_xml(tree, output) self.assert_equals_long(expected_xml_output, output.getvalue())
def generateSegment(self, coords, attr): featureMember = Element("gml:featureMember") feature = SubElement(featureMember, "segment") feature.set("gml:fid", str(attr["id"])) FID = SubElement(feature, "FID") FID.text = str(attr["id"]) geometryProperty = SubElement(feature, "gml:geometryProperty") lineString = SubElement(geometryProperty, "gml:LineString") coordinates = SubElement(lineString, "gml:coordinates") coordinates.text = " ".join(map(lambda x: "%s,%s" % x, coords)) for k, v in attr.iteritems(): if k in exportTags: SubElement(feature, "" + k).text = v ElementTree(featureMember).write(self.fh, "utf-8") self.fh.write("\n")
def generateMultiWay(self, attr): featureMember = Element("gml:featureMember") feature = SubElement(featureMember, "way") FID = SubElement(feature, "FID") FID.text = str(attr["id"]) geometryProperty = SubElement(feature, "gml:geometryProperty") lineString = SubElement(geometryProperty, "gml:MultiLineString") data = [] for i in attr['segments']: lsm = SubElement(lineString, "gml:lineStringMember") ls = SubElement(lsm, "gml:LineString") coordinates = SubElement(ls, "gml:coordinates") coordinates.text = " ".join(map(lambda x: "%s,%s" % x, i)) for k, v in attr.iteritems(): if k != "segments": SubElement(feature, "" + k).text = v ElementTree(featureMember).write(self.fh, "utf-8") self.fh.write("\n")