使用ArcPy实现创建ags文件
目录
ArcPy创建ags文件
由于项目需要,在项目开发过程中,需要自己生成一个ags文件,ags文件是ESRI用来保存ArcGIS Server连接信息的文件。故本人根据ArcPy接口,通过Toolbox实现ArcGIS Server文件的自动生成。
ToolBox界面如下图所示:
在执行过程中用到的脚本语言:
def create_ags(server_url, username, password,out_folder_path):
out_name = Domain2IP(server_url)
use_arcgis_desktop_staging_folder = False
if not os.path.exists(out_folder_path):
os.makedirs(out_folder_path)
postfix = '.ags'
analysis =arcpy.mapping.CreateGISServerConnectionFile("ADMINISTER_GIS_SERVICES", out_folder_path, out_name + postfix server_url, 'ARCGIS_SERVER', use_arcgis_desktop_staging_folder, out_folder_path,
username, password, 'SAVE_USERNAME')
def Domain2IP(url):
try:
pattern = re.compile(r'\d+[\.]\d+[\.]\d+[\.]\d+')
if re.findall(pattern, url):
hostname = url.split('/')[2]
return hostname[0 : hostname.index(':')]
else:
hostname = url.split('/')[2]
return socket.gethostbyname(hostname)
except:
print 'Error'
执行后的结果展示:
执行本ToolBox所需环境:
- ArcGIS Desktop
- ArcGIS Pro
资源
- GitHub Help
- Learn more about ArcGIS Solutions.
- Learn more about ArcGIS Pro for ArcPy.
- Learn more about ArcGIS for ArcPy.
- Learn more about Python
注:源码查看DataShare
转载自:https://blog.csdn.net/xzwspy/article/details/78988467