python地理数据处理_在 Python 中使用地理处理服务

与其他地理处理工具类似,地理处理服务器工具有一组固定的参数,这些参数为工具的执行提供所需的信息。在脚本中使用异步服务器工具时,可通过 Result 的 getOutput 方法对输出进行检索。

提示:

在下面的示例中,GetParameterValue 函数用于从服务器工具获取 FeatureSet 对象。此 FeatureSet 对象包含工具输入参数的模式。该 FeatureSet 对象随后随要素类加载,而服务器工具则在服务器上执行。脚本以使用 Result 对象的 getOutput 方法获取工具的输出而结束,然后使用 FeatureSet 的 save 方法将输出保存在本地。import arcpy

import time

# Add a toolbox from a server

arcpy.ImportToolbox("http://flame7/arcgis/services;GP/BufferByVal", "mytools")

# Use GetParameterValue to get a featureset object with the default

# schema of the first parameter of the tool 'bufferpoints'

inFeatureSet = arcpy.GetParameterValue("bufferpoints", 0)

# Load a shapefile into the featureset

inFeatureSet.load("c:/base/roads.shp")

# Run a server tool named BufferPoints with featureset created above

result = arcpy.BufferPoints_mytools(inFeatureSet, "5 feet")

# Check the status of the result object every 0.2 seconds until it has a value

# of 4 (succeeded) or greater

while result.status < 4:

time.sleep(0.2)

# Get the output FeatureSet back from the server and save to a local geodatabase

outFeatSet = result[0]

outFeatSet.save("c:/temp/base.gdb/towers_buffer")从服务器工具获取栅格数据结果

栅格数据结果以标记图像文件格式 (TIFF) 的形式返回。默认情况下,使用 getOutput 时,TIFF 将被写入到系统的 TEMP 文件夹。要控制 TIFF 的位置,请将 scratchWorkspace 环境设置为一个文件夹。import arcpy

import time

# Set the scratchworkspace to a folder.

arcpy.env.scratchWorkspace = "c:/temp/rasteroutput"

# Add a toolbox from a server

arcpy.ImportToolbox("http://flame7/arcgis/services;SlopeByVal", "mytools")

dem = "c:/dems/k_ne_g"

# Run a server tool named RunSlope

result = arcpy.RunSlope_mytools(dem)

# Check the status of the result object every 0.2 seconds until it has a value

# of 4 (succeeded) or greater

while result.status < 4:

print result.status

time.sleep(0.2)

# Raster output will be written to the scratchworkspace

outTIFF = result[0]获取地图影像

地理处理服务可包含结果地图服务,以创建任务结果的数字地图图像。数字地图包含向用户传达信息的地理数据集的直观表示。数字地图以图像形式(如 .jpeg)通过 Web 进行传输。与要素类中的原始要素相比,字节组成的地图图像中包含的信息更易于为人类所理解。地图图像也是易于管理的 - 可轻松地压缩,被分成易于管理的块,而且也建立了在 Web 上传输和查看图像的各种方法。

地图图像由 ArcGIS Server 地图服务创建,通过发布 ArcMap 文档 (.mxd) 而生成。鉴于地图图像的上述特征,您可能更希望为地理处理任务的结果创建一个地图图像,然后在 Web 上传输该图像,而不是传输一个或多个结果数据集。地理处理服务可包含一个 ArcGIS Server 结果地图服务,以创建输出数据的地图图像。import arcpy

import time

from urllib.request import urlretrieve

# Add a toolbox from a server

arcpy.ImportToolbox("http://flame7/arcgis/services;GP/BufferByVal", "mytools")

# Use GetParameterValue to get a featureset object with the default schema of the

# first parameter of the tool 'bufferpoints'

inFeatureSet = arcpy.GetParameterValue("bufferpoints", 0)

# Load a shapefile into the featureset

inFeatureSet.load("c:/base/roads.shp")

# Run a server tool named BufferPoints with featureset created above

result = arcpy.BufferPoints_mytools(inFeatureSet, "5 feet")

# Check the status of the result object every 0.2 seconds until it has a value

# of 4 (succeeded) or greater

while result.status < 4:

time.sleep(0.2)

print(result.status)

# Return a map service

mapimage = result.getMapImageURL(0)

# Use Python's urllib.request's urlretrieve method to copy the image locally

urlretrieve(mapimage, "c:/base/road_buffer.jpg")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值