コード例 #1
0
ファイル: test_geom_cabinet.py プロジェクト: NCPP/ocgis
 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)
コード例 #2
0
 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)
コード例 #3
0
ファイル: test_geom_cabinet.py プロジェクト: NCPP/ocgis
    def test_number_in_shapefile_name(self):
        """Test number in shapefile name."""

        sc = GeomCabinet()
        path = sc.get_shp_path('state_boundaries')
        out_path = os.path.join(self.current_dir_output, '51_states.shp')
        with fiona.open(path) as source:
            with fiona.open(out_path, mode='w', driver='ESRI Shapefile', schema=source.meta['schema'],
                            crs=source.meta['crs']) as sink:
                for record in source:
                    sink.write(record)
        ret = list(GeomCabinetIterator(select_uid=[23], path=out_path))
        self.assertEqual(len(ret), 1)
コード例 #4
0
    def test_number_in_shapefile_name(self):
        """Test number in shapefile name."""

        sc = GeomCabinet()
        path = sc.get_shp_path('state_boundaries')
        out_path = os.path.join(self.current_dir_output, '51_states.shp')
        with fiona.open(path) as source:
            with fiona.open(out_path, mode='w', driver='ESRI Shapefile', schema=source.meta['schema'],
                            crs=source.meta['crs']) as sink:
                for record in source:
                    sink.write(record)
        ret = list(GeomCabinetIterator(select_uid=[23], path=out_path))
        self.assertEqual(len(ret), 1)
コード例 #5
0
ファイル: test_shp_process.py プロジェクト: NCPP/ocgis
    def test_process_name(self):
        copy_path = os.path.join(self.current_dir_output, 'test_shp_process')
        sc = GeomCabinet()
        test_path = os.path.split(sc.get_shp_path('wc_4326'))[0]
        shutil.copytree(test_path, copy_path)

        shp_path = os.path.join(copy_path, 'wc_4326.shp')
        out_folder = tempfile.mkdtemp(dir=self.current_dir_output)
        sp = ShpProcess(shp_path, out_folder)
        sp.process(key='world_countries', ugid=None, name='new_id')
        path = os.path.join(out_folder, 'world_countries.shp')
        with fiona.open(path, 'r') as sci:
            uids = [record['properties']['new_id'] for record in sci]
        self.assertEqual(uids, list(range(1, 212)))
コード例 #6
0
    def test_process_name(self):
        copy_path = os.path.join(self.current_dir_output, 'test_shp_process')
        sc = GeomCabinet()
        test_path = os.path.split(sc.get_shp_path('wc_4326'))[0]
        shutil.copytree(test_path, copy_path)

        shp_path = os.path.join(copy_path, 'wc_4326.shp')
        out_folder = tempfile.mkdtemp(dir=self.current_dir_output)
        sp = ShpProcess(shp_path, out_folder)
        sp.process(key='world_countries', ugid=None, name='new_id')
        path = os.path.join(out_folder, 'world_countries.shp')
        with fiona.open(path, 'r') as sci:
            uids = [record['properties']['new_id'] for record in sci]
        self.assertEqual(uids, list(range(1, 212)))
コード例 #7
0
ファイル: test_shp_process.py プロジェクト: NCPP/ocgis
    def test_shp_process(self):
        copy_path = os.path.join(self.current_dir_output, 'test_shp_process')
        sc = GeomCabinet()
        test_path = os.path.split(sc.get_shp_path('wc_4326'))[0]
        shutil.copytree(test_path, copy_path)

        shp_path = os.path.join(copy_path, 'wc_4326.shp')
        out_folder = tempfile.mkdtemp(dir=self.current_dir_output)
        sp = ShpProcess(shp_path, out_folder)
        sp.process(key='world_countries', ugid=None)

        sc = GeomCabinet(path=out_folder)
        select_ugid = [33, 126, 199]
        geoms = list(sc.iter_geoms('world_countries', select_uid=select_ugid))
        self.assertEqual(len(geoms), 3)
        names = [item['properties']['NAME'] for item in geoms]
        self.assertEqual(set(names), set(['Canada', 'Mexico', 'United States']))
コード例 #8
0
    def test_shp_process(self):
        copy_path = os.path.join(self.current_dir_output, 'test_shp_process')
        sc = GeomCabinet()
        test_path = os.path.split(sc.get_shp_path('wc_4326'))[0]
        shutil.copytree(test_path, copy_path)

        shp_path = os.path.join(copy_path, 'wc_4326.shp')
        out_folder = tempfile.mkdtemp(dir=self.current_dir_output)
        sp = ShpProcess(shp_path, out_folder)
        sp.process(key='world_countries', ugid=None)

        sc = GeomCabinet(path=out_folder)
        select_ugid = [33, 126, 199]
        geoms = list(sc.iter_geoms('world_countries', select_uid=select_ugid))
        self.assertEqual(len(geoms), 3)
        names = [item['properties']['NAME'] for item in geoms]
        self.assertEqual(set(names), set(['Canada', 'Mexico', 'United States']))