예제 #1
0
        public static void DeleteFeatureClass(IWorkspace pWorkspace, string pFeatureClassName)
        {
            IFeatureClass featureClass = DBOperator.getFeatureClass(pWorkspace, pFeatureClassName);
            IDataset      dataSet      = featureClass as IDataset;

            dataSet.Delete();
        }
예제 #2
0
        private void itemPanel1_ItemDoubleClick(object sender, MouseEventArgs e)
        {
            //若是左建双击缩放至要素:
            if (e.Clicks == 2)
            {
                ButtonItem item = new ButtonItem();
                item = sender as ButtonItem;
                if (item == null)
                {
                    return;
                }
                string FeatureClassName = item.Tooltip.Substring(item.Tooltip.IndexOf('.') + 1);
                string strOID           = item.Tooltip.Substring(0, item.Tooltip.IndexOf('.'));
                int    OID = Convert.ToInt32(strOID);

                IFeature   feature  = DBOperator.getFeatureFrom(OID, FeatureClassName, m_GlobalWorkspace);
                IGeometry5 geometry = feature.Shape as IGeometry5;
                this.m_MapCtrls.CenterAt(geometry.CentroidEx);
                this.m_MapCtrls.ActiveView.Extent = geometry.Envelope;
                ILayer iLayer = null;

                if (FeatureClassName.Contains("CheckItemPtn"))
                {
                    iLayer = m_MapCtrls.Map.Layer[1];
                }
                else if (FeatureClassName.Contains("CheckItemPtn"))
                {
                    iLayer = m_MapCtrls.Map.Layer[2];
                }
                else
                {
                    iLayer = m_MapCtrls.Map.Layer[3];
                }

                clearFeatureSelection();

                m_MapCtrls.Map.SelectFeature(iLayer, feature);
                //this.m_MapCtrls.ActiveView.FocusMap.SelectByShape(feature.Shape, null, true);
                //this.m_MapCtrls.ActiveView.FocusMap.SelectByShape(feature.Shape, selectionEnv, true);
            }
        }
예제 #3
0
 private void itemPanel3_ItemDoubleClick(object sender, MouseEventArgs e)
 {
     //双击,且不是点击非button item;
     if (e.Clicks == 2)
     {
         ButtonItem item = new ButtonItem();
         item = sender as ButtonItem;
         if (item == null)
         {
             return;
         }
         IFeature feature = DBOperator.getFeatureFrom(item.Name, Properties.Settings.Default.Grid, Properties.Settings.Default.GridCodeField, m_GlobalWorkspace);
         if (feature == null)
         {
             return;
         }
         IGeometry5 geometry = feature.Shape as IGeometry5;
         this.m_MapCtrls.CenterAt(geometry.CentroidEx);
         this.m_MapCtrls.ActiveView.Extent = geometry.Envelope;
     }
 }
예제 #4
0
        //public static ICursor UncheckGridCode(ITable pTable,string pVersionName)
        //{
        //    //根据表格数据获取grid code:
        //    IQueryFilter filter = new QueryFilterClass();
        //    filter.WhereClause = "TaskName = '" + pVersionName + "'";
        //    ICursor cursor = pTable.Search(filter, true);
        //    return cursor;
        //}

        //public static void Check(IFeature pFeature, IWorkspace pWorkspace,string pVersionName)
        //{
        //    //更新检查状态:
        //    int ii = 1;
        //    int fieldindex = pFeature.Fields.FindField("passed");
        //    if (pFeature.get_Value(pFeature.Fields.FindField("VersionName")).ToString() == pVersionName)
        //    {
        //        pFeature.set_Value(fieldindex, ii);
        //        pFeature.Store();
        //    }

        //}

        //public static void Check(IFeature pFeature, IWorkspace pWorkspace)
        //{
        //    //更新检查状态:
        //    int ii = 1;
        //    int fieldindex = pFeature.Fields.FindFieldByAliasName("Pass");

        //        pFeature.set_Value(fieldindex, ii);
        //        pFeature.Store();

        //}

        public static bool ExportSHP(string pDestPath, IWorkspace pWorkspace)
        {
            IWorkspace    sourceWorkspace    = pWorkspace;
            IFeatureClass sourceFeatureClass = DBOperator.getFeatureClass(pWorkspace, "CheckArea");
            string        shpFolderPath      = pDestPath.Substring(0, pDestPath.LastIndexOf("\\"));
            string        shpFileName        = pDestPath.Substring(pDestPath.LastIndexOf("\\") + 1);

            shpFileName = shpFileName.Substring(0, shpFileName.Length - 4);

            IWorkspace targetWorkspace = DBOperator.openShapeFileWorkspace(shpFolderPath);

            if (File.Exists(pDestPath) == true)
            {
                DBOperator.DeleteFeatureClass(targetWorkspace, shpFileName);
            }

            IDataset       sourcedataset       = sourceWorkspace as IDataset;
            IWorkspaceName sourceWorkspaceName = sourcedataset.FullName as IWorkspaceName;
            IDataset       targetdataset       = targetWorkspace as IDataset;
            IWorkspaceName targetWorkspaceName = targetdataset.FullName as IWorkspaceName;

            sourcedataset = sourceFeatureClass as IDataset;
            IFeatureClassName sourceFeatureClassName = sourcedataset.FullName as IFeatureClassName;

            // Create a name object for the target dataset.
            IFeatureClassName targetFeatureClassName = new FeatureClassNameClass();
            IDatasetName      targetDatasetName      = (IDatasetName)targetFeatureClassName;

            targetDatasetName.Name          = shpFileName;
            targetDatasetName.WorkspaceName = targetWorkspaceName;

            // Create the objects and references necessary for field validation.
            IFieldChecker   fieldChecker   = new FieldCheckerClass();
            IFields         sourceFields   = sourceFeatureClass.Fields;
            IFields         targetFields   = null;
            IEnumFieldError enumFieldError = null;

            // Validate the fields and check for errors.
            fieldChecker.Validate(sourceFields, out enumFieldError, out targetFields);
            if (enumFieldError != null)
            {
                IFieldError error = enumFieldError.Next();
                while (error != null)
                {
                    // Handle the errors in a way appropriate to your application.
                    Console.WriteLine("Errors were encountered during field validation.");
                    error = enumFieldError.Next();
                }
            }

            // Find the shape field.
            String shapeFieldName  = sourceFeatureClass.ShapeFieldName;
            int    shapeFieldIndex = sourceFeatureClass.FindField(shapeFieldName);
            IField shapeField      = sourceFields.get_Field(shapeFieldIndex);

            // Get the geometry definition from the shape field and clone it.
            IGeometryDef geometryDef            = shapeField.GeometryDef;
            IClone       geometryDefClone       = (IClone)geometryDef;
            IClone       targetGeometryDefClone = geometryDefClone.Clone();
            IGeometryDef targetGeometryDef      = (IGeometryDef)targetGeometryDefClone;

            // Cast the IGeometryDef to the IGeometryDefEdit interface.
            IGeometryDefEdit targetGeometryDefEdit = (IGeometryDefEdit)targetGeometryDef;

            // Set the IGeometryDefEdit properties.
            targetGeometryDefEdit.GridCount_2 = 1;
            targetGeometryDefEdit.set_GridSize(0, 0.75);

            // Set the required properties for the IFieldChecker interface.
            fieldChecker.InputWorkspace    = sourceWorkspace;
            fieldChecker.ValidateWorkspace = targetWorkspace;

            // Create the converter and run the conversion.
            IFeatureDataConverter2 featureDataConverter = new FeatureDataConverterClass();

            IDatasetName       sourceFClassName  = sourceFeatureClassName as IDatasetName;
            IEnumInvalidObject enumInvalidObject = featureDataConverter.ConvertFeatureClass
                                                       (sourceFClassName, null, null, null, targetFeatureClassName,
                                                       targetGeometryDef, targetFields, "", 1000, 0);
            // Check for errors.
            IInvalidObjectInfo invalidObjectInfo = null;

            enumInvalidObject.Reset();
            while ((invalidObjectInfo = enumInvalidObject.Next()) != null)
            {
                // Handle the errors in a way appropriate to the application.
                Console.WriteLine("Errors occurred for the following feature: {0}",
                                  invalidObjectInfo.InvalidObjectID);
                return(false);
            }
            return(true);
        }