def get_vector_result(self, order_params): """ Queries vector data for stats and updates the CSV element for output :param order_params: params to query for :param csv_element: The CSV row to update :return: None """ result_data = None vector_url = VECTOR_TYPE_QUERY.substitute(upper=str(order_params.top), right=str(order_params.right), lower=str(order_params.bottom), left=str(order_params.left)) headers = self.headers.copy() headers[HEADER_CONTENT_TYPE] = CONTENT_TYPE_JSON for i in range(0, NUM_TIMES_TO_TRY): response = None try: request = urllib2.Request(vector_url, None, headers) response = self.opener.open(request) response_data = response.read() result_data = json.loads(response_data, strict=False) self.is_login_successful = True except Exception, e: self.is_login_successful = False QgsMessageLog.instance().logMessage("Unable to hit the vector end point due to: " + str(e) + "; trying " + str(NUM_TIMES_TO_TRY - i - 1) + " more times.", TAG_NAME, level=QgsMessageLog.CRITICAL) if response and self.is_login_successful: return result_data
def __init__(self, iface, parent=None): super(BlockGridDialog, self).__init__(parent) # Set up the user interface from Designer. self.setupUi(self) # The qgis interface self.iface = iface self.DISP_TEMP_LAYERS = read_setting(PLUGIN_NAME + '/DISP_TEMP_LAYERS', bool) # Catch and redirect python errors directed at the log messages python error tab. QgsMessageLog.instance().messageReceived.connect(errorCatcher) if not os.path.exists(TEMPDIR): os.mkdir(TEMPDIR) # Setup for validation messagebar on gui----------------------------- self.messageBar = QgsMessageBar( self) # leave this message bar for bailouts self.validationLayout = QtGui.QFormLayout(self) # new layout to gui if isinstance(self.layout(), QtGui.QFormLayout): # create a validation layout so multiple messages can be added and cleaned up. self.layout().insertRow(0, self.validationLayout) self.layout().insertRow(0, self.messageBar) else: self.layout().insertWidget( 0, self.messageBar) # for use with Vertical/horizontal layout box self.setMapLayers() # GUI Runtime Customisation ----------------------------------------------- self.setWindowIcon( QtGui.QIcon(':/plugins/pat/icons/icon_blockGrid.svg')) # hide some objects on the form, delete later if no longer needed. self.chkDisplayResults.hide() self.lblNoDataVal.hide() self.spnNoDataVal.hide()
def get_vector_result(self, order_params): """ Queries vector data for stats and updates the CSV element for output :param order_params: params to query for :param csv_element: The CSV row to update :return: None """ result_data = None vector_url = VECTOR_TYPE_QUERY.substitute( upper=str(order_params.top), right=str(order_params.right), lower=str(order_params.bottom), left=str(order_params.left)) headers = self.headers.copy() headers[HEADER_CONTENT_TYPE] = CONTENT_TYPE_JSON for i in range(0, NUM_TIMES_TO_TRY): response = None try: request = urllib2.Request(vector_url, None, headers) response = self.opener.open(request) response_data = response.read() result_data = json.loads(response_data, strict=False) self.is_login_successful = True except Exception, e: self.is_login_successful = False QgsMessageLog.instance().logMessage( "Unable to hit the vector end point due to: " + str(e) + "; trying " + str(NUM_TIMES_TO_TRY - i - 1) + " more times.", TAG_NAME, level=QgsMessageLog.CRITICAL) if response and self.is_login_successful: return result_data