private static void TestWithSplittingLargeShapeFIle(ProgramOptions options, int z) { var helper = new OgrHelper(new DefaultEnvironmentVariableProvider( readOnlyValues: new Dictionary<string, string>{ { "gdal" , @"C:\python\WinPython-64bit-2.7.6.4-gdal\tools\gdal"}, { "GDAL_DATA",@"C:\python\WinPython-64bit-2.7.6.4-gdal\tools\gdal-data"} })); var source = new OgrDataSource(helper, options.Source); source.CacheDir = options.CacheDir; var layer = source.GetLayerContext("jordstykke") as OgrLayer<OgrEntity>; var extent = layer.ExtentAsync.Result; var from = ProjectionInfo.FromProj4String(layer.Proj4TextAsync.Result); var to = ProjectionInfo.FromEpsgCode(3857); Reproject.ReprojectPoints(extent, null, from, to, 0, 2); var grid = new XYZTileGrid(new TileGrid.TileGridOptions { MinZoom = 0, }); TileRange range; do { range = grid.GetTileRangeForExtentAndZ(extent, z); } while (!(range.MinX == range.MaxX && range.MinY == range.MaxY) && z-- > 0); range = grid.GetTileCoordChildTileRange(new int[] { z, range.MinX, range.MinY }); var createOriginalVectorBlock = grid.CreateCoordinateTreeWalker(extent, async (xyz, parent, tileExtent) => { var targetPath = string.Format(@"C:\TestCacheDir\{0}\{1}\{2}.shp", xyz[0], xyz[1], xyz[2]); var sourcePath = string.Format(@"C:\TestCacheDir\{0}\{1}\{2}.shp", parent[0], parent[1], parent[2]); if (!File.Exists(targetPath)) { if (!File.Exists(sourcePath)) { sourcePath = @"C:\dev\DK_SHAPE_UTM32-EUREF89\MINIMAKS\BASIS\JORDSTYKKE.shp"; Reproject.ReprojectPoints(tileExtent, null, to, from, 0, 2); } Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); try { var exitcode = await helper.Ogr2OgrClipAsync( sourcePath, targetPath, "epsg:" + to.AuthorityCode, tileExtent); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }, z, 5); createOriginalVectorBlock.LinkTo(new ActionBlock<TileRange>((r) => { })); createOriginalVectorBlock.Post(range); createOriginalVectorBlock.Complete(); createOriginalVectorBlock.Completion.Wait(); }
private static void TestWithSplittingLargeShapeFIle(ProgramOptions options, int z) { var helper = new OgrHelper(new DefaultEnvironmentVariableProvider(readOnlyValues: new Dictionary <string, string> { { "gdal", @"C:\python\WinPython-64bit-2.7.6.4-gdal\tools\gdal" }, { "GDAL_DATA", @"C:\python\WinPython-64bit-2.7.6.4-gdal\tools\gdal-data" } })); var source = new OgrDataSource(helper, options.Source); source.CacheDir = options.CacheDir; var layer = source.GetLayerContext("jordstykke") as OgrLayer <OgrEntity>; var extent = layer.ExtentAsync.Result; var from = ProjectionInfo.FromProj4String(layer.Proj4TextAsync.Result); var to = ProjectionInfo.FromEpsgCode(3857); Reproject.ReprojectPoints(extent, null, from, to, 0, 2); var grid = new XYZTileGrid(new TileGrid.TileGridOptions { MinZoom = 0, }); TileRange range; do { range = grid.GetTileRangeForExtentAndZ(extent, z); } while (!(range.MinX == range.MaxX && range.MinY == range.MaxY) && z-- > 0); range = grid.GetTileCoordChildTileRange(new int[] { z, range.MinX, range.MinY }); var createOriginalVectorBlock = grid.CreateCoordinateTreeWalker(extent, async(xyz, parent, tileExtent) => { var targetPath = string.Format(@"C:\TestCacheDir\{0}\{1}\{2}.shp", xyz[0], xyz[1], xyz[2]); var sourcePath = string.Format(@"C:\TestCacheDir\{0}\{1}\{2}.shp", parent[0], parent[1], parent[2]); if (!File.Exists(targetPath)) { if (!File.Exists(sourcePath)) { sourcePath = @"C:\dev\DK_SHAPE_UTM32-EUREF89\MINIMAKS\BASIS\JORDSTYKKE.shp"; Reproject.ReprojectPoints(tileExtent, null, to, from, 0, 2); } Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); try { var exitcode = await helper.Ogr2OgrClipAsync( sourcePath, targetPath, "epsg:" + to.AuthorityCode, tileExtent); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }, z, 5); createOriginalVectorBlock.LinkTo(new ActionBlock <TileRange>((r) => { })); createOriginalVectorBlock.Post(range); createOriginalVectorBlock.Complete(); createOriginalVectorBlock.Completion.Wait(); }