コード例 #1
0
 private void btnEnd_Click(object sender, RoutedEventArgs e)
 {
     MainWindow.m_DotMap.Cursor = System.Windows.Forms.Cursors.Default;
     if (m_ResultFeaset != null)
     {
         m_ResultFeaset.SaveAs(this.txtPath.Text, true);
         MessageBox.Show("Save successfully,the layer has been added in map");
         HasSaved = true;
     }
     this.Close();
 }
コード例 #2
0
        /// <summary>
        /// Executes the Union Opaeration tool programaticaly
        /// </summary>
        /// <param name="sourceData">The source FeatureSet to aggregate the features for..</param>
        /// <param name="resultData">The result FeatureSet of aggregated features..</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns>Boolean if the result is true.</returns>
        public bool Execute(
            IFeatureSet sourceData, IFeatureSet resultData, ICancelProgressHandler cancelProgressHandler)
        // removed "static" dpa 12/2009 so that this can be run from an external call directly.
        {
            // Validates the input and output data
            if (sourceData == null || sourceData.Features == null || sourceData.Features.Count == 0 ||
                resultData == null)
            {
                return(false);
            }

            IFeature oneFeature = sourceData.Features[0];

            // MapWindow.Main.ProgressMeter pm = new MapWindow.Main.ProgressMeter(cancelProgressHandler, TextStrings.UnioningShapes, self.Features.Count);
            for (int i = 1; i < sourceData.Features.Count; i++)
            {
                if (sourceData.Features[i] == null)
                {
                    continue;
                }

                oneFeature = oneFeature.Union(sourceData.Features[i]);

                // pm.CurrentValue = i;
            }

            // pm.Reset();
            resultData.Features.Add(oneFeature);
            resultData.SaveAs(resultData.Filename, true);
            return(true);
        }
コード例 #3
0
ファイル: Aggregate.cs プロジェクト: vahidarr/DotSpatial
        /// <summary>
        /// Executes the Union Opaeration tool programaticaly
        /// </summary>
        /// <param name="sourceData">The source FeatureSet to aggregate the features for..</param>
        /// <param name="resultData">The result FeatureSet of aggregated features..</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns>Boolean if the result is true.</returns>
        public bool Execute(IFeatureSet sourceData, IFeatureSet resultData, ICancelProgressHandler cancelProgressHandler)
        // removed "static" dpa 12/2009 so that this can be run from an external call directly.
        {
            // Validates the input and output data
            if (sourceData == null || sourceData.Features == null || sourceData.Features.Count == 0 || resultData == null)
            {
                return(false);
            }

            IFeature oneFeature = sourceData.Features[0];

            for (int i = 1; i < sourceData.Features.Count; i++)
            {
                if (sourceData.Features[i] == null)
                {
                    continue;
                }

                oneFeature = oneFeature.Union(sourceData.Features[i].Geometry);
            }

            resultData.Features.Add(oneFeature);
            resultData.SaveAs(resultData.Filename, true);
            return(true);
        }
コード例 #4
0
ファイル: SFR2.cs プロジェクト: zhaowilliam/Visual-HEIFLOW
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            var dt_stream = _stream_layer.DataTable;
            var segid = from dr in dt_stream.AsEnumerable() select (dr.Field<int>(SegmentField) + 1);
            var dic = Path.GetDirectoryName(_stream_layer.FilePath);
            var out_fn = Path.Combine(dic, "sfr_cpm.shp");
            string msg="";
            Dictionary<int, ReachFeatureCollection> fea_list = new Dictionary<int, ReachFeatureCollection>();

            foreach(var id in segid)
            {
                fea_list.Add(id, new ReachFeatureCollection(id));
            }
              cancelProgressHandler.Progress("Package_Tool", 10, "Calculating...");
              if (StreamGridInctLayer != null)
                  _out_sfr_layer = StreamGridInctLayer.DataSet as FeatureSet;
              else
              {
                  _out_sfr_layer = _stream_layer.Intersection1(_grid_layer, FieldJoinType.All, null);
                  _out_sfr_layer.Projection = _stream_layer.Projection;
                  _out_sfr_layer.SaveAs(out_fn, true);
              }
            cancelProgressHandler.Progress("Package_Tool", 30, "Calculation of intersectons between Grid and Stream finished");
            PrePro(fea_list, out msg);
            cancelProgressHandler.Progress("Package_Tool", 70, "Calculation of reach parameters finished");
            if(msg != "")
                cancelProgressHandler.Progress("Package_Tool", 80, "Warnings: " + msg);
            Save2SFRFile(fea_list);

            cancelProgressHandler.Progress("Package_Tool", 90, "SFR file saved");
            return true;
        }
コード例 #5
0
        /// <summary>
        /// Executes the overwrite feature Opaeration tool programaticaly.
        /// </summary>
        /// <param name="input1">The input FeatureSet.</param>
        /// <param name="index">The Index to overwrite</param>
        /// <param name="input2">The input2 featureSet which has the new feature to overwrite.</param>
        /// <param name="output">The output FeatureSet.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input1, int index, IFeatureSet input2, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input1 == null || input2 == null || output == null)
            {
                return(false);
            }

            if (cancelProgressHandler.Cancel)
            {
                return(false);
            }

            IFeature newFeature = input2.Features[0];

            output.FeatureType = input1.FeatureType;
            foreach (IFeature f in input1.Features)
            {
                output.Features.Add(f);
            }

            if (index > -1)
            {
                if (index < output.Features.Count)
                {
                    output.Features.RemoveAt(index);
                    output.Features.Insert(index, newFeature);
                }
            }

            output.SaveAs(output.Filename, true);
            cancelProgressHandler.Progress(string.Empty, 100, 100 + TextStrings.progresscompleted);
            return(true);
        }
コード例 #6
0
ファイル: JoinDialog.cs プロジェクト: terribletim/DotSpatial
        private void cmdOk_Click(object sender, EventArgs e)
        {
            if (tbPath.Text == null)
            {
                MessageBox.Show("Select an excel file first.");
                return;
            }
            string local = (string)cbLocalField.SelectedItem;

            if (string.IsNullOrEmpty(local))
            {
                MessageBox.Show("Choose a local field to join on first.");
                return;
            }
            string foreign = (string)cbForeignField.SelectedItem;

            if (string.IsNullOrEmpty(foreign))
            {
                MessageBox.Show("Choose a foreign field to join on first.");
                return;
            }
            if (string.IsNullOrEmpty(tbSave.Text))
            {
                MessageBox.Show("Select an output file first.");
                return;
            }

            IFeatureSet temp = _featureSet.Join(tbPath.Text, local, foreign);

            temp.SaveAs(tbSave.Text, true);
        }
コード例 #7
0
        private void CmdOkClick(object sender, EventArgs e)
        {
            if (tbPath.Text == null)
            {
                MessageBox.Show(SymbologyFormsMessageStrings.JoinDialog_SelectExcelFile);
                return;
            }

            string local = (string)cbLocalField.SelectedItem;

            if (string.IsNullOrEmpty(local))
            {
                MessageBox.Show(SymbologyFormsMessageStrings.JoinDialog_SelectLocalField);
                return;
            }

            string foreign = (string)cbForeignField.SelectedItem;

            if (string.IsNullOrEmpty(foreign))
            {
                MessageBox.Show(SymbologyFormsMessageStrings.JoinDialog_SelectForeignField);
                return;
            }

            if (string.IsNullOrEmpty(tbSave.Text))
            {
                MessageBox.Show(SymbologyFormsMessageStrings.JoinDialog_SelectOutputFile);
                return;
            }

            IFeatureSet temp = _featureSet.Join(tbPath.Text, local, foreign);

            temp.SaveAs(tbSave.Text, true);
        }
コード例 #8
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);
        }
コード例 #9
0
        /// <summary>
        /// Ping Yang Overwrite the function for Executes the Erase Opaeration tool for external testing
        /// </summary>
        public bool Execute(IFeatureSet self, IFeatureSet other, IFeatureSet output)
        {
            if (self == null || other == null || output == null)
            {
                return(false);
            }

            output.CopyTableSchema(self); // Fill the 1st Featureset fields
            IFeatureSet tempSet = self.CombinedFields(other);

            // go through every feature in 1st featureSet
            foreach (IFeature t in self.Features)
            {
                // go through every feature in 2nd featureSet
                foreach (IFeature t1 in other.Features)
                {
                    t.Difference(t1, tempSet, FieldJoinType.All);
                }
            }

            // Add to the Output Feature Set
            for (int a = 0; a < tempSet.Features.Count; a++)
            {
                output.Features.Add(tempSet.Features[a]);
            }

            output.SaveAs(output.Filename, true);

            // add to map?
            return(true);
        }
コード例 #10
0
        /// <summary>
        /// Executes the ClipPolygonWithPolygon tool with programatic input
        /// </summary>
        /// <param name="input">The input feature set to clip</param>
        /// <param name="input2">The input polygon feature set to clip with</param>
        /// <param name="output">The output feature set</param>
        /// <param name="cancelProgressHandler">The progress handler for progress message updates</param>
        /// <returns></returns>
        /// Ping delete "static" for external testing
        public bool Execute(
            IFeatureSet input, IFeatureSet input2, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input == null || input2 == null || output == null)
            {
                cancelProgressHandler.Progress(string.Empty, 100, TextStrings.Oneparameterinnull);
                return(false);
            }

            if (input2.FeatureType != FeatureType.Polygon)
            {
                cancelProgressHandler.Progress(string.Empty, 100, TextStrings.secondinputlayer);
                return(false);
            }

            output.FeatureType = input.FeatureType;

            // we add all the old features to output
            IFeatureSet tempoutput = input.Intersection(input2, FieldJoinType.LocalOnly, cancelProgressHandler);

            // We add all the fields
            foreach (DataColumn inputColumn in tempoutput.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            foreach (var fe in tempoutput.Features)
            {
                output.Features.Add(fe);
            }

            output.SaveAs(output.Filename, true);
            return(true);
        }
コード例 #11
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);
        }
コード例 #12
0
ファイル: GenerateCentroid.cs プロジェクト: osome/DotSpatial
        /// <summary>
        /// Executes the generate centroid FeatureSet Opaeration tool programaticaly.
        /// Ping deleted static for external testing 01/2010
        /// </summary>
        /// <param name="input1">The input FeatureSet.</param>
        /// <param name="output">The output FeatureSet.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input1, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input1 == null || output == null)
            {
                return(false);
            }

            bool multiPoint = false;

            foreach (IFeature f1 in input1.Features)
            {
                if (f1.Geometry.NumGeometries > 1)
                {
                    multiPoint = true;
                }
            }

            output.FeatureType = multiPoint == false ? FeatureType.Point : FeatureType.MultiPoint;

            int previous   = 0;
            int i          = 0;
            int maxFeature = input1.Features.Count;

            output.CopyTableSchema(input1);
            foreach (IFeature f in input1.Features)
            {
                if (cancelProgressHandler.Cancel)
                {
                    return(false);
                }

                IFeature fnew = new Feature(f.Geometry.Centroid);

                // Add the centroid to output
                output.Features.Add(fnew);

                fnew.CopyAttributes(f);

                int current = Convert.ToInt32(Math.Round(i * 100D / maxFeature));

                // only update when increment in percentage
                if (current > previous)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                }

                previous = current;
                i++;
            }

            output.AttributesPopulated = true;
            output.SaveAs(output.Filename, true);
            return(true);
        }
コード例 #13
0
        /// <summary>
        /// This code demonstrates how to open an existing shapefile as a new feature set, buffer the features and then save them to a different file.
        /// </summary>
        /// <param name="fileName">Path of your shapefile (e.g. C:\myShapefile.shp).</param>
        public static void BufferFeatures(string fileName)
        {
            // Pass in the file path of the shapefile that will be opened
            IFeatureSet fs = FeatureSet.Open(@"C:\[Your File Path]\Municipalities.shp");

            // Buffer the features of the feature set "fs"
            IFeatureSet bs = fs.Buffer(10, true);

            // Saves the buffered feature set as a new file
            bs.SaveAs(@"C:\[Your File Path]\Municipalities_Buffer.shp", true);
        }
コード例 #14
0
        public static void BufferingAFeatureSet()
        {
            //Declares a new feature set and passes in the file path for the standard
            //shapefile that will be opened
            IFeatureSet fs = FeatureSet.Open(@"C:\[Your File Path]\Municipalities.shp");
            //Buffers the feature set "fs"
            IFeatureSet bs = fs.Buffer(10, true);

            //Saves the buffered feature set as a new file
            bs.SaveAs(@"C:\[Your File Path]\Municipalities_Buffer.shp", true);
        }
コード例 #15
0
        /// <summary>
        /// Bu kod, mevcut bir şekil dosyasının yeni bir özellik kümesi olarak nasıl açılacağını, özellikleri arabelleğe almayı ve ardından farklı bir dosyaya kaydetmeyi gösterir.
        /// </summary>
        /// <param name="fileName">Path of your shapefile (e.g. C:\myShapefile.shp).</param>
        public static void BufferFeatures(string fileName)
        {
            // Açılacak şekil dosyasının dosya yolunu iletin
            IFeatureSet fs = FeatureSet.Open(@"C:\[Your File Path]\Municipalities.shp");

            // "fs" özellik kümesinin özelliklerini arabelleğe alın
            IFeatureSet bs = fs.Buffer(10, true);

            //Arabelleğe alınan özellik kümesini yeni bir dosya olarak kaydeder
            bs.SaveAs(@"C:\[Your File Path]\Municipalities_Buffer.shp", true);
        }
コード例 #16
0
ファイル: ControlZone.cs プロジェクト: giszzt/GeoSOS
        /// <summary>
        /// 创建管控区
        /// </summary>
        public void CreateControlZone()
        {
            _featureSet = MultiPlan.CommonMethod.GetFeatureSetByPath(_plan.Address);

            if (_featureSet != null)
            {
                AddBSMColumn(_featureSet);
                IFeatureSet selectedSet = SelectTransFeatures(_featureSet, _sql, _spatialRigon);
                TransferAttributes(selectedSet);
                selectedSet.SaveAs(_address, true);
            }
        }
コード例 #17
0
        /// <summary>
        /// Executes the Erase Opaeration tool programaticaly.
        /// Ping deleted static for external testing 01/2010
        /// </summary>
        /// <param name="input1">The input FeatureSet.</param>
        /// <param name="input2">The input Expression string to select features to Delete.</param>
        /// <param name="output">The output FeatureSet.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns></returns>
        public bool Execute(
            IFeatureSet input1, string input2, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input1 == null || input2 == null || output == null)
            {
                return(false);
            }

            if (cancelProgressHandler.Cancel)
            {
                return(false);
            }

            int             previous             = 0;
            List <IFeature> fetList              = input1.SelectByAttribute(input2);
            int             noOfFeaturesToDelete = fetList.Count;
            int             noOfFeatures         = input1.Features.Count;

            output.FeatureType = input1.FeatureType;
            foreach (IFeature f in input1.Features)
            {
                output.Features.Add(f);
            }

            // Go through every item in the list
            for (int i = 0; i < noOfFeaturesToDelete; i++)
            {
                int current = Convert.ToInt32(Math.Round(i * 100D / noOfFeaturesToDelete));

                // only update when increment in percentage
                if (current > previous)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                }

                previous = current;

                // loop through every item in the list
                for (int j = 0; j < noOfFeatures; j++)
                {
                    // Select the Feature from Feature set to detlete
                    if (fetList[i] == input1.Features[j])
                    {
                        output.Features.Remove(input1.Features[j]);
                    }
                }
            }

            output.SaveAs(output.Filename, true);
            return(true);
        }
コード例 #18
0
        public static IFeatureSet Complement(IFeatureSet l, string workdir)
        {
            IFeatureSet fs    = FeatureSet.Open(CSV_FILE_DIR + "/all.shp");
            var         world = fs.Features[0];

            foreach (var ft in l.Features)
            {
                world = world.Difference(ft);
            }
            fs.Features[0] = world;
            fs.SaveAs(WORKSPACE_DIR + workdir + "/compl.shp", true);
            return(fs);
        }
コード例 #19
0
        /// <summary>
        /// Executes the Erase Opaeration tool programaticaly
        /// </summary>
        /// <param name="self">The input feature that is to be erased</param>
        /// <param name="other">The other feature defining the area to remove</param>
        /// <param name="output">The resulting erased content</param>
        /// <param name="cancelProgressHandler">The progress handler</param>
        /// <returns>Boolean, true if the operation was a success</returns>
        public static bool Execute(
            IFeatureSet self, IFeatureSet other, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (self == null || other == null || output == null)
            {
                return(false);
            }

            int previous;
            int max = self.Features.Count * other.Features.Count;

            output.CopyTableSchema(self); // Fill the 1st Featureset fields
            IFeatureSet tempSet = self.CombinedFields(other);

            // go through every feature in 1st featureSet
            for (int i = 0; i < self.Features.Count; i++)
            {
                // go through every feature in 2nd featureSet
                for (int j = 0; j < other.Features.Count; j++)
                {
                    self.Features[i].Difference(other.Features[j], tempSet, FieldJoinType.All);
                    previous = Convert.ToInt32(Math.Round(i * j * 50D / max));
                    if (cancelProgressHandler.Cancel)
                    {
                        return(false);
                    }

                    cancelProgressHandler.Progress(string.Empty, previous, previous + TextStrings.progresscompleted);
                }
            }

            // Add to the Output Feature Set
            for (int a = 0; a < tempSet.Features.Count; a++)
            {
                output.Features.Add(tempSet.Features[a]);
                previous = Convert.ToInt32(Math.Round((a * 50D / tempSet.Features.Count) + 50D));
                if (cancelProgressHandler.Cancel)
                {
                    return(false);
                }

                cancelProgressHandler.Progress(string.Empty, previous, previous + TextStrings.progresscompleted);
            }

            output.SaveAs(output.Filename, true);

            // add to map?
            return(true);
        }
コード例 #20
0
        // metric coordinates
        public static IFeatureSet ApplyBuffer(string filter, double distance, bool isMin, string workdir)
        {
            string      filename = PoiList.GetShapefile(filter);
            IFeatureSet fs       = FeatureSet.Open(CSV_FILE_DIR + '/' + filename);
            IFeatureSet bs       = fs.Buffer(distance, false);

            if (isMin)
            {
                bs = Complement(bs, workdir);
            }

            for (int i = 0; ; i++)
            {
                if (!File.Exists(WORKSPACE_DIR + workdir + "/buf" + i + ".shp"))
                {
                    bs.SaveAs(WORKSPACE_DIR + workdir + "/buf" + i + ".shp", true);
                    break;
                }
            }

            bs.SaveAs(WORKSPACE_DIR + workdir + "/buf.shp", true);
            return(bs);
        }
コード例 #21
0
        /// <summary>
        /// Executes the add features Opaeration tool programaticaly.
        /// Ping deleted "static" for external Testing
        /// </summary>
        /// <param name="input1">The input FeatureSet.</param>
        /// <param name="input2">The input2 featureSet which has the new features to add.</param>
        /// <param name="output">The output FeatureSet.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns></returns>
        public bool Execute(
            IFeatureSet input1, IFeatureSet input2, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input1 == null || input2 == null || output == null)
            {
                return(false);
            }

            int previous   = 0;
            int i          = 0;
            int maxFeature = input2.Features.Count;

            output.FeatureType = input1.FeatureType;
            foreach (IFeature f1 in input1.Features)
            {
                output.Features.Add(f1);
            }

            // go through new featureset that wanted to add.
            foreach (IFeature f in input2.Features)
            {
                if (cancelProgressHandler.Cancel)
                {
                    return(false);
                }

                if (input1.FeatureType == input2.FeatureType)
                {
                    output.Features.Add(f);
                }

                int current = Convert.ToInt32(Math.Round(i * 100D / maxFeature));

                // only update when increment in percentage
                if (current > previous)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                }

                previous = current;
                i++;
            }

            output.SaveAs(output.Filename, true);

            // cancelProgressHandler.Progress("", 100, 100.ToString() + TextStrings.progresscompleted);
            return(true);
        }
コード例 #22
0
        /// <summary>
        /// Executes the ReprojectFeatureSet Operation tool programmatically.
        /// </summary>
        /// <param name="featureSet">The input FeatureSet.</param>
        /// <param name="sourceProjection">The input Expression string to select features to Delete.</param>
        /// <param name="destProjection">The target projected coordinate system to reproject the featureset to</param>
        /// <param name="output">The output FeatureSet.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns>True, if executed successfully.</returns>
        public bool Execute(IFeatureSet featureSet, ProjectionInfo sourceProjection, ProjectionInfo destProjection, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            string filename = output.Filename;

            output = featureSet.CopySubset(string.Empty);

            if (sourceProjection != null)
            {
                output.Projection = sourceProjection;
            }

            output.Reproject(destProjection);
            output.SaveAs(filename, true);
            return(true);
        }
コード例 #23
0
        /// <summary>
        /// Executes the ReprojectFeatureSet Operation tool programaticaly.
        /// </summary>
        /// <param name="featureSet">The input FeatureSet.</param>
        /// <param name="sourceProjection">The input Expression string to select features to Delete.</param>
        /// <param name="destProjection">The target projected coordinate system to reproject the featureset to</param>
        /// <param name="output">The output FeatureSet.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// Ping deleted "static" for external testing
        /// <returns></returns>
        public bool Execute(
            IFeatureSet featureSet,
            ProjectionInfo sourceProjection,
            ProjectionInfo destProjection,
            IFeatureSet output,
            ICancelProgressHandler cancelProgressHandler)
        {
            output.CopyFeatures(featureSet, true);
            output.Projection = featureSet.Projection;
            if (sourceProjection != null)
            {
                output.Projection = sourceProjection;
            }

            output.Reproject(destProjection);
            output.SaveAs(output.Filename, true);
            return(true);
        }
コード例 #24
0
        static void DuplicateShapeElimination()
        {
            IFeatureSet      centroid = FeatureSet.Open(@"D:\OneDrive\2017研究生毕业设计\数据\项目用数据\newCentroid.shp");
            HashSet <string> set      = new HashSet <string>();
            List <int>       index    = new List <int>(5);

            foreach (var item in centroid.Features)
            {
                string name = item.DataRow["name"].ToString();
                if (!set.Add(name))
                {
                    index.Add(item.Fid);
                }
            }
            centroid.RemoveShapesAt(index);
            Console.WriteLine("数据删除完毕");
            centroid.SaveAs("newCentroidNoDup.shp", true);
            Console.ReadKey();
        }
コード例 #25
0
        public static string ProcessRequest(UserRequest req)
        {
            var workdir = CreateWorkspace();

            IFeatureSet resultArea = CreateUserInputLayer(req.Lon, req.Lat, req.Radius, workdir);
            var         c          = Complement(resultArea, workdir);

            foreach (var f in req.Filters)
            {
                bool isMin    = f.MinMaxType == "Minimum";
                var  buffered = ApplyBuffer(f.ObjectType, f.Distance, isMin, workdir);
                resultArea = Intersect(resultArea, buffered, workdir);
            }

            resultArea.SaveAs(WORKSPACE_DIR + workdir + "/output.shp", true);
            var json = ToGeoJson(WORKSPACE_DIR + workdir + "/output.shp");

            CleanWorkspace(workdir);

            return(json);
            //foreach (var s in resultArea.ShapeIndices)
            //{
            //    foreach (var part in s.Parts)
            //    {
            //        var item = new PolygonModel() { Vertices = new List<Coord>() };
            //        // TODO use Shoelace formula to determine if polygon is clockwise - if yes:
            //        // this is exterior polygon, else - interior polygon (a hole)

            //        for (int i = part.StartIndex * 2; i <= part.EndIndex * 2; i += 2)
            //        {
            //            Coord point = new Coord();
            //            point.Lon = part.Vertices[i];
            //            point.Lat = part.Vertices[i + 1];

            //            item.Vertices.Add(point);
            //        }
            //        polygons.Add(item);
            //    }
            //}
            //return polygons;
        }
コード例 #26
0
        static void GetDataOfEachPoints()
        {
            //是按照O-D的顺序来的
            IFeatureSet desPoints     = FeatureSet.Open(@"D:\OneDrive\2017研究生毕业设计\数据\项目用数据\DesGauss.shp");
            IFeatureSet orgPoints     = FeatureSet.Open(@"D:\OneDrive\2017研究生毕业设计\数据\项目用数据\OriginalGauss.shp");
            string      newColumnName = "Subject";

            desPoints.DataTable.Columns.Add(newColumnName, typeof(int));
            orgPoints.DataTable.Columns.Add(newColumnName, typeof(int));
            StreamReader sr = new StreamReader(@"D:\OneDrive\2017研究生毕业设计\数据\项目用数据\统计用数据\cluster数据.txt");

            sr.ReadLine();
            Console.WriteLine("标题栏读取结束");
            int count  = 0;
            int NUMBER = 105243;

            while (!sr.EndOfStream)
            {
                string[] line = sr.ReadLine().Split();
                if (count < NUMBER)
                {
                    IFeature current = orgPoints.Features[count];
                    current.DataRow.BeginEdit();
                    current.DataRow[newColumnName] = int.Parse(line[1]) - 1;
                    current.DataRow.EndEdit();
                }
                else
                {
                    IFeature current = desPoints.Features[count - NUMBER];
                    current.DataRow.BeginEdit();
                    current.DataRow[newColumnName] = int.Parse(line[1]) - 1;
                    current.DataRow.EndEdit();
                }
                count++;
            }
            sr.Close();
            Console.WriteLine("字段添加完成,开始保存数据");
            orgPoints.SaveAs("OriginalGaussWithSubject.shp", true);
            desPoints.SaveAs("DesGaussWithSubject.shp", true);
        }
コード例 #27
0
        /// <summary>
        /// Executes the ClipPolygonWithPolygon tool with programatic input
        /// </summary>
        /// <param name="input">The input feature set to clip</param>
        /// <param name="input2">The input polygon feature set to clip with</param>
        /// <param name="output">The output feature set</param>
        /// <param name="cancelProgressHandler">The progress handler for progress message updates</param>
        /// <returns>True if executed successfully.</returns>
        public bool Execute(IFeatureSet input, IFeatureSet input2, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input == null || input2 == null || output == null)
            {
                cancelProgressHandler.Progress(100, TextStrings.Oneparameterinnull);
                return(false);
            }

            if (input2.FeatureType != FeatureType.Polygon)
            {
                cancelProgressHandler.Progress(100, TextStrings.secondinputlayer);
                return(false);
            }

            output.FeatureType = input.FeatureType;

            // we add all the old features to output
            IFeatureSet tempoutput = input.Intersection(input2, FieldJoinType.LocalOnly, cancelProgressHandler);

            // We add all the fields
            foreach (DataColumn inputColumn in tempoutput.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            foreach (var fe in tempoutput.Features)
            {
                output.Features.Add(fe);
            }

            // Setting the AttributesPopulated to true here means the output shapefile will get attribute columns copied from
            // the source file. This problem occurs when using the ClipPolygonWithPolygon tool due to how the input/output files
            // are loaded. https://github.com/DotSpatial/DotSpatial/issues/892
            output.AttributesPopulated = true;

            output.SaveAs(output.Filename, true);
            return(true);
        }
コード例 #28
0
        /// <summary>
        /// Executes the Union Opaeration tool programaticaly
        /// </summary>
        /// <param name="input">The input are feature sets</param>
        /// <param name="output">The output feature set</param>
        /// <param name="CancelProgressHandler">The progress handler</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet self, IFeatureSet output, MapWindow.Tools.ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (self == null || self.Features == null || self.Features.Count == 0 || output == null)
            {
                return false;
            }

            IFeature result = self.Features[0];
            MapWindow.Main.ProgressMeter pm = new MapWindow.Main.ProgressMeter(cancelProgressHandler, "Unioning Shapes", self.Features.Count);
            for(int i = 1; i < self.Features.Count; i++)
            {
                if (self.Features[i] == null) continue;
                result = result.Union(self.Features[i]);
                pm.CurrentValue = i;
            }
            pm.Reset();
            output.Features.Add(result);
            output.SaveAs(output.Filename, true);
            return true;
                
        }
コード例 #29
0
 /// <summary>
 /// Executes the ReprojectFeatureSet Operation tool programaticaly.
 /// </summary>
 /// <param name="featureSet">The input FeatureSet.</param>
 /// <param name="sourceProjection">The input Expression string to select features to Delete.</param>
 /// <param name="destProjection">The target projected coordinate system to reproject the featureset to</param>
 /// <param name="output">The output FeatureSet.</param>
 /// <param name="cancelProgressHandler">The progress handler.</param>
 /// Ping deleted "static" for external testing 
 /// <returns></returns>
 public bool Execute(IFeatureSet featureSet, ProjectionInfo sourceProjection, ProjectionInfo destProjection, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
 {             
         output.CopyFeatures(featureSet, true);
         output.Projection = featureSet.Projection;
         if(sourceProjection != null) output.Projection = sourceProjection;
         output.Reproject(destProjection);
         output.SaveAs(output.Filename, true);
         return true;      
 }
コード例 #30
0
        /// <summary>
        /// Executes the ClipPolygonWithPolygon tool with programatic input
        /// </summary>
        /// <param name="input">The input feature set to clip</param>
        /// <param name="input2">The input polygon feature set to clip with</param>
        /// <param name="output">The output feature set</param>
        /// <param name="cancelProgressHandler">The progress handler for progress message updates</param>
        /// <returns></returns>
        /// Ping delete "static" for external testing
        public bool Execute(
            IFeatureSet input, IFeatureSet input2, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input == null || input2 == null || output == null)
            {
                cancelProgressHandler.Progress(string.Empty, 100, TextStrings.Oneparameterinnull);
                return false;
            }

            if (input2.FeatureType != FeatureType.Polygon)
            {
                cancelProgressHandler.Progress(string.Empty, 100, TextStrings.secondinputlayer);
                return false;
            }

            output.FeatureType = input.FeatureType;

            // we add all the old features to output
            IFeatureSet tempoutput = input.Intersection(input2, FieldJoinType.LocalOnly, cancelProgressHandler);

            // We add all the fields
            foreach (DataColumn inputColumn in tempoutput.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            foreach (var fe in tempoutput.Features)
            {
                output.Features.Add(fe);
            }

            output.SaveAs(output.Filename, true);
            return true;
        }
コード例 #31
0
ファイル: Union.cs プロジェクト: ExRam/DotSpatial-PCL
        /// <summary>
        /// Executes the Union Opaeration tool programaticaly
        /// </summary>
        /// <param name="self">The input are feature set</param>
        /// <param name="other">The second input feature set</param>
        /// <param name="output">The output feature set</param>
        /// <param name="cancelProgressHandler">The progress handler</param>
        /// <returns></returns>
        public bool Execute(
            IFeatureSet self, IFeatureSet other, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (self == null || other == null || output == null)
            {
                return false;
            }

            IFeatureSet tempOutput = self.Intersection(other, FieldJoinType.All, null);
            IFeatureSet tempFeatureSet = self.CombinedFields(other);

            int previous = 0;
            int max = self.Features.Count;

            // Take (Self-Intersect Featureset)
            List<IFeature> intersectList;
            for (int i = 0; i < self.Features.Count; i++)
            {
                intersectList = other.Select(self.Features[i].Envelope.ToExtent());
                foreach (IFeature feat in intersectList)
                {
                    if (cancelProgressHandler.Cancel)
                    {
                        return false;
                    }

                    self.Features[i].Difference(feat, tempFeatureSet, FieldJoinType.LocalOnly);
                }

                if (Math.Round(i * 40D / max) <= previous)
                {
                    continue;
                }

                previous = Convert.ToInt32(Math.Round(i * 40D / max));
                cancelProgressHandler.Progress(string.Empty, previous, previous + TextStrings.progresscompleted);
            }

            max = other.Features.Count;

            // Take (Other-Intersect Featureset)
            for (int i = 0; i < other.Features.Count; i++)
            {
                intersectList = self.Select(other.Features[i].Envelope.ToExtent());
                foreach (IFeature feat in intersectList)
                {
                    if (cancelProgressHandler.Cancel)
                    {
                        return false;
                    }

                    other.Features[i].Difference(feat, tempFeatureSet, FieldJoinType.LocalOnly);
                }

                if (Math.Round((i * 40D / max) + 40D) <= previous)
                {
                    continue;
                }

                previous = Convert.ToInt32(Math.Round((i * 40D / max) + 40D));
                cancelProgressHandler.Progress(string.Empty, previous, previous + TextStrings.progresscompleted);
            }

            max = tempFeatureSet.Features.Count;
            output.CopyTableSchema(tempFeatureSet);

            // Add the individual feature to output
            for (int i = 0; i < tempFeatureSet.Features.Count; i++)
            {
                output.Features.Add(tempFeatureSet.Features[i]);
                if (Math.Round((i * 10D / max) + 80D) <= previous)
                {
                    continue;
                }

                previous = Convert.ToInt32(Math.Round((i * 10D / max) + 80D));
                if (cancelProgressHandler.Cancel)
                {
                    return false;
                }

                cancelProgressHandler.Progress(string.Empty, previous, previous + TextStrings.progresscompleted);
            }

            max = tempOutput.Features.Count;

            // Add the Intersect feature to output
            for (int i = 0; i < tempOutput.Features.Count; i++)
            {
                output.Features.Add(tempOutput.Features[i]);
                if (cancelProgressHandler.Cancel)
                {
                    return false;
                }

                if (Math.Round((i * 10D / max) + 90D) <= previous)
                {
                    continue;
                }

                previous = Convert.ToInt32(Math.Round((i * 10D / max) + 90D));
                cancelProgressHandler.Progress(string.Empty, previous, previous + TextStrings.progresscompleted);
            }

            output.SaveAs(output.Filename, true);
            return true;
        }
コード例 #32
0
        /// <summary>
        /// Executes the generate centroid FeatureSet Opaeration tool programaticaly.
        /// Ping deleted static for external testing 01/2010
        /// </summary>
        /// <param name="input1">The input FeatureSet.</param>
        /// <param name="output">The output FeatureSet.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input1, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input1 == null || output == null)
            {
                return false;
            }

            bool multiPoint = false;
            foreach (IFeature f1 in input1.Features)
            {
                if (f1.NumGeometries > 1)
                {
                    multiPoint = true;
                }
            }

            output.FeatureType = multiPoint == false ? FeatureType.Point : FeatureType.MultiPoint;

            int previous = 0;
            int i = 0;
            int maxFeature = input1.Features.Count;
            output.CopyTableSchema(input1);
            foreach (IFeature f in input1.Features)
            {
                if (cancelProgressHandler.Cancel)
                {
                    return false;
                }

                IFeature fnew = new Feature(f.Centroid());

                // Add the centroid to output
                output.Features.Add(fnew);

                fnew.CopyAttributes(f);

                int current = Convert.ToInt32(Math.Round(i * 100D / maxFeature));

                // only update when increment in percentage
                if (current > previous)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                }

                previous = current;
                i++;
            }

            output.SaveAs(output.Filename, true);
            return true;
        }
コード例 #33
0
        /// <summary>
        /// Finds the average slope in the given polygons.
        /// </summary>
        /// <param name="ras">The dem Raster(Grid file).</param>
        /// <param name="zFactor">The scaler factor</param>
        /// <param name="poly">The flow poly shapefile path.</param>
        /// <param name="output">The resulting DEM of slopes</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        public bool Execute(
            IRaster ras,
            double zFactor,
            IFeatureSet poly,
            IFeatureSet output,
            ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (ras == null || poly == null || output == null)
            {
                return(false);
            }

            output.FeatureType = poly.FeatureType;
            foreach (IFeature f in poly.Features)
            {
                output.Features.Add(f);
            }

            output.DataTable.Columns.Add("FID", typeof(int));
            output.DataTable.Columns.Add(TextStrings.AveSlope, typeof(Double));

            IRaster slopeGrid = new Raster {
                DataType = ras.DataType, Bounds = ras.Bounds
            };

            // FeatureSet polyShape = new FeatureSet();
            int previous = 0;

            if (Slope(ref ras, zFactor, false, ref slopeGrid, cancelProgressHandler) == false)
            {
                return(false);
            }

            int shapeCount = output.Features.Count;

            int[]    areaCount = new int[shapeCount];
            double[] areaTotal = new double[shapeCount];
            double[] areaAve   = new double[shapeCount];
            double   dxHalf    = slopeGrid.CellWidth / 2;
            double   dyHalf    = slopeGrid.CellHeight / 2;

            // check whether those two envelope are intersect
            if (ras.Extent.Intersects(output.Extent) == false)
            {
                return(false);
            }

            RcIndex start = slopeGrid.ProjToCell(output.Extent.MinX, output.Extent.MaxY);
            RcIndex stop  = slopeGrid.ProjToCell(output.Extent.MaxX, output.Extent.MinY);

            int rowStart = start.Row;
            int colStart = start.Column;
            int rowStop  = stop.Row;
            int colStop  = stop.Column;

            for (int row = rowStart - 1; row < rowStop + 1; row++)
            {
                int current = Convert.ToInt32((row - rowStart + 1) * 100.0 / (rowStop + 1 - rowStart + 1));

                // only update when increment in percentage
                if (current > previous + 5)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                    previous = current;
                }

                for (int col = colStart - 1; col < colStop + 1; col++)
                {
                    Coordinate cent  = slopeGrid.CellToProj(row, col);
                    double     xCent = cent.X;
                    double     yCent = cent.Y;
                    for (int shpindx = 0; shpindx < output.Features.Count; shpindx++)
                    {
                        IFeature tempFeat = output.Features[shpindx];
                        Point    pt1      = new Point(xCent, yCent);
                        Point    pt2      = new Point(xCent - dxHalf, yCent - dyHalf);
                        Point    pt3      = new Point(xCent + dxHalf, yCent - dyHalf);
                        Point    pt4      = new Point(xCent + dxHalf, yCent + dyHalf);
                        Point    pt5      = new Point(xCent - dxHalf, yCent + dyHalf);
                        if ((((!tempFeat.Covers(pt1) && !tempFeat.Covers(pt2)) && !tempFeat.Covers(pt3)) &&
                             !tempFeat.Covers(pt4)) && !tempFeat.Covers(pt5))
                        {
                            continue;
                        }

                        areaCount[shpindx]++;
                        areaTotal[shpindx] += slopeGrid.Value[row, col] / 100;

                        if (cancelProgressHandler.Cancel)
                        {
                            return(false);
                        }
                    }
                }
            }

            for (int shpindx = 0; shpindx < output.Features.Count; shpindx++)
            {
                if (areaCount[shpindx] == 0)
                {
                    areaAve[shpindx] = 0;
                }
                else
                {
                    areaAve[shpindx] = areaTotal[shpindx] / areaCount[shpindx];
                }

                output.Features[shpindx].DataRow["FID"] = shpindx;
                output.Features[shpindx].DataRow[TextStrings.AveSlope] = areaAve[shpindx];
            }

            poly.Close();
            slopeGrid.Close();
            output.SaveAs(output.Filename, true);
            return(true);
        }
コード例 #34
0
ファイル: Union.cs プロジェクト: rprouse/DotSpatial
        /// <summary>
        /// Executes the Union Opaeration tool programmatically.
        /// </summary>
        /// <param name="self">The input are feature set.</param>
        /// <param name="other">The second input feature set.</param>
        /// <param name="output">The output feature set.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns>True, if executed successfully.</returns>
        public bool Execute(IFeatureSet self, IFeatureSet other, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (self == null || other == null || output == null)
            {
                return(false);
            }

            IFeatureSet tempOutput     = self.Intersection(other, FieldJoinType.All, null);
            IFeatureSet tempFeatureSet = self.CombinedFields(other);

            int previous = 0;
            int max      = self.Features.Count;

            // Take (Self-Intersect Featureset)
            List <IFeature> intersectList;

            for (int i = 0; i < self.Features.Count; i++)
            {
                intersectList = other.Select(self.Features[i].Geometry.EnvelopeInternal.ToExtent());
                foreach (IFeature feat in intersectList)
                {
                    if (cancelProgressHandler.Cancel)
                    {
                        return(false);
                    }

                    self.Features[i].Difference(feat, tempFeatureSet, FieldJoinType.LocalOnly);
                }

                if (Math.Round(i * 40D / max) <= previous)
                {
                    continue;
                }

                previous = Convert.ToInt32(Math.Round(i * 40D / max));
                cancelProgressHandler.Progress(previous, previous + TextStrings.progresscompleted);
            }

            max = other.Features.Count;

            // Take (Other-Intersect Featureset)
            for (int i = 0; i < other.Features.Count; i++)
            {
                intersectList = self.Select(other.Features[i].Geometry.EnvelopeInternal.ToExtent());
                foreach (IFeature feat in intersectList)
                {
                    if (cancelProgressHandler.Cancel)
                    {
                        return(false);
                    }

                    other.Features[i].Difference(feat, tempFeatureSet, FieldJoinType.LocalOnly);
                }

                if (Math.Round((i * 40D / max) + 40D) <= previous)
                {
                    continue;
                }

                previous = Convert.ToInt32(Math.Round((i * 40D / max) + 40D));
                cancelProgressHandler.Progress(previous, previous + TextStrings.progresscompleted);
            }

            max = tempFeatureSet.Features.Count;
            output.CopyTableSchema(tempFeatureSet);

            // Add the individual feature to output
            for (int i = 0; i < tempFeatureSet.Features.Count; i++)
            {
                output.Features.Add(tempFeatureSet.Features[i]);
                if (Math.Round((i * 10D / max) + 80D) <= previous)
                {
                    continue;
                }

                previous = Convert.ToInt32(Math.Round((i * 10D / max) + 80D));
                if (cancelProgressHandler.Cancel)
                {
                    return(false);
                }

                cancelProgressHandler.Progress(previous, previous + TextStrings.progresscompleted);
            }

            max = tempOutput.Features.Count;

            // Add the Intersect feature to output
            for (int i = 0; i < tempOutput.Features.Count; i++)
            {
                output.Features.Add(tempOutput.Features[i]);
                if (cancelProgressHandler.Cancel)
                {
                    return(false);
                }

                if (Math.Round((i * 10D / max) + 90D) <= previous)
                {
                    continue;
                }

                previous = Convert.ToInt32(Math.Round((i * 10D / max) + 90D));
                cancelProgressHandler.Progress(previous, previous + TextStrings.progresscompleted);
            }

            output.SaveAs(output.Filename, true);
            return(true);
        }
コード例 #35
0
        /// <summary>
        /// Finds the average slope in the given polygons.
        /// </summary>
        /// <param name="gridIn">The Polygon Raster(Grid file).</param>
        /// <param name="polyOut">The Polygon shapefile path.</param>
        /// <param name="progress">The progress handler.</param>
        public bool Execute(IRaster gridIn, IFeatureSet polyOut, ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (gridIn == null || polyOut == null)
            {
                return false;
            }
            int maxX, maxY;
            int current = 0;
            int previous = 0;
            double noData, currVal, currTrack;
            string strTrackPath;
            IRaster gridTrack = new Raster();


            maxX = gridIn.NumRows - 1;
            maxY = gridIn.NumColumns - 1;
            noData = gridIn.NoDataValue;

            //strTrackPath = System.IO.Path.GetDirectoryName(strInRast) + "\\" + System.IO.Path.GetFileNameWithoutExtension(strInRast) + "_track.bgd";
            gridTrack = Raster.Create("gridTrack.bgd", "", gridIn.NumColumns, gridIn.NumRows, 1, gridIn.DataType, new string[] { "" });
            //gridTrack.CreateNew("gridTrack", "", gridIn.NumColumns, gridIn.NumRows, 1, gridIn.DataType, new string[] { "" });
            gridTrack.Bounds = gridIn.Bounds;
            gridTrack.NoDataValue = gridIn.NoDataValue;

            polyOut.DataTable.Columns.Add("Value", typeof(int));
            polyOut.DataTable.Columns.Add("Zone", typeof(string));
            polyOut.DataTable.Columns.Add("Area", typeof(double));
            polyOut.DataTable.Columns.Add("COMID", typeof(string));
            polyOut.DataTable.Columns.Add("AveSlope", typeof(double));

            for (int i = 0; i <= maxX; i++)
            {

                current = Convert.ToInt32(i * 100 / maxX);
                //only update when increment in percentage
                if (current > previous+5)
                {
                    cancelProgressHandler.Progress("", current, current.ToString() + "% progress completed");
                    previous = current;
                }
                    

                for (int j = 0; j <= maxY; j++)
                {
                    if (i > 0 && j > 0)
                    {
                        currVal = Convert.ToInt16(gridIn.Value[i, j]);
                        currTrack = Convert.ToInt16(gridTrack.Value[i, j]);
                        if (currVal == gridIn.NoDataValue)
                        {
                            gridTrack.Value[i, j] = 1;

                            if (cancelProgressHandler.Cancel == true)
                                return false;
                        }
                        else
                        {
                            if (currTrack == 1)
                            {
                            }
                            else
                            {
                                formPolyFromCell(gridIn, gridTrack, i, j, polyOut, cancelProgressHandler);

                                if (cancelProgressHandler.Cancel == true)
                                    return false;
                            }
                        }
                    }
                    else
                    {
                        gridTrack.Value[i, j] = gridIn.NoDataValue;
                    }

                    

                }
            }
            gridIn.Close();
            gridTrack.Close();
            polyOut.SaveAs(polyOut.Filename, true);
            polyOut.Close();
            return true;

        }
コード例 #36
0
ファイル: DeleteFeatures.cs プロジェクト: hanchao/DotSpatial
        /// <summary>
        /// Executes the Erase Opaeration tool programaticaly.
        /// Ping deleted static for external testing 01/2010
        /// </summary>
        /// <param name="input1">The input FeatureSet.</param>
        /// <param name="input2">The input Expression string to select features to Delete.</param>
        /// <param name="output">The output FeatureSet.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns></returns>
        public bool Execute(
            IFeatureSet input1, string input2, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input1 == null || input2 == null || output == null)
            {
                return false;
            }

            if (cancelProgressHandler.Cancel)
            {
                return false;
            }

            int previous = 0;
            List<IFeature> fetList = input1.SelectByAttribute(input2);
            int noOfFeaturesToDelete = fetList.Count;
            int noOfFeatures = input1.Features.Count;
            output.FeatureType = input1.FeatureType;
            foreach (IFeature f in input1.Features)
            {
                output.Features.Add(f);
            }

            // Go through every item in the list
            for (int i = 0; i < noOfFeaturesToDelete; i++)
            {
                int current = Convert.ToInt32(Math.Round(i * 100D / noOfFeaturesToDelete));

                // only update when increment in percentage
                if (current > previous)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                }

                previous = current;

                // loop through every item in the list
                for (int j = 0; j < noOfFeatures; j++)
                {
                    // Select the Feature from Feature set to detlete
                    if (fetList[i] == input1.Features[j])
                    {
                        output.Features.Remove(input1.Features[j]);
                    }
                }
            }

            output.SaveAs(output.Filename, true);
            return true;
        }
コード例 #37
0
ファイル: Erase.cs プロジェクト: DIVEROVIEDO/DotSpatial
        /// <summary>
        /// Ping Yang Overwrite the function for Executes the Erase Opaeration tool for external testing
        /// </summary>
        public bool Execute(IFeatureSet self, IFeatureSet other, IFeatureSet output)
        {
            if (self == null || other == null || output == null)
            {
                return false;
            }

            output.CopyTableSchema(self); // Fill the 1st Featureset fields
            IFeatureSet tempSet = self.CombinedFields(other);

            // go through every feature in 1st featureSet
            foreach (IFeature t in self.Features)
            {
                // go through every feature in 2nd featureSet
                foreach (IFeature t1 in other.Features)
                {
                    t.Difference(t1, tempSet, FieldJoinType.All);
                }
            }

            // Add to the Output Feature Set
            for (int a = 0; a < tempSet.Features.Count; a++)
            {
                output.Features.Add(tempSet.Features[a]);
            }

            output.SaveAs(output.Filename, true);

            // add to map?
            return true;
        }
コード例 #38
0
ファイル: Erase.cs プロジェクト: DIVEROVIEDO/DotSpatial
        /// <summary>
        /// Executes the Erase Opaeration tool programaticaly
        /// </summary>
        /// <param name="self">The input feature that is to be erased</param>
        /// <param name="other">The other feature defining the area to remove</param>
        /// <param name="output">The resulting erased content</param>
        /// <param name="cancelProgressHandler">The progress handler</param>
        /// <returns>Boolean, true if the operation was a success</returns>
        public static bool Execute(
            IFeatureSet self, IFeatureSet other, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (self == null || other == null || output == null)
            {
                return false;
            }

            int previous;
            int max = self.Features.Count * other.Features.Count;

            output.CopyTableSchema(self); // Fill the 1st Featureset fields
            IFeatureSet tempSet = self.CombinedFields(other);

            // go through every feature in 1st featureSet
            for (int i = 0; i < self.Features.Count; i++)
            {
                // go through every feature in 2nd featureSet
                for (int j = 0; j < other.Features.Count; j++)
                {
                    self.Features[i].Difference(other.Features[j], tempSet, FieldJoinType.All);
                    previous = Convert.ToInt32(Math.Round(i * j * 50D / max));
                    if (cancelProgressHandler.Cancel)
                    {
                        return false;
                    }

                    cancelProgressHandler.Progress(string.Empty, previous, previous + TextStrings.progresscompleted);
                }
            }

            // Add to the Output Feature Set
            for (int a = 0; a < tempSet.Features.Count; a++)
            {
                output.Features.Add(tempSet.Features[a]);
                previous = Convert.ToInt32(Math.Round((a * 50D / tempSet.Features.Count) + 50D));
                if (cancelProgressHandler.Cancel)
                {
                    return false;
                }

                cancelProgressHandler.Progress(string.Empty, previous, previous + TextStrings.progresscompleted);
            }

            output.SaveAs(output.Filename, true);

            // add to map?
            return true;
        }
コード例 #39
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (this.cboLayer.Text == "")
            {
                MessageBox.Show("Please select a layer");
                return;
            }
            if (this.txtFilePath.Text.Trim() == "")
            {
                MessageBox.Show("Please select a remot file");
                return;
            }
            if (this.txtSavePath.Text.Trim() == "")
            {
                MessageBox.Show("Please select a save path");
                return;
            }
            //新建一个FeatureSet 几何与原图层一致
            IFeatureSet pResultSet = (m_CurrentFeaLyr as FeatureLayer).FeatureSet.CopyFeatures(false);

            pResultSet.DataTable = Common.CHelp.CopyDataTable(m_CurrentFeaLyr.DataSet.DataTable);
            DataTable SrcDT = pResultSet.DataTable;
            DataTable TarDt = m_RemoteFeaSet.DataTable.Copy();
            //添加字段
            List <string> FiledsName = new List <string>();

            foreach (DataColumn col in TarDt.Columns)
            {
                if (SrcDT.Columns.Contains(col.ColumnName))
                {
                    continue;
                }
                DataColumn column = new DataColumn(col.ColumnName);
                SrcDT.Columns.Add(column);
                FiledsName.Add(col.ColumnName);
            }
            //相交查询
            int i = 0;

            foreach (var LayerFea in pResultSet.Features)
            {
                foreach (var remoteFea in m_RemoteFeaSet.Features)
                {
                    if (LayerFea.Geometry.IsEmpty)
                    {
                        continue;
                    }
                    //找到第一个匹配项即返回
                    if (LayerFea.Geometry.Intersects(remoteFea.Geometry))
                    {
                        foreach (string colname in FiledsName)
                        {
                            SrcDT.Rows[i][colname] = remoteFea.DataRow[colname];
                        }
                        break;
                    }
                }
                i++;
            }
            //保存
            pResultSet.Name = System.IO.Path.GetFileNameWithoutExtension(this.txtSavePath.Text);
            pResultSet.SaveAs(this.txtSavePath.Text, true);
            //加载图层
            MainWindow.m_DotMap.Layers.Add(pResultSet);
            MessageBox.Show("Successfully");
            this.Close();
        }
コード例 #40
0
ファイル: Erase.cs プロジェクト: zhongshuiyuan/mapwindowsix
        /// <summary>
        /// Ping Yang Overwrite the function for Executes the Erase Opaeration tool for external testing
        /// </summary>
        public bool Execute(IFeatureSet self, IFeatureSet other, IFeatureSet output)
        {
            if (self == null || other == null || output == null)
            {
                return false;
            }

            int previous;
            int max = self.Features.Count * other.Features.Count;

            output.CopyTableSchema(self);//Fill the 1st Featureset fields
            IFeatureSet tempSet = self.CombinedFields(other);
            //go through every feature in 1st featureSet
            for (int i = 0; i < self.Features.Count; i++)
            {
                //go through every feature in 2nd featureSet
                for (int j = 0; j < other.Features.Count; j++)
                {
                    self.Features[i].Difference(other.Features[j], tempSet, FieldJoinType.All);
                    previous = Convert.ToInt32(Math.Round((i * j * 50D / max)));
                  }
            }
            //Add to the Output Feature Set
            for (int a = 0; a < tempSet.Features.Count; a++)
            {
                output.Features.Add(tempSet.Features[a]);
                previous = Convert.ToInt32(Math.Round((a * 50D / tempSet.Features.Count) + 50D));
            }

            output.SaveAs(output.Filename, true);
            //add to map?
            return true;
        }
コード例 #41
0
ファイル: Aggregate.cs プロジェクト: ExRam/DotSpatial-PCL
        /// <summary>
        /// Executes the Union Opaeration tool programaticaly
        /// </summary>
        /// <param name="sourceData">The source FeatureSet to aggregate the features for..</param>
        /// <param name="resultData">The result FeatureSet of aggregated features..</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns>Boolean if the result is true.</returns>
        public bool Execute(
            IFeatureSet sourceData, IFeatureSet resultData, ICancelProgressHandler cancelProgressHandler)
        // removed "static" dpa 12/2009 so that this can be run from an external call directly.
        {
            // Validates the input and output data
            if (sourceData == null || sourceData.Features == null || sourceData.Features.Count == 0
                || resultData == null)
            {
                return false;
            }

            IFeature oneFeature = sourceData.Features[0];

            // MapWindow.Main.ProgressMeter pm = new MapWindow.Main.ProgressMeter(cancelProgressHandler, TextStrings.UnioningShapes, self.Features.Count);
            for (int i = 1; i < sourceData.Features.Count; i++)
            {
                if (sourceData.Features[i] == null)
                {
                    continue;
                }

                oneFeature = oneFeature.Union(sourceData.Features[i]);

                // pm.CurrentValue = i;
            }

            // pm.Reset();
            resultData.Features.Add(oneFeature);
            resultData.SaveAs(resultData.Filename, true);
            return true;
        }
コード例 #42
0
        /// <summary>
        /// Executes the overwrite feature Opaeration tool programaticaly.
        /// </summary>
        /// <param name="input1">The input FeatureSet.</param>
        /// <param name="index">The Index to overwrite</param>
        /// <param name="input2">The input2 featureSet which has the new feature to overwrite.</param>
        /// <param name="output">The output FeatureSet.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input1,int index,IFeatureSet input2, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (input1 == null|| input2 == null || output == null)
            {
                return false;
            }
            if (cancelProgressHandler.Cancel)
                return false;

            IFeature newFeature = input2.Features[0];
            output.FeatureType = input1.FeatureType;
            foreach (IFeature f in input1.Features)
                output.Features.Add(f);

            if (index > -1)
            {
                if (index < output.Features.Count)
                {
                    output.Features.RemoveAt(index);
                    output.Features.Insert(index, newFeature);
                }
            }
            output.SaveAs(output.Filename, true);
            cancelProgressHandler.Progress("", 100, 100 + TextStrings.progresscompleted);
            return true;

        }
コード例 #43
0
        /// <summary>
        /// Finds the average slope in the given polygons.
        /// </summary>
        /// <param name="ras">The dem Raster(Grid file).</param>
        /// <param name="zFactor">The scaler factor</param>
        /// <param name="poly">The flow poly shapefile path.</param>
        /// <param name="output">The resulting DEM of slopes</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        public bool Execute(
            IRaster ras,
            double zFactor,
            IFeatureSet poly,
            IFeatureSet output,
            ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (ras == null || poly == null || output == null)
            {
                return false;
            }

            output.FeatureType = poly.FeatureType;
            foreach (IFeature f in poly.Features)
            {
                output.Features.Add(f);
            }

            output.DataTable.Columns.Add("FID", typeof(int));
            output.DataTable.Columns.Add(TextStrings.AveSlope, typeof(Double));

            IRaster slopeGrid = new Raster { DataType = ras.DataType, Bounds = ras.Bounds };

            // FeatureSet polyShape = new FeatureSet();
            int previous = 0;

            if (Slope(ref ras, zFactor, false, ref slopeGrid, cancelProgressHandler) == false)
            {
                return false;
            }

            int shapeCount = output.Features.Count;
            int[] areaCount = new int[shapeCount];
            double[] areaTotal = new double[shapeCount];
            double[] areaAve = new double[shapeCount];
            double dxHalf = slopeGrid.CellWidth / 2;
            double dyHalf = slopeGrid.CellHeight / 2;

            // check whether those two envelope are intersect
            if (ras.Extent.Intersects(output.Extent) == false)
            {
                return false;
            }

            RcIndex start = slopeGrid.ProjToCell(output.Extent.MinX, output.Extent.MaxY);
            RcIndex stop = slopeGrid.ProjToCell(output.Extent.MaxX, output.Extent.MinY);

            int rowStart = start.Row;
            int colStart = start.Column;
            int rowStop = stop.Row;
            int colStop = stop.Column;
            for (int row = rowStart - 1; row < rowStop + 1; row++)
            {
                int current = Convert.ToInt32((row - rowStart + 1) * 100.0 / (rowStop + 1 - rowStart + 1));

                // only update when increment in percentage
                if (current > previous + 5)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                    previous = current;
                }

                for (int col = colStart - 1; col < colStop + 1; col++)
                {
                    Coordinate cent = slopeGrid.CellToProj(row, col);
                    double xCent = cent.X;
                    double yCent = cent.Y;
                    for (int shpindx = 0; shpindx < output.Features.Count; shpindx++)
                    {
                        IFeature tempFeat = output.Features[shpindx];
                        Point pt1 = new Point(xCent, yCent);
                        Point pt2 = new Point(xCent - dxHalf, yCent - dyHalf);
                        Point pt3 = new Point(xCent + dxHalf, yCent - dyHalf);
                        Point pt4 = new Point(xCent + dxHalf, yCent + dyHalf);
                        Point pt5 = new Point(xCent - dxHalf, yCent + dyHalf);
                        if ((((!tempFeat.Covers(pt1) && !tempFeat.Covers(pt2)) && !tempFeat.Covers(pt3))
                             && !tempFeat.Covers(pt4)) && !tempFeat.Covers(pt5))
                        {
                            continue;
                        }

                        areaCount[shpindx]++;
                        areaTotal[shpindx] += slopeGrid.Value[row, col] / 100;

                        if (cancelProgressHandler.Cancel)
                        {
                            return false;
                        }
                    }
                }
            }

            for (int shpindx = 0; shpindx < output.Features.Count; shpindx++)
            {
                if (areaCount[shpindx] == 0)
                {
                    areaAve[shpindx] = 0;
                }
                else
                {
                    areaAve[shpindx] = areaTotal[shpindx] / areaCount[shpindx];
                }

                output.Features[shpindx].DataRow["FID"] = shpindx;
                output.Features[shpindx].DataRow[TextStrings.AveSlope] = areaAve[shpindx];
            }

            poly.Close();
            slopeGrid.Close();
            output.SaveAs(output.Filename, true);
            return true;
        }
コード例 #44
0
ファイル: AddFeature.cs プロジェクト: DIVEROVIEDO/DotSpatial
        /// <summary>
        /// Executes the add features Opaeration tool programaticaly.
        /// Ping deleted "static" for external Testing
        /// </summary>
        /// <param name="input1">The input FeatureSet.</param>
        /// <param name="input2">The input2 featureSet which has the new features to add.</param>
        /// <param name="output">The output FeatureSet.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns></returns>
        public bool Execute(
            IFeatureSet input1, IFeatureSet input2, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input1 == null || input2 == null || output == null)
            {
                return false;
            }

            int previous = 0;
            int i = 0;
            int maxFeature = input2.Features.Count;
            output.FeatureType = input1.FeatureType;
            foreach (IFeature f1 in input1.Features)
            {
                output.Features.Add(f1);
            }

            // go through new featureset that wanted to add.
            foreach (IFeature f in input2.Features)
            {
                if (cancelProgressHandler.Cancel)
                {
                    return false;
                }

                if (input1.FeatureType == input2.FeatureType)
                {
                    output.Features.Add(f);
                }

                int current = Convert.ToInt32(Math.Round(i * 100D / maxFeature));

                // only update when increment in percentage
                if (current > previous)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                }

                previous = current;
                i++;
            }

            output.SaveAs(output.Filename, true);

            // cancelProgressHandler.Progress("", 100, 100.ToString() + TextStrings.progresscompleted);
            return true;
        }
コード例 #45
0
        /// <summary>
        /// Finds the average slope in the given polygons with more user preferences.
        /// </summary>
        /// <param name="ras">The dem Raster(Grid file).</param>
        /// <param name="inZFactor">The scaler factor</param>
        /// <param name="slopeInPercent">The slope in percentage.</param>
        /// <param name="poly">The flow poly shapefile path.</param>
        /// <param name="fldInPolyToStoreSlope">The field name to store average slope in the attribute.</param>
        /// <param name="outerShpFile">The Featureset where we have the area of interest</param>
        /// <param name="outerShpIndex">The index of featureset which give paticular area of interest.</param>
        /// <param name="output">The path to save created slope Feature set.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns></returns>
        public bool Execute(
            IRaster ras,
            double inZFactor,
            bool slopeInPercent,
            IFeatureSet poly,
            string fldInPolyToStoreSlope,
            IFeatureSet outerShpFile,
            int outerShpIndex,
            IFeatureSet output,
            ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (ras == null || poly == null || outerShpFile == null || output == null)
            {
                return false;
            }

            if (poly.FeatureType != FeatureType.Polygon || outerShpFile.FeatureType != FeatureType.Polygon)
            {
                return false;
            }

            int previous = 0;
            IRaster slopegrid = new Raster();

            int[] areaCount = new int[poly.Features.Count];
            double[] areaTotal = new double[poly.Features.Count];
            double[] areaAve = new double[poly.Features.Count];

            Slope(ras, inZFactor, slopeInPercent, slopegrid, cancelProgressHandler);
            if (slopegrid == null)
            {
                throw new SystemException(TextStrings.Slopegridfileisnull);
            }

            foreach (IFeature f in poly.Features)
            {
                output.Features.Add(f);
            }

            for (int i = 0; i < slopegrid.NumRows; i++)
            {
                int current = Convert.ToInt32(Math.Round(i * 100D / slopegrid.NumRows));

                // only update when increment in percentage
                if (current > previous + 5)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                    previous = current;
                }

                for (int j = 0; j < slopegrid.NumColumns; j++)
                {
                    Coordinate coordin = slopegrid.CellToProj(i, j);
                    IPoint pt = new Point(coordin);
                    IFeature point = new Feature(pt);
                    if (!outerShpFile.Features[outerShpIndex].Covers(point))
                    {
                        continue; // not found the point inside.
                    }

                    for (int c = 0; c < poly.Features.Count; c++)
                    {
                        if (output.Features[c].Covers(point))
                        {
                            areaCount[c]++;
                            areaTotal[c] += slopegrid.Value[i, j] / 100;
                        }

                        if (cancelProgressHandler.Cancel)
                        {
                            return false;
                        }
                    }
                }
            }

            // Add the column
            output.DataTable.Columns.Add("FID", typeof(int));
            output.DataTable.Columns.Add(fldInPolyToStoreSlope, typeof(Double));
            for (int c = 0; c < output.Features.Count; c++)
            {
                if (areaCount[c] == 0)
                {
                    areaAve[c] = 0.0;
                }
                else
                {
                    areaAve[c] = areaTotal[c] / areaCount[c];
                }

                // Add the field values
                output.Features[c].DataRow["FID"] = c;
                output.Features[c].DataRow[fldInPolyToStoreSlope] = areaAve[c];
            }

            output.SaveAs(output.Filename, true);
            slopegrid.Close();
            ras.Close();
            return true;
        }