Exemplo n.º 1
0
        public void CanExportPointShapeWithNullShapes(bool indexMode)
        {
            string path   = Common.AbsolutePath(@"Data\Shapefiles\Yield\Yield 2012.shp");
            var    target = new PointShapefile(path);

            Assert.IsTrue(target.Features.Count > 0);
            target.IndexMode = indexMode;

            var exportPath = FileTools.GetTempFileName(".shp");

            target.SaveAs(exportPath, true);

            try
            {
                var actual = new PointShapefile(exportPath);
                Assert.IsNotNull(actual);
                Assert.AreEqual(target.ShapeIndices.Count, actual.ShapeIndices.Count);
                Assert.AreEqual(target.ShapeIndices.Count(d => d.ShapeType == ShapeType.NullShape), actual.ShapeIndices.Count(d => d.ShapeType == ShapeType.NullShape));
                Assert.AreEqual(target.Features.Count, actual.Features.Count);
                Assert.AreEqual(target.Features.Count(d => d.Geometry.IsEmpty), actual.Features.Count(d => d.Geometry.IsEmpty));
            }
            finally
            {
                FileTools.DeleteShapeFile(exportPath);
            }
        }
Exemplo n.º 2
0
        public void CanLoadShapePointWithNullShapes()
        {
            const string path   = @"Data\Shapefiles\Yield\Yield 2012.shp";
            var          target = new PointShapefile(path);

            Assert.IsNotNull(target);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This create new method implies that this provider has the priority for creating a new file.
        /// An instance of the dataset should be created and then returned.  By this time, the fileName
        /// will already be checked to see if it exists, and deleted if the user wants to overwrite it.
        /// </summary>
        /// <param name="fileName">The string fileName for the new instance</param>
        /// <param name="featureType">Point, Line, Polygon etc.  Sometimes this will be specified, sometimes it will be "Unspecified"</param>
        /// <param name="inRam">Boolean, true if the dataset should attempt to store data entirely in ram</param>
        /// <param name="progressHandler">An IProgressHandler for status messages.</param>
        /// <returns>An IRaster</returns>
        public virtual IFeatureSet CreateNew(string fileName, FeatureType featureType, bool inRam, IProgressHandler progressHandler)
        {
            if (featureType == FeatureType.Point)
            {
                PointShapefile ps = new PointShapefile();
                ps.Filename = fileName;
                return(ps);
            }
            else if (featureType == FeatureType.Line)
            {
                LineShapefile ls = new LineShapefile();
                ls.Filename = fileName;
                return(ls);
            }
            else if (featureType == FeatureType.Polygon)
            {
                PolygonShapefile ps = new PolygonShapefile();
                ps.Filename = fileName;
                return(ps);
            }
            else if (featureType == FeatureType.MultiPoint)
            {
                MultiPointShapefile mps = new MultiPointShapefile();
                mps.Filename = fileName;
                return(mps);
            }

            return(null);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PointShapeFileWriter"/> class.
 /// </summary>
 public PointShapeFileWriter()
 {
     ShapeFile = new PointShapefile
     {
         FeatureType = FeatureType.Point
     };
 }
Exemplo n.º 5
0
 public void CanReadPointZWithoutM()
 {
     const string path = @"Data\Shapefiles\shp-no-m\SPATIAL_F_LUFTNINGSVENTIL.shp";
     var target = new PointShapefile(path);
     Assert.AreEqual(CoordinateType.Z, target.CoordinateType);
     Assert.IsNotNull(target.Z);
     Assert.IsNotNull(target.M);
     Assert.IsTrue(target.M.All(d => d < -1e38));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Generates a default instance of the data type so that tools have something to write to.
        /// </summary>
        /// <param name="path">Path of the generated shapefile.</param>
        public override void GenerateDefaultOutput(string path)
        {
            FeatureSet addedFeatureSet = new PointShapefile
            {
                Filename = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + ModelName + ".shp"
            };

            Value = addedFeatureSet;
        }
Exemplo n.º 7
0
        public void CanLoadShapePointWithNullShapes()
        {
            string path   = Common.AbsolutePath(@"Data\Shapefiles\Yield\Yield 2012.shp");
            var    target = new PointShapefile(path);

            Assert.IsNotNull(target);
            Assert.AreEqual(target.ShapeIndices.Count(d => d.ShapeType == ShapeType.NullShape), 1792);
            Assert.AreEqual(target.Features.Count(d => d.Geometry.IsEmpty), 1792);
        }
Exemplo n.º 8
0
        public void CanReadPointZWithoutM()
        {
            const string path   = @"Data\Shapefiles\shp-no-m\SPATIAL_F_LUFTNINGSVENTIL.shp";
            var          target = new PointShapefile(path);

            Assert.AreEqual(CoordinateType.Z, target.CoordinateType);
            Assert.IsNotNull(target.Z);
            Assert.IsNotNull(target.M);
            Assert.IsTrue(target.M.All(d => d < -1e38));
        }
Exemplo n.º 9
0
 public void CanLoadPointZWithoutM()
 {
     var path = FileTools.PathToTestFile(@"Shapefiles\shp-no-m\SPATIAL_F_LUFTNINGSVENTIL.shp");
     var target = new PointShapefile(path);
     Assert.AreEqual(CoordinateType.Z, target.CoordinateType);
     Assert.IsTrue(target.Count > 0);
     for (var i = 0; i < target.Count; i++)
     {
         var shape = target.GetShape(i, false);
         Assert.IsNotNull(shape.Z);
         Assert.IsNotNull(shape.M);
         Assert.IsTrue(shape.M[0] < -1e38);
     }
 }
Exemplo n.º 10
0
        private bool createSHPFile(string filename)
        {
            PointShapefile pointLayer = new PointShapefile();

            pointLayer.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            pointLayer.DataTable.Columns.Add("FID");
            pointLayer.DataTable.Columns.Add("TAMSID");
            try
            {
                pointLayer.SaveAs(filename, true);
            }
            catch (Exception e)
            {
                Log.Error("Could not create ShapeFile" + Environment.NewLine + e.ToString());
                return(false);
            }
            return(true);
        }
Exemplo n.º 11
0
        private void BtnAddDataClick(object sender, EventArgs e)
        {
            // Replace with something that uses the default data provider
            using var sfd = new SaveFileDialog { OverwritePrompt = true, Filter = @"Shape Files|*.shp" };
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            IFeatureSet addedFeatureSet = new PointShapefile();

            addedFeatureSet.Filename = sfd.FileName;

            // This inserts the new featureset into the list
            textBox1.Text = Path.GetFileNameWithoutExtension(addedFeatureSet.Filename);
            Param.Value   = addedFeatureSet;
            Status        = ToolStatus.Ok;
            LightTipText  = ModelingMessageStrings.FeaturesetValid;
        }
Exemplo n.º 12
0
 /// <summary>
 /// Creates a new instance of <see cref="PointShapeFileReader"/>.
 /// </summary>
 /// <param name="filePath">The path to the shape file.</param>
 /// <exception cref="ArgumentException">Thrown when <paramref name="filePath"/> is invalid.</exception>
 /// <exception cref="CriticalFileReadException">Thrown when
 /// <list type="bullet">
 /// <item><paramref name="filePath"/> points to a file that doesn't exist.</item>
 /// <item>The shapefile has non-point geometries in it.</item>
 /// <item>An unexpected error occurred when reading the shapefile.</item>
 /// </list>
 /// </exception>
 public PointShapeFileReader(string filePath) : base(filePath)
 {
     try
     {
         ShapeFile = new PointShapefile(filePath);
     }
     catch (ApplicationException e)
     {
         string message = new FileReaderErrorMessageBuilder(filePath)
                          .Build(GisIOResources.PointShapeFileReader_File_contains_geometries_not_points);
         throw new CriticalFileReadException(message, e);
     }
     catch (ArgumentException e)
     {
         string message = new FileReaderErrorMessageBuilder(filePath)
                          .Build(GisIOResources.PointShapeFileReader_File_contains_geometries_not_points);
         throw new CriticalFileReadException(message, e);
     }
     catch (IOException exception)
     {
         string message = new FileReaderErrorMessageBuilder(filePath).Build(CoreCommonUtilResources.Error_General_IO_Import_ErrorMessage);
         throw new CriticalFileReadException(message, exception);
     }
 }
Exemplo n.º 13
0
 public void CanLoadShapePointWithNullShapes()
 {
     const string path = @"Data\Shapefiles\Yield\Yield 2012.shp";
     var target = new PointShapefile(path);
     Assert.IsNotNull(target);
 }