一.打开图层操作
将图层文件放入 …\bin\Debug文件夹下
//设置地图投影
axMap1.Projection = tkMapProjection.PROJECTION_WGS84;
//打开图层
Shapefile sf = new Shapefile();
sf.Open(Environment.CurrentDirectory + @"\tantou5.shp", null);
int handler=axMap1.AddLayer(sf, true);//定义句柄
这里利用arcgis软件进行图层绘制,图层绘制的时候地理坐标系投影选择PROJECTION_WGS84,与mapwingis自带的地图投影一致。
二.根据图层类型更换图片
1.利用arcgis打开相应的图层,更改其类型属性
有两种类型,分别是pip和line类型
2.在…\bin\Debug文件夹放入需要更换的图片,图片名称需要和类型一致
代码:
//图标方法
int index = sf.Table.FieldIndexByName["Type"];
var names = new HashSet<string>();
for (int i = 0; i < sf.Table.NumRows; i++)
{
names.Add((string)sf.Table.CellValue[index, i]);
}
string[] files = Directory.GetFiles("D:/研究生项目/辽河项目/前端架构/winform小程序/WFMDemo/NEWDemo/bin/Debug/");
foreach (string file in files)
{
string name = Path.GetFileNameWithoutExtension(file);//返回图片名称的完整路径
if (Path.GetExtension(file).ToLower() == ".png" && names.Contains(name))
{
MapWinGIS.Image img = new MapWinGIS.Image();
if (img.Open(file, ImageType.USE_FILE_EXTENSION, true, null))
{
ShapefileCategory ct = sf.Categories.Add(name);
ct.Expression = "[Type] = \"" + name + "\"";
ct.DrawingOptions.PointType = tkPointSymbolType.ptSymbolPicture;
ct.DrawingOptions.Picture = img;
}
}
}
sf.DefaultDrawingOptions.Visible = false; // hide all the unclassified points
sf.Categories.ApplyExpressions();
axMap1.Redraw();
修改完成