ArcPy中;使用XY创建点并正确显示它们

时间:2018-04-16 14:03:01

标签: python arcpy

我有一个python脚本可以为要素类添加点。这些点具有XY值,但它们不会显示它们在地图上的位置。我已经阅读了Adding new record with specific coordinates into shapefile using ArcGIS for Desktop?,所以我理解为什么它不起作用。我知道我可以将FC导出到表格,显示XY数据并保存到shapefile。我的问题是,这一切都可以在python脚本中自动完成,如果是这样,当我运行脚本添加另一个点时,最后会发生什么?

我也尝试过使用arcpy.MakeXYEventLayer_management和arcpy.SaveToLayerFile_management,但似乎没有出现任何内容。我会感激任何回复我的人提出一些建议。 谢谢

以下是我尝试的代码;

import arcpy, os
arcpy.env.workspace = r'F:\MyWork\Assignment\folklore.gdb'

arcpy.MakeXYEventLayer_management('Folklore', 'x_coord', 'y_coord', 'folklore_Layer', "PROJCS['IRENET95_Irish_Transverse_Mercator',GEOGCS['GCS_IRENET95',DATUM['D_IRENET95',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',600000.0],PARAMETER['False_Northing',750000.0],PARAMETER['Central_Meridian',-8.0],PARAMETER['Scale_Factor',0.99982],PARAMETER['Latitude_Of_Origin',53.5],UNIT['Meter',1.0]];-5022200 -15179500 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision", '#')
save_output = r'F:\MyWork\Assignment\studyquadsLyr.lyr'
save_output2 = r'F:\MyWork\Assignment\folklore.gdb/folklore'
arcpy.SaveToLayerFile_management('folklore_Layer', save_output)
arcpy.Delete_management(r'F:\MyWork\Assignment\folklore.gdb/folklore')
arcpy.CopyFeatures_management('studyquadsLyr.lyr', save_output2) 

1 个答案:

答案 0 :(得分:0)

搞定了。问题是我试图保存事件层。似乎你不必。这是代码;

import arcpy, os
arcpy.env.workspace = r'F:\MyProject\Assignment\folklore.gdb'

arcpy.MakeXYEventLayer_management('Folklore', 'x_coord', 'y_coord', 'folklore_Layer', "PROJCS['IRENET95_Irish_Transverse_Mercator',GEOGCS['GCS_IRENET95',DATUM['D_IRENET95',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',600000.0],PARAMETER['False_Northing',750000.0],PARAMETER['Central_Meridian',-8.0],PARAMETER['Scale_Factor',0.99982],PARAMETER['Latitude_Of_Origin',53.5],UNIT['Meter',1.0]];-5022200 -15179500 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision", '#')

# run this once without the Delete line to create the shp file. From then on
# you delete the shp file in order to replace it with the new shp file plus the extra record.
arcpy.Delete_management(r'F:\EGM722 - Customising GIS apps\Assignment\test_shp.shp')
arcpy.FeatureClassToFeatureClass_conversion("folklore_Layer", "F:\EGM722 - Customising GIS apps\Assignment", "test_shp") 
相关问题