Esempio n. 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
Esempio n. 2
0
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
Esempio n. 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)
Esempio n. 4
0
class QgisLayerWrapperTest(unittest.TestCase):
    """Test that context help works."""

    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)

    def test_get_keywords(self):
        """Test get_keywords work
        """
        expected = {
            'map_title': 'Roads inundated',
            'target_field': 'flooded',
            'title': 'aggregation_test_roads'
        }
        keywords = self.wrapper.get_keywords()
        self.assertEquals(keywords, expected)

        expected = 'flooded'
        keyword = self.wrapper.get_keywords('target_field')
        self.assertEquals(keyword, expected)

        self.assertRaises(
            KeywordNotFoundError,
            self.wrapper.get_keywords,
            'ThisKeyDoesNotExist'
        )

    def test_get_name(self):
        """Test get_name work
        """
        name = self.wrapper.get_name()
        expected = 'aggregation_test_roads'
        self.assertEquals(name, expected)

        name = 'NewName'
        self.wrapper.set_name(name)
        self.assertEquals(self.wrapper.get_name(), name)

    def test_get_layer(self):
        """Test get_layer work
        """
        layer = self.wrapper.get_layer()
        self.assertEquals(self.layer, layer)
class QgisLayerWrapperTest(unittest.TestCase):
    """Test that context help works."""
    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)

    def test_get_keywords(self):
        """Test get_keywords work
        """
        expected = {
            'map_title': 'Roads inundated',
            'target_field': 'flooded',
            'title': 'aggregation_test_roads'
        }
        keywords = self.wrapper.get_keywords()
        self.assertEquals(keywords, expected)

        expected = 'flooded'
        keyword = self.wrapper.get_keywords('target_field')
        self.assertEquals(keyword, expected)

        self.assertRaises(KeywordNotFoundError, self.wrapper.get_keywords,
                          'ThisKeyDoesNotExist')

    def test_get_name(self):
        """Test get_name work
        """
        name = self.wrapper.get_name()
        expected = 'aggregation_test_roads'
        self.assertEquals(name, expected)

        name = 'NewName'
        self.wrapper.set_name(name)
        self.assertEquals(self.wrapper.get_name(), name)

    def test_get_layer(self):
        """Test get_layer work
        """
        layer = self.wrapper.get_layer()
        self.assertEquals(self.layer, layer)
 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)