Index: wflow-py/wflow/create_grid.py =================================================================== diff -u -r58f139b2afc2424fc9f8796934878bd6e49c31de -r46c7ef5e63348942bb261b5042c57b66d7234749 --- wflow-py/wflow/create_grid.py (.../create_grid.py) (revision 58f139b2afc2424fc9f8796934878bd6e49c31de) +++ wflow-py/wflow/create_grid.py (.../create_grid.py) (revision 46c7ef5e63348942bb261b5042c57b66d7234749) @@ -266,27 +266,25 @@ ) # create grid.xml - root = ElementTree.Element("regular", locationId=locationid) - ElementTree.SubElement(root, "rows").text = str(rows) - ElementTree.SubElement(root, "columns").text = str(cols) - ElementTree.SubElement(root, "geoDatum").text = geodatum - ElementTree.SubElement(root, "firstCellCenter") - ElementTree.SubElement(root[3], "x").text = str(xorg + 0.5 * cellsize) - ElementTree.SubElement(root[3], "y").text = str(yorg - 0.5 * cellsize) - ElementTree.SubElement(root, "xCellSize").text = str(cellsize) - ElementTree.SubElement(root, "yCellSize").text = str(cellsize) - xml_file = os.path.abspath(os.path.join(destination, "grid.xml")) - logger.info("Writing Delft-FEWS grid definition to {:s}".format(xml_file)) - gridxml = open(xml_file, "w+") - gridxml.write(ElementTree.tostring(root)) - gridxml.close() + root = ElementTree.Element('regular', locationId=locationid) + ElementTree.SubElement(root, 'rows').text = str(rows) + ElementTree.SubElement(root, 'columns').text = str(cols) + ElementTree.SubElement(root, 'geoDatum').text = geodatum + ElementTree.SubElement(root, 'firstCellCenter') + ElementTree.SubElement(root[3], 'x').text = str(xorg + 0.5 * cellsize) + ElementTree.SubElement(root[3], 'y').text = str(yorg - 0.5 * cellsize) + ElementTree.SubElement(root, 'xCellSize').text = str(cellsize) + ElementTree.SubElement(root, 'yCellSize').text = str(cellsize) + xml_file = os.path.abspath(os.path.join(destination, 'grid.xml')) + logger.info('Writing Delft-FEWS grid definition to {:s}'.format(xml_file)) + with open(xml_file, 'w+') as f: + f.write(ElementTree.tostring(root, encoding='unicode')) # create shape file Driver = ogr.GetDriverByName("ESRI Shapefile") - shp_file = os.path.abspath(os.path.join(destination, "mask.shp")) - logger.info("Writing shape of clone to {:s}".format(shp_file)) - # for encode see https://gis.stackexchange.com/a/53939 - shp_att = os.path.splitext(os.path.basename(shp_file))[0].encode("utf-8") + shp_file = os.path.abspath(os.path.join(destination, 'mask.shp')) + logger.info('Writing shape of clone to {:s}'.format(shp_file)) + shp_att = os.path.splitext(os.path.basename(shp_file))[0] shp = Driver.CreateDataSource(shp_file) lyr = shp.CreateLayer(shp_att, srs, geom_type=ogr.wkbPolygon) fieldDef = ogr.FieldDefn("ID", ogr.OFTString)