设置HTTP代理选项前取Web数据源

设置HTTP代理选项前取Web数据源
发布日期: 2016-10-06 更新日期: 1970-01-01 编辑:yubiao 浏览次数: 2837

 import sys

try:
    from osgeo import ogr, osr, gdal
except:
    sys.exit('ERROR: cannot find GDAL/OGR modules')

server = 'proxy.example.com'
port = 3128

# specify proxy server
gdal.SetConfigOption('GDAL_HTTP_PROXY', server + ':' + port)

# setup proxy authentication option for NTLM with no username or password so single sign-on works
gdal.SetConfigOption('GDAL_PROXY_AUTH', 'NTLM')
gdal.SetConfigOption('GDAL_HTTP_PROXYUSERPWD', ' : ')

# now fetch a HTTP datasource and do something...
ds = ogr.Open('http://featureserver/cities/.geojson')
if not ds:
    sys.exit('ERROR: can not open GeoJSON datasource')
lyr = ds.GetLayer('OGRGeoJSON')
for feat in lyr:
    geom = feat.GetGeometryRef()
    print geom.ExportToWkt()
说明:

这个方法的设置选项的一个HTTP代理服务,使用NTLM身份验证(企业环境,使用Active Directory中的单点登录代理服务器支持的典型)。关于GDAL的HTTP代理服务器选项的更多信息可以在这里找到