Пример #1
0
    def test_get_features_object_file_geodatabase(self):
        ds = mock.create_autospec(ogr.DataSource, spec_set=True)
        m_Driver = mock.Mock()
        m_Driver.GetName = mock.Mock(return_value='OpenFileGDB')
        ds.GetDriver = mock.Mock(return_value=m_Driver)
        ds.GetLayerByName = mock.Mock()

        with self.assertRaises(ValueError):
            _ = GeomCabinet._get_features_object_(ds)

        desired = {'feature_class': 'foo'}
        _ = GeomCabinet._get_features_object_(ds, driver_kwargs=desired)
        ds.GetLayerByName.assert_called_once_with(desired['feature_class'])
Пример #2
0
    def test_get_features_object_file_geodatabase(self):
        ds = mock.create_autospec(ogr.DataSource, spec_set=True)
        m_Driver = mock.Mock()
        m_Driver.GetName = mock.Mock(return_value='OpenFileGDB')
        ds.GetDriver = mock.Mock(return_value=m_Driver)
        ds.GetLayerByName = mock.Mock()

        with self.assertRaises(ValueError):
            _ = GeomCabinet._get_features_object_(ds)

        desired = {'feature_class': 'foo'}
        _ = GeomCabinet._get_features_object_(ds, driver_kwargs=desired)
        ds.GetLayerByName.assert_called_once_with(desired['feature_class'])
Пример #3
0
 def _run_(s, func):
     try:
         ds = ogr.Open(path)
         obj = GeomCabinet._get_features_object_(ds, select_sql_where=s)
         func(obj)
     finally:
         ds.Destroy()
Пример #4
0
 def _run_(s, func):
     try:
         ds = ogr.Open(path)
         obj = GeomCabinet._get_features_object_(ds, select_sql_where=s)
         func(obj)
     finally:
         ds.Destroy()
Пример #5
0
    def test_get_features_object(self):
        # Test with a shapefile not having the default unique geometry identifier
        path = self.get_shapefile_path_with_no_ugid()
        keywords = dict(uid=[None, 'ID'],
                        select_uid=[None, [8, 11, 13]],
                        select_sql_where=[None, "STATE_NAME = 'Hawaii'"])

        for k in self.iter_product_keywords(keywords):
            # print(k)
            ds = ogr.Open(path)
            try:
                try:
                    obj = GeomCabinet._get_features_object_(
                        ds,
                        uid=k.uid,
                        select_uid=k.select_uid,
                        select_sql_where=k.select_sql_where)
                except RuntimeError:
                    self.assertIsNone(k.uid)
                    self.assertIsNotNone(k.select_uid)
                    continue

                if k.select_sql_where is not None:
                    length = 1
                elif k.select_uid is not None:
                    length = 3
                else:
                    length = 11
                self.assertEqual(len(obj), length)
                self.assertIsInstance(obj, Layer)
            finally:
                ds.Destroy()

        # Test on a shapefile having the default unique geometry identifier
        path = GeomCabinet().get_shp_path('state_boundaries')
        ds = ogr.Open(path)
        try:
            obj = GeomCabinet._get_features_object_(ds, select_uid=[8, 11, 13])
            self.assertEqual(len(obj), 3)
        finally:
            ds.Destroy()
Пример #6
0
    def test_get_features_object(self):
        # Test with a shapefile not having the default unique geometry identifier
        path = self.get_shapefile_path_with_no_ugid()
        keywords = dict(uid=[None, 'ID'],
                        select_uid=[None, [8, 11, 13]],
                        select_sql_where=[None, "STATE_NAME = 'Hawaii'"])

        for k in self.iter_product_keywords(keywords):
            # print(k)
            ds = ogr.Open(path)
            try:
                try:
                    obj = GeomCabinet._get_features_object_(ds, uid=k.uid, select_uid=k.select_uid,
                                                            select_sql_where=k.select_sql_where)
                except RuntimeError:
                    self.assertIsNone(k.uid)
                    self.assertIsNotNone(k.select_uid)
                    continue

                if k.select_sql_where is not None:
                    length = 1
                elif k.select_uid is not None:
                    length = 3
                else:
                    length = 11
                self.assertEqual(len(obj), length)
                self.assertIsInstance(obj, Layer)
            finally:
                ds.Destroy()

        # Test on a shapefile having the default unique geometry identifier
        path = GeomCabinet().get_shp_path('state_boundaries')
        ds = ogr.Open(path)
        try:
            obj = GeomCabinet._get_features_object_(ds, select_uid=[8, 11, 13])
            self.assertEqual(len(obj), 3)
        finally:
            ds.Destroy()