Пример #1
0
        public static void MakeDistanceArray(IFeature InputFeature, int GruopID)
        {
            List <DistanceFeatureClass> DistFeatureList = new List <DistanceFeatureClass>();
            IEnumLayer pEnumLayer = Form1.pMap.Layers;
            ILayer     pLayer;

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


                if (pLayer.Name.Equals(Form1.OperationLayer))
                {
                    IFeatureLayer2 pFeatureLayer = (IFeatureLayer2)pLayer;
                    IFeatureClass  pFeatureClass = pFeatureLayer.FeatureClass;

                    IQueryFilter pQueryFilter = new QueryFilter();
                    pQueryFilter.WhereClause = "SpltGropus = 0";

                    IFeatureCursor pFeatureCursor = pFeatureClass.Search(pQueryFilter, false);

                    IFeature CheckFeature = pFeatureCursor.NextFeature();

                    while (CheckFeature != null)
                    {
                        IProximityOperator pProxOper = (IProximityOperator)CheckFeature.Shape;
                        double             distance  = pProxOper.ReturnDistance(InputFeature.Shape);
                        CheckFeature.set_Value(CheckFeature.Fields.FindField("Distance"), distance);
                        CheckFeature.Store();


                        DistanceFeatureClass DistFeature = new DistanceFeatureClass(distance, CheckFeature);
                        DistFeatureList.Add(DistFeature);



                        CheckFeature = pFeatureCursor.NextFeature();
                    }


                    DistFeatureList = DistFeatureList.OrderBy(a => a.getDistance()).ToList();

                    double formarValue = 0;
                    double addValue    = 0;

                    for (int j = 0; j < DistFeatureList.Count; j++)
                    {
                        //MessageBox.Show("..." + Form1.Group.getCalculatedSplitValue() + "..." + Form1.EqualPartValue, "hi");
                        if (Form1.GroupIDTotalList[GruopID - 1].getCalculatedSplitValue() < Form1.EqualPartValue)
                        {
                            formarValue = Form1.GroupIDTotalList[GruopID - 1].getCalculatedSplitValue();
                            addValue    = Convert.ToDouble(DistFeatureList[j].getFeature().get_Value(DistFeatureList[j].getFeature().Fields.FindField(Form1.OperationAttribute)));

                            DistFeatureList[j].getFeature().set_Value(DistFeatureList[j].getFeature().Fields.FindField("SpltGropus"), GruopID);
                            DistFeatureList[j].getFeature().Store();

                            Form1.GroupIDTotalList[GruopID - 1].setCalculatedSplitValue(formarValue + addValue);
                        }
                        //Form1.Group.setCalculatedSplitValue(DistFeatureList[j].getFeature().get_Value(DistFeatureList[j].getFeature().Fields.FindField("SpltGropus")));
                        //DistFeatureList[j].set_Value(FeatureList[j].Fields.FindField("SpltGropus"), 10);
                        //FeatureList[j].Store();

                        //MessageBox.Show("..." + DistFeatureList[j].getDistance(), "hi");
                    }

                    Form1.RegionFormed = Form1.RegionFormed + 1;
                    //MessageBox.Show("..." + ((Form1.NoOfSplit - 1) == Form1.RegionFormed), "hi");
                    if ((Form1.NoOfSplit - 1) == Form1.RegionFormed)
                    {
                        IGeoFeatureLayer pGeoFetLayer = (IGeoFeatureLayer)pLayer;
                        Symbology.DefineUniqueValueRenderer(pGeoFetLayer, "SpltGropus");
                    }

                    //Creating convexhull of the generated region ??? if does not work you have to make the concave hull??
                    IQueryFilter RegionQueryFilter = new QueryFilter();
                    RegionQueryFilter.WhereClause = "SpltGropus = " + GruopID;
                    IFeatureCursor RegionFeatureCursor = pFeatureClass.Search(RegionQueryFilter, false);

                    Form1.RegionGeomtry = StaticMethodsClass.CreateConvexHull(RegionFeatureCursor);


                    //IFeature dd = pFeatureClass.CreateFeature();
                    //dd.Shape = pPol;
                    //dd.set_Value(dd.Fields.FindField("SpltGropus"), GruopID);
                    //dd.Store();

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

                    //
                    //MessageBox.Show("..." , "hi");
                }
            }
        }
Пример #2
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");
        }