/// <summary>
        /// 3.根据级别提取到不同要素类(m_MiddleWorkspace)
        /// 进行初步合并,合并距离由区域道路宽度确定
        /// </summary>
        private void ExtractAggregate(double[] gradeNodes, double distThreld)
        {
            //1.Select the feature in the interval, lik score in [low,high)
            SelectLayerByAttribute selectbyattriTool = new SelectLayerByAttribute();
            selectbyattriTool.in_layer_or_view = m_FeaLyr;
            selectbyattriTool.selection_type = "NEW_SELECTION";

            //2.Aggregating for the selected features and save it in aggregation folder
            AggregatePolygons aggregateTool = new AggregatePolygons();
            aggregateTool.in_features = m_FeaLyr;
            aggregateTool.aggregation_distance = distThreld;
            aggregateTool.orthogonality_option = "ORTHOGONAL";

            try
            {
                for (int i = 0; i < gradeNodes.Length - 1; i++)
                {
                    m_GPProcess.Clear();

                    double scorenode_low = gradeNodes[i];
                    double scorenode_high = gradeNodes[i + 1];
                    string clause = "";
                    if (i == gradeNodes.Length - 2)
                        clause = m_PartitionField + " >= " + scorenode_low.ToString() + " AND " + m_PartitionField + " <= " + scorenode_high.ToString();
                    else
                        clause = m_PartitionField + " >= " + scorenode_low.ToString() + " AND " + m_PartitionField + " < " + scorenode_high.ToString();
                    selectbyattriTool.where_clause = clause;

                    string outname = "aggregation" + i.ToString();
                    aggregateTool.out_feature_class = outname;

                    if (PhaseExcutedEvent != null)
                        PhaseExcutedEvent(this, "Process on grade " + Convert.ToString(i + 1));

                    m_GP.Execute(selectbyattriTool, null);
                    m_GP.Execute(aggregateTool, null);

                    IFeatureClass feacls_agg = m_GP.Open(aggregateTool.out_feature_class) as IFeatureClass;
                    setFeatureClassFieldValue(feacls_agg, "Grade", i + 1);

                }
            }
            catch (System.Exception ex)
            {

            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 多边形合并二
        /// </summary>
        /// <param name="dirpath"></param>
        /// <param name="filename"></param>
        /// <param name="socreInterval"></param>
        /// <param name="distance"></param>
        public void AggreationProcessing2(string dirpath, string filename, string filed, int[] socreInterval, int distance)
        {
            //1.Make a layer form the origin featureclass ;
            MakeFeatureLayer makefeaturelayer = new MakeFeatureLayer();
            makefeaturelayer.in_features = m_Dirpath + m_Filename + ".shp";
            makefeaturelayer.out_layer = "origin_lyr";
            m_GP.Execute(makefeaturelayer, null);

            #region Dissovle and Aggregation
            for (int i = 0; i < socreInterval.Length - 1; i++)
            {
                //2.Select the feature in the interval, lik score in [low,high)
                SelectLayerByAttribute selectbyattri = new SelectLayerByAttribute();
                selectbyattri.in_layer_or_view = "origin_lyr";
                int scorenode_low = socreInterval[i];
                int scorenode_high = socreInterval[i + 1];
                selectbyattri.selection_type = "NEW_SELECTION";
                string clause = "";
                if (i == socreInterval.Length - 2)
                    clause = filed + " >= " + scorenode_low.ToString() + " AND " + filed + " <= " + scorenode_high.ToString();
                else
                    clause = filed + " >= " + scorenode_low.ToString() + " AND " + filed + " < " + scorenode_high.ToString();
                selectbyattri.where_clause = clause;
                m_GP.Execute(selectbyattri, null);

                //3.Dissolve first
                m_GP.SetEnvironmentValue("workspace", m_OutputTemp_Dissolve);
                string dissolepath = "dissolve" + i.ToString();
                Dissolve dissolvetool = new Dissolve();
                dissolvetool.in_features = "origin_lyr";
                dissolvetool.out_feature_class = dissolepath;
                dissolvetool.multi_part = "SINGLE_PART";
                m_GP.Execute(dissolvetool, null);
                    //set Id value
                IFeatureClass feacls_dissolve = m_GP.Open(dissolvetool.out_feature_class) as IFeatureClass;
                setFeatureClassFieldValue(feacls_dissolve, "Id",i+1);

                //3. aggregating for the selected features and save it in aggregation folder
                string outname = "aggregation" + i.ToString();
                m_GP.SetEnvironmentValue("workspace", m_OutputTemp_Aggregation);
                AggregatePolygons aggregateTool = new AggregatePolygons();
                aggregateTool.in_features = dissolvetool.out_feature_class;
                aggregateTool.aggregation_distance = distance;
                aggregateTool.out_feature_class = outname;
                m_GP.Execute(aggregateTool, null);
                    //set Id Value
                IFeatureClass feacls_agg = m_GP.Open(aggregateTool.out_feature_class) as IFeatureClass;
                setFeatureClassFieldValue(feacls_agg, "Id", i + 1);

            }
            #endregion

            #region Append all layers
            // 4. Compositing all the shapfiles into one file
            //    Use Append tool

            appendFeatureClasses(m_OutputTemp_Dissolve, "result_dissolve");

            appendFeatureClasses(m_OutputTemp_Aggregation, "result_aggregation");
            #endregion
        }
Ejemplo n.º 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (pMap.SelectionCount > 1)
            {
                MessageBox.Show("Please select only one feature (starting point)", "Selection error...");
                return;
            }

            OperationLayer     = comboBox2.Text;
            OperationAttribute = comboBox3.Text;
            Tolerance          = Convert.ToDouble(textBox2.Text);
            NoOfSplit          = Convert.ToInt16(textBox1.Text);


            IEnumLayer pEnumLayer = pMap.Layers;

            ILayer pLayer;


            for (int i = 0; i < pMap.LayerCount; i++)
            {
                pLayer = pEnumLayer.Next();

                if (pLayer.Name.Equals(OperationLayer))
                {
                    IDataset pDataSet = (IDataset)(pLayer);

                    Geoprocessor GP = new Geoprocessor();
                    GP.OverwriteOutput = true;

                    AddField SplitGroup = new AddField();
                    SplitGroup.in_table = pDataSet.Workspace.PathName + System.IO.Path.DirectorySeparatorChar + pDataSet.Name + ".shp";
                    //........
                    workSpacePath = pDataSet.Workspace.PathName;

                    //........
                    SplitGroup.field_name = "SpltGropus";
                    SplitGroup.field_type = "SHORT";

                    GP.Execute(SplitGroup, null);

                    CalculateField CalculateField = new CalculateField();
                    CalculateField.in_table   = pDataSet.Workspace.PathName + System.IO.Path.DirectorySeparatorChar + pDataSet.Name + ".shp";
                    CalculateField.field      = "SpltGropus";
                    CalculateField.expression = "0";
                    GP.Execute(CalculateField, null);


                    AddField TempGroup = new AddField();
                    TempGroup.in_table   = pDataSet.Workspace.PathName + System.IO.Path.DirectorySeparatorChar + pDataSet.Name + ".shp";
                    TempGroup.field_name = "Distance";
                    TempGroup.field_type = "DOUBLE";
                    GP.Execute(TempGroup, null);

                    AggregatePolygons ConcaveHull = new AggregatePolygons();
                    ConcaveHull.aggregation_distance = Tolerance;
                    ConcaveHull.in_features          = pDataSet.Workspace.PathName + System.IO.Path.DirectorySeparatorChar + pDataSet.Name + ".shp";
                    ConcaveHull.out_feature_class    = System.IO.Path.GetTempPath() + System.IO.Path.DirectorySeparatorChar + "Temp_ConcaveHull.shp";

                    GP.AddOutputsToMap = false;

                    GP.Execute(ConcaveHull, null);

                    //IFeatureLayer2 pFeatureLayer21 = (IFeatureLayer2)pLayer;
                    //IFeatureClass pFeatureClass1 = pFeatureLayer21.FeatureClass;

                    //IField spltgrp = new FieldClass();
                    //IFieldEdit spltgrp1 = (IFieldEdit)spltgrp;
                    //spltgrp1.Name_2 = "SpltGropus";
                    //spltgrp1.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                    //spltgrp = spltgrp1;

                    //IField tmpgrp = new FieldClass();
                    //IFieldEdit tmpgrp1 = (IFieldEdit)tmpgrp;
                    //tmpgrp1.Name_2 = "TempGroups";
                    //tmpgrp1.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                    //tmpgrp = tmpgrp1;

                    //pFeatureClass1.AddField(spltgrp);
                    //pFeatureClass1.AddField(tmpgrp);

                    IFeatureLayer     pFeatureLayer     = (IFeatureLayer)pLayer;
                    IFeatureSelection pFeatureSelection = (IFeatureSelection)pFeatureLayer;
                    ISelectionSet     pSelectionSet     = pFeatureSelection.SelectionSet;

                    ICursor pCursor;
                    pSelectionSet.Search(null, false, out pCursor);
                    IFeatureCursor pFeatureCursor = (IFeatureCursor)pCursor;

                    IFeature pFeature = pFeatureCursor.NextFeature();

                    GroupIDTotal Group = new GroupIDTotal();
                    Group.setID(1);
                    Group.setCalculatedSplitValue(Convert.ToDouble(pFeature.get_Value(pFeature.Fields.FindField(OperationAttribute))));

                    pFeature.set_Value(pFeature.Fields.FindField("SpltGropus"), 1);
                    pFeature.Store();

                    GroupIDTotalList.Add(Group);

                    //Group = new GroupIDTotal (1,(double)pFeature.get_Value(pFeature.Fields.FindField(OperationAttribute)));


                    IFeatureLayer2 pFeatureLayer2 = (IFeatureLayer2)pLayer;
                    IFeatureClass  pFeatureClass  = pFeatureLayer2.FeatureClass;
                    IQueryFilter   pQueryFilter   = new QueryFilter();
                    pQueryFilter.WhereClause = null;

                    IFeatureCursor pFeatureCursor1 = pFeatureClass.Search(pQueryFilter, false);
                    IFeature       pFeature1;

                    for (int j = 0; j < pFeatureClass.FeatureCount(pQueryFilter); j++)
                    {
                        pFeature1  = pFeatureCursor1.NextFeature();
                        FieldTotal = FieldTotal + Convert.ToDouble(pFeature1.get_Value(pFeature1.Fields.FindField(OperationAttribute)));
                    }

                    EqualPartValue = FieldTotal / Convert.ToInt16(textBox1.Text);

                    F2FDistance.MakeDistanceArray(pFeature, GroupIDTotalList[0].getID());

                    int k = 2;
                    while ((NoOfSplit - 1) != RegionFormed)
                    {
                        IFeature NextStartingFeature = StaticMethodsClass.FindNextStartingFeature(RegionGeomtry);

                        //MessageBox.Show("..." + NextStartingFeature.OID, "hi");
                        GroupIDTotal NextGroup = new GroupIDTotal();
                        NextGroup.setID((short)k);
                        NextGroup.setCalculatedSplitValue(Convert.ToDouble(NextStartingFeature.get_Value(NextStartingFeature.Fields.FindField(OperationAttribute))));

                        NextStartingFeature.set_Value(NextStartingFeature.Fields.FindField("SpltGropus"), k);
                        NextStartingFeature.Store();

                        GroupIDTotalList.Add(NextGroup);

                        F2FDistance.MakeDistanceArray(NextStartingFeature, GroupIDTotalList[k - 1].getID());

                        k = k + 1;
                    }


                    //
                    //IGeometry pPol = CreateConvexHull.Create(pFeatureCursor1);
                    //IFeature dd = pFeatureClass.CreateFeature();
                    //dd.Shape = pPol;

                    //dd.Store();

                    //IActiveView activeView = pMap as IActiveView;
                    //activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                    //MessageBox.Show("...", "hi");

                    //
                }
            }


            MessageBox.Show("..." + FieldTotal + "..." + EqualPartValue, "hi");
            //MessageBox.Show("..." + pFeature1.OID, "hi");
        }
Ejemplo n.º 4
0
        private IFeatureClass aggregateOnfeaturclass(IFeatureClass feacls, int distance)
        {
            //seems only the tool can be used
            //the tool output is the file in disk(a string of file path)
            m_GP.SetEnvironmentValue("workspace", m_OutputTemp_Aggregation);
            AggregatePolygons aggrePolygons = new AggregatePolygons();
            aggrePolygons.aggregation_distance = distance;
            aggrePolygons.in_features = feacls;
            aggrePolygons.out_feature_class = feacls.AliasName;
            m_GP.Execute(aggrePolygons, null);
            object obj = aggrePolygons.out_feature_class;

            MakeFeatureLayer makefealyr = new MakeFeatureLayer();
            makefealyr.in_features = aggrePolygons.out_feature_class;
            makefealyr.out_layer = feacls.AliasName;
            m_GP.Execute(makefealyr, null);
            IFeatureLayer pfealyr = makefealyr.out_layer as IFeatureLayer;
            return pfealyr.FeatureClass;
        }
        /// <summary>
        /// 3.根据级别提取到不同要素类(m_MiddleWorkspace)
        /// 进行初步合并,合并距离由区域道路宽度确定
        /// </summary>
        private void ExtractAggregate(double[] gradeNodes, double distThreld)
        {
            MakeFeatureLayer makefeaturelayer = new MakeFeatureLayer();
            makefeaturelayer.in_features = m_FeaCls;
            makefeaturelayer.out_layer = "origin_lyr";
            m_GP.Execute(makefeaturelayer, null);

            //1.Select the feature in the interval, lik score in [low,high)
            SelectLayerByAttribute selectbyattriTool = new SelectLayerByAttribute();
            selectbyattriTool.in_layer_or_view = "origin_lyr";
            selectbyattriTool.selection_type = "NEW_SELECTION";

            //2.Aggregating for the selected features and save it in aggregation folder
            AggregatePolygons aggregateTool = new AggregatePolygons();
            aggregateTool.in_features = "origin_lyr";
            aggregateTool.aggregation_distance = distThreld;
            aggregateTool.orthogonality_option = "ORTHOGONAL";

            try
            {
                for (int i = 0; i < gradeNodes.Length - 1; i++)
                {
                    double scorenode_low = gradeNodes[i];
                    double scorenode_high = gradeNodes[i + 1];
                    string clause = "";
                    if (i == gradeNodes.Length - 2)
                        clause = m_PartitionField + " >= " + scorenode_low.ToString() + " AND " + m_PartitionField + " <= " + scorenode_high.ToString();
                    else
                        clause = m_PartitionField + " >= " + scorenode_low.ToString() + " AND " + m_PartitionField + " < " + scorenode_high.ToString();
                    selectbyattriTool.where_clause = clause;

                    string outname = "aggregation" + i.ToString();
                    aggregateTool.out_feature_class = outname;

                    m_GP.Execute(selectbyattriTool, null);
                    m_GP.Execute(aggregateTool, null);

                    IFeatureClass feacls_agg = m_GP.Open(aggregateTool.out_feature_class) as IFeatureClass;
                    setFeatureClassFieldValue(feacls_agg, "Grade", i + 1);

                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("Exception in ExtractAggregate!");
            }
        }