Ejemplo n.º 1
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
            });
        }
Ejemplo n.º 2
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'");
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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); }
        }
Ejemplo n.º 5
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);
                }
            }
        }
Ejemplo n.º 6
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));
        }