def _run_(s, func): try: ds = ogr.Open(path) obj = GeomCabinet._get_features_object_(ds, select_sql_where=s) func(obj) finally: ds.Destroy()
def test_misc_sql_subset(self): sc = GeomCabinet() path = sc.get_shp_path('state_boundaries') ds = ogr.Open(path) ret = ds.ExecuteSQL("select * from state_boundaries where state_name = 'New Jersey'") ret.ResetReading() self.assertEqual(len(ret), 1)
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()