예제 #1
0
    def get_ressources(self, params: Dict[str, str],
                       project: QgsProject) -> CadastreResources:
        """ Find layer and feature corresponding to given parameters
        """
        def get_param(name: str, allowed_values: Sequence[str] = None) -> str:
            v = params.get(name)
            if not v:
                raise CadastreError(400, "Missing parameter '%s'" % name)
            v = v
            if allowed_values and v not in allowed_values:
                raise CadastreError(400,
                                    "Invalid or missing value for '%s'" % name)
            return v

        # Get layer and expression
        player = get_param('LAYER')
        pparcelle = get_param('PARCELLE')
        ptype = get_param('TYPE', ('parcelle', 'proprietaire', 'fiche'))

        # Get feature
        if not PARCELLE_FORMAT_RE.match(pparcelle):
            raise CadastreError(400, "Invalid PARCELLE format: %s" % pparcelle)

        # Find layer
        layer = None
        lr = project.mapLayersByName(player)
        if len(lr) > 0:
            layer = lr[0]
        else:
            raise CadastreError(404, "Layer '%s' not found" % player)

        req = QgsFeatureRequest()
        req.setFilterExpression(' "geo_parcelle" = \'%s\' ' % pparcelle)

        it = layer.getFeatures(req)
        feat = QgsFeature()
        if not it.nextFeature(feat):
            raise CadastreError(
                404, "Feature not found for parcelle '%s' in layer '%s'" %
                (pparcelle, player))

        # Get layer connection parameters
        connectionParams = cadastre_common.getConnectionParameterFromDbLayer(
            layer)
        connector = cadastre_common.getConnectorFromUri(connectionParams)

        return CadastreResources(geo_parcelle=pparcelle,
                                 feature=feat,
                                 type=ptype,
                                 layer=layer,
                                 layername=player,
                                 connector=connector,
                                 connectionParams=connectionParams)
    def get_ressources(self, params: Dict[str,str], project: QgsProject) -> CadastreResources:
        """ Find layer and feature corresponding to given parameters
        """

        def get_param(name: str, allowed_values: Sequence[str]=None) -> str:
            v = params.get(name)
            if not v:
                raise CadastreError(400,"Missing parameter '%s'" % name)
            v = v
            if allowed_values and not v in allowed_values:
                raise CadastreError(400,"Invalid or missing value for '%s'" % name)
            return v

        # Get layer and expression
        player    = get_param('LAYER')
        pparcelle = get_param('PARCELLE')
        ptype     = get_param('TYPE',('parcelle', 'proprietaire', 'fiche'))

        # Get feature
        if not PARCELLE_FORMAT_RE.match(pparcelle):
            raise CadastreError(400, "Invalid PARCELLE format: %s" % pparcelle)

        # Find layer
        layer = None
        lr = project.mapLayersByName(player)
        if len(lr) > 0:
            layer = lr[0]
        else:
            raise CadastreError(404,"Layer '%s' not found" % player)

        req = QgsFeatureRequest()
        req.setFilterExpression(' "geo_parcelle" = \'%s\' ' % pparcelle)

        it = layer.getFeatures(req)
        feat = QgsFeature()
        if not it.nextFeature(feat):
            raise CadastreError(404,"Feature not found for parcelle '%s' in layer '%s'" % (pparcelle,player))

        # Get layer connection parameters
        connectionParams = cadastre_common.getConnectionParameterFromDbLayer(layer)
        connector = cadastre_common.getConnectorFromUri( connectionParams )

        return CadastreResources(geo_parcelle = pparcelle,
                                 feature = feat,
                                 type = ptype,
                                 layer = layer,
                                 layername = player,
                                 connector = connector,
                                 connectionParams = connectionParams)
예제 #3
0
    def __init__(self,
                 project: QgsProject,
                 layer: QgsMapLayer,
                 etype: str,
                 comptecommunal: str,
                 geo_parcelle: str = None,
                 target_dir: str = None) -> None:

        self.plugin_dir = str(Path(__file__).resolve().parent)

        self.print_parcelle_page = False

        if not hasattr(self, 'mProgress'):
            self.mProgress = _printProgress

        # Store project from context
        self.mProject = project

        # Store an instance of QgsComposition
        self.currentComposition = None

        # Get instance needed for QgsComposition
        self.mInstance = self.getMapInstance()

        # type of export : proprietaire or parcelle
        self.etype = etype

        # id of the parcelle
        self.geo_parcelle = geo_parcelle

        # memory layer for redlining
        self.redlineLayer = None

        self.ccFilter = None

        if isinstance(comptecommunal, list):
            self.isMulti = True
            comptecommunal = list(set(comptecommunal))
            if len(comptecommunal) == 1:
                self.isMulti = False
                comptecommunal = comptecommunal[0].strip(" '")
        else:
            self.isMulti = False

        self.comptecommunal = comptecommunal

        self.maxLineNumber = 15  # max number of line per main table
        self.numPages = 1
        self.pageHeight = 210
        self.pageWidth = 297
        self.printResolution = 300

        # target directory for saving
        s = QSettings()
        tempDir = s.value("cadastre/tempDir",
                          '%s' % tempfile.gettempdir(),
                          type=str)
        if not target_dir or not os.path.exists(target_dir):
            self.targetDir = tempfile.mkdtemp('', 'cad_export_', tempDir)
        else:
            self.targetDir = target_dir

        # label for header2
        if self.etype == 'proprietaire':
            self.typeLabel = u'DE PROPRIÉTÉ'
        else:
            self.typeLabel = u'PARCELLAIRE'

        self.layer = layer
        self.connectionParams = cadastre_common.getConnectionParameterFromDbLayer(
            self.layer)
        self.connector = cadastre_common.getConnectorFromUri(
            self.connectionParams)
        self.dbType = self.connectionParams['dbType']
예제 #4
0
    def __init__(self, project: QgsProject, layer: QgsMapLayer, etype: str, comptecommunal: str,
                 geo_parcelle: str=None, target_dir: str=None) -> None:

        self.plugin_dir = str(Path(__file__).resolve().parent)

        self.print_parcelle_page = False

        if not hasattr(self,'mProgress'):
            self.mProgress =  _printProgress

        # Store project from context
        self.mProject = project

        # Store an instance of QgsComposition
        self.currentComposition = None

        # Get instance needed for QgsComposition
        self.mInstance = self.getMapInstance()

        # type of export : proprietaire or parcelle
        self.etype = etype

        # id of the parcelle
        self.geo_parcelle = geo_parcelle

        # memory layer for redlining
        self.redlineLayer = None

        self.ccFilter = None

        if isinstance(comptecommunal, list):
            self.isMulti = True
            comptecommunal = list(set(comptecommunal))
            if len(comptecommunal) == 1:
                self.isMulti = False
                comptecommunal = comptecommunal[0].strip(" '")
        else:
            self.isMulti = False

        self.comptecommunal = comptecommunal

        self.maxLineNumber = 15 # max number of line per main table
        self.numPages = 1
        self.pageHeight = 210
        self.pageWidth = 297
        self.printResolution = 300
        self.addExperimentalWatershed = False

        # target directory for saving
        s = QSettings()
        tempDir = s.value("cadastre/tempDir", '%s' % tempfile.gettempdir(), type=str)
        if not target_dir or not os.path.exists(target_dir):
            self.targetDir = tempfile.mkdtemp('', 'cad_export_', tempDir)
        else:
            self.targetDir = target_dir

        # label for header2
        if self.etype == 'proprietaire':
            self.typeLabel = u'DE PROPRIÉTÉ'
        else:
            self.typeLabel = u'PARCELLAIRE'

        self.layer = layer
        self.connectionParams = cadastre_common.getConnectionParameterFromDbLayer(self.layer)
        self.connector = cadastre_common.getConnectorFromUri(self.connectionParams)
        self.dbType = self.connectionParams['dbType']