Пример #1
0
        private void btnDestFeatures_Click(object sender, EventArgs e)
        {
            IGxDialog gxDialog    = new GxDialogClass();
            var       gxFilterCol = (IGxObjectFilterCollection)gxDialog;

            gxFilterCol.AddFilter(new GxFilterPolygonFeatureClasses(), false);
            gxDialog.AllowMultiSelect = false;
            gxDialog.Title            = " 添加目标要素类";

            IEnumGxObject gxSelection = null;

            gxDialog.DoModalOpen(ArcMap.Application.hWnd, out gxSelection);
            var gxObject = gxSelection.Next();

            if (gxObject != null)
            {
                string features_path            = gxObject.Parent.FullName;
                string features_name            = gxObject.Name;
                string features_parent_path     = System.IO.Path.GetDirectoryName(features_path);
                string features_parent_path_ext = System.IO.Path.GetExtension(features_parent_path);
                if (features_parent_path_ext == ".gdb" || features_parent_path_ext == ".mdb")
                {
                    features_path = features_parent_path;
                }

                cmbDestFeatures.Text = "";
                cmbDestFeatures.Items.Clear();

                DataManagementTools dataManagementTools = new DataManagementTools();
                DestFeatureClass = dataManagementTools.OpenFeatureClass(features_path, features_name);

                if (DestFeatureClass == null)
                {
                    cmbDestFeatures.Text = "";
                    return;
                }

                cmbDestFeatures.Text = gxObject.FullName;

                var table = (ITable)DestFeatureClass;
                for (int i = 0; i < table.Fields.FieldCount; i++)
                {
                    var field = table.Fields.Field[i];
                    if (field.Type != esriFieldType.esriFieldTypeDate)
                    {
                        cmbDestField.Items.Add(field.Name); // 添加Feature UID字段的控件选择
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 创建同位流模式分析结果要素
        /// </summary>
        /// <param name="originFeatureClass">输出的矢量要素</param>
        /// <param name="originUIDField">区分要素的唯一字段名</param>
        /// <param name="patternTable">同位流模式表</param>
        /// <param name="out_path">输出要素的路径</param>
        /// <param name="out_name">输出要素的名称</param>
        /// <param name="outObjectClass">输出区域要素类</param>
        /// <param name="outFlowClass">输出流线要素类</param>
        public void CreatePatternFeatures(IFeatureClass originFeatureClass,
                                          string originUIDField,
                                          IFeatureClass destFeatureClass,
                                          string destUIDField,
                                          DataTable patternTable,
                                          string out_path,
                                          string out_name,
                                          ref IFeatureClass outObjectClass,
                                          ref IFeatureClass outFlowClass,
                                          ref string message)
        {
            string parent_path         = System.IO.Path.GetDirectoryName(out_path);
            string featuredataset_name = "";
            string extension           = System.IO.Path.GetExtension(parent_path);

            if (extension == ".gdb" || extension == ".mdb")
            {
                featuredataset_name = System.IO.Path.GetFileName(out_path);
                out_path            = parent_path;
            }

            var    originSpatialRef = ((IGeoDataset)originFeatureClass).SpatialReference;
            var    destSpatialRef   = ((IGeoDataset)destFeatureClass).SpatialReference;
            IClone comparison       = originSpatialRef as IClone;

            if (!comparison.IsEqual((IClone)destSpatialRef))
            {
                message = "Different Spatial Reference in Origin and Destination FeatureClass.";
                return;
            }

            // 获取 UID字段-要素 字典
            var originPolygonDict = GetUIDPolygonDict(originFeatureClass, originUIDField);
            Dictionary <string, IPolygon> destPolygonDict = null;

            if (originFeatureClass == destFeatureClass)
            {
                destPolygonDict = originPolygonDict;
            }
            else
            {
                destPolygonDict = GetUIDPolygonDict(destFeatureClass, destUIDField);
            }


            // 字段的最大长度
            int d_length   = patternTable.AsEnumerable().Max(r => ((string)r["Dests"]).Length);
            int o_length   = patternTable.AsEnumerable().Max(r => ((string)r["Origins"]).Length);
            int max_length = d_length;

            if (o_length > d_length)
            {
                max_length = o_length;
            }

            var dataMangementTools = new DataManagementTools();

            // 合并后的区域要素
            outObjectClass = dataMangementTools.CreateFeatureClass(
                out_path, out_name + "_OBJ", featuredataset_name, originFeatureClass.ShapeType, originSpatialRef);
            // 同位流要素
            outFlowClass = dataMangementTools.CreateFeatureClass(
                out_path, out_name + "_FLOW", featuredataset_name, esriGeometryType.esriGeometryPolyline, originSpatialRef);

            // 复制合并前要素的字段
            var pID         = dataMangementTools.AddField((ITable)outObjectClass, "PID", esriFieldType.esriFieldTypeSmallInteger, true);
            var pType       = dataMangementTools.AddField((ITable)outObjectClass, "PTYPE", esriFieldType.esriFieldTypeString, true);
            var pGUID       = dataMangementTools.AddField((ITable)outObjectClass, "PGUID", esriFieldType.esriFieldTypeString, true, max_length);
            var pGCount     = dataMangementTools.AddField((ITable)outObjectClass, "PGCOUNT", esriFieldType.esriFieldTypeString, true, max_length);
            int pID_idx     = outObjectClass.FindField(pID);
            int pType_idx   = outObjectClass.FindField(pType);
            int pZUID_idx   = outObjectClass.FindField(pGUID);
            int pZCount_idx = outObjectClass.FindField(pGCount);

            // 复制同位流字段
            var flowFieldDict = dataMangementTools.CopyFields(patternTable, (ITable)outFlowClass, max_length);

            IFeatureBuffer outObjectBuffer = null;
            IFeatureCursor outObjectCursor = outObjectClass.Insert(true);

            IFeatureBuffer outFlowBuffer = null;
            IFeatureCursor outFlowCursor = outFlowClass.Insert(true);

            AddStepProgressor(patternTable.Rows.Count, "Creating spatiotemporal self-co-location flow features . . . ");
            for (int i = 0; i < patternTable.Rows.Count; i++)
            {
                if (!ContinueStepProgressor(new object[] { outObjectCursor, outFlowCursor }))
                {
                    return;
                }

                var dataRow = patternTable.Rows[i];
                var rowPID  = (int)dataRow["PID"];

                string[] originStrArr  = ((string)dataRow["Origins"]).Split(';');
                IPolygon originPolygon = DissolvePolygon(originSpatialRef, originPolygonDict, originStrArr);
                outObjectBuffer                    = outObjectClass.CreateFeatureBuffer();
                outObjectBuffer.Shape              = originPolygon;
                outObjectBuffer.Value[pID_idx]     = rowPID;
                outObjectBuffer.Value[pType_idx]   = "Origin";
                outObjectBuffer.Value[pZUID_idx]   = string.Join(";", originStrArr);
                outObjectBuffer.Value[pZCount_idx] = originStrArr.Length;
                outObjectCursor.InsertFeature(outObjectBuffer);

                IPoint originPoint = ((IArea)originPolygon).Centroid;

                string[] destStrArr  = ((string)dataRow["Dests"]).Split(';');
                IPolygon destPolygon = DissolvePolygon(destSpatialRef, destPolygonDict, destStrArr);
                outObjectBuffer                    = outObjectClass.CreateFeatureBuffer();
                outObjectBuffer.Shape              = destPolygon;
                outObjectBuffer.Value[pID_idx]     = rowPID;
                outObjectBuffer.Value[pType_idx]   = "Destination";
                outObjectBuffer.Value[pZUID_idx]   = string.Join(";", destStrArr);
                outObjectBuffer.Value[pZCount_idx] = destStrArr.Length;
                outObjectCursor.InsertFeature(outObjectBuffer);

                IPoint destPoint = ((IArea)destPolygon).Centroid;

                // 创建同位流要素
                outFlowBuffer       = outFlowClass.CreateFeatureBuffer();
                outFlowBuffer.Shape = CreateCirculeArc(originPoint, destPoint, 0.3);

                foreach (var item in flowFieldDict)
                {
                    outFlowBuffer.Value[item.Value] = dataRow[item.Key];
                }

                outFlowCursor.InsertFeature(outFlowBuffer);
            } // for (int i = 0; i < patternTable.Rows.Count; i++)
            outObjectCursor.Flush();
            outFlowCursor.Flush();

            Marshal.ReleaseComObject(outObjectCursor);
            Marshal.ReleaseComObject(outFlowCursor);
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Пример #3
0
        private void btnFlowTable_Click(object sender, EventArgs e)
        {
            IGxDialog gxDialog    = new GxDialogClass();
            var       gxFilterCol = (IGxObjectFilterCollection)gxDialog;

            gxFilterCol.AddFilter(new GxFilterTablesClass(), true);
            gxFilterCol.AddFilter(new GxFilterPolylineFeatureClasses(), false);
            gxDialog.AllowMultiSelect = false;
            gxDialog.Title            = " 添加表";

            IEnumGxObject gxSelection = null;

            gxDialog.DoModalOpen(ArcMap.Application.hWnd, out gxSelection);
            var gxObject = gxSelection.Next();

            if (gxObject != null)
            {
                cmbFlowOrigin.Text = "";
                cmbFlowOrigin.Items.Clear();
                cmbFlowOriginTime.Text = "";
                cmbFlowOriginTime.Items.Clear();

                cmbFlowDest.Text = "";
                cmbFlowDest.Items.Clear();
                cmbFlowDestTime.Text = "";
                cmbFlowDestTime.Items.Clear();

                cmbFlowValue.Text = "";
                cmbFlowValue.Items.Clear();

                DataManagementTools dataManagementTools = new DataManagementTools();

                string table_path = gxObject.Parent.FullName;
                string table_name = gxObject.Name;
                FlowTable = dataManagementTools.OpenTable(table_path, table_name);

                if (FlowTable == null)
                {
                    cmbFlowTable.Text = "";
                    txtOutPath.Text   = "";
                    txtOutName.Text   = "";
                    return;
                }

                txtOutPath.Text = table_path;
                txtOutName.Text = table_name + "_SCLF";

                cmbFlowTable.Text = gxObject.FullName;

                for (int i = 0; i < FlowTable.Fields.FieldCount; i++)
                {
                    var field = FlowTable.Fields.Field[i];

                    cmbFlowOrigin.Items.Add(field.Name);
                    cmbFlowDest.Items.Add(field.Name);

                    if (field.Type == esriFieldType.esriFieldTypeDouble ||     // double
                        field.Type == esriFieldType.esriFieldTypeInteger ||    // long int
                        field.Type == esriFieldType.esriFieldTypeSingle ||     // float
                        field.Type == esriFieldType.esriFieldTypeSmallInteger) // short int
                    {
                        cmbFlowValue.Items.Add(field.Name);
                    }

                    if (field.Type == esriFieldType.esriFieldTypeDate)
                    {
                        cmbFlowOriginTime.Items.Add(field.Name);
                        cmbFlowDestTime.Items.Add(field.Name);
                    }
                }
            }
        }