コード例 #1
0
    def _get_layer(self, layer):
        """Analyze style of self._function and return appropriate
            class of the layer.

        :param layer: A layer.
        :type layer:  QgsMapLayer or SAFE layer.

        :returns:   The layer of appropriate type
        :rtype:     SAFE or QgisWrapper

        :raises: InsufficientParametersError if self._function is not set,
                 InvalidParameterError if style of self._function is not
                     in ('old-style', 'qgis2.0')
                 Any exceptions raised by other libraries will be propogated.
        """

        if self._function is None or self._function == '':
            message = self.tr('Error: Function not set.')
            raise InsufficientParametersError(message)

        # Get type of the impact function (old-style or new-style)
        try:
            func_type = getSafeImpactFunctionType(self._function)
            if func_type == 'old-style':
                return convertToSafeLayer(layer)
            elif func_type == 'qgis2.0':
                # convert for new style impact function
                return QgisWrapper(layer)
            else:
                message = self.tr('Error: Function has unknown style.')
                raise InvalidParameterError(message)
        except:
            raise
コード例 #2
0
ファイル: views.py プロジェクト: Saumitra-Shukla/webandgis
def get_layer_data(layer_name):
    layer = Layer.objects.get(name=layer_name)
    layer_path = os.path.join(settings.MEDIA_ROOT, 'layers', layer.slug, 'raw')
    os.chdir(layer_path)
    filename = glob.glob('*.shp')[0]
    layer_file = os.path.join(layer_path, filename)
    layer_object = QgsVectorLayer(layer_file, layer.name, 'ogr')
    map_layer = QgisWrapper(layer_object)

    return map_layer
コード例 #3
0
 def setUp(self):
     data_path = os.path.join(UNITDATA, 'impact',
                              'aggregation_test_roads.shp')
     self.layer = QgsVectorLayer(data_path, 'test vector', 'ogr')
     self.wrapper = QgisWrapper(self.layer)