Exemplo n.º 1
0
        public void DissolveLargefile(tkGeometryEngine geometryEngine)
        {
            var          tempFolder = Helper.WorkingFolder("DissolveLargefile");
            const string sfLocation = @"D:\dev\GIS-Data\Issues\MWGIS-78 Clipper\FishnetClipped_fix.shp";
            var          sfOutput   = Path.Combine(tempFolder, $"FishnetDissolved-{geometryEngine.ToString()}.shp");

            if (File.Exists(sfOutput))
            {
                Helper.DeleteShapefile(sfOutput);
            }
            const int fieldIndex = 5;

            var sf = Helper.OpenShapefile(sfLocation);

            sf.GeometryEngine = geometryEngine;
            Helper.DebugMsg("numShapes Input: " + sf.NumShapes);
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var sfDissolved = sf.Dissolve(fieldIndex, false);

            Helper.DebugMsg("Time it took to dissolve: " + stopWatch.Elapsed);
            stopWatch.Restart();

            Assert.IsNotNull(sfDissolved, "sfDissolved is null: " + sf.ErrorMsg[sf.LastErrorCode]);

            Helper.SaveAsShapefile(sfDissolved, sfOutput);
            Helper.DebugMsg("NumShapes: " + sfDissolved.NumShapes);
            Helper.CheckValidity(sfDissolved);
            Assert.IsFalse(sfDissolved.HasInvalidShapes(), "Result has invalid shapes");
            if (!sfDissolved.Close())
            {
                Assert.Fail("Can't close sfDissolved Error: " + sfDissolved.ErrorMsg[sfDissolved.LastErrorCode]);
            }
            ;
            if (!sf.Close())
            {
                Assert.Fail("Can't close sf Error: " + sf.ErrorMsg[sf.LastErrorCode]);
            }
            ;
        }
Exemplo n.º 2
0
        private static void MergeShapefile(tkGeometryEngine geometryEngine)
        {
            var tempFolder = Helper.WorkingFolder("MergeShapefile");

            const string sfInputfile  = @"D:\dev\GIS-Data\Issues\MWGIS-78 Clipper\FewPolygons.shp";
            var          sfOutputFile = Path.Combine(tempFolder, $"FewPolygons_Merged_{geometryEngine.ToString()}.shp");

            var sfInput = Helper.OpenShapefile(sfInputfile);

            if (File.Exists(sfOutputFile))
            {
                Helper.DeleteShapefile(sfOutputFile);
            }

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            sfInput.GeometryEngine = geometryEngine;
            var newShape = sfInput.Shape[0];

            for (var i = 1; i < sfInput.NumShapes; i++)
            {
                // Union all shapes together:
                newShape = newShape.Clip(sfInput.Shape[i], tkClipOperation.clUnion);
            }
            Helper.DebugMsg("Time it took: " + stopWatch.Elapsed);
            stopWatch.Restart();
            Assert.IsNotNull(newShape, "newShape is null: " + newShape.ErrorMsg[newShape.LastErrorCode]);

            var sfOutput = new Shapefile();

            sfOutput.CreateNewWithShapeID(sfOutputFile, ShpfileType.SHP_POLYGON);
            var numShape = 0;
            var retVal   = sfOutput.EditInsertShape(newShape, ref numShape);

            Assert.IsTrue(retVal, "Failed to add shape");
            sfOutput.StopEditingShapes();

            Assert.IsTrue(File.Exists(sfOutputFile), "Output does not exists");
            Helper.DebugMsg(sfOutputFile);

            Helper.DebugMsg("NumShapes: " + sfOutput.NumShapes);
            Assert.AreEqual(sfOutput.NumShapes, 1);

            if (!sfInput.Close())
            {
                Assert.Fail("Can't close sfBorder Error: " + sfInput.ErrorMsg[sfInput.LastErrorCode]);
            }
            if (!sfOutput.Close())
            {
                Assert.Fail("Can't close sfClipped Error: " + sfOutput.ErrorMsg[sfOutput.LastErrorCode]);
            }
        }
Exemplo n.º 3
0
        private static void Clipfile(tkGeometryEngine geometryEngine, double multiplier, double size)
        {
            if (_settings == null)
            {
                Assert.Fail("Settings are not set");
            }
            var tempFolder = Helper.WorkingFolder("Clipfile");
            var stopWatch  = new Stopwatch();

            _settings.MinPolygonArea = Math.Min(_settings.MinPolygonArea, size * size / 4);

            stopWatch.Start();
            var sfBorder = CreateBorder(multiplier);

            Helper.DebugMsg("Time it took to create the border: " + stopWatch.Elapsed);
            stopWatch.Restart();

            Helper.SaveAsShapefile(sfBorder, Path.Combine(tempFolder, $"{DateTime.Now.Ticks} clip_border_{geometryEngine.ToString()}_{multiplier}.shp"));
            var sfFishnet = Helper.CreateFishnet(sfBorder.Extents, size, size);

            Helper.DebugMsg("Time it took to create the fishnet: " + stopWatch.Elapsed);
            stopWatch.Restart();

            sfFishnet.GeoProjection = sfBorder.GeoProjection;
            Helper.SaveAsShapefile(sfFishnet, Path.Combine(tempFolder, $"{DateTime.Now.Ticks} clip_smallFishnet_{geometryEngine.ToString()}_{size}.shp"));

            if (sfBorder.HasInvalidShapes())
            {
                Helper.DebugMsg("Border has invalid shapes");
            }
            if (sfFishnet.HasInvalidShapes())
            {
                Helper.DebugMsg("Fishnet has invalid shapes");
            }

            sfFishnet.GeometryEngine = geometryEngine;
            var sfClipped = sfFishnet.Clip(false, sfBorder, false);

            Helper.DebugMsg("Time it took to clip: " + stopWatch.Elapsed);
            stopWatch.Restart();

            Assert.IsNotNull(sfClipped, "sfClipped is null: " + sfFishnet.ErrorMsg[sfFishnet.LastErrorCode]);

            var sfOutputFile = Path.Combine(tempFolder, $"{DateTime.Now.Ticks}  FishnetClipped_{geometryEngine.ToString()}_{multiplier}_{size}.shp");

            Helper.SaveAsShapefile(sfClipped, sfOutputFile);

            if (!sfBorder.Close())
            {
                Assert.Fail("Can't close sfBorder Error: " + sfBorder.ErrorMsg[sfBorder.LastErrorCode]);
            }
            if (!sfFishnet.Close())
            {
                Assert.Fail("Can't close sfClipped Error: " + sfFishnet.ErrorMsg[sfFishnet.LastErrorCode]);
            }

            Helper.DebugMsg("Checking if the output file has any invalid shapes .... ");
            Assert.IsFalse(sfClipped.HasInvalidShapes(), "Output file has invalid shapes");
            if (!sfClipped.Close())
            {
                Assert.Fail("Can't close sfClipped Error: " + sfClipped.ErrorMsg[sfClipped.LastErrorCode]);
            }
        }
Exemplo n.º 4
0
        private static void ClipLargefile(tkGeometryEngine geometryEngine)
        {
            // When not calles
            if (_settings == null)
            {
                Assert.Fail("Settings are not set");
            }

            // ogr2ogr -clipsrc "Droog-Sloefweg.WGS 84 - UTM zone 31N.shp" clipped.shp Fishnet.shp
            var tempFolder = Helper.WorkingFolder("ClipLargefile");

            const string sfFishnetFile = @"D:\dev\GIS-Data\Issues\MWGIS-78 Clipper\Fishnet.shp";
            const string sfBorderFile  = @"D:\dev\GIS-Data\Issues\MWGIS-78 Clipper\border.shp";
            var          sfOutputFile  = Path.Combine(tempFolder, $"{DateTime.Now.Ticks} FishnetClipped_{geometryEngine.ToString()}.shp");

            var sfFishnet = Helper.OpenShapefile(sfFishnetFile, false);
            var sfBorder  = Helper.OpenShapefile(sfBorderFile, false);

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            sfFishnet.GeometryEngine = geometryEngine;
            var sfClipped = sfFishnet.Clip(false, sfBorder, false);

            Helper.DebugMsg("Time it took to clip: " + stopWatch.Elapsed);
            stopWatch.Restart();
            Helper.DebugMsg("sfBorder.ErrorMsg: " + sfBorder.ErrorMsg[sfBorder.LastErrorCode]);
            Helper.DebugMsg("sfFishnet.ErrorMsg: " + sfFishnet.ErrorMsg[sfFishnet.LastErrorCode]);
            Helper.DebugMsg("sfClipped.ErrorMsg: " + sfClipped.ErrorMsg[sfClipped.LastErrorCode]);
            Assert.IsNotNull(sfClipped, "sfClipped is null: " + sfClipped.ErrorMsg[sfClipped.LastErrorCode]);

            Helper.SaveAsShapefile(sfClipped, sfOutputFile);
            Helper.DebugMsg("NumShapes: " + sfClipped.NumShapes);

            if (!sfBorder.Close())
            {
                Assert.Fail("Can't close sfBorder Error: " + sfBorder.ErrorMsg[sfBorder.LastErrorCode]);
            }
            if (!sfFishnet.Close())
            {
                Assert.Fail("Can't close sfClipped Error: " + sfFishnet.ErrorMsg[sfFishnet.LastErrorCode]);
            }

            Helper.DebugMsg("Checking if the output file has any invalid shapes .... ");
            Assert.IsFalse(sfClipped.HasInvalidShapes(), "Output file has invalid shapes");
            if (!sfClipped.Close())
            {
                Assert.Fail("Can't close sfClipped Error: " + sfClipped.ErrorMsg[sfClipped.LastErrorCode]);
            }
        }
Exemplo n.º 5
0
        private static void DissolveSmallfile(tkGeometryEngine geometryEngine)
        {
            var tempFolder = Helper.WorkingFolder("DissolveSmallfile");
            // const string sfLocation = @"D:\dev\GIS-Data\Issues\MWGIS-78 Clipper\FewPolygons.shp";
            const string sfLocation = @"D:\dev\GIS-Data\Issues\MWGIS-78 Clipper\FishnetClipped_export2.shp";
            var          sfOutput   = Path.Combine(tempFolder, $"FewPolygons-Dissolved_{geometryEngine.ToString()}.shp");
            const int    fieldIndex = 5;

            var sf = Helper.OpenShapefile(sfLocation);

            if (File.Exists(sfOutput))
            {
                Helper.DeleteShapefile(sfOutput);
            }

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            sf.GeometryEngine = geometryEngine;
            var sfDissolved = sf.Dissolve(fieldIndex, false);

            Helper.DebugMsg("Time it took: " + stopWatch.Elapsed);
            stopWatch.Restart();
            Assert.IsNotNull(sfDissolved, "sfDissolved is null: " + sf.ErrorMsg[sf.LastErrorCode]);

            Helper.SaveAsShapefile(sfDissolved, sfOutput);
            Helper.DebugMsg("NumShapes: " + sfDissolved.NumShapes);
            Assert.AreEqual(12, sfDissolved.NumShapes, 1, "Too few shapes");

            Helper.CheckValidity(sfDissolved);
            Assert.IsFalse(sfDissolved.HasInvalidShapes(), "Result has invalid shapes");
        }