コード例 #1
0
 private void OpenDatasource()
 {
     _datasource.Close();
     if (!OgrHelper.OpenDatasource(_datasource, _connection))
     {
         return;
     }
     PopulateList();
 }
コード例 #2
0
        public static void ImportOgrLayer()
        {
            int layerHandle = App.Legend.SelectedLayer;

            if (layerHandle == -1)
            {
                return;
            }

            var sf = App.Map.get_Shapefile(layerHandle);

            if (sf == null)
            {
                MessageHelper.Info("Selected layer is not a vector layer.");
                return;
            }

            using (var form = new OgrConnectionForm())
            {
                if (form.ShowDialog(MainForm.Instance) == DialogResult.OK)
                {
                    var ds = new OgrDatasource();
                    if (!OgrHelper.OpenDatasource(ds, form.ConnectionParams))
                    {
                        return;
                    }

                    string layerName = App.Map.get_LayerName(layerHandle);
                    layerName = layerName.Replace(".", "_");

                    using (var importForm = new OgrImportShapefile(layerName))
                    {
                        if (importForm.ShowDialog(MainForm.Instance) == DialogResult.OK)
                        {
                            layerName = importForm.LayerName;
                            if (!ds.ImportShapefile(sf, layerName, "", tkShapeValidationMode.NoValidation))
                            {
                                MessageHelper.Warn("Failed to import shapefile: " + ds.GdalLastErrorMsg);
                            }
                            else
                            {
                                MessageHelper.Info("Layer was imported: " + layerName);
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
 public OgrDataSource(OgrHelper helper, string source)
 {
     Source    = source;
     OgrHelper = helper;
 }
コード例 #4
0
        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();
        }