Пример #1
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);
        }
Пример #2
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.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);
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// Removes portions of the input polygon shapefile that are within the erase polygons.
        /// </summary>
        /// <param name="inputShapefile">The input polygon shapefile.</param>
        /// <param name="eraseShapefile">The erase polygon shapefile.</param>
        /// <param name="resultShapefile">The resulting shapefile, with portions removed.</param>
        public static void ErasePolygonShapefileWithPolygonShapefile(
            IFeatureSet inputShapefile, IFeatureSet eraseShapefile, IFeatureSet resultShapefile)
        {
            // Validates the input and resultSF data
            if (inputShapefile == null || eraseShapefile == null || resultShapefile == null)
            {
                return;
            }

            resultShapefile.CopyTableSchema(inputShapefile); // Fill the 1st Featureset fields
            IFeatureSet tempSet = inputShapefile.CombinedFields(eraseShapefile);

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

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

            resultShapefile.Save();
            return;
        }
Пример #5
0
        /// <summary>
        /// Returns the portions of the polygons in polySF that lie within polygon as a
        /// new shapefile of polygons: resultPolySF.
        /// </summary>
        /// <param name="polygonFeatureSet">The shapefile of polygons that are to be clipped.</param>
        /// <param name="polygon">The polygon used for clipping.</param>
        /// <param name="resultFeatureSet">The result shapefile for the resulting polygons to be saved (in-memory).</param>
        /// <param name="copyAttributes">True if copying attrs</param>
        /// <returns>False if an error was encountered, true otherwise.</returns>
        public static bool ClipPolygonFeatureSetWithPolygon(
            IFeatureSet polygonFeatureSet, IFeature polygon, IFeatureSet resultFeatureSet, bool copyAttributes)
        {
            if (copyAttributes)
            {
                polygonFeatureSet.FillAttributes();
                resultFeatureSet.CopyTableSchema(polygonFeatureSet);
            }

            if (polygonFeatureSet.Features.Count != 0 && polygon.NumPoints != 0
                && polygonFeatureSet.FeatureType == FeatureType.Polygon)
            {
                int numShapes = polygonFeatureSet.Features.Count;
                for (int i = 0; i <= numShapes - 1; i++)
                {
                    polygonFeatureSet.Features[i].Intersection(polygon, resultFeatureSet, FieldJoinType.LocalOnly);
                }
            }

            return true;
        }
Пример #6
0
        /// <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;
        }
Пример #7
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;
        }
        /// <summary>
        /// Removes portions of the input polygon shapefile that are within the erase polygons.
        /// </summary>
        /// <param name="inputSF">The input polygon shapefile.</param>
        /// <param name="eraseSF">The erase polygon shapefile.</param>
        /// <param name="resultSF">The resulting shapefile, with portions removed.</param>
        /// <returns>False if an error was encountered, true otherwise.</returns>
        public static void ErasePolySFWithPolySF(ref IFeatureSet inputSF, ref IFeatureSet eraseSF, ref IFeatureSet resultSF)
        {
            //Validates the input and resultSF data
            if (inputSF == null || eraseSF == null || resultSF == null)
            {
                return;
            }

            resultSF.CopyTableSchema(inputSF);//Fill the 1st Featureset fields
            IFeatureSet tempSet = inputSF.CombinedFields(eraseSF);
            //go through every feature in 1st featureSet
            for (int i = 0; i < inputSF.Features.Count; i++)
            {

                //go through every feature in 2nd featureSet
                for (int j = 0; j < eraseSF.Features.Count; j++)
                {
                    inputSF.Features[i].Difference(eraseSF.Features[j], tempSet, FieldJoinType.All);

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

            }

            resultSF.Save();
            return;
        }
Пример #9
0
        /// <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);
        }
Пример #10
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;
        }
Пример #11
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;
        }
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (this.cboLayer.Text == "")
            {
                MessageBox.Show("Please select a input layer");
                return;
            }
            if (this.txtSavePath.Text.Trim() == "")
            {
                MessageBox.Show("Please select a save path");
                return;
            }

            if (bufferMethod == "Selected features")
            {
                FeatureSet fs = null;
                fs            = m_CurrentFeaLyr.Selection.ToFeatureSet();
                m_InputFeaSet = fs as IFeatureSet;
            }

            double bufferDistance = 0;

            try
            {
                bufferDistance = Convert.ToDouble(this.txtBufferDis.Text);
            }
            catch
            {
                MessageBox.Show("input a number");
            }

            DotSpatial.Analysis.Buffer.AddBuffer(m_InputFeaSet, bufferDistance, m_OutputFeaSet, cancelProgressHandler);

            //dissolve
            if (ifDissolve == true)
            {
                m_OutputFeaSet.DataTable.Columns.Add("id");
                m_OutputFeaSet = FeatureSetExt.Dissolve(m_OutputFeaSet, m_OutputFeaSet.DataTable.Columns["id"].ColumnName);
                for (int i = 0; i < m_OutputFeaSet.Features.Count; i++)
                {
                    m_OutputFeaSet.Features[i].DataRow["id"] = i.ToString();
                }
            }
            else
            {
                m_OutputFeaSet.CopyTableSchema(m_InputFeaSet.DataTable);
                if (m_OutputFeaSet.Features.Count == m_InputFeaSet.Features.Count)
                {
                    for (int i = 0; i < m_OutputFeaSet.Features.Count; i++)
                    {
                        for (int j = 0; j < m_OutputFeaSet.DataTable.Columns.Count; j++)
                        {
                            m_OutputFeaSet.Features[i].DataRow[j] = m_InputFeaSet.Features[i].DataRow[j];
                        }
                    }
                }
            }
            //保存
            m_OutputFeaSet.Name = System.IO.Path.GetFileNameWithoutExtension(this.txtSavePath.Text);
            m_OutputFeaSet.SaveAs(this.txtSavePath.Text, true);
            m_OutputFeaSet.Projection = MainWindow.m_DotMap.Projection;
            //加载图层
            MainWindow.m_DotMap.Layers.Add(m_OutputFeaSet);
            MessageBox.Show("Successfully");
            this.Close();
        }
Пример #13
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;
            }

            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;
        }