AE Add XY Data(转)
读入文件,然后选择X、Y字段,再创建一个新的Feaclass,根据每一行的数据创建feature,添加到featureclass,另外,要根据文件属性打开文件,如excel、txt等。
调用GP里面的make xy event layer工具:
Dim MxyLyr As MakeXYEventLayer = New MakeXYEventLayer MxyLyr.table = Application.StartupPath & "\shiyan.txt" MxyLyr.in_x_field = "x坐标" MxyLyr.in_y_field = "y坐标" MxyLyr.out_layer = "Temp" GP.Execute(MxyLyr, Nothing)
C#实现:
public IFeatureClass CreateXYEventSource(ITable table, ISpatialReference spatialReference) {
// Create and populate the XY Event2Fields Properties object.
IXYEvent2FieldsProperties xyEvent2FieldsProperties = new XYEvent2FieldsPropertiesClass(); xyEvent2FieldsProperties.XFieldName = "X";
xyEvent2FieldsProperties.YFieldName = "Y"; // xyEvent2FieldsProperties.ZFieldName = "Z"; // This property is optional. // Get a name object for the source table. IDataset sourceDataset = (IDataset)table; IName sourceName = sourceDataset.FullName; // Create an event source name using the properties and the spatial reference. IXYEventSourceName xyEventSourceName = new XYEventSourceNameClass(); xyEventSourceName.EventProperties = xyEvent2FieldsProperties;
xyEventSourceName.EventTableName = sourceName;
xyEventSourceName.SpatialReference = spatialReference; // Create the XY event source. IName name = (IName)xyEventSourceName; IXYEventSource xyEventSource = (IXYEventSource)name.Open(); // Cast the event source to the IFeatureClass interface. IFeatureClass featureClass = (IFeatureClass)xyEventSource; return featureClass; }
更多GIS开发相关问题请加入 GIS开发学习QQ交流群 192251607 共同交流学习!

浙公网安备 33010602011771号