コード例 #1
0
    def new_feature(self, set_defaults=True, geometry=None):
        """
        Returns a new feature that is created for the layer this form is bound too
        :return: A new QgsFeature
        """

        layer = self.QGISLayer
        fields = layer.pendingFields()
        feature = QgsFeature(fields)
        if geometry:
            feature.setGeometry(geometry)

        if set_defaults:
            for index in xrange(fields.count()):
                pkindexes = layer.dataProvider().pkAttributeIndexes()
                if index in pkindexes and layer.dataProvider().name() == 'spatialite':
                    continue

                value = layer.dataProvider().defaultValue(index)
                feature[index] = value
            # Update the feature with the defaults from the widget config
            defaults = self.default_values(feature)
            for key, value in defaults.iteritems():
                feature[key] = value

        return feature
コード例 #2
0
    def new_feature(self, set_defaults=True, geometry=None, data=None):
        """
        Returns a new feature that is created for the layer this form is bound too
        :return: A new QgsFeature
        """

        layer = self.QGISLayer
        fields = layer.pendingFields()
        feature = QgsFeature(fields)
        if data:
            print "Loading data"
            for key, value in data.iteritems():
                feature[key] = value
        else:
            data = {}

        if geometry:
            feature.setGeometry(geometry)

        if set_defaults:
            for index in xrange(fields.count()):
                pkindexes = layer.dataProvider().pkAttributeIndexes()
                if index in pkindexes and layer.dataProvider().name(
                ) == 'spatialite':
                    continue

                # Don't override fields we have already set.
                if fields.field(index).name() in data:
                    continue

                value = layer.dataProvider().defaultValue(index)
                feature[index] = value
            # Update the feature with the defaults from the widget config
            defaults = self.default_values(feature)
            utils.log(defaults)
            for key, value in defaults.iteritems():
                # Don't override fields we have already set.
                if key is None:
                    continue
                utils.log("Default key {0}".format(key))
                datakeys = [key.lower() for key in data.keys()]
                if key.lower() in datakeys:
                    utils.log("Skippping {0}".format(key))
                    continue
                try:
                    feature[key] = value
                except KeyError:
                    roam.utils.info(
                        "Couldn't find key {} on feature".format(key))

        return feature
コード例 #3
0
ファイル: project.py プロジェクト: skeenp/Roam
    def new_feature(self, set_defaults=True, geometry=None, data=None):
        """
        Returns a new feature that is created for the layer this form is bound too
        :return: A new QgsFeature
        """

        layer = self.QGISLayer
        fields = layer.pendingFields()
        feature = QgsFeature(fields)
        if data:
            print "Loading data"
            for key, value in data.iteritems():
                feature[key] = value
        else:
            data = {}

        if geometry:
            feature.setGeometry(geometry)

        if set_defaults:
            for index in xrange(fields.count()):
                pkindexes = layer.dataProvider().pkAttributeIndexes()
                if index in pkindexes and layer.dataProvider().name() == 'spatialite':
                    continue

                # Don't override fields we have already set.
                if fields.field(index).name() in data:
                    continue

                value = layer.dataProvider().defaultValue(index)
                feature[index] = value
            # Update the feature with the defaults from the widget config
            defaults = self.default_values(feature)
            utils.log(defaults)
            for key, value in defaults.iteritems():
                # Don't override fields we have already set.
                if key is None:
                    continue
                utils.log("Default key {0}".format(key))
                datakeys = [key.lower() for key in data.keys()]
                if key.lower() in datakeys:
                    utils.log("Skippping {0}".format(key))
                    continue
                try:
                    feature[key] = value
                except KeyError:
                    roam.utils.info("Couldn't find key {} on feature".format(key))

        return feature