/// <summary>
 /// 根据障碍点和经过点求解最短路径
 /// </summary>
 /// <param name="mapControl"></param>
 /// <param name="featureLayer"></param>
 /// <param name="dbPath"></param>
 /// <param name="featureSetName"></param>
 /// <param name="ndsName"></param>
 /// <param name="stopPoints"></param>
 /// <param name="barryPoints"></param>
 /// <param name="routeLayer"></param>
 /// <returns></returns>
 public bool QueryTheRoue(ESRI.ArcGIS.Controls.AxMapControl mapControl, ESRI.ArcGIS.Carto.IFeatureLayer featureLayer, string dbPath, string featureSetName, string ndsName, List<ESRI.ArcGIS.Geometry.IPoint> stopPoints, List<ESRI.ArcGIS.Geometry.IPoint> barryPoints, ref ILayer routeLayer)
 {
    // List<IPoint>   newStopPoints;
   //  List<IPoint>  newBarryPoints;
 //    UpdatePointsToRouteCore(featureLayer, stopPoints, barryPoints, out newStopPoints, out newBarryPoints);
     //实例化站点和障碍点要素
     IFeatureClass stopFeatureClass =
         FeatureClassUtil.CreateMemorySimpleFeatureClass(esriGeometryType.esriGeometryPoint, mapControl.SpatialReference, "stops");
     IFeatureClass barriesFeatureClass =
         FeatureClassUtil.CreateMemorySimpleFeatureClass(esriGeometryType.esriGeometryPoint, mapControl.SpatialReference, "barries");
     //添加站点
     foreach (var value in stopPoints)
     {
         FeatureClassUtil.InsertSimpleFeature(value, stopFeatureClass);
     }
     //添加障碍
     foreach (var value in barryPoints)
     {
         FeatureClassUtil.InsertSimpleFeature(value, barriesFeatureClass);
     }
     //组装站点和障碍点要素
     IDictionary<string, DecorateRouteFeatureClass> featureClasses = new Dictionary<string, DecorateRouteFeatureClass>();
     featureClasses.Add("Stops", new DecorateRouteFeatureClass(0.2,stopFeatureClass));
     featureClasses.Add("Barriers", new DecorateRouteFeatureClass(0.2,barriesFeatureClass));
     //最短路径分析
     bool result=NormalNetworkUtil.Short_Path(mapControl, dbPath, featureSetName, ndsName, featureClasses, false, false, ref routeLayer);
     //if (result)
    //    {
   //        showRouteShape(routeLayer as IFeatureLayer, mapControl);
   //  }
     return result;
 }
Ejemplo n.º 2
0
        public bool QueryTheRoue(IPoint breakPoint, AxMapControl mapControl, IFeatureLayer featureLayer, string dbPath, string featureSetName, string ndsName, ref IPoint rightPoint)
        {
            IFeature feature  = null;
            double   distance = 0;
            int      distNum  = 0;

            rightPoint = DistanceUtil.GetNearestLineInFeatureLayer(featureLayer, breakPoint, ref feature, ref distance, ref distNum);
            if (rightPoint == null)
            {
                return(false);
            }
            //获取线要素的点集合
            IPointCollection lineCollection = feature.Shape as IPointCollection;
            //实例化站点和障碍点要素
            IFeatureClass stopFeatureClass =
                FeatureClassUtil.CreateMemorySimpleFeatureClass(esriGeometryType.esriGeometryPoint, mapControl.SpatialReference, "stops");
            IFeatureClass barriesFeatureClass =
                FeatureClassUtil.CreateMemorySimpleFeatureClass(esriGeometryType.esriGeometryPoint, mapControl.SpatialReference, "barries");

            //添加站点
            FeatureClassUtil.InsertSimpleFeature(lineCollection.get_Point(0), stopFeatureClass);
            FeatureClassUtil.InsertSimpleFeature(lineCollection.get_Point(lineCollection.PointCount - 1), stopFeatureClass);
            //添加障碍
            FeatureClassUtil.InsertSimpleFeature(rightPoint, barriesFeatureClass);
            //组装站点和障碍点要素
            IDictionary <string, DecorateRouteFeatureClass> featureClasses = new Dictionary <string, DecorateRouteFeatureClass>();

            featureClasses.Add("Stops", new DecorateRouteFeatureClass(0.2, stopFeatureClass));
            featureClasses.Add("Barriers", new DecorateRouteFeatureClass(0.2, barriesFeatureClass));
            ILayer routeLayer = null;

            //最短路径分析
            return(NormalNetworkUtil.Short_Path(mapControl, dbPath, featureSetName, ndsName, featureClasses, false, false, ref routeLayer));
        }
Ejemplo n.º 3
0
        private void Okbutton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(nameTbb.Text))
            {
                MessageBox.Show("请输入字段名称");
                this.nameTbb.Focus();
                return;
            }
            if (string.IsNullOrEmpty(aliasTbb.Text))
            {
                MessageBox.Show("请输入字段别名");
                this.aliasTbb.Focus();
                return;
            }
            if (this.typeComboBox.SelectedIndex < 0)
            {
                MessageBox.Show("请选择数据类型");
                this.typeComboBox.Focus();
                return;
            }
            var type = AtrributeUtil.ConvertToEsriFiled(this.typeComboBox.SelectedItem.ToString());

            if (FeatureClassUtil.AddField(pFeatureClass, nameTbb.Text, aliasTbb.Text, type))
            {
                this.DialogResult = DialogResult.OK;
                CreateDataColumn();
                MessageBox.Show("添加成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败,请检查字段名称是否重复");
            }
        }
Ejemplo n.º 4
0
        public void DoesFeatureClassExist_Test(string subDirectory, string pgdbFilename, string featureclassName)
        {
            string temp = System.IO.Path.Combine(_dataDirectory, subDirectory);
            string pgdb = System.IO.Path.Combine(temp, pgdbFilename);

            IWorkspace workspace = GeodatabaseUtil.GetAccessWorkspace(pgdb);

            Assert.IsTrue(FeatureClassUtil.DoesFeatureClassExist(workspace, featureclassName, true), "Unable to open FeatureClass inside a workspace");
        }
Ejemplo n.º 5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                IDictionary <int, IGeometry> boundGeometrys = this.ucExtentSetting1.BoundGeometrys;
                if (boundGeometrys == null || boundGeometrys.Count <= 0)
                {
                    MessageBox.Show(@"请选择输出数据的范围!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (_layerFieldsList == null || !_layerFieldsList.Any(c => c.Checked))
                {
                    MessageBox.Show(@"请选择要输出的图层!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (string.IsNullOrWhiteSpace(this.ucSelectFile1.FileName))
                {
                    MessageBox.Show(@"请选择要输出数据的存放位置!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                AccessTools tools = new AccessTools(this.ucSelectFile1.FileName);
                foreach (UcLayerFields layerFields in _layerFieldsList)
                {
                    try
                    {
                        if (!layerFields.Checked)
                        {
                            continue;
                        }
                        DataTable dataTable =
                            FeatureClassUtil.FeatureClassToDataTable(layerFields.FeatureLayer.FeatureClass, boundGeometrys, null, layerFields.SelectedFieldDictionary);
                        if (tools.CreateTable(layerFields.SelectedFieldDictionary, layerFields.FeatureLayer.FeatureClass.AliasName))
                        {
                            tools.FillTable(dataTable);
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
                if (!string.IsNullOrEmpty(tools.GetStrErrorInfo()))
                {
                    MessageBox.Show(tools.GetStrErrorInfo());
                }
                else
                {
                    Process.Start(ucSelectFile1.FileName);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Ejemplo n.º 6
0
        public void OpenFeatureClass_Test(string subDirectory, string pgdbFilename, string featureclassName)
        {
            string temp = System.IO.Path.Combine(_dataDirectory, subDirectory);
            string pgdb = System.IO.Path.Combine(temp, pgdbFilename);

            IWorkspace        workspace        = GeodatabaseUtil.GetAccessWorkspace(pgdb);
            IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;

            IFeatureClass featureClass = FeatureClassUtil.OpenFeatureClass(featureWorkspace, featureclassName);

            Assert.IsNotNull(featureClass, "Unable to open Feature class '" + featureclassName + "' in the PGDB '" + pgdbFilename + "'.");
        }
Ejemplo n.º 7
0
        private IFeatureClass CreateFeatureClass(string tableName, esriGeometryType type, List <FieldMapping> fieldMappings)
        {
            IWorkspaceEdit pWorkspaceEdit = _targetWorkspace as IWorkspaceEdit;

            if (pWorkspaceEdit == null)
            {
                return(null);
            }
            if (pWorkspaceEdit.IsBeingEdited())
            {
                pWorkspaceEdit.StopEditOperation();
                pWorkspaceEdit.StopEditing(true);
            }
            IFeatureClass pFeatureClass = WorkspaceHelper.CreateFeatureClass(_targetWorkspace, tableName, type, _spatialReference);

            FeatureClassUtil.AddZ(pFeatureClass);
            FeatureClassUtil.AddM(pFeatureClass);
            foreach (FieldMapping fieldMapping in fieldMappings)
            {
                switch (fieldMapping.Type)
                {
                case esriFieldType.esriFieldTypeInteger:
                    FeatureClassUtil.AddIntField(pFeatureClass, fieldMapping.Name, fieldMapping.Length, null, fieldMapping.AliasName);
                    break;

                case esriFieldType.esriFieldTypeDouble:
                    FeatureClassUtil.AddDoubleField(pFeatureClass, fieldMapping.Name, fieldMapping.Length, fieldMapping.Precision, null, fieldMapping.AliasName);
                    break;

                case esriFieldType.esriFieldTypeString:
                    FeatureClassUtil.AddStringField(pFeatureClass, fieldMapping.Name, fieldMapping.Length, null, fieldMapping.AliasName);
                    break;

                case esriFieldType.esriFieldTypeDate:
                    FeatureClassUtil.AddDateField(pFeatureClass, fieldMapping.Name, fieldMapping.AliasName);
                    break;

                default:
                    break;
                }
                fieldMapping.IndexTargetField = pFeatureClass.FindField(fieldMapping.Name);
            }

            return(pFeatureClass);
        }
Ejemplo n.º 8
0
        public List <ExpandoObject> ConvertToExpandoObjectList(List <FeatureItem> featureItems)
        {
            List <ExpandoObject> list = new List <ExpandoObject>();

            foreach (FeatureItem featureItem in featureItems)
            {
                var expandoObject = new ExpandoObject() as IDictionary <string, System.Object>;
                expandoObject.Add("[编号]", featureItem.OID);
                if (_displayName)
                {
                    expandoObject.Add("[信息]", featureItem.Name);
                }

                IFields fields = featureItem.MainFeature.Fields;
                for (int i = 0; i < fields.FieldCount; i++)
                {
                    IField field       = fields.Field[i];
                    string strGeometry = FeatureClassUtil.GetShapeString(featureItem.MainFeature);
                    if (field.Type == esriFieldType.esriFieldTypeGeometry)
                    {
                        expandoObject.Add(field.AliasName, strGeometry);
                    }
                    else if (field.Type != esriFieldType.esriFieldTypeBlob)
                    {
                        expandoObject.Add(field.AliasName, featureItem.MainFeature.Value[i]);
                    }
                    else
                    {
                        expandoObject.Add(field.AliasName, "二进制数据");
                    }
                }
                if (_displayRemarks)
                {
                    expandoObject.Add("[备注]", featureItem.Remarks);
                }

                list.Add(expandoObject as ExpandoObject);
            }

            return(list);
        }
Ejemplo n.º 9
0
        public List <ExpandoObject> ConvertToExpandoObjectList(List <FeatureItem> featureItems)
        {
            List <ExpandoObject> list = new List <ExpandoObject>();

            foreach (FeatureItem featureItem in featureItems)
            {
                var expandoObject = new ExpandoObject() as IDictionary <string, System.Object>;
                expandoObject.Add("[图层组]", featureItem.PipelineName);
                expandoObject.Add("[图层]", featureItem.PipeLayerName);
                expandoObject.Add("[检查项]", featureItem.CheckItem);
                expandoObject.Add("[检查信息]", featureItem.ErrDesc);

                if (featureItem.MainFeature != null)
                {
                    expandoObject.Add("[编号]", featureItem.OID);
                    IFields fields = featureItem.MainFeature.Fields;
                    for (int i = 0; i < fields.FieldCount; i++)
                    {
                        IField field       = fields.Field[i];
                        string strGeometry = FeatureClassUtil.GetShapeString(featureItem.MainFeature);
                        if (field.Type == esriFieldType.esriFieldTypeGeometry)
                        {
                            expandoObject.Add(field.AliasName, strGeometry);
                        }
                        else if (field.Type != esriFieldType.esriFieldTypeBlob)
                        {
                            expandoObject.Add(field.AliasName, featureItem.MainFeature.Value[i]);
                        }
                        else
                        {
                            expandoObject.Add(field.AliasName, "二进制数据");
                        }
                    }
                }
                list.Add(expandoObject as ExpandoObject);
            }

            return(list);
        }
Ejemplo n.º 10
0
        public void TransferData_Test(string subDirectory, string inputPGDBFile, string inputFeatureClassName)
        {
            string temp = System.IO.Path.Combine(_dataDirectory, subDirectory);
            string pgdb = System.IO.Path.Combine(temp, inputPGDBFile);

            IWorkspace        inWorkspace        = GeodatabaseUtil.GetAccessWorkspace(pgdb);
            IFeatureWorkspace inFeatureWorkspace = (IFeatureWorkspace)inWorkspace;
            IFeatureClass     inFeatureClass     = FeatureClassUtil.OpenFeatureClass(inFeatureWorkspace, inputFeatureClassName);
            IGeoDataset       geoDataset         = (IGeoDataset)inFeatureClass;

            string[] files = Directory.GetFiles(temp, inputFeatureClassName + ".*", SearchOption.TopDirectoryOnly);

            foreach (string item in files)
            {
                File.Delete(item);
            }

            IWorkspace        outWorkspace        = GeodatabaseUtil.GetShapefileWorkspace(temp);
            IFeatureWorkspace outFeatureWorkspace = (IFeatureWorkspace)outWorkspace;
            IWorkspaceName    outWorkspaceName    = GeodatabaseUtil.GetWorkspaceName(outWorkspace);
            IFeatureClassName outFeatureclassName = GeodatabaseUtil.GetFeatureClassName(outWorkspaceName, inputFeatureClassName);

            IEnumInvalidObject invalidObjects = GeodatabaseUtil.TransferData(inFeatureWorkspace, inFeatureClass, outFeatureWorkspace, outFeatureclassName, null, null, geoDataset.SpatialReference);
        }
Ejemplo n.º 11
0
        private void btnReadData_Click(object sender, EventArgs e)
        {
            Reset();
            try
            {
                this.Cursor = Cursors.WaitCursor;
                if (string.IsNullOrEmpty(ucAxfFolder.SelectedPath))
                {
                    return;
                }
                if (ucTargetFeatureClass.SelectFeatureLayer == null)
                {
                    return;
                }

                _axfInfoList = new List <AxfInfo>();
                List <FileInfo> axfFileInfos = FolderHelper.GetFileInfos(this.ucAxfFolder.SelectedPath,
                                                                         new List <string>()
                {
                    ".axf"
                });

                foreach (FileInfo axfFileInfo in axfFileInfos)
                {
                    if (axfFileInfo.Name.StartsWith("BackgroundLayers"))
                    {
                        continue;
                    }

                    if (db.Open(axfFileInfo.FullName))
                    {
                        System.Data.SqlServerCe.SqlCeResultSet pSqlCeResultSet = db.GetTableData("AXF_TABLES", null, SortOrder.None) as System.Data.SqlServerCe.SqlCeResultSet;
                        dataGridView1.DataSource = pSqlCeResultSet;
                        List <AxfTables> pAxfTablesList = AxfTables.GetAxfTablesList(pSqlCeResultSet, dataGridView1);
                        foreach (AxfTables axfTables in pAxfTablesList)
                        {
                            if (axfTables.TableName != this.ucTargetFeatureClass.SelectFeatureLayer.Name)
                            {
                                continue;
                            }
                            pSqlCeResultSet          = db.GetTableData(axfTables.TableName, null, SortOrder.None) as System.Data.SqlServerCe.SqlCeResultSet;
                            dataGridView1.DataSource = pSqlCeResultSet;
                            List <AxfField> pAxfFieldList = AxfField.GetAxfFieldList(pSqlCeResultSet, dataGridView1);
                            AxfInfo         pAxfInfo      = new AxfInfo
                            {
                                AddCount        = pAxfFieldList.Count(c => c.AxfStatus == 1),
                                ModifyCount     = pAxfFieldList.Count(c => c.AxfStatus == 2),
                                DeleteCount     = pAxfFieldList.Count(c => c.AxfStatus == 128),
                                NoEditCount     = pAxfFieldList.Count(c => c.AxfStatus == 0),
                                AxfFieldList    = pAxfFieldList,
                                SourceLayerName = axfTables.TableName
                            };
                            IFeatureClass sourceFeatureClass = FeatureClassUtil.GetFeatureClass(axfFileInfo.FullName, axfTables.TableName);
                            if (sourceFeatureClass == null)
                            {
                                pAxfInfo.IsSelect = false;
                            }
                            else
                            {
                                pAxfInfo.IsSelect = true;
                            }
                            pAxfInfo.SourceFeatureClass = sourceFeatureClass;
                            pAxfInfo.TargetLayerName    = this.ucTargetFeatureClass.SelectFeatureLayer.Name;
                            pAxfInfo.TargetFeatureLayer = this.ucTargetFeatureClass.SelectFeatureLayer;
                            pAxfInfo.AxfFilePath        = axfFileInfo.FullName;

                            _axfInfoList.Add(pAxfInfo);
                        }

                        db.Close();
                    }
                }
                dataGridView2.DataSource = _axfInfoList;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Ejemplo n.º 12
0
 public FrmCode(IFeatureLayer featureLayer, string codeName)
 {
     InitializeComponent();
     _featureLayer = featureLayer;
     Code          = FeatureClassUtil.GetMaxValue(_featureLayer.FeatureClass, codeName);
 }
Ejemplo n.º 13
0
 //删除字段
 private void RemoveColumn(string columnName)
 {
     FeatureClassUtil.DeleteField(layer.FeatureClass, columnName);
     dataTable.Columns.Remove(columnName);
     RefreshFeaturesByFids();
 }
Ejemplo n.º 14
0
        public List <FeatureItem> Check(IFeatureClass featureClass, string pipelineName, string xFieldName, string yFieldName, string zFieldName)
        {
            List <FeatureItem> list = new List <FeatureItem>();
            int xIdx = featureClass.FindField(xFieldName);
            int yIdx = featureClass.FindField(yFieldName);
            int zIdx = featureClass.FindField(zFieldName);

            if (xIdx < 0 || yIdx < 0 || zIdx < 0)
            {
                list.Add(new FeatureItem()
                {
                    PipelineName  = pipelineName,
                    PipeLayerName = featureClass.AliasName,
                    CheckItem     = "坐标信息检查",
                    ErrDesc       = "字段配置错误 字段 " + (xIdx < 0 ? xFieldName + " " : "") + (yIdx < 0 ? yFieldName + " " : "") + (zIdx < 0 ? zFieldName + " " : "") + "不存在",
                });
                return(list);
            }
            bool           hasZ          = FeatureClassUtil.CheckHasZ(featureClass);
            IFeatureCursor featureCursor = featureClass.Search(null, false);
            IFeature       feature;

            while ((feature = featureCursor.NextFeature()) != null)
            {
                if (_worker != null && _worker.CancellationPending)
                {
                    return(list);
                }
                IPoint point = feature.Shape as IPoint;
                if (point == null || point.IsEmpty)
                {
                    list.Add(new FeatureItem(feature)
                    {
                        PipelineName  = pipelineName,
                        PipeLayerName = featureClass.AliasName,
                        CheckItem     = "坐标信息检查",
                        ErrDesc       = "几何图形为空",
                    });
                    continue;
                }

                object xValue = feature.Value[xIdx];
                object yValue = feature.Value[yIdx];
                object zValue = feature.Value[zIdx];
                double x = 0, y = 0, z = 0;
                bool   isX = true, isY = true, isZ = true;
                if (xValue == null || xValue is DBNull || !double.TryParse(xValue.ToString(), out x))
                {
                    isX = false;
                }
                if (yValue == null || yValue is DBNull || !double.TryParse(yValue.ToString(), out y))
                {
                    isY = false;
                }
                if (zValue == null || zValue is DBNull || !double.TryParse(zValue.ToString(), out z))
                {
                    isZ = false;
                }
                if (!isX || !isY || !isZ)
                {
                    list.Add(new FeatureItem(feature)
                    {
                        PipelineName  = pipelineName,
                        PipeLayerName = featureClass.AliasName,
                        CheckItem     = "坐标信息检查",
                        ErrDesc       = "字段 " + (isX ? "" : xFieldName + " ") + (isY ? "" : yFieldName + " ") + (isZ ? "" : zFieldName + " ") + "属性错误或为空",
                    });
                    continue;
                }
                IPoint virtualPoint = new PointClass();
                virtualPoint.PutCoords(x, y);
                string errDesc = "";
                if (GeometryHelper.GetDistance(point, virtualPoint) > _dataCheck.DataCheckConfig.SurfaceTolerance)
                {
                    errDesc += "平面误差超过容差值 ";
                }
                if (hasZ)
                {
                    if (Math.Abs(point.Z - z) > _dataCheck.DataCheckConfig.ElevationTolerance)
                    {
                        errDesc += "高程误差超过容差值";
                    }
                }
                list.Add(new FeatureItem(feature)
                {
                    PipelineName  = pipelineName,
                    PipeLayerName = featureClass.AliasName,
                    CheckItem     = "坐标信息检查",
                    ErrDesc       = errDesc,
                });
            }

            return(list);
        }
Ejemplo n.º 15
0
        public IFeatureClass CreateFeatureClass(IWorkspace workspace, IFeatureDataset featureDataset = null, ISpatialReference spatialReference = null)
        {
            try
            {
                _fieldMappingInts = new Dictionary <int, int>();
                IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;
                if (featureWorkspace == null)
                {
                    return(null);
                }
                IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
                IObjectClassDescription  objectClassDescription  = featureClassDescription as IObjectClassDescription;
                IFields     requiredFields     = objectClassDescription.RequiredFields;
                IFieldsEdit requiredFieldsEdit = requiredFields as IFieldsEdit;
                for (int i = 0; i < requiredFields.FieldCount; i++)
                {
                    if (requiredFieldsEdit.Field[i].Type == esriFieldType.esriFieldTypeGeometry)
                    {
                        IFieldEdit       requiredFieldEdit = requiredFieldsEdit.Field[i] as IFieldEdit;
                        IGeometryDef     geometryDef       = new GeometryDefClass();
                        IGeometryDefEdit geometryDefEdit   = geometryDef as IGeometryDefEdit;
                        geometryDefEdit.GeometryType_2     = _featureLayer.FeatureClass.ShapeType;
                        geometryDefEdit.SpatialReference_2 = spatialReference ?? FeatureClassUtil.GetGeometryDef(_featureLayer.FeatureClass).SpatialReference;
                        requiredFieldEdit.GeometryDef_2    = geometryDefEdit;
                    }
                }
                for (int i = 0; i < _selectedFieldList.Count; i++)
                {
                    IField field = _selectedFieldList[i];
                    if (requiredFieldsEdit.FindField(field.Name) >= 0)
                    {
                        continue;
                    }
                    IField     newField     = new FieldClass();
                    IFieldEdit newFieldEdit = newField as IFieldEdit;
                    newFieldEdit.Name_2         = field.Name;
                    newFieldEdit.AliasName_2    = field.AliasName;
                    newFieldEdit.DefaultValue_2 = field.DefaultValue;
                    newFieldEdit.Domain_2       = field.Domain;
                    newFieldEdit.DomainFixed_2  = field.DomainFixed;
                    newFieldEdit.Editable_2     = field.Editable;
                    newFieldEdit.IsNullable_2   = field.IsNullable;
                    newFieldEdit.Length_2       = field.Length;
                    newFieldEdit.Precision_2    = field.Precision;
                    newFieldEdit.Required_2     = field.Required;
                    newFieldEdit.Scale_2        = field.Scale;
                    newFieldEdit.Type_2         = field.Type;
                    requiredFieldsEdit.AddField(newFieldEdit);
                }

                IFieldChecker   fieldChecker    = new FieldCheckerClass();
                IEnumFieldError enumFieldError  = null;
                IFields         validatedFields = null;
                fieldChecker.ValidateWorkspace = workspace;
                fieldChecker.Validate(requiredFields, out enumFieldError, out validatedFields);
                string        esriName     = ((IDataset)_featureLayer.FeatureClass).Name;
                IFeatureClass featureClass = null;
                if (featureDataset == null)
                {
                    featureClass = featureWorkspace.CreateFeatureClass(esriName, requiredFields, objectClassDescription.InstanceCLSID,
                                                                       objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple,
                                                                       _featureLayer.FeatureClass.ShapeFieldName, "");
                }
                else
                {
                    featureClass = featureDataset.CreateFeatureClass(esriName, requiredFields, objectClassDescription.InstanceCLSID,
                                                                     objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple,
                                                                     _featureLayer.FeatureClass.ShapeFieldName, "");
                }

                foreach (IField field in _selectedFieldList)
                {
                    if (field.Editable)
                    {
                        _fieldMappingInts.Add(featureClass.FindField(field.Name), _featureLayer.FeatureClass.FindField(field.Name));
                    }
                }

                return(featureClass);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
Ejemplo n.º 16
0
        public override Result Execute()
        {
            if (!base.InitComplete)
            {
                throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL_INIT, "初始化工作未完成");
            }
            DMEWorkspaceBridge <IWorkspace, IFeatureClass> dmeWorkspaceBridge = new DMEWorkspaceBridge <IWorkspace, IFeatureClass>();

            dmeWorkspaceBridge.SetWorkspace(new EsriWorkspace());
            // 目前先以ORACLE和MDB为数据源类型
            // 获取source feature class
            this.SourceFeatureClass = dmeWorkspaceBridge.GetFeatureClass(this.sourceFeatureClassDTO);
            // 获取target feature class
            this.TargetFeatureClass = dmeWorkspaceBridge.GetFeatureClass(this.targetFeatureClassDTO);

            if (AnalysisType.COVER == this.AnalysisType)
            {
                OverlayCommonTool.GetTopounionGeometryByQuery(this.SourceFeatureClass, null, null, esriSpatialRelEnum.esriSpatialRelUndefined,
                                                              out IGeometry sourceGeom, out IList <string> oidList);
                //找出touch的要素oid,排除掉touch的图形
                OverlayCommonTool.GetTopounionGeometryByQuery(this.TargetFeatureClass, null, sourceGeom, esriSpatialRelEnum.esriSpatialRelTouches, out IGeometry touchGeom, out IList <string> touchOIDList);
                //通过intersect查找压盖部分的要素
                string queryClause = null;
                if (touchOIDList != null && touchOIDList.Count > 0)
                {
                    queryClause = $"OBJECTID  NOT in ({string.Join(",", ((List<string>)touchOIDList).ToArray())})";
                }
                // 求取空间相交的部分
                OverlayCommonTool.GetIntersectFeaturesByQuery(this.TargetFeatureClass, queryClause, sourceGeom,
                                                              out IList <IntersectFeatureDTO> intersectFeatureDTOs, out double sumIntersectArea);

                if (intersectFeatureDTOs?.Count > 0)
                {
                    OverlayRespDTO overlayRespDTO = new OverlayRespDTO
                    {
                        SumArea = sumIntersectArea
                    };
                    foreach (var item in intersectFeatureDTOs)
                    {
                        FeatureRespDTO intersectFeatureRespDTO = new FeatureRespDTO
                        {
                            OID         = item.OID,
                            Area        = item.Area,
                            Coordinates = item.Coordinates,
                            GeoType     = item.GeoType
                        };
                        overlayRespDTO.Features.Add(intersectFeatureRespDTO);
                    }
                    Property resultProp = base.OutputParametersMeta[nameof(Result)];
                    resultProp.Value = overlayRespDTO;
                    return(new Result(EnumSystemStatusCode.DME_SUCCESS, "运行完成", EnumSystemStatusCode.DME_SUCCESS, null));
                }
            }
            else if (AnalysisType.OVERTOP == this.AnalysisType)
            {
                // 先拷贝一份mdb模板
                string sTemplate = System.AppDomain.CurrentDomain.BaseDirectory + GlobalSystemConfig.PATH_TEMPLATE_PGDB;// @"\template\pgdb.mdb";
                string sPath     = System.AppDomain.CurrentDomain.BaseDirectory + GlobalSystemConfig.DIR_TEMP + "/" + GuidUtil.NewGuid() + ".mdb";
                File.Copy(sTemplate, sPath);
                IWorkspace mdbWorkspace = WorkspaceUtil.OpenMdbWorspace(sPath);
                if (FeatureClassUtil.ExportToWorkspace(this.SourceFeatureClass, mdbWorkspace))
                {
                    // 获取导出的临时要素类信息
                    IFeatureClass tempExpFeatureClass = WorkspaceUtil.GetFeatureClass(mdbWorkspace, this.sourceFeatureClassDTO.Name);
                    // 进行擦除操作
                    OverlayCommonTool.Erase(tempExpFeatureClass, this.TargetFeatureClass);
                    // 计算完保存结果,如何保存?
                    if (tempExpFeatureClass != null)
                    {
                        OverlayRespDTO overlayRespDTO = new OverlayRespDTO();
                        // 总面积
                        double         sumArea        = 0;
                        IFeatureCursor pFeatureCursor = tempExpFeatureClass.Search(null, false);
                        IFeature       pFeature       = null;
                        //获得“Area”字段
                        //IFields fields = pFeatureCursor.Fields;
                        //int areaIndex = fields.FindField("Area");
                        while ((pFeature = pFeatureCursor.NextFeature()) != null)
                        {
                            double area = ((IArea)pFeature.Shape).Area;// (double)pFeature.get_Value(areaIndex);
                            sumArea += area;
                            FeatureRespDTO featureRespDTO = new FeatureRespDTO
                            {
                                OID         = pFeature.OID,
                                Area        = area,
                                Coordinates = GeometryUtil.ConvertGeometryToJson(pFeature.Shape, out string msg)
                            };
                            overlayRespDTO.Features.Add(featureRespDTO);
                            pFeature = pFeatureCursor.NextFeature();
                        }
                        overlayRespDTO.SumArea = sumArea;
                        Property resultProp = base.OutputParametersMeta[nameof(Result)];
                        resultProp.Value = overlayRespDTO;
                        return(new Result(EnumSystemStatusCode.DME_SUCCESS, "运行完成", EnumSystemStatusCode.DME_SUCCESS, null));
                    }
                }
                // 删除临时文件
                if (IsClearTemp && File.Exists(sPath))
                {
                    File.Delete(sPath);
                }
            }
            else
            {
                throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, "分析类型不匹配");
            }

            return(new Result(EnumSystemStatusCode.DME_SUCCESS, "运行完成,但没有运算结果", EnumSystemStatusCode.DME_SUCCESS, null));
        }
Ejemplo n.º 17
0
        public override void OnMouseDown(int button, int shift, int x, int y)
        {
            if (_feature == null)
            {
                return;
            }
            IPoint       mapPoint         = _context.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
            IInvalidArea invalidAreaClass = new InvalidAreaClass()
            {
                Display = (_context.FocusMap as IActiveView).ScreenDisplay
            };

            invalidAreaClass.Add(_feature);
            Yutai.ArcGIS.Common.Editor.Editor.StartEditOperation(_feature.Class as IDataset);
            try
            {
                if (_codeSetting == null)
                {
                    _codeSetting = new FrmCode(_pointFeatureLayer, _gdbhFieldName);
                }
                _codeSetting.Next();
                if (_codeSetting.ShowDialog() == DialogResult.OK)
                {
                    ILineFeatureCalculate pCalculate = new LineFeatureCalculate(_feature, _lineFeatureLayer, _pointFeatureLayer);
                    pCalculate.LineFeatureLayer  = _lineFeatureLayer;
                    pCalculate.PointFeatureLayer = _pointFeatureLayer;
                    pCalculate.LineFeature       = _feature;
                    pCalculate.Point             = mapPoint;
                    pCalculate.IdxDMGCField      = _idxDmgcField;
                    pCalculate.IdxQDMSField      = _idxQdmsField;
                    pCalculate.IdxZDMSField      = _idxZdmsField;
                    double dmgcValue = pCalculate.GetGroundHeightByPoint();
                    double gxmsValue = pCalculate.GetDepthByPoint();
                    ISet   set       = (_feature as IFeatureEdit).Split(mapPoint);
                    set.Reset();

                    IFeature feature = set.Next() as IFeature;
                    if (CommonHelper.IsFromPoint(feature.Shape as IPolyline, mapPoint))
                    {
                        feature.Value[_idxQdbhField] = _codeSetting.Code;
                        feature.Value[_idxQdmsField] = gxmsValue.ToString("##0.0000");
                        feature.Value[_idxQdgcField] = (dmgcValue - gxmsValue).ToString("##0.0000");
                    }
                    else
                    {
                        feature.Value[_idxZdbhField] = _codeSetting.Code;
                        feature.Value[_idxZdmsField] = gxmsValue.ToString("##0.0000");
                        feature.Value[_idxZdgcField] = (dmgcValue - gxmsValue).ToString("##0.0000");
                    }
                    feature.Store();

                    feature = set.Next() as IFeature;
                    if (CommonHelper.IsFromPoint(feature.Shape as IPolyline, mapPoint))
                    {
                        feature.Value[_idxQdbhField] = _codeSetting.Code;
                        feature.Value[_idxQdmsField] = gxmsValue.ToString("##0.0000");
                        feature.Value[_idxQdgcField] = (dmgcValue - gxmsValue).ToString("##0.0000");
                    }
                    else
                    {
                        feature.Value[_idxZdbhField] = _codeSetting.Code;
                        feature.Value[_idxZdmsField] = gxmsValue.ToString("##0.0000");
                        feature.Value[_idxZdgcField] = (dmgcValue - gxmsValue).ToString("##0.0000");
                    }
                    feature.Store();


                    IFeature newFeature = _pointFeatureLayer.FeatureClass.CreateFeature();
                    newFeature.Value[_idxGdbhField] = _codeSetting.Code;
                    newFeature.Value[_idxDmgcField] = dmgcValue.ToString("##0.0000");
                    IPoint nearPoint = CommonHelper.GetNearestPoint(feature.Shape as IPolyline, mapPoint);
                    newFeature.Shape = GeometryHelper.CreatePoint(nearPoint.X, nearPoint.Y, nearPoint.Z, nearPoint.M, FeatureClassUtil.CheckHasZ(_pointFeatureLayer.FeatureClass), FeatureClassUtil.CheckHasM(_pointFeatureLayer.FeatureClass));
                    newFeature.Store();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            Yutai.ArcGIS.Common.Editor.Editor.StopEditOperation(_feature.Class as IDataset);
            invalidAreaClass.Invalidate(-2);
            _context.ClearCurrentTool();
            _feature = null;
            _context.ActiveView.Refresh();
        }
Ejemplo n.º 18
0
        private void btnDetele_Click(object sender, EventArgs e)
        {
            try
            {
                if (_lineFeature1 == null)
                {
                    return;
                }
                if (_lineFeature2 == null)
                {
                    return;
                }
                IPolyline firstPolyline  = _lineFeature1.Shape as IPolyline;
                IPolyline secondPolyline = _lineFeature2.Shape as IPolyline;
                if (firstPolyline == null)
                {
                    return;
                }
                if (secondPolyline == null)
                {
                    return;
                }
                List <IPoint> points = new List <IPoint>()
                {
                    firstPolyline.FromPoint,
                    firstPolyline.ToPoint,
                    secondPolyline.FromPoint,
                    secondPolyline.ToPoint
                };
                IPoint        startPoint          = CommonHelper.GetFarthestPoint(firstPolyline, _linkPoint);
                IPoint        endPoint            = CommonHelper.GetFarthestPoint(secondPolyline, _linkPoint);
                int           firstfrompointcount = points.Count(point1 => Math.Abs(firstPolyline.FromPoint.X - point1.X) < 0.01 && Math.Abs(firstPolyline.FromPoint.Y - point1.Y) < 0.01);
                IFeatureClass pFeatureClass       = _featureLayer.FeatureClass;
                bool          hasZ     = FeatureClassUtil.CheckHasZ(pFeatureClass);
                bool          hasM     = FeatureClassUtil.CheckHasM(pFeatureClass);
                IFeature      pFeature = pFeatureClass.CreateFeature();

                startPoint = GeometryHelper.CreatePoint(startPoint.X, startPoint.Y, startPoint.Z, startPoint.M, hasZ, hasM);
                endPoint   = GeometryHelper.CreatePoint(endPoint.X, endPoint.Y, endPoint.Z, endPoint.M, hasZ, hasM);

                pFeature.Shape = GeometryHelper.CreatePointCollection(startPoint, endPoint, hasZ, hasM) as IPolyline;

                foreach (TreeRecord treeRecord in _treeRecords)
                {
                    if (treeRecord.IsDomain)
                    {
                        List <CodeValuePair> pairs = treeRecord.DoaminValue as List <CodeValuePair>;
                        CodeValuePair        pair  = pairs.FirstOrDefault(p => p.Name == treeRecord.FirstValue.ToString());
                        pFeature.Value[treeRecord.FieldId] = pair == null ? null : pair.Value;
                    }
                    pFeature.Value[treeRecord.FieldId] = treeRecord.MergeValue;
                }
                pFeature.Store();
                _featureoid       = pFeature.OID;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }