예제 #1
0
        private void btnAddData_Click(object sender, EventArgs e)
        {
            /////////////////////////////////
            //Replace with something that uses the default data provider
            System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
            sfd.OverwritePrompt = true;
            sfd.Filter = "Shape Files|*.shp";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                IFeatureSet addedFeatureSet = new MapWindow.Data.PointShapefile();
                addedFeatureSet.Filename = sfd.FileName;

                //If the features set is null do nothing the user probably hit cancel
                if (addedFeatureSet == null)
                    return;

                //If the feature type is good save it
                else
                {
                    //This inserts the new featureset into the list
                    textBox1.Text = System.IO.Path.GetFileNameWithoutExtension(addedFeatureSet.Filename);
                    base.Param.Value = addedFeatureSet;
                    base.Status = ToolStatus.Ok;
                    base.LightTipText = MapWindow.MessageStrings.FeaturesetValid;
                }
            }
        }
 /// <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, FeatureTypes featureType, bool inRam, IProgressHandler progressHandler)
 {
     if (featureType == FeatureTypes.Point)
     {
         PointShapefile ps = new PointShapefile();
         ps.Filename = filename;
         return ps;
     }
     else if (featureType == FeatureTypes.Line)
     {
         LineShapefile ls = new LineShapefile();
         ls.Filename = filename;
         return ls;
     }
     else if (featureType == FeatureTypes.Polygon)
     {
         PolygonShapefile ps = new PolygonShapefile();
         ps.Filename = filename;
         return ps;
     }
     else if (featureType == FeatureTypes.MultiPoint)
     {
         MultiPointShapefile mps = new MultiPointShapefile();
         mps.Filename = filename;
         return mps;
     }
   
     return null;
     
    
 }
예제 #3
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">recieves 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 new static Shapefile OpenFile(string filename, IProgressHandler progressHandler)
        {

            ShapefileHeader head = new ShapefileHeader();
            head.Open(filename);
            PointShapefile psf;
            LineShapefile lsf;
            PolygonShapefile pgsf;
            MultiPointShapefile mpsf;
            switch (head.ShapeType)
            {
                case ShapeTypes.MultiPatch:
                    throw new NotImplementedException("This shape type is not yet supported.");
                   // break;
                case ShapeTypes.MultiPoint:
                    mpsf = new MultiPointShapefile();
                    mpsf.Open(filename, progressHandler);
                    return mpsf;
                case ShapeTypes.MultiPointM:
                    mpsf = new MultiPointShapefile();
                    mpsf.Open(filename, progressHandler);
                    return mpsf;
                case ShapeTypes.MultiPointZ:
                    mpsf = new MultiPointShapefile();
                    mpsf.Open(filename, progressHandler);
                    return mpsf;
                case ShapeTypes.NullShape:
                    throw new NotImplementedException("This shape type is not yet supported.");
                  //  break;
                case ShapeTypes.Point:
                    
                    // 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(filename, progressHandler);

                    return psf;
                    
                   

                case ShapeTypes.PointM:
                    // 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(filename, progressHandler);

                    return psf;

                    

                case ShapeTypes.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(filename, progressHandler);

                    return psf;

                   

                case ShapeTypes.Polygon:
                    pgsf = new PolygonShapefile();
                    pgsf.Open(filename, progressHandler);
                    return pgsf;
                 
                case ShapeTypes.PolygonM:
                    pgsf = new PolygonShapefile();
                    pgsf.Open(filename, progressHandler);
                    return pgsf;

                case ShapeTypes.PolygonZ:
                    pgsf = new PolygonShapefile();
                    pgsf.Open(filename, progressHandler);
                    return pgsf;

                case ShapeTypes.PolyLine:
                    lsf = new LineShapefile();
                    lsf.Open(filename, progressHandler);
                    return lsf;

                case ShapeTypes.PolyLineM:
                    lsf = new LineShapefile();
                    lsf.Open(filename, progressHandler);
                    return lsf;

                case ShapeTypes.PolyLineZ:
                    lsf = new LineShapefile();
                    lsf.Open(filename, progressHandler);
                    return lsf;
            }
            
            
            return null;
        }