產製ShapeFile的時候
漏了一個型態的檔案 - MultiPoint
也改寫了一下寫法
讓呼叫更簡單
點位傳入參數的方式是利用Geometry的格式
這裡把他補上提供大家參考
public static string CreateMultiPoint(string SaveFileName, int EpsgCode, string[] GeometryText, string[] MetaData)
{
try
{
DotSpatial.Data.FeatureSet fs = new DotSpatial.Data.FeatureSet(DotSpatial.Topology.FeatureType.MultiPoint);
fs.Projection = DotSpatial.Projections.ProjectionInfo.FromEpsgCode(EpsgCode);
//宣告MetaData欄位
string[] strColumn = MetaData[0].Split(',');
for (int i = 0; i < strColumn.Length; i++)
{
fs.DataTable.Columns.Add(new System.Data.DataColumn(strColumn[i], typeof(string)));
}
for (int i = 0; i < GeometryText.Length; i++)
{
string strGeometry = GeometryText[i].Replace("MULTIPOINT ", "");
strGeometry = strGeometry.Replace("(", "");
strGeometry = strGeometry.Replace(")", "");
string[] Geometry = strGeometry.Split(',');
string[] ColumnData = MetaData[i + 1].Split(',');
//設定點位
DotSpatial.Topology.Coordinate[] coord = new DotSpatial.Topology.Coordinate[Geometry.Length];
for (int j = 0; j < Geometry.Length; j++)
{
string[] Points = Geometry[j].Trim().Split(' ');
coord[j] = new DotSpatial.Topology.Coordinate(Convert.ToDouble(Points[0]), Convert.ToDouble(Points[1]));
}
DotSpatial.Topology.MultiPoint geom = new DotSpatial.Topology.MultiPoint(coord);
DotSpatial.Data.IFeature feature = fs.AddFeature(geom);
//設定MetaData資料
feature.DataRow.BeginEdit();
for (int j = 0; j < strColumn.Length; j++)
{
feature.DataRow[j] = ColumnData[j];
}
feature.DataRow.EndEdit();
}
fs.SaveAs(SaveFileName, true);
return "Success";
}
catch (Exception er)
{
return er.Message.ToString();
}
}
參數意義:
SaveFileName:要建立的檔案名稱含路徑
EpsgCode:要建立檔案的EpsgCode
GeometryText:Geometry的陣列資料
MetaData:屬性陣列資料
string[] GeometryText = new string[1];
string[] MetaData = new string[3];
MetaData[0] = "A,B,C";
MetaData[1] = "1,11,111";
GeometryText[0] = "MULTIPOINT ((120.674172658635 24.1101156784629), (120.669897953672 24.1081119105116))";
strResult = Cls_ShapeFile.CreateMultiPoint(@"多點.shp", 4326, GeometryText, MetaData);
結果圖如下:
沒有留言:
張貼留言