
整理了 MapConrol各基本功能的实现代码
using System;
using SystemCollectionsGeneric;
using SystemLinq;
using SystemText;
using SystemIO;
using SystemWindowsForms;
using ESRIArcGISControls;
using ESRIArcGISesriSystem;
using ESRIArcGISCarto;
using ESRIArcGISGeometry;
using ESRIArcGISDisplay;
using ESRIArcGISGeodatabase;
namespace MapCtrol//直接引用时需替换成自己当前的命名空间
{
public class MapBaseOperate
{
/// <summary>
/// 添加SHP文当
/// </summary>
/// <param name="mapControl"></param>
public static void AddShapeFile(IMapControlDefault mapControl)
{
OpenFileDialog openfileDlg = new OpenFileDialog();
openfileDlgTitle = "添加shp图层文件";
openfileDlgFilter = "map document (shp)|shp";
openfileDlgShowDialog();
string filepath = openfileDlgFileName;
bool exist = FileExists(filepath);
if (!exist)
{
MessageBoxShow("路径不存在!");
return;
}
string path;
string filename;
//int istart = filepathLastIndexOf("\\");
//int iend = filepathLastIndexOf("");
//path = filepathSubstring(0, istart);
//filename = filepathSubstring(istart + 1, iend - istart - 1);
FileInfo fileinfo = new FileInfo(filepath);
path = filepathSubstring(0, filepathLength - fileinfoNameLength);
filename = fileinfoName;
try
{
//加载图层文件
mapControlAddShapeFile(path, filename);
//设置MapControl的显示范围到数据的全局范围
mapControlExtent = mapControlFullExtent;
}
catch (SystemException ex)
{
MessageBoxShow("添加图层文件失败!" + exMessage);
}
}
/// <summary>
/// 添加LYR文当
/// </summary>
/// <param name="mapControl"></param>
public static void AddLayerFile(IMapControlDefault mapControl)
{
OpenFileDialog openfileDlg = new OpenFileDialog();
openfileDlgTitle = "添加lyr图层文件";
openfileDlgFilter = "map documents (lyr)|lyr";
openfileDlgShowDialog();
string filepath = openfileDlgFileName;
bool exist = FileExists(filepath);
if (!exist)
{
MessageBoxShow("路径不存在!");
return;
}
try
{
mapControlAddLayerFromFile(filepath);
//设置MapControl的显示范围到数据的全局范围
mapControlExtent = mapControlFullExtent;
}
catch (SystemException ex)
{
MessageBoxShow("添加图层文件失败!" + exMessage);
}
}
/// <summary>
/// 删除地图所有图层
/// </summary>
public static void DeleteAllLayers(IMapControlDefault mapControl)
{
try
{
for (int i = mapControlLayerCount - 1; i >= 0; i-- )
{
mapControlDeleteLayer(i);
}
}
catch (SystemException ex)
{
MessageBoxShow("删除图层失败!" + exMessage);
}
}
/// <summary>
/// 将最底图层,移动到最上层
/// </summary>
public static void MoveLayerToTop(IMapControlDefault mapControl)
{
try
{
if (mapControlLayerCount > 0)
{
mapControlMoveLayerTo(mapControlLayerCount - 1, 0);
}
}
catch (SystemException ex)
{
MessageBoxShow("移动图层失败!" + exMessage);
}
}
/// <summary>
/// 加载地图文当
/// </summary>
/// <param name="mapControl"></param>
public static void LoadMapDocument(IMapControlDefault mapControl)
{
OpenFileDialog openfileDlg = new OpenFileDialog();
openfileDlgTitle = "加载地图文当";
openfileDlgFilter = "map document (mxd)|mxd";
openfileDlgShowDialog();
string filepath = openfileDlgFileName;
if (mapControlCheckMxFile(filepath))
{
mapControlMousePointer = esriControlsMousePointeresriPointerHourglass;
mapControlLoadMxFile(filepath, 0, TypeMissing);
mapControlMousePointer = esriControlsMousePointeresriPointerDefault;
}
else
{
MessageBoxShow(filepath + "不是有效的地图文当!");
}
}
/// <summary>
/// 加载特定地图文当
/// </summary>
/// <param name="mapControl"></param>
public static void LoadSpecificMapDocument(IMapControlDefault mapControl, string specificMapName)
{
OpenFileDialog openfileDlg = new OpenFileDialog();
openfileDlgTitle = "加载特定地图文当";
openfileDlgFilter = "map document (mxd)|mxd";
openfileDlgShowDialog();
string filepath = openfileDlgFileName;
if (mapControlCheckMxFile(filepath))
{
if (stringIsNullOrWhiteSpace(specificMapName))
{
int istart = filepathLastIndexOf("\\");
int iend = filepathLastIndexOf("");
specificMapName = filepathSubstring(istart + 1, iend - istart - 1);
}
IArray arrayMap = mapControlReadMxMaps(filepath, TypeMissing);
for (int i = 0; i < arrayMapCount; i++)
{
IMap map = arrayMapget_Element(i) as IMap;
if (specificMapName == mapName)
{
mapControlMousePointer = esriControlsMousePointeresriPointerHourglass;
mapControlLoadMxFile(filepath, 0, TypeMissing);
mapControlMousePointer = esriControlsMousePointeresriPointerDefault;
break;
}
}
}
else
{
MessageBoxShow(filepath + "不是有效的地图文当!");
}
}
/// <summary>
/// By MapDocument
/// </summary>
public static IMapDocument LoadMapDoc(IMapControlDefault mapControl)
{
MapDocument mapdoc = new MapDocument();
try
{
OpenFileDialog openfileDlg = new OpenFileDialog();
openfileDlgTitle = "加载地图文当";
openfileDlgFilter = "map document (mxd)|mxd";
openfileDlgShowDialog();
string filepath = openfileDlgFileName;
mapdocOpen(filepath, "");
for (int i = 0; i < mapdocMapCount; i++ )
{
mapControlMap = mapdocget_Map(i);
}
mapControlRefresh();
}
catch (SystemException ex)
{
MessageBoxShow("加载地图文当失败" + exMessage);
mapdoc = null;
}
return mapdoc;
}
在arcgis里圈画log的区域,要注意shapefile文件和所有底图是同一个extent,同一个地理参考系,同一个地理水准面,同一个地理投影坐标系在图层的properties查,也就是roi可能会出现其中一个图层上,但不能出现在另一个图层上。反正数据的坐标信息和范围一定要一致。在envi里圈画roi的区域,基于A1的结果,直接在两个窗口打开roi文件,goto到相应的区域arcgis图像log对比图就可以了。
我也遇到了类似的问题。通过代码测试了好多次。
(1)在保证授权许可没有问题;
(2)文件路径和文件名没有问题;
在以上两种情况下,可能是shp数据文件出现了错误。可以用ArcMap打开这个文件试试看,是不是这个错误。
1、建个记事本文件,示例如下:x,y,z102,33,100103,345,1022、在ArcGIS中添加最好的上述记事本文件,通过Tools菜单下的AddXYData命令(指定X,Y和坐标系统,如果你的点是地理坐标且通过GPS接收仪获取的,坐标系统选择GCS下的WGS84)。3、如果点可正常显示在合适位置,将该数据导出成shapefile就可以了。
以上就是关于C#+AE中MapControl加载进来的地图不在控件的正中间,向右偏了一点,这是为什么呢如何全部的内容,包括:C#+AE中MapControl加载进来的地图不在控件的正中间,向右偏了一点,这是为什么呢如何、arcgis图像log对比图怎么、arcgis engine的问题,在visual studio2010下的AddShapeFile函数等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)