def extent_string_to_array(extent_text): """Convert an extent string to an array. .. versionadded: 2.2.0 :param extent_text: String representing an extent e.g. 109.829170982, -8.13333290561, 111.005344795, -7.49226294379 :type extent_text: str :returns: A list of floats, or None :rtype: list, None """ coordinates = extent_text.replace(' ', '').split(',') count = len(coordinates) if count != 4: message = ( 'Extent need exactly 4 value but got %s instead' % count) LOGGER.error(message) return None # parse the value to float type try: coordinates = [float(i) for i in coordinates] except ValueError as e: message = str(e) LOGGER.error(message) return None return coordinates
def extent_string_to_array(extent_text): """Convert an extent string to an array. .. versionadded: 2.2.0 :param extent_text: String representing an extent e.g. 109.829170982, -8.13333290561, 111.005344795, -7.49226294379 :type extent_text: str :returns: A list of floats, or None :rtype: list, None """ coordinates = extent_text.replace(' ', '').split(',') count = len(coordinates) if count != 4: message = ('Extent need exactly 4 value but got %s instead' % count) LOGGER.error(message) return None # parse the value to float type try: coordinates = [float(i) for i in coordinates] except ValueError as e: message = e.message LOGGER.error(message) return None return coordinates
def setup_printer( filename, resolution=300, page_height=297, page_width=210, page_margin=None): """Create a QPrinter instance defaulted to print to an A4 portrait pdf. :param filename: Filename for the pdf print device. :type filename: str :param resolution: Resolution (in dpi) for the output. :type resolution: int :param page_height: Height of the page in mm. :type page_height: int :param page_width: Width of the page in mm. :type page_width: int :param page_margin: Page margin in mm in form [left, top, right, bottom]. :type page_margin: list """ # # Create a printer device (we are 'printing' to a pdf # LOGGER.debug('InaSAFE Map setupPrinter called') printer = QtGui.QPrinter() printer.setOutputFormat(QtGui.QPrinter.PdfFormat) printer.setOutputFileName(filename) printer.setPaperSize( QtCore.QSizeF(page_width, page_height), QtGui.QPrinter.Millimeter) printer.setColorMode(QtGui.QPrinter.Color) printer.setResolution(resolution) if page_margin is None: page_margin = [10, 10, 10, 10] printer.setPageMargins( page_margin[0], page_margin[1], page_margin[2], page_margin[3], QtGui.QPrinter.Millimeter) return printer