Exemple #1
0
        /// <summary>
        /// 导出拓扑错误图形, 在指定要素数据集(IFeatureDataset)或工作空间(IWorkspace)新建要素类以保存拓扑错误图形
        /// </summary>
        /// <param name="topologyRule">拓扑规则</param>
        /// <param name="topology">拓扑</param>
        /// <param name="resultObject">指定的要素数据集(IFeatureDataset)或工作空间(IWorkspace),用于创建新要素类,保存拓扑错误图形</param>
        public static IFeatureClass TopoErrorToNewFeatureClass(this ITopologyRule topologyRule, ITopology topology, object resultObject, string resultClassName = null)
        {
            //获得指定拓扑规则类型的拓扑错误要素
            var errorFeatures = GetTopoErrorFeatures(topologyRule, topology);

            if (errorFeatures.Count < 1)
            {
                return(null);
            }

            //创建保存拓扑错误的要素类
            var feature = errorFeatures[0] as IFeature;
            var geoType = feature.Shape.GeometryType;

            if (string.IsNullOrEmpty(resultClassName))
            {
                resultClassName = topologyRule.TopologyRuleType.ToString();
            }

            IFeature tmpFeature         = errorFeatures[0] as IFeature;
            var      resultFeatureClass = FeatureClassEx.Create(resultObject, resultClassName,
                                                                tmpFeature.Shape.SpatialReference, geoType, new FieldsClass());

            //将拓扑错误要素存入要素类中
            TopoErrorInsertToFeatureClass(errorFeatures, resultFeatureClass);
            return(resultFeatureClass);
        }
Exemple #2
0
        /// <summary>
        /// 将指定路径下的要素图层加载到地图控件中
        /// <para>可加载lyr/shp/mdb/gdb/dwg等多种数据源图层,允许的路径形式参考<see cref="FeatureClassEx.FromPath"/>方法</para>
        /// </summary>
        /// <param name="mapControl">地图控件</param>
        /// <param name="layerPath">要素类图层的完整路径,允许的路径形式参考<see cref="FeatureClassEx.FromPath"/>方法</param>
        public static void LoadFeatureLayer(this AxMapControl mapControl, string layerPath)
        {
            if (Path.GetExtension(layerPath) == ".lyr" && File.Exists(layerPath))
            {
                mapControl.AddLayerFromFile(layerPath);
                return;
            }
            var featureClass = FeatureClassEx.FromPath(layerPath);

            mapControl.AddLayer(new FeatureLayerClass {
                FeatureClass = featureClass, Name = featureClass.AliasName
            });
        }
Exemple #3
0
        private void Test()
        {
            double sumRiverLength = 0.0;

            FeatureClassEx.FromPath(@"c:\River.shp").QueryFeatures(@"XZQDM = '440000'",
                                                                   feature => sumRiverLength += feature.ToDouble("RiverLength"));

            var workspace = WorkspaceEx.GetWorkSpace(@"c:\World.mdb");

            FeatureClassEx.FromPath(@"c:\World.mdb\river").CopyStruct(workspace, "NewRiver", "河流");

            var connString = DbHelper.Dbf_OleDb4(@"c:\River.dbf");
            var dbHelper   = DbHelper.GetOleDbHelper(connString).ExcNonQuery(@"update River set Name = 'Pearl River' where RiverCode ='003'");
        }
Exemple #4
0
        /// <summary>
        /// 检查多个路径下的要素类的坐标系是否完全一致
        /// </summary>
        /// <param name="paths"></param>
        /// <returns>若坐标系不一致则返回提示信息,一致则返回null</returns>
        public static string CheckCoordinates(params string[] paths)
        {
            var classes = new List <IFeatureClass>();

            foreach (var path in paths)
            {
                var featureClass = FeatureClassEx.FromPath(path);
                if (featureClass != null)
                {
                    classes.Add(featureClass);
                }
            }
            return(SpatialRefOpt.CheckSpatialRef(classes, out var message) ? message : null);
        }
Exemple #5
0
        /// <summary>
        /// 检查路径下的要素类是否被占用
        /// </summary>
        /// <param name="path">要素类的完整路径,参考<see cref="FeatureClassEx.FromPath"/></param>
        /// <param name="autoAddExtension">是否自动在路径末尾增加.shp/.mdb/.dwg后缀,以再次查找要素类</param>
        /// <returns>若要素类被锁定则返回提示信息,要素类不存在或未锁定返回null,若检查失败抛出异常</returns>
        public static string CheckClassLock(string path, bool autoAddExtension = false)
        {
            try
            {
                var featureClass = FeatureClassEx.FromPath(path, autoAddExtension);
                if (featureClass == null)
                {
                    return(null);
                }

                featureClass.CheckClassLock(out var message);
                return(message);
            }
            catch (Exception ex) { throw new Exception($"打开或检查要素类是否锁定失败:{ex.Message}\r\n请检查要素类路径“{path}”无误", ex); }
        }
Exemple #6
0
        /// <summary>
        /// 将指定路径下的要素数据源数据,加载到地图控件中
        /// <para>可加载lyr/shp/mdb/gdb/dwg等多种数据源数据,允许的路径形式参考<see cref="FeatureClassEx.AllFromPath"/>方法</para>
        /// </summary>
        /// <param name="mapControl">地图控件</param>
        /// <param name="connStrOrPath">要素数据源路径,允许的路径形式参考<see cref="FeatureClassEx.AllFromPath(string)"/>方法</param>
        public static void LoadFeatureLayers(this AxMapControl mapControl, string connStrOrPath)
        {
            if (Path.GetExtension(connStrOrPath) == ".lyr" && File.Exists(connStrOrPath))
            {
                mapControl.AddLayerFromFile(connStrOrPath);
                return;
            }
            var featureClasses = FeatureClassEx.AllFromPath(connStrOrPath);

            foreach (var featureClass in featureClasses)
            {
                mapControl.AddLayer(new FeatureLayerClass {
                    FeatureClass = featureClass, Name = featureClass.AliasName
                });
            }
        }
Exemple #7
0
        /// <summary>
        /// 设置地图显示范围
        /// </summary>
        /// <param name="map">地图</param>
        /// <param name="mapFrameInfo">地图框信息</param>
        protected virtual void SetMapExtent(IMap map, MapFrameInfo mapFrameInfo)
        {
            //若MapExtent不为null,则地图缩放至MapExtent指定的范围;否则查找LayerInfo.ZoomTo为True的图层来定位缩放
            var activeView = map as IActiveView;

            if (mapFrameInfo.MapExtent != null)
            {
                activeView.MapZoomTo(mapFrameInfo.MapExtent, 1.3);
            }
            else
            {
                var layerInfo = mapFrameInfo.LayerInfos.FirstOrDefault(v => v.ZoomTo);
                if (layerInfo != null)
                {
                    var featureClass = FeatureClassEx.FromPath(layerInfo.DataSource);
                    var geometries   = featureClass.QueryGeometries(layerInfo.Definition);
                    activeView.MapZoomTo(geometries, 1.3);
                }
            }
        }
Exemple #8
0
 /// <summary>
 /// 将指定要素类复制到工作空间中
 /// </summary>
 /// <param name="workspace"></param>
 /// <param name="sourceClass">源要素类</param>
 /// <param name="targetClassName">新要素类名称,若为null则使用源要素类名称</param>
 /// <param name="whereClause">筛选条件,从源要素类中筛选指定的要素复制到目标要素,为null或Empty时将复制全部要素</param>
 /// <returns></returns>
 public static IFeatureClass CreateFeatureClass(this IWorkspace workspace, IFeatureClass sourceClass, string targetClassName = null, string whereClause = null)
 {
     return(FeatureClassEx.CopyDataTo(sourceClass, workspace, targetClassName, whereClause));
 }
Exemple #9
0
 /// <summary>
 /// 创建要素类
 /// </summary>
 /// <param name="name">要素类名称(如果为shapefile,不能包含文件扩展名".shp")</param>
 /// <param name="sptialRef">空间参考坐标系。若参数obj为IFeatureDataset则应赋值为null;否则不能为null,
 /// 可使用<see cref="SpatialRefOpt.CreateSpatialRef(esriSRProjCS4Type)"/>或其重载方法进行创建</param>
 /// <param name="geometryType">几何类型(点/线/面等)</param>
 /// <param name="fields">要创建的字段集(可以为null,该方法自动修改或加入OID和SHAPE字段以确保几何类型、坐标系与参数一致)</param>
 /// <returns></returns>
 public static IFeatureClass CreateFeatureClass(this IWorkspace workspace, string name, ISpatialReference sptialRef, esriGeometryType geometryType, IFields fields = null)
 {
     return(FeatureClassEx.Create(workspace, name, sptialRef, geometryType, fields));
 }
Exemple #10
0
 /// <summary>
 /// 创建要素类
 /// </summary>
 /// <param name="obj">IWorkspace、IFeatureWorkspace或IFeatureDataset对象,在该对象中创建要素类</param>
 /// <param name="name">要素类名称(如果为shapefile,不能包含文件扩展名".shp")</param>
 /// <param name="fields">要创建的字段集(必须包含SHAPE字段),可参考<see cref="FieldOpt.CreateBaseFields"/>等方法创建字段集</param>
 /// <returns></returns>
 public static IFeatureClass CreateFeatureClass(this IWorkspace workspace, string name, IFields fields)
 {
     return(FeatureClassEx.Create(workspace, name, fields));
 }
Exemple #11
0
        /// <summary>
        /// 多边形转点,将多边形要素类每个图斑的中心(重心)点存入新的点要素类中
        /// </summary>
        /// <param name="sourceClassPath"></param>
        /// <param name="targeClassPath"></param>
        /// <returns></returns>
        public static IFeatureClass PolygonClassToPoint(string sourceClassPath, string targeClassPath)
        {
            var sourceClass = FeatureClassEx.FromPath(sourceClassPath);

            return(sourceClass.PolygonClassToPoint(targeClassPath));
        }