本文整理汇总了Python中owslib.wms.WebMapService类的典型用法代码示例。如果您正苦于以下问题:Python WebMapService类的具体用法?Python WebMapService怎么用?Python WebMapService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebMapService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ncwms2
def test_ncwms2():
"""Test with an ncWMS2 server.
"""
# Note that this does not exercise the bug in https://github.com/geopython/OWSLib/issues/556
wms = WebMapService(NCWMS2_URL, version='1.3.0')
rsp = wms.getmap(
layers=['f33_thredds/min_temp'],
styles=['default'],
srs='CRS:84',
bbox=(-124.17, 46.02, -123.29, 46.38),
size=(256, 256),
format='image/png',
transparent=True,
mode='32bit',
)
assert type(rsp) is ResponseWrapper
assert "service=WMS" in wms.request
assert "version=1.3.0" in wms.request
assert "request=GetMap" in wms.request
assert "layers=f33_thredds/min_temp" in wms.request
assert "styles=default" in wms.request
assert "crs=CRS%3A84" in wms.request
assert "width=256" in wms.request
assert "height=256" in wms.request
assert "format=image%2Fpng" in wms.request
assert "transparent=TRUE" in wms.request
示例2: get_wms_image_size
def get_wms_image_size(self, layer_name, srs, min_x, min_y, max_x, max_y):
"""
Get the size of the png image returned for the current service url
| set service url | ${WMS_URL} |
| ${image_size_in_kb} | get wms image size | bathymetry | EPSG:4326 | -112 | 55 | -106 | 71 |
| ${greater_than_5kb} | ${image_size_in_kb} > 5 |
| Should Be True | ${greater_than_5kb} |
returns an integer which is the size of the image in kB
"""
wms = WebMapService(self._url, version=self._ogc_version)
img = wms.getmap(layers=[layer_name], srs=srs,
bbox=(float(min_x),
float(min_y),
float(max_x),
float(max_y)),
size=(300, 300), format='image/png')
out = open('test.png', 'wb')
out.write(img.read())
out.close()
f = open('test.png', 'rb')
size = os.path.getsize('test.png') / 1024
f.close()
os.remove('test.png')
return int(math.ceil(size))
示例3: test_ows_interfaces_wms
def test_ows_interfaces_wms():
wmsxml = open(resource_file('wms_JPLCapabilities.xml'), 'rb').read()
service = WebMapService('url', version='1.1.1', xml=wmsxml)
# Check each service instance conforms to OWSLib interface
service.alias = 'WMS'
isinstance(service, owslib.map.wms111.WebMapService_1_1_1)
# URL attribute
assert service.url == 'url'
# version attribute
assert service.version == '1.1.1'
# Identification object
assert hasattr(service, 'identification')
# Check all ServiceIdentification attributes
assert service.identification.type == 'OGC:WMS'
for attribute in ['type', 'version', 'title', 'abstract', 'keywords', 'accessconstraints', 'fees']:
assert hasattr(service.identification, attribute)
# Check all ServiceProvider attributes
for attribute in ['name', 'url', 'contact']:
assert hasattr(service.provider, attribute)
# Check all operations implement IOperationMetadata
for op in service.operations:
for attribute in ['name', 'formatOptions', 'methods']:
assert hasattr(op, attribute)
# Check all contents implement IContentMetadata as a dictionary
isinstance(service.contents, OrderedDict)
# Check any item (WCS coverage, WMS layer etc) from the contents of each service
# Check it conforms to IContentMetadata interface
# get random item from contents dictionary -has to be a nicer way to do this!
content = service.contents[list(service.contents.keys())[0]]
for attribute in ['id', 'title', 'boundingBox', 'boundingBoxWGS84', 'crsOptions', 'styles', 'timepositions']:
assert hasattr(content, attribute)
示例4: test_getmap_130_national_map
def test_getmap_130_national_map():
"""National Map"""
# TODO: use flaky tests or fix it: https://pypi.python.org/pypi/pytest-ignore-flaky
url = SERVICE_URL_NATIONAL_MAP
wms = WebMapService(url, version='1.3.0')
rsp = wms.getmap(
layers=['3'],
styles=['default'],
srs='CRS:84',
bbox=(-176.646, 17.7016, -64.8017, 71.2854),
size=(500, 300),
format='image/png',
transparent=True)
assert type(rsp) is ResponseWrapper
assert "service=WMS" in wms.request
assert "version=1.3.0" in wms.request
assert "request=GetMap" in wms.request
assert "layers=3" in wms.request
assert "styles=default" in wms.request
assert "crs=CRS%3A84" in wms.request
assert "box=-176.646%2C17.7016%2C-64.8017%2C71.2854" in wms.request
assert "width=500" in wms.request
assert "height=300" in wms.request
assert "format=image%2Fpng" in wms.request
assert "transparent=TRUE" in wms.request
示例5: HandleWMS
class HandleWMS():
def __init__(self, url, version="1.1.1"):
self.wms = WebMapService(url, version=version)
self.type = self.wms.identification.type
self.version = self.wms.identification.version
self.title = self.wms.identification.title
self.abstract = self.wms.identification.abstract
self.size = (256, 256)
def get_service_url(self, method='Get'):
return self.wms.getOperationByName('GetMap').methods[method]['url']
def get_format_options(self, format='image/png'):
formats = self.wms.getOperationByName('GetMap').formatOptions
if format in formats:
return format
else:
return formats
def get_srs(self, layer, srs='EPSG:4326'):
this_layer = self.wms[layer]
srs_list = this_layer.crsOptions
if srs in srs_list:
return srs
else:
return "SRS Not Found"
def get_bbox(self, layer):
this_layer = self.wms[layer]
return this_layer.boundingBoxWGS84
def do_layer_check(self, resource):
layer_list = list(self.wms.contents)
this_layer = resource.get("layer")
try:
first_layer = layer_list[0]
if this_layer in layer_list:
return this_layer
elif this_layer.lower() in layer_list:
return this_layer.lower()
else:
return first_layer
except Exception:
pass
def get_layer_info(self, data_dict):
layer = self.do_layer_check(data_dict)
bbox = self.get_bbox(layer)
srs = self.get_srs(layer)
format = self.get_format_options()
service_url = self.get_service_url()
return {
'layer': layer,
'bbox': bbox,
'srs': srs,
'format': format,
'service_url': service_url
}
示例6: addLayersFromWms
def addLayersFromWms(self):
"""Add new LayerDownloaders from the result of a WMS GetCapabilities
"""
wmsUrl = self.forgeOwsUrl('wms')
wms = WebMapService(wmsUrl, version='1.1.1')
layers = wms.items()
for l in layers:
self.addLayerDownloader(l[1])
return self.layerDownloaders
示例7: gui_addgeos
def gui_addgeos(self,website='http://wms.gsfc.nasa.gov/cgi-bin/wms.cgi?project=GEOS.fp.fcst.inst1_2d_hwl_Nx'):
'GUI handler for adding the figures from WMS support of GEOS'
from gui import Popup_list
try:
from owslib.wms import WebMapService
from owslib.util import openURL
from StringIO import StringIO
from PIL import Image
self.line.tb.set_message('Loading WMS from :'+website.split('/')[2])
wms = WebMapService(website)
cont = list(wms.contents)
except Exception as ie:
print ie
import tkMessageBox
tkMessageBox.showwarning('Sorry','Loading WMS map file from '+website.split('/')[2]+' servers not working...')
return
titles = [wms[c].title for c in cont]
arr = [x.split('-')[-1]+': '+y for x,y in zip(cont,titles)]
i = Popup_list(arr)
self.line.tb.set_message('Selected WMS map: '+titles[i].split(',')[-1])
if wms[cont[i]].timepositions:
times = wms[cont[i]].timepositions
j = Popup_list(times)
time_sel = times[j]
else:
time_sel = None
try:
if not time_sel:
time_sel = self.line.ex.datestr+'T12:00'
ylim = self.line.line.axes.get_ylim()
xlim = self.line.line.axes.get_xlim()
#img = wms.getdata(layers=[cont[i]],
# bbox=(ylim[0],xlim[0],ylim[1],xlim[1]),
# size=(480,240),
# transparent=True,
# time=time_sel,
# srs='EPSG:4326',
# format='image/png')
#leg_call = openURL(img.geturl().replace('GetMap','GetLegend'))
img = wms.getdata(layers=[cont[i],'countries'],
bbox=(ylim[0],xlim[0],ylim[1],xlim[1]),
size=(480,240),
transparent=True,
time=time_sel,
srs='EPSG:4326',
format='image/png')
geos = Image.open(StringIO(img.read()))
self.line.addfigure_under(geos,xlim[0],ylim[0],xlim[1],ylim[1])
#self.line.line.figure.add
#leg = Image.open(StringIO(leg_call.read()))
#self.line.addfigure_under(leg,xlim[0],ylim[0],xlim[1],ylim[1],outside=True)
except:
import tkMessageBox
tkMessageBox.showwarning('Sorry','Problem getting the image to load')
return
示例8: generate_preview_image
def generate_preview_image(self, styles=None):
wms = WebMapService(self.wms.online_resource)
img = wms.getmap(layers=[self.name],
srs='EPSG:4326',
bbox=self.latlon_bbox,
size=(300,250), # TODO: Calculate optimum size for preview image at this approx size
format='image/jpeg',
transparent=True)
out = open(('%s.jpg' % (self.name)), 'wb')
out.write(img.read())
out.close()
示例9: build_wms_image
def build_wms_image(bbox):
url = "%s/wms" % settings.GEOSERVER_BASE_URL
wms = WebMapService(url, version='1.1.1')
img = wms.getmap(layers=['haiti'],
srs='EPSG:4326',
bbox=bbox,
size=(1400, 700),
bgcolor="#b5d0d0",
format='image/jpeg',
transparent=True)
return img
示例10: test_wms_getmap_130
def test_wms_getmap_130():
"""GetMap 1.3.0"""
wms = WebMapService(SERVICE_URL, version='1.3.0')
rsp = wms.getmap(
layers=['nexrad_base_reflect'],
styles=['default'],
srs='EPSG:4326',
bbox=(-126, 24, -66, 50),
size=(250, 250),
format='image/jpeg',
transparent=True)
assert type(rsp) is ResponseWrapper
示例11: test_wms_getmap_111
def test_wms_getmap_111():
"""MESONET GetMap 1.1.1"""
wms = WebMapService(SERVICE_URL, version='1.1.1')
assert wms.request == '{}?service=WMS&request=GetCapabilities&version=1.1.1'.format(SERVICE_URL)
rsp = wms.getmap(
layers=['nexrad_base_reflect'],
styles=['default'],
srs='EPSG:4326',
bbox=(-126, 24, -66, 50),
size=(250, 250),
format='image/jpeg',
transparent=True)
import owslib.util
assert type(rsp) is ResponseWrapper
示例12: check_advertised_wms_layers
def check_advertised_wms_layers(self):
"""
Makes a GetMap request for each layer advertised by WMS service.
An exception is raised on failure.
| Check advertised wms layers |
"""
wms = WebMapService(self._url, version=self._ogc_version)
for layer in wms.contents.values():
wms.getmap(
layers=[layer.name],
srs=layer.crsOptions[0],
bbox=layer.boundingBox[0:-1],
size=(300, 300),
format=wms.getOperationByName('GetMap').formatOptions[0])
示例13: get_layer
def get_layer(layer_name):
wms = WebMapService('http://geoserver.gis.irisnetlab.be/geoserver/wfs', version="1.3")
kml = wms.getmap(
layers=[layer_name],
srs="epsg:4326",
bbox=wms[layer_name].boundingBox[:-1],
size=(3000, 3000),
format='kml',
transparent=True
).read()
return kml
示例14: __init__
def __init__(self, url, version="1.1.1"):
self.wms = WebMapService(url, version=version)
self.type = self.wms.identification.type
self.version = self.wms.identification.version
self.title = self.wms.identification.title
self.abstract = self.wms.identification.abstract
self.size = (256, 256)
示例15: test_wms_getmap_130_service_exception
def test_wms_getmap_130_service_exception():
"""GetMap 1.3.0 ServiceException for an invalid CRS"""
wms = WebMapService(SERVICE_URL, version='1.3.0')
try:
wms.getmap(
layers=['nexrad_base_reflect'],
styles=['default'],
srs='EPSG:4328',
bbox=(-126, 24, -66, 50),
size=(250, 250),
format='image/jpeg',
transparent=True)
except ServiceException as e:
assert "msWMSLoadGetMapParams(): WMS server error. Invalid CRS given : CRS must be valid for all requested layers." in str(e) # noqa
else:
assert False