public static MapXLib.LayerInfo AddShpLayer(string DataPath, string LayerName, AxMapXLib.AxMap Axmap)
{
#region 載入圖檔並傳回圖層
MapXLib.LayerInfo linfo = new MapXLib.LayerInfoClass();
MapXLib.LayerInfo li = new MapXLib.LayerInfoClass();
MapXLib.LayerInfo newlayer = new MapXLib.LayerInfoClass();
MapXLib.Dataset dt = null;
MapXLib.Layer lyr = null;
FileInfo file = new FileInfo(DataPath + LayerName + ".shp");
if (file.Exists)
{
linfo.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeShape;
linfo.AddParameter("Name", LayerName + "shp");
linfo.AddParameter("FileSpec", DataPath + LayerName + ".shp");
linfo.AddParameter("CoordSys", Axmap.NumericCoordSys);
linfo.AddParameter("AutoCreateDataset", true);
linfo.AddParameter("DatasetName", LayerName);
lyr = Axmap.Layers.Add(linfo, Axmap.Layers.Count);
lyr.BeginAccess(MapXLib.LayerBeginAccessConstants.miAccessRead);
dt = lyr.DataSets[1];
linfo = null;
MapXLib.Dataset ds = Axmap.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetLayer, lyr, LayerName + "2", 0, 0, 0, dt.Fields, false);
li.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeNewTable;
FileInfo tabfile = new FileInfo(Application.StartupPath + "\\temp\\" + LayerName + ".tab");
if (tabfile.Exists)
{
tabfile.Delete();
tabfile = new FileInfo(Application.StartupPath + "\\temp\\" + LayerName + ".map");
tabfile.Delete();
tabfile = new FileInfo(Application.StartupPath + "\\temp\\" + LayerName + ".id");
tabfile.Delete();
tabfile = new FileInfo(Application.StartupPath + "\\temp\\" + LayerName + ".dat");
tabfile.Delete();
}
li.AddParameter("FileSpec", Application.StartupPath + "\\temp\\" + LayerName + ".tab");
li.AddParameter("Name", LayerName);
li.AddParameter("Fields", ds.Fields);
li.AddParameter("AutoCreateDataset", true);
//newlayer.AddParameter("CoordSys", Axmap.NumericCoordSys);
li.AddParameter("Features", lyr.AllFeatures);
return li;
}
else { return null; }
#endregion
}
- Jul 15 Thu 2010 15:10
MapX5 載入Shp檔(中文亂碼)
全站熱搜
留言列表