示例#1
0
    def curvify(self):

        if not self.auto_curve_enabled:
            return

        if self._prevent_recursion:
            # Avoiding recursion as the algorithm will also trigger geometryChanged
            return

        # Get custom convert to curve tolerance settings
        params = {
            "DISTANCE":
            QgsSettings().value(
                "/qgis/digitizing/convert_to_curve_distance_tolerance", 1e-6),
            "ANGLE":
            QgsSettings().value(
                "/qgis/digitizing/convert_to_curve_angle_tolerance", 1e-6),
        }

        alg = QgsApplication.processingRegistry().createAlgorithmById(
            'native:converttocurves')
        layer = self.iface.activeLayer()
        layer.selectByIds(self.changed_fids)
        self._prevent_recursion = True
        AlgorithmExecutor.execute_in_place(alg, params)
        self._prevent_recursion = False
        layer.removeSelection()
示例#2
0
    def preprocess(self, layer):
        '''
        Preprocesses the layer with the corresponding preprocess hook and returns the path to the
        resulting layer. If no preprocessing is performed, it returns the input layer itself
        '''
        if not processingOk:
            return layer

        if layer.type() == layer.RasterLayer:
            try:
                hookFile = str(QSettings().value("/OpenGeo/Settings/GeoServer/PreuploadRasterHook", ""))
                alg = self.getAlgorithmFromHookFile(hookFile)
                if (len(alg.parameters) == 1 and isinstance(alg.parameters[0], ParameterRaster)
                    and len(alg.outputs) == 1 and isinstance(alg.outputs[0], OutputRaster)):
                    alg.parameters[0].setValue(layer)
                    if AlgorithmExecutor.runalg(alg, SilentProgress()):
                        return load(alg.outputs[0].value)
                    return layer
            except:
                return layer
        elif layer.type() == layer.VectorLayer:
            try:
                hookFile = str(QSettings().value("/OpenGeo/Settings/GeoServer/PreuploadVectorHook", ""))
                alg = self.getAlgorithmFromHookFile(hookFile)
                if (len(alg.parameters) == 1 and isinstance(alg.parameters[0], ParameterVector)
                    and len(alg.outputs) == 1 and isinstance(alg.outputs[0], OutputVector)):
                    alg.parameters[0].setValue(layer)
                    if AlgorithmExecutor.runalg(alg, SilentProgress()):
                        return load(alg.outputs[0].value)
                    return layer
            except:
                return layer
示例#3
0
def importLayerIntoPostgis(layer, host, port, username, password, dbname,
                           schema, tablename):
    extent = '{},{},{},{}'.format(layer.extent().xMinimum(),
                                  layer.extent().xMaximum(),
                                  layer.extent().yMinimum(),
                                  layer.extent().yMaximum())
    geomtypes = {
        QGis.WKBPoint: 3,
        QGis.WKBLineString: 4,
        QGis.WKBPolygon: 5,
        QGis.WKBMultiPoint: 7,
        QGis.WKBMultiLineString: 9,
        QGis.WKBMultiPolygon: 8
    }
    geomtype = geomtypes.get(layer.wkbType(), 0)

    params = {
        ogr2ogr.INPUT_LAYER: layer,
        ogr2ogr.DBNAME: dbname,
        ogr2ogr.PORT: port,
        ogr2ogr.HOST: host,
        ogr2ogr.USER: username,
        ogr2ogr.PASSWORD: password,
        ogr2ogr.SCHEMA: schema,
        ogr2ogr.GTYPE: geomtype,
        ogr2ogr.TABLE: tablename,
        ogr2ogr.A_SRS: "EPSG:3857",
        ogr2ogr.S_SRS: layer.crs().authid(),
        ogr2ogr.T_SRS: "EPSG:3857",
        ogr2ogr.DIM: 0,
        ogr2ogr.OVERWRITE: True,
        ogr2ogr.APPEND: False,
        ogr2ogr.SPAT: extent,
        ogr2ogr.GT: '',
        ogr2ogr.SEGMENTIZE: '',
        ogr2ogr.SIMPLIFY: '',
        ogr2ogr.OPTIONS: '',
        ogr2ogr.PK: '',
        ogr2ogr.GEOCOLUMN: '',
        ogr2ogr.WHERE: ''
    }

    alg = Processing.getAlgorithm(
        "gdalogr:importvectorintopostgisdatabasenewconnection")
    for name, value in params.iteritems():
        param = alg.getParameterFromName(name)
        if param and param.setValue(value):
            continue
        output = alg.getOutputFromName(name)
        if output and output.setValue(value):
            continue
    AlgorithmExecutor.runalg(alg)
示例#4
0
def importLayerIntoPostgis(layer, host, port, username, password, dbname, schema, tablename):
	extent = '{},{},{},{}'.format(
	        layer.extent().xMinimum(), layer.extent().xMaximum(),
	        layer.extent().yMinimum(), layer.extent().yMaximum())
	geomtypes = {QGis.WKBPoint: 3,
	             QGis.WKBLineString: 4,
	             QGis.WKBPolygon: 5,
	             QGis.WKBMultiPoint: 7,
	             QGis.WKBMultiLineString: 9,
	             QGis.WKBMultiPolygon: 8}
	geomtype = geomtypes.get(layer.wkbType(), 0)

	params = {ogr2ogr.INPUT_LAYER: layer,
	            ogr2ogr.DBNAME: dbname,
	            ogr2ogr.PORT : port,
	            ogr2ogr.HOST : host,
	            ogr2ogr.USER : username,
	            ogr2ogr.PASSWORD: password,
	            ogr2ogr.SCHEMA: schema,
	            ogr2ogr.GTYPE: geomtype,
	            ogr2ogr.TABLE: tablename,
	            ogr2ogr.A_SRS: "EPSG:3857",
	            ogr2ogr.S_SRS: layer.crs().authid(),
	            ogr2ogr.T_SRS: "EPSG:3857",
	            ogr2ogr.DIM: 0,
	            ogr2ogr.OVERWRITE: True,
	            ogr2ogr.APPEND: False,
	            ogr2ogr.SPAT: extent,
	            ogr2ogr.GT: '',
	            ogr2ogr.SEGMENTIZE: '',
	            ogr2ogr.SIMPLIFY: '',
	            ogr2ogr.OPTIONS: '',
	            ogr2ogr.PK: '',
	            ogr2ogr.GEOCOLUMN: '',
	            ogr2ogr.WHERE: ''
	            }

	alg = Processing.getAlgorithm("gdalogr:importvectorintopostgisdatabasenewconnection")
	for name, value in params.iteritems():
		param = alg.getParameterFromName(name)
		if param and param.setValue(value):
			continue
		output = alg.getOutputFromName(name)
		if output and output.setValue(value):
			continue
	AlgorithmExecutor.runalg(alg)
示例#5
0
    def preprocess(self, layer):
        '''
        Preprocesses the layer with the corresponding preprocess hook and returns the path to the
        resulting layer. If no preprocessing is performed, it returns the input layer itself
        '''
        if not processingOk:
            return layer

        if layer.type() == layer.RasterLayer:
            try:
                hookFile = str(QSettings().value(
                    "/OpenGeo/Settings/GeoServer/PreuploadRasterHook", ""))
                alg = self.getAlgorithmFromHookFile(hookFile)
                if (len(alg.parameters) == 1
                        and isinstance(alg.parameters[0], ParameterRaster)
                        and len(alg.outputs) == 1
                        and isinstance(alg.outputs[0], OutputRaster)):
                    alg.parameters[0].setValue(layer)
                    if AlgorithmExecutor.runalg(alg, SilentProgress()):
                        return load(alg.outputs[0].value)
                    return layer
            except:
                return layer
        elif layer.type() == layer.VectorLayer:
            try:
                hookFile = str(QSettings().value(
                    "/OpenGeo/Settings/GeoServer/PreuploadVectorHook", ""))
                alg = self.getAlgorithmFromHookFile(hookFile)
                if (len(alg.parameters) == 1
                        and isinstance(alg.parameters[0], ParameterVector)
                        and len(alg.outputs) == 1
                        and isinstance(alg.outputs[0], OutputVector)):
                    alg.parameters[0].setValue(layer)
                    if AlgorithmExecutor.runalg(alg, SilentProgress()):
                        return load(alg.outputs[0].value)
                    return layer
            except:
                return layer
示例#6
0
    def check_algorithm(self, name, defs):
        """
        Will run an algorithm definition and check if it generates the expected result
        :param name: The identifier name used in the test output heading
        :param defs: A python dict containing a test algorithm definition
        """
        params = self.load_params(defs['params'])

        alg = processing.Processing.getAlgorithm(defs['algorithm']).getCopy()

        if isinstance(params, list):
            for param in zip(alg.parameters, params):
                param[0].setValue(param[1])
        else:
            for k, p in params.iteritems():
                alg.setParameterValue(k, p)

        for r, p in defs['results'].iteritems():
            alg.setOutputValue(r, self.load_result_param(p))

        self.assertTrue(AlgorithmExecutor.runalg(alg))
        print(alg.getAsCommand())
        self.check_results(alg.getOutputValuesAsDictionary(), defs['results'])
示例#7
0
    def check_algorithm(self, name, defs):
        """
        Will run an algorithm definition and check if it generates the expected result
        :param name: The identifier name used in the test output heading
        :param defs: A python dict containing a test algorithm definition
        """
        params = self.load_params(defs['params'])

        alg = processing.Processing.getAlgorithm(defs['algorithm']).getCopy()

        if isinstance(params, list):
            for param in zip(alg.parameters, params):
                param[0].setValue(param[1])
        else:
            for k, p in params.iteritems():
                alg.setParameterValue(k, p)

        for r, p in defs['results'].iteritems():
            alg.setOutputValue(r, self.load_result_param(p))

        print(alg.getAsCommand())
        self.assertTrue(AlgorithmExecutor.runalg(alg))
        self.check_results(alg.getOutputValuesAsDictionary(), defs['results'])