Esempio n. 1
0
        /// <summary>
        /// Export Mike SHP Results to AC file
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="ac_filename"></param>
        /// <param name="shpfiles"></param>
        /// <param name="field"></param>
        public void Export(ITriangularGrid grid, string ac_filename, string[] shpfiles, string field)
        {
            int steps = shpfiles.Length;
            int nfeature = grid.VertexCount;
            var buf = new DataCube<float>(1, steps, nfeature);

            for (int i = 0; i < steps; i++)
            {
                var fs = FeatureSet.Open(shpfiles[i]);
                var vec = (from dr in fs.DataTable.AsEnumerable() select (float)dr.Field<double>(field)).ToArray();
                for (int k = 0; k < grid.VertexCount; k++)
                {
                    var cells = grid.Topology.NodeConnectedCells[k];
                    float temp = 0;
                    for (int c = 0; c < cells.Length; c++)
                    {
                        temp += vec[cells[c]];
                    }
                    temp /= cells.Length;
                    buf[0, i, k] = temp;
                }
                fs.Close();
            }
            buf.Variables = new string[] { field };
            DataCubeStreamWriter ac = new DataCubeStreamWriter(ac_filename);
            ac.WriteAll(buf);
        }
Esempio n. 2
0
        public void Extract(string mfn_file, string fs_file, int lurow, int lucol, int rlrow, int rlcol)
        {
            IFeatureSet fs = FeatureSet.Open(fs_file);
            Modflow     mf = new Modflow();

            mf.TimeUnit   = this.TimeUnit;
            mf.LengthUnit = this.LengthUnit;

            MFGrid rawgrid = this.Grid as MFGrid;

            mf.Grid = rawgrid.Extract(fs, lurow, lucol, rlrow, rlcol);
            FileInfo finfo = new FileInfo(mfn_file);
            string   mfn   = Path.GetFileNameWithoutExtension(mfn_file);

            foreach (var pckname in this.Packages.Keys)
            {
                var pck = this.Packages[pckname] as IExtractMFPackage;
                if (pck != null)
                {
                    var newpck = pck.Extract(mf);
                    if (newpck != null)
                    {
                        newpck.FileName = Path.Combine(finfo.DirectoryName, mfn + newpck.PackageInfo.FileExtension);
                        mf.AddInSilence(newpck);
                    }
                }
            }

            foreach (var pck in mf.Packages.Values)
            {
                pck.Save(null);
            }

            _MFNameManager.Save(ControlFileName);
        }
Esempio n. 3
0
        public override void CreateGridFeature()
        {
            this.GridFeatureFilePath     = ".\\GeoSpatial\\Grid.shp";
            this.CentroidFeatureFilePath = ".\\GeoSpatial\\Centroid.shp";
            var full_gridfea_file  = Path.Combine(this.AbsolutePathToProjectFile, GridFeatureFilePath);
            var full_centroid_file = Path.Combine(this.AbsolutePathToProjectFile, CentroidFeatureFilePath);

            this.Model.Grid.Build(full_gridfea_file);
            var fs_grid = FeatureSet.Open(full_gridfea_file);

            _GridLayer = new MapPolygonLayer(fs_grid);

            this.Model.Grid.FeatureSet   = fs_grid;
            this.Model.Grid.FeatureLayer = _GridLayer;
            this.Map.Layers.Add(_GridLayer);

            this.Model.Grid.BuildCentroid(full_centroid_file);
            var fs_centroid = FeatureSet.Open(full_centroid_file);

            _CentroidLayer = new MapPointLayer(fs_centroid);
            this.Model.Grid.CentroidFeature      = fs_centroid;
            this.Model.Grid.CentroidFeatureLayer = _CentroidLayer;
            this.Map.Layers.Add(_CentroidLayer);

            this.Map.Invalidate();
        }
        public void TestMapFrameIsNotNull()
        {
            const string filename        = @".\TestFiles\test-RandomPts.shp";
            const string projectFileName = @".\testmapframeisnotnull.dspx";
            //string projPath = Path.Combine(Path.GetTempPath(), projectFileName);

            AppManager manager = new AppManager();
            Map        map     = new Map();

            manager.Map = map;

            IFeatureSet   fs = FeatureSet.Open(filename);
            MapPointLayer l  = new MapPointLayer(fs);

            map.Layers.Add(l);
            Assert.Greater(map.Layers.Count, 0);

            manager.SerializationManager.SaveProject(projectFileName);
            Assert.True(System.IO.File.Exists(projectFileName));

            //reopen the project
            map.Layers.Clear();
            Assert.AreEqual(map.Layers.Count, 0);

            manager.SerializationManager.OpenProject(projectFileName);
            Assert.Greater(map.Layers.Count, 0);
            Assert.IsNotNull(map.Layers[0].MapFrame);

            //delete file
            System.IO.File.Delete(projectFileName);
        }
Esempio n. 5
0
        public bool ImportShapefile(string filePath, string name, string p, bool addedFromProject, bool relativePath = false)
        {
            IFeatureSet fs = null;

            try
            {
                fs = FeatureSet.Open(filePath);
            }
            catch
            {
                fs = null;
                return(false);
            }

            var mapLayer = GetMapLayerFromFeatureSet(fs);

            mapLayer.LegendText = name;
            mapLayer.Reproject(this.map.MapFrame.Projection);

            this.map.Layers.Add(mapLayer);

            if (!addedFromProject)
            {
                string savePath = filePath;
                if (relativePath)
                {
                    savePath = Path.GetFileName(filePath);
                }
                this.projectMgr.SetProperty(Section_Layers, mapLayer.LegendText, savePath);
            }

            return(true);
        }
Esempio n. 6
0
        public static void Initial()
        {
            var featureSet = FeatureSet.Open(ConfigurationManager.AppSettings["shpPath"]);

            Streets = featureSet.Features;
            featureSet.Dispose();
        }
Esempio n. 7
0
        private void NewFeatureLayer(DotSpatial.Controls.IMap map, string directory)
        {
            string filename = Path.Combine(directory, this.Name + ".shp");

            if (!File.Exists(filename))
            {
                CreateFeature(map.Projection, directory);
            }

            this.Feature = FeatureSet.Open(filename);
            if (this.Feature.FeatureType == FeatureType.Polygon)
            {
                var layer = new MapPolygonLayer(this.Feature);
                map.Layers.Add(layer);
                this.FeatureLayer = layer;
            }
            else if (this.Feature.FeatureType == FeatureType.Line)
            {
                var layer = new MapLineLayer(this.Feature);
                map.Layers.Add(layer);
                this.FeatureLayer = layer;
            }
            else if (this.Feature.FeatureType == FeatureType.Point)
            {
                var layer = new MapPointLayer(this.Feature);
                map.Layers.Add(layer);
                this.FeatureLayer = layer;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Default loading: We add the U.S states layer to our map
        /// </summary>
        private void frmMain_Load(object sender, EventArgs e)
        {
            //set superscript in grpVolume
            grpResults.Text = "Results";

            string executablePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string dataFolder     = Path.Combine(executablePath, "Snow_Data");

            //get path of the shapefile in the Snow_Data subfolder
            string statesShapefile = Path.Combine(dataFolder, "us_states.shp");

            if (File.Exists(statesShapefile))
            {
                //set map symbol to transparent color and black outline
                IFeatureSet     statesF     = FeatureSet.Open(statesShapefile);
                MapPolygonLayer statesLayer = new MapPolygonLayer(statesF);
                statesLayer.Symbolizer.SetOutline(Color.Black, 1.0);
                statesLayer.Symbolizer.SetFillColor(Color.Transparent);
                mapMain.Layers.Add(statesLayer);
            }

            //get path of the shapefile in the Snow_Data subfolder
            string lakesShapefile = Path.Combine(dataFolder, "us_lakes.shp");

            if (File.Exists(lakesShapefile))
            {
                //set map symbol to blue color and blue outline
                IFeatureSet     lakesF     = FeatureSet.Open(lakesShapefile);
                MapPolygonLayer lakesLayer = new MapPolygonLayer(lakesF);
                lakesLayer.Symbolizer.SetOutline(Color.Blue, 1.0);
                lakesLayer.Symbolizer.SetFillColor(Color.LightBlue);
                mapMain.Layers.Add(lakesLayer);
            }
        }
Esempio n. 9
0
        static void ReadTest1Shp(string shpPath)
        {
            IFeatureSet fs = FeatureSet.Open(shpPath);

            var ntsFec = fs.ToNtsFeatureCollection();

            var newShpPath = Path.Combine(
                Path.GetDirectoryName(shpPath),
                Path.GetFileNameWithoutExtension(shpPath) + "_new.shp");

            var newFs = ntsFec.ToCsFeatureSet();

            newFs.Save(newShpPath);



            var sb         = new StringBuilder();
            var writer     = new StringWriter(sb);
            var serializer = GeoJsonSerializer.CreateDefault();

            serializer.NullValueHandling = NullValueHandling.Ignore;
            serializer.Serialize(writer, ntsFec);
            writer.Flush();


            Console.WriteLine(writer.ToString());
            writer.Dispose();
            Console.WriteLine();
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            string shpPath = "../../Data";

            string[] shpFile = Directory.GetFiles(shpPath, "*.shp", SearchOption.TopDirectoryOnly);

            string savePath = "../../GeoJSON/ShpConverterResult";

            foreach (var file in shpFile)
            {
                IFeatureSet fs = FeatureSet.Open(file);

                IShpConvert shpConvert = new ShpConvert(fs);
                var         geojson    = shpConvert.ToGeoJSON();
                Console.WriteLine(geojson);

                //将GeoJSON保存到本地
                var fileName = Path.GetFileNameWithoutExtension(file) + ".json";
                var fileSave = Path.Combine(savePath, fileName ?? throw new InvalidOperationException());
                using (StreamWriter sw = new StreamWriter(fileSave, false, Encoding.UTF8))
                {
                    sw.Write(geojson);
                }
                Console.WriteLine();
                Console.WriteLine(new string('=', 150));
                Console.WriteLine();
            }


            Console.WriteLine("All Finished");
            Console.ReadLine();
        }
Esempio n. 11
0
        public void loadReleaseFile(string inFileName)
        {
            List <base_release> myReleaseSites = new List <base_release>();
            IFeatureSet         fs             = FeatureSet.Open(inFileName);

            DataTable dt = fs.DataTable;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                base_release br = new base_release();
                IFeature     f  = fs.Features[i];
                br.geom = DbGeometry.FromBinary(f.BasicGeometry.ToBinary(), 0);

                br.MALES      = GetLong(dt.Rows[i], "MALES");
                br.FEMS       = GetLong(dt.Rows[i], "FEMS");
                br.RELEASESIT = GetLong(dt.Rows[i], "RELEASESIT");
                myReleaseSites.Add(br);
            }
            using (me = new MapEntites())
            {
                me.Database.ExecuteSqlCommand("Truncate Table [base_release]");
                me.base_release.AddRange(myReleaseSites);
                me.SaveChanges();
            }
        }
Esempio n. 12
0
        /// <summary>
        /// For all of the significant power that geometries provide, from doing overlay calculations to buffers and convex hulls,
        /// they consume extra memory and are significantly slower for simple tasks. When all you need is access to the shapes,
        /// parts and coordinates (as is the case for drawing) or even if you just need to determine if two shapes intersect,
        /// you can rely on the FeatureSet.ShapeIndices. The code below demonstrates how this works in C#.
        /// Point and MultiPoint shapes only have one part per shape, but in the case of MultiPart, that part may have more than one vertex.
        /// For Lines, each part represents the vertices connected by straight lines, while separate parts are not connected.
        /// For polygons, the parts may be islands or holes. According to the ArcGIS shapefile specification,
        /// each part of a polygon is a simple polygon and the vertices of the polygons are ordered clockwise.
        /// (Effectively so that the inside of the shape is on the right side of the line segments.)
        /// Holes should be ordered counter clockwise. For rendering with MapWindow 6, as long as the winding order
        /// of a hole is the opposite from the islands it will still draw correctly.
        /// </summary>
        public static void CycleThroughShapesPartsAndVertices(string shapefilePath)
        {
            // The feature set class works directly with vector data.
            // Opening a shapefile from disk loads data in "Index" mode by default.
            IFeatureSet fs = FeatureSet.Open(shapefilePath);

            // The shapes rely on an array of double precision interleaved
            // [X1, Y1, X2, Y2, ... Xn, Yn] coordinates.
            double x1 = fs.Vertex[0];
            double y1 = fs.Vertex[1];

            // The shaperange indexes values based on the coordinate index,
            // not the position in the double array.
            // Do access the coordinate directly from the Vertex, multiply by 2.
            x1 = fs.ShapeIndices[2].StartIndex * 2;
            y1 = fs.ShapeIndices[2].StartIndex * 2 + 1;

            // You can use the startindex and count in order to cycle values manually,
            // but it can be confusing.  To make things simpler, the ShapeIndices support an
            // enumeration that allows cycling though the shapes, parts and the vertices.
            foreach (ShapeRange shape in fs.ShapeIndices)
            {
                foreach (PartRange part in shape.Parts)
                {
                    foreach (Vertex vertex in part)
                    {
                        if (vertex.X > 0 && vertex.Y > 0)
                        {
                            // do something
                            Console.WriteLine(vertex.X);
                        }
                    }
                }
            }
        }
Esempio n. 13
0
        }//误点

        private void button1_Click(object sender, EventArgs e)
        {
            //define the projections
            map1.Projection = KnownCoordinateSystems.Projected.UtmNad1983.NAD1983UTMZone12N;
            map2.Projection = KnownCoordinateSystems.Projected.NorthAmerica.NorthAmericaAlbersEqualAreaConic;
            map3.Projection = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousLambertConformalConic;
            map4.Projection = KnownCoordinateSystems.Projected.World.CylindricalEqualAreaworld;
            map5.Projection = KnownCoordinateSystems.Projected.Polar.NorthPoleAzimuthalEquidistant;
            map6.Projection = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousAlbersEqualAreaConicUSGS;

            //add the layers
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Filter = "Shapefiles|*.shp";

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                //add layer to first map
                FeatureSet featureSet1 = new FeatureSet();
                featureSet1.Open(fileDialog.FileName);

                //Populate the FiledName dropdownlist with the help of featureset1.
                //We need to pass featureset as an input paramter to FillColumnNames method.
                FillColumnNames(featureSet1);

                //set the projection
                featureSet1.Reproject(map1.Projection);
                map1.Layers.Add(featureSet1);

                //add layer to second map
                FeatureSet featureSet2 = new FeatureSet();
                featureSet2.Open(fileDialog.FileName);
                featureSet2.Reproject(map2.Projection);
                map2.Layers.Add(featureSet2);

                //add layer to map3
                FeatureSet featureSet3 = new FeatureSet();
                featureSet3.Open(fileDialog.FileName);
                featureSet3.Reproject(map3.Projection);
                map3.Layers.Add(featureSet3);

                //add layer to map4
                FeatureSet featureSet4 = new FeatureSet();
                featureSet4.Open(fileDialog.FileName);
                featureSet4.Reproject(map4.Projection);
                map4.Layers.Add(featureSet4);

                //add layer to map5
                FeatureSet featureSet5 = new FeatureSet();
                featureSet5.Open(fileDialog.FileName);
                featureSet5.Reproject(map5.Projection);
                map5.Layers.Add(featureSet5);

                //add layer to map6
                FeatureSet featureSet6 = new FeatureSet();
                featureSet6.Open(fileDialog.FileName);
                featureSet6.Reproject(map6.Projection);
                map6.Layers.Add(featureSet6);
            }
        }//误点
Esempio n. 14
0
        public void loadMoveFiles(string inFileName)
        {
            List <base_move> myMoveSites = new List <base_move>();
            IFeatureSet      fs          = FeatureSet.Open(inFileName);
            DataTable        dt          = fs.DataTable;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                base_move move = new base_move();
                IFeature  f    = fs.Features[i];
                move.geom       = DbGeometry.FromText(f.BasicGeometry.ToString());
                move.CROSSING   = GetNullableDouble(dt.Rows[i], "CROSSING");
                move.ENERGYUSED = GetNullableDouble(dt.Rows[i], "ENERGYUSED");
                move.MSL        = GetLong(dt.Rows[i], "MSL");
                move.MVL        = GetNullableDouble(dt.Rows[i], "MVL");
                move.PR_X       = GetNullableDouble(dt.Rows[i], "PR_X");
                myMoveSites.Add(move);
            }
            using (me = new MapEntites())
            {
                me.Database.ExecuteSqlCommand("Truncate Table [base_move]");
                me.base_move.AddRange(myMoveSites);
                me.SaveChanges();
            }
        }
Esempio n. 15
0
        public static void UnionShapes()
        {
            IFeatureSet fs     = FeatureSet.Open(@"C:\[Your File Path]\Centroids.shp");
            IFeatureSet result = fs.UnionShapes(ShapeRelateType.Intersecting);

            result.SaveAs(@"C:\[Your File Path]\Municipalities_Test.shp", true);
        }
Esempio n. 16
0
        public void NoDirEdges()
        {
            IFeatureSet fs1 = FeatureSet.Open(Path.Combine(_shapefiles, @"noDirEdgeFiles\catchment.shp"));
            IFeatureSet fs2 = FeatureSet.Open(Path.Combine(_shapefiles, @"noDirEdgeFiles\siteDesignArea.shp"));

            Assert.DoesNotThrow(() => fs1.Intersection(fs2, FieldJoinType.All, null));
        }
Esempio n. 17
0
        public void TestMapFrameIsNotNull()
        {
            string filename        = Path.Combine("Data", "test-RandomPts.shp");
            string projectFileName = FileTools.GetTempFileName(".dspx");

            _filesToRemove.Add(projectFileName);

            AppManager manager = new AppManager();
            Map        map     = new Map();

            manager.Map = map;

            IFeatureSet   fs = FeatureSet.Open(filename);
            MapPointLayer l  = new MapPointLayer(fs);

            map.Layers.Add(l);
            Assert.Greater(map.Layers.Count, 0);

            manager.SerializationManager.SaveProject(projectFileName);
            Assert.True(File.Exists(projectFileName));

            //reopen the project
            map.Layers.Clear();
            Assert.AreEqual(map.Layers.Count, 0);

            manager.SerializationManager.OpenProject(projectFileName);
            Assert.Greater(map.Layers.Count, 0);
            Assert.IsNotNull(map.Layers[0].MapFrame);
        }
Esempio n. 18
0
        public void CoordinateTypeWriteOnSaveAs()
        {
            var         outfile = FileTools.GetTempFileName(".shp");
            IFeatureSet fs      = new FeatureSet();
            var         c       = new Coordinate(10.1, 20.2, 3.3, 4.4);

            fs.CoordinateType = CoordinateType.Z;
            fs.Projection     = KnownCoordinateSystems.Geographic.World.WGS1984;
            fs.DataTable.Columns.Add(new DataColumn("ID", typeof(int)));

            IFeature f = fs.AddFeature(new Point(c));

            f.DataRow.BeginEdit();
            f.DataRow["ID"] = 1;
            f.DataRow.EndEdit();

            fs.SaveAs(outfile, true);

            var actual = FeatureSet.Open(outfile);

            try
            {
                Assert.AreEqual(fs.CoordinateType, actual.CoordinateType);
            }
            finally
            {
                FileTools.DeleteShapeFile(outfile);
            }
        }
        public static void CorrectionCentroid()
        {
            //中心点数据
            List <Coordinate> centroidPoints = new List <Coordinate>(80);
            StreamReader      sr             = new StreamReader(@"D:\OneDrive\2017研究生毕业设计\数据\项目用数据\中心点80.txt");

            sr.ReadLine();//读取标题行
            while (!sr.EndOfStream)
            {
                string[] line = sr.ReadLine().Split(',');
                centroidPoints.Add(new Coordinate(double.Parse(line[1]), double.Parse(line[2])));
            }
            sr.Close();
            //Bus数据,并且构造KD树
            KdTree            myKdtree       = new KdTree(2);
            IFeatureSet       busFS          = FeatureSet.Open(@"D:\OneDrive\2017研究生毕业设计\数据\项目用数据\BusStopGauss.shp");
            List <Coordinate> busStopPoints  = new List <Coordinate>(busFS.NumRows());
            HashSet <int>     checkDuplicate = new HashSet <int>();

            foreach (var item in busFS.Features)
            {
                var c = item.Coordinates[0];
                busStopPoints.Add(c);
                myKdtree.Insert(new double[] { c.X, c.Y }, item);
            }
            Console.WriteLine("数据读取完毕,开始纠正数据");
            IFeatureSet newCentroid = new FeatureSet(FeatureType.Point);

            newCentroid.Name       = "优化过的中心点";
            newCentroid.Projection = ProjectionInfo.FromEpsgCode(GAUSS_EPSG);
            int count = 0;

            foreach (var item in centroidPoints)
            {
                var      nearsestBus = myKdtree.Nearest(new double[] { item.X, item.Y }, 3);
                bool     addSuccess  = false;
                IFeature addFeature  = null;
                for (int i = 0; i < 3; i++)
                {
                    IFeature f = nearsestBus[i] as IFeature;
                    if (f.Coordinates[0].Distance(item) < 100)
                    {
                        if (checkDuplicate.Add(f.Fid))
                        {
                            addFeature = newCentroid.AddFeature(f.BasicGeometry);
                            addSuccess = true;
                        }
                    }
                }
                if (!addSuccess)
                {
                    addFeature = newCentroid.AddFeature(new Point(item));
                    count++;
                }
            }
            Console.WriteLine("数据优化结束,共有{0}个数据没有优化", count);
            newCentroid.SaveAs("newCentroid2.shp", true);
            Console.ReadKey();
        }
Esempio n. 20
0
        public static void SavingFeatureSetAsNewShapefile()
        {
            //Declare a new feature set
            IFeatureSet fs = FeatureSet.Open(@"C:\[Your File Path]\Municipalities.shp");

            //Saves the open shapefile
            fs.SaveAs(@"C:\[Your File Path]\Municipalities_Test.shp", true);
        }
Esempio n. 21
0
        public SpatialAnalysis(string globalShapeFileDataPath)
        {
            string dataPath = globalShapeFileDataPath;

            fsWorldCountries = FeatureSet.Open(dataPath);
            fsWorldCountries.Reproject(DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984);
            countryCodes = GetCountryCodeMappings();
        }
Esempio n. 22
0
        public void SavePointToShapefileWithMandZ(CoordinateType c)
        {
            var fileName = FileTools.GetTempFileName(".shp");

            try
            {
                var fs = new FeatureSet(FeatureType.Point)
                {
                    Projection     = KnownCoordinateSystems.Geographic.World.WGS1984,
                    CoordinateType = c
                };

                fs.AddFeature(new Point(new CoordinateZM(1, 2, 7, 4)));

                Assert.DoesNotThrow(() => fs.SaveAs(fileName, true));

                var loaded = FeatureSet.Open(fileName);

                if (c == CoordinateType.Regular)
                {
                    Assert.IsTrue(loaded.Features[0].Geometry.Coordinates[0] is Coordinate);
                    Assert.IsFalse(loaded.Features[0].Geometry.Coordinates[0] is CoordinateZ);
                    Assert.IsFalse(loaded.Features[0].Geometry.Coordinates[0] is CoordinateM);
                }
                else if (c == CoordinateType.M)
                {
                    Assert.IsTrue(loaded.Features[0].Geometry.Coordinates[0] is CoordinateM);
                    Assert.IsFalse(loaded.Features[0].Geometry.Coordinates[0] is CoordinateZ);

                    if (loaded.Features[0].Geometry.Coordinates[0] is CoordinateM cm)
                    {
                        Assert.AreEqual(4, cm.M);
                        Assert.AreEqual(4, loaded.Features[0].Geometry.MinM());
                        Assert.AreEqual(4, loaded.Features[0].Geometry.MaxM());
                    }
                }
                else if (c == CoordinateType.Z)
                {
                    Assert.IsTrue(loaded.Features[0].Geometry.Coordinates[0] is CoordinateZM);

                    if (loaded.Features[0].Geometry.Coordinates[0] is CoordinateZM cm)
                    {
                        Assert.AreEqual(7, cm.Z);
                        Assert.AreEqual(7, loaded.Features[0].Geometry.MinZ());
                        Assert.AreEqual(7, loaded.Features[0].Geometry.MaxZ());

                        Assert.AreEqual(4, cm.M);
                        Assert.AreEqual(4, loaded.Features[0].Geometry.MinM());
                        Assert.AreEqual(4, loaded.Features[0].Geometry.MaxM());
                    }
                }
            }
            finally
            {
                FileTools.DeleteShapeFile(fileName);
            }
        }
Esempio n. 23
0
        public void UnionFeatureSetTest()
        {
            var         file  = Path.Combine(_shapefiles, @"Topology_Test.shp");
            IFeatureSet fs    = FeatureSet.Open(file);
            var         union = fs.UnionShapes(ShapeRelateType.Intersecting);

            Assert.IsNotNull(union);
            Assert.IsTrue(union.Features.Count > 0);
        }
Esempio n. 24
0
        public void IndexModeToFeaturesClear()
        {
            IFeatureSet fs = FeatureSet.Open(_shapefiles + @"Topology_Test.shp");

            fs.FillAttributes();
            fs.Features.Clear();
            Assert.AreEqual(fs.Features.Count, 0);
            Assert.AreEqual(fs.DataTable.Rows.Count, 0);
        }
Esempio n. 25
0
        static void ReadTest1Shp(string shpPath)
        {
            IFeatureSet fs = FeatureSet.Open(shpPath);

            Console.WriteLine("FeatureType:" + fs.FeatureType);
            Console.WriteLine();

            var dataTable = fs.AttrTable;

            Console.WriteLine("属性表字段:");
            foreach (DataColumn col in dataTable.Columns)
            {
                Console.Write(col.ColumnName + "\t");
            }
            Console.WriteLine();
            Console.WriteLine(new string('=', 50));

            Console.WriteLine();
            foreach (var fe in fs.Features)
            {
                Console.WriteLine();
                Console.WriteLine("GeometryType:" + fe.GeometryType);
                if (fe.GeometryType == GeometryType.MultiPolyLine)
                {
                    MultiPolyLine multiPolyLine = fe.Geometry.BasicGeometry as MultiPolyLine;
                    if (multiPolyLine != null)
                    {
                        Console.WriteLine("PartsNum:" + multiPolyLine.PartsNum);
                    }
                    Console.WriteLine("起始点:");
                    if (multiPolyLine != null)
                    {
                        foreach (var line in multiPolyLine.PolyLines)
                        {
                            Console.WriteLine(line[0]);
                        }
                    }
                }

                Console.WriteLine("\r\n所有点信息:");
                foreach (var point in fe.Geometry.Coordinates)
                {
                    Console.Write($"{point.X},{point.Y}\t");
                }
                Console.WriteLine("\r\n属性信息:");

                var datarow = fe.DataRow.ItemArray;
                foreach (var o in datarow)
                {
                    Console.Write(o + "\t");
                }
                Console.WriteLine();
                Console.WriteLine(new string('-', 20));
                Console.WriteLine();
            }
        }
Esempio n. 26
0
        public SpatialAnalysis(string globalShapeFileDataPath)
        {
            System.Text.Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            string dataPath = globalShapeFileDataPath;

            fsWorldCountries = FeatureSet.Open(dataPath);
            fsWorldCountries.Reproject(DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984);
            countryCodes = GetCountryCodeMappings();
        }
Esempio n. 27
0
        public override bool Execute(ICancelProgressHandler cancelProgressHandler)
        {
            IFeatureSet fs         = FeatureSet.Open(FeatureFile);
            IFeatureSet polygon_fs = FeatureSet.Open(PolygonFile);

            var outfs = fs.Intersection1(polygon_fs, FieldJoinType.All, cancelProgressHandler);

            outfs.SaveAs(OutputFeatureFile, true);
            return(true);
        }
Esempio n. 28
0
        static void Tin()
        {
            var fs = FeatureSet.Open(@"./data/points.shp");

            var tin  = fs.Tin();
            var fecc = tin.ToGeoJSON();

            Console.WriteLine(fs.ToGeoJSON());
            Console.WriteLine(fecc);
        }
Esempio n. 29
0
        /// <summary>
        /// This code demonstrates how to use DotSpatial.Analysis.Buffer.AddBuffer.
        /// </summary>
        /// <param name="fileName">Path of your shapefile (e.g. C:\myShapefile.shp).</param>
        public static void AnalysisBufferAddBuffer(string fileName)
        {
            // Pass in the file path of the shapefile that will be opened
            IFeatureSet fs = FeatureSet.Open(fileName);

            // create an output feature set of the same feature type
            IFeatureSet fs2 = new FeatureSet(fs.FeatureType);

            // buffer the features of the first feature set by 10 and add them to the output feature set
            Buffer.AddBuffer(fs, 10, fs2);
        }
Esempio n. 30
0
        /// <summary>
        /// Displays a dialog, allowing the users to open a raster.
        /// </summary>
        /// <param name="self">this.</param>
        public static void Open(this FeatureSet self)
        {
            string filter = DataManager.DefaultDataManager.RasterReadFilter;

            using var ofd = new OpenFileDialog { Filter = filter };
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            FeatureSet.Open(ofd.FileName);
        }