Ejemplo n.º 1
1
        /// <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;
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Generates a default instance of the data type so that tools have something to write too
 /// </summary>
 /// <param name="path"></param>
 public override void GenerateDefaultOutput(string path)
 {
     FeatureSet addedFeatureSet = new PointShapefile
                                      {
                                          Filename =
                                              Path.GetDirectoryName(path) +
                                              Path.DirectorySeparatorChar + ModelName + ".shp"
                                      };
     Value = addedFeatureSet;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// This will return the correct shapefile type by reading the fileName.
        /// </summary>
        /// <param name="fileName">A string specifying the file with the extension .shp to open.</param>
        /// <param name="progressHandler">receives progress messages and overrides the ProgressHandler on the DataManager.DefaultDataManager</param>
        /// <returns>A correct shapefile object which is exclusively for reading the .shp data</returns>
        public static new Shapefile OpenFile(string fileName, IProgressHandler progressHandler)
        {
            var ext = Path.GetExtension(fileName);

            if (ext != null)
            {
                ext = ext.ToLower();
            }
            if (ext != ".shp" && ext != ".shx" && ext != ".dbf")
            {
                throw new ArgumentException(String.Format("The file extension {0} is not supported by Shapefile data provider.", ext));
            }
            string name = Path.ChangeExtension(fileName, ".shp");
            var    head = new ShapefileHeader();

            head.Open(name);
            switch (head.ShapeType)
            {
            case ShapeType.MultiPatch:
                throw new NotImplementedException("This shape type is not yet supported.");

            case ShapeType.MultiPoint:
            case ShapeType.MultiPointM:
            case ShapeType.MultiPointZ:
                var mpsf = new MultiPointShapefile();
                mpsf.Open(name, progressHandler);
                return(mpsf);

            case ShapeType.NullShape:
                throw new NotImplementedException("This shape type is not yet supported.");

            case ShapeType.Point:
            case ShapeType.PointM:
            case ShapeType.PointZ:
                var psf = new PointShapefile();
                psf.Open(name, progressHandler);
                return(psf);

            case ShapeType.Polygon:
            case ShapeType.PolygonM:
            case ShapeType.PolygonZ:
                var pgsf = new PolygonShapefile();
                pgsf.Open(name, progressHandler);
                return(pgsf);

            case ShapeType.PolyLine:
            case ShapeType.PolyLineM:
            case ShapeType.PolyLineZ:
                var lsf = new LineShapefile();
                lsf.Open(name, progressHandler);
                return(lsf);
            }

            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This will return the correct shapefile type by reading the fileName.
        /// </summary>
        /// <param name="fileName">A string specifying the file with the extension .shp to open.</param>
        /// <param name="progressHandler">receives progress messages and overrides the ProgressHandler on the DataManager.DefaultDataManager</param>
        /// <exception cref="NotImplementedException">Throws a NotImplementedException if the ShapeType of the loaded file is NullShape or MultiPatch.</exception>
        /// <returns>A correct shapefile object which is exclusively for reading the .shp data</returns>
        public static new Shapefile OpenFile(string fileName, IProgressHandler progressHandler)
        {
            var ext = Path.GetExtension(fileName)?.ToLower();

            if (ext != ".shp" && ext != ".shx" && ext != ".dbf")
            {
                throw new ArgumentException(string.Format(DataStrings.FileExtension0NotSupportedByShapefileDataProvider, ext));
            }

            string name = Path.ChangeExtension(fileName, ".shp");
            var    head = new ShapefileHeader();

            head.Open(name);
            switch (head.ShapeType)
            {
            case ShapeType.MultiPatch:
            case ShapeType.NullShape:
                throw new NotImplementedException(DataStrings.ShapeTypeNotYetSupported);

            case ShapeType.MultiPoint:
            case ShapeType.MultiPointM:
            case ShapeType.MultiPointZ:
                var mpsf = new MultiPointShapefile();
                mpsf.Open(name, progressHandler);
                return(mpsf);

            case ShapeType.Point:
            case ShapeType.PointM:
            case ShapeType.PointZ:
                var psf = new PointShapefile();
                psf.Open(name, progressHandler);
                return(psf);

            case ShapeType.Polygon:
            case ShapeType.PolygonM:
            case ShapeType.PolygonZ:
                var pgsf = new PolygonShapefile();
                pgsf.Open(name, progressHandler);
                return(pgsf);

            case ShapeType.PolyLine:
            case ShapeType.PolyLineM:
            case ShapeType.PolyLineZ:
                var lsf = new LineShapefile();
                lsf.Open(name, progressHandler);
                return(lsf);
            }

            return(null);
        }
Ejemplo n.º 6
0
        private void BtnAddDataClick(object sender, EventArgs e)
        {
            /////////////////////////////////
            //Replace with something that uses the default data provider
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.OverwritePrompt = true;
            sfd.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;
            base.Status = ToolStatus.Ok;
            LightTipText = ModelingMessageStrings.FeaturesetValid;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This will return the correct shapefile type by reading the fileName.
        /// </summary>
        /// <param name="fileName">A string specifying the file with the extension .shp to open.</param>
        /// <param name="progressHandler">receives progress messages and overrides the ProgressHandler on the DataManager.DefaultDataManager</param>
        /// <returns>A correct shapefile object which is exclusively for reading the .shp data</returns>
        public static new Shapefile OpenFile(string fileName, IProgressHandler progressHandler)
        {
            var ext = Path.GetExtension(fileName);
            if (ext != null) ext = ext.ToLower();
            if (ext != ".shp" && ext != ".shx" && ext != ".dbf")
                throw new ArgumentException(String.Format("The file extension {0} is not supported by Shapefile data provider.", ext));
            string name = Path.ChangeExtension(fileName, ".shp");
            var head = new ShapefileHeader();
            head.Open(name);
            switch (head.ShapeType)
            {
                case ShapeType.MultiPatch:
                    throw new NotImplementedException("This shape type is not yet supported.");

                case ShapeType.MultiPoint:
                case ShapeType.MultiPointM:
                case ShapeType.MultiPointZ:
                    var mpsf = new MultiPointShapefile();
                    mpsf.Open(name, progressHandler);
                    return mpsf;

                case ShapeType.NullShape:
                    throw new NotImplementedException("This shape type is not yet supported.");

                case ShapeType.Point:
                case ShapeType.PointM:
                case ShapeType.PointZ:
                    var psf = new PointShapefile();
                    psf.Open(name, progressHandler);
                    return psf;

                case ShapeType.Polygon:
                case ShapeType.PolygonM:
                case ShapeType.PolygonZ:
                    var pgsf = new PolygonShapefile();
                    pgsf.Open(name, progressHandler);
                    return pgsf;

                case ShapeType.PolyLine:
                case ShapeType.PolyLineM:
                case ShapeType.PolyLineZ:
                    var lsf = new LineShapefile();
                    lsf.Open(name, progressHandler);
                    return lsf;
            }

            return null;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// This will return the correct shapefile type by reading the fileName.
        /// </summary>
        /// <param name="fileName">A string specifying the file with the extension .shp to open.</param>
        /// <param name="progressHandler">receives progress messages and overrides the ProgressHandler on the DataManager.DefaultDataManager</param>
        /// <returns>A correct shapefile object which is exclusively for reading the .shp data</returns>
        public static new Shapefile OpenFile(string fileName, IProgressHandler progressHandler)
        {
            string ext = Path.GetExtension(fileName).ToLower();

            if (ext != ".shp" && ext != ".shx" && ext != ".dbf")
            {
                throw new ArgumentException(String.Format("The file extension {0} is not supported by Shapefile data provider.", ext));
            }
            string          name = Path.ChangeExtension(fileName, ".shp");
            ShapefileHeader head = new ShapefileHeader();

            head.Open(name);
            PointShapefile      psf;
            LineShapefile       lsf;
            PolygonShapefile    pgsf;
            MultiPointShapefile mpsf;

            switch (head.ShapeType)
            {
            case ShapeType.MultiPatch:
                throw new NotImplementedException("This shape type is not yet supported.");

            case ShapeType.MultiPoint:
            case ShapeType.MultiPointM:
            case ShapeType.MultiPointZ:
                mpsf = new MultiPointShapefile();
                mpsf.Open(name, progressHandler);
                return(mpsf);

            case ShapeType.NullShape:
                throw new NotImplementedException("This shape type is not yet supported.");

            case ShapeType.Point:
            case ShapeType.PointM:
            case ShapeType.PointZ:

                // Instantiate a new object to handle the point shapefile
                psf = new PointShapefile();

                // Open the geometric components of the data (but not the dbf components)
                psf.Open(name, progressHandler);

                return(psf);

            case ShapeType.Polygon:
            case ShapeType.PolygonM:
            case ShapeType.PolygonZ:
                pgsf = new PolygonShapefile();
                pgsf.Open(name, progressHandler);
                return(pgsf);

            case ShapeType.PolyLine:
            case ShapeType.PolyLineM:
            case ShapeType.PolyLineZ:
                lsf = new LineShapefile();
                lsf.Open(name, progressHandler);
                return(lsf);
            }

            return(null);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a default output locations for tools.
 /// </summary>
 /// <param name="par"></param>
 public void GenerateDefaultOutput(Parameter par)
 {
     IFeatureSet addedFeatureSet;
     switch (par.ParamType)
     {
         case "DotSpatial FeatureSet Param":
             addedFeatureSet = new Shapefile
                                   {
                                       Filename =
                                           Path.GetTempPath() +
                                           Path.DirectorySeparatorChar + par.ModelName + ".shp"
                                   };
             par.Value = addedFeatureSet;
             break;
         case "DotSpatial LineFeatureSet Param":
             addedFeatureSet = new LineShapefile
                                   {
                                       Filename =
                                           Path.GetTempPath() +
                                           Path.DirectorySeparatorChar + par.ModelName + ".shp"
                                   };
             par.Value = addedFeatureSet;
             break;
         case "DotSpatial PointFeatureSet Param":
             addedFeatureSet = new PointShapefile
                                   {
                                       Filename =
                                           Path.GetTempPath() +
                                           Path.DirectorySeparatorChar + par.ModelName + ".shp"
                                   };
             par.Value = addedFeatureSet;
             break;
         case "DotSpatial PolygonFeatureSet Param":
             addedFeatureSet = new PolygonShapefile
                                   {
                                       Filename =
                                           Path.GetTempPath() +
                                           Path.DirectorySeparatorChar + par.ModelName + ".shp"
                                   };
             par.Value = addedFeatureSet;
             break;
         case "DotSpatial Raster Param":
             break;
         default:
             par.GenerateDefaultOutput(Path.GetTempPath());
             break;
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// This will return the correct shapefile type by reading the fileName.
        /// </summary>
        /// <param name="fileName">A string specifying the file with the extension .shp to open.</param>
        /// <param name="progressHandler">receives progress messages and overrides the ProgressHandler on the DataManager.DefaultDataManager</param>
        /// <returns>A correct shapefile object which is exclusively for reading the .shp data</returns>
        public static new Shapefile OpenFile(string fileName, IProgressHandler progressHandler)
        {
            string ext = Path.GetExtension(fileName).ToLower();
            if (ext != ".shp" && ext != ".shx" && ext != ".dbf")
                throw new ArgumentException(String.Format("The file extension {0} is not supported by Shapefile data provider.", ext));
            string name = Path.ChangeExtension(fileName, ".shp");
            ShapefileHeader head = new ShapefileHeader();
            head.Open(name);
            PointShapefile psf;
            LineShapefile lsf;
            PolygonShapefile pgsf;
            MultiPointShapefile mpsf;
            switch (head.ShapeType)
            {
                case ShapeType.MultiPatch:
                    throw new NotImplementedException("This shape type is not yet supported.");

                case ShapeType.MultiPoint:
                case ShapeType.MultiPointM:
                case ShapeType.MultiPointZ:
                    mpsf = new MultiPointShapefile();
                    mpsf.Open(name, progressHandler);
                    return mpsf;

                case ShapeType.NullShape:
                    throw new NotImplementedException("This shape type is not yet supported.");

                case ShapeType.Point:
                case ShapeType.PointM:
                case ShapeType.PointZ:

                    // Instantiate a new object to handle the point shapefile
                    psf = new PointShapefile();

                    // Open the geometric components of the data (but not the dbf components)
                    psf.Open(name, progressHandler);

                    return psf;

                case ShapeType.Polygon:
                case ShapeType.PolygonM:
                case ShapeType.PolygonZ:
                    pgsf = new PolygonShapefile();
                    pgsf.Open(name, progressHandler);
                    return pgsf;

                case ShapeType.PolyLine:
                case ShapeType.PolyLineM:
                case ShapeType.PolyLineZ:
                    lsf = new LineShapefile();
                    lsf.Open(name, progressHandler);
                    return lsf;
            }

            return null;
        }