def test_wmts_rest_only(): # ServiceMetadata wmts = WebMapTileService(SERVICE_URL) assert wmts.identification.type == 'OGC WMTS' assert wmts.identification.version == '1.0.0' assert wmts.identification.title == 'WMTS-Testserver DOP80' # Content assert sorted(list(wmts.contents)) == ['dop80'] # RESTful WMTS assert wmts.restonly resource = wmts.buildTileResource(layer='dop80', tilematrixset='webmercator', tilematrix='11', row='706', column='1089') assert resource == 'http://geoserv.weichand.de/mapproxy/wmts/dop80/webmercator/11/1089/706.png' tile = wmts.gettile(layer='dop80', tilematrixset='webmercator', tilematrix='11', row='706', column='1089') out = open(scratch_file('bvv_bayern_dop80.png'), 'wb') bytes_written = out.write(tile.read()) out.close()
def request(self, service): try: if service == 'WMS': self.resp['resp'] = WebMapService( "https://data.linz.govt.nz/services;" "key=" + self.key + "/wms/", version='1.1.1') return if service == 'WMTS': self.resp['resp'] = WebMapTileService( "https://data.linz.govt.nz/services;" "key=" + self.key + "/wmts/1.0.0/WMTSCapabilities.xml?" "count=10", version='1.0.0') return if service == 'WFS': self.resp['resp'] = WebFeatureService( "https://data.linz.govt.nz/services;" "key=" + self.key + "/wfs/?" "service=WFS&" "request=GetCapabilities", version='1.1.0') return except: self.resp[ 'err'] = "ERROR: Something went wrong with the request. Timeout? Incorrect API KEY?"
def update_layers_wmts(service): """ Update layers for an OGC_WMTS service. """ wmts = WebMapTileService(service.url) layer_names = list(wmts.contents) for layer_name in layer_names: ows_layer = wmts.contents[layer_name] print 'Updating layer %s' % ows_layer.name layer, created = Layer.objects.get_or_create(name=ows_layer.name, service=service) if layer.active: layer.title = ows_layer.title layer.abstract = ows_layer.abstract layer.url = service.url layer.page_url = reverse('layer_detail', kwargs={'layer_id': layer.id}) bbox = list(ows_layer.boundingBoxWGS84 or (-179.0, -89.0, 179.0, 89.0)) layer.bbox_x0 = bbox[0] layer.bbox_y0 = bbox[1] layer.bbox_x1 = bbox[2] layer.bbox_y1 = bbox[3] layer.save() # dates add_mined_dates(layer)
def connectToDGTile(config): return WebMapTileService( "https://evwhs.digitalglobe.com/earthservice/wmtsaccess?connectid=" + config['connectid'], username=config['uname'], password=config['passwd'], version='1.1.1')
def check_wmts(source, info_msgs, warning_msgs, error_msgs): """ Check WMTS source Parameters ---------- source : dict Source dictionary info_msgs : list Good messages warning_msgs: list Warning messages error_msgs: list: Error Messages """ try: wmts_url = source["properties"]["url"] if not validators.url(wmts_url): error_msgs.append(f"URL validation error: {wmts_url}") with warnings.catch_warnings(): warnings.simplefilter("ignore") WebMapTileService(wmts_url) except Exception as e: error_msgs.append(f"Exception: {e}")
def wmtsRequest(self, layer='AGRICULTURE'): self.layer = layer ID = 'your ID' wmts_url = 'https://services.sentinel-hub.com/ogc/wmts/'+ID wmts = WebMapTileService(wmts_url) self.x, self.y = self.deg2num(self.lat_center, self.lon_center, self.zoom) self.wmtsOut = wmts.gettile(layer=self.layer, tilematrixset='PopularWebMercator256', tilematrix=self.zoom, row=self.y, column=self.x, format="image/png") self.imgArr = imread(io.BytesIO(wmtsOut.read())) self.lat_max, self.lon_min = self.num2deg(self.x, self.y, self.zoom) self.lat_min, self.lon_max = self.num2deg(self.x+1, self.y+1, self.zoom) imgurl = image_to_url(image=self.imgArr) self.map.add_layer(ImageOverlay(url=imgurl, bounds=[[self.lat_min, self.lon_min], [self.lat_max, self.lon_max]]))
def test_wmts(): # Find out what a WMTS has to offer. Service metadata: wmts = WebMapTileService(SERVICE_URL) assert wmts.identification.type == 'OGC WMTS' assert wmts.identification.version == '1.0.0' assert wmts.identification.title == 'NASA Global Imagery Browse Services for EOSDIS' bytearray(wmts.identification.abstract, 'utf-8') bytearray(b'Near real time imagery from multiple NASA instruments') assert wmts.identification.keywords == ['World', 'Global'] # Service Provider: assert wmts.provider.name == 'National Aeronautics and Space Administration' assert wmts.provider.url == 'https://earthdata.nasa.gov/' # Available Layers: assert len(wmts.contents.keys()) > 0 assert sorted(list(wmts.contents))[0] == 'AIRS_CO_Total_Column_Day' # Fetch a tile (using some defaults): tile = wmts.gettile(layer='MODIS_Terra_CorrectedReflectance_TrueColor', tilematrixset='EPSG4326_250m', tilematrix='0', row=0, column=0, format="image/jpeg") out = open(scratch_file('nasa_modis_terra_truecolour.jpg'), 'wb') bytes_written = out.write(tile.read()) out.close() # Test styles for several layers # TODO: fix dict order # assert wmts.contents['MLS_SO2_147hPa_Night'].styles == {'default': {'isDefault': True, 'title': 'default'}} assert wmts.contents['MLS_SO2_147hPa_Night'].styles['default'][ 'isDefault'] is True # assert wmts.contents['MLS_SO2_147hPa_Night'].styles == {'default': {'isDefault': True, 'title': 'default'}} assert wmts.contents['MLS_SO2_147hPa_Night'].styles['default'][ 'isDefault'] is True
def test_wmts_rest_only(): # Test a WMTS with REST only from owslib.wmts import WebMapTileService wmts = WebMapTileService(SERVICE_URL_REST) tile = wmts.gettile(layer="bmaporthofoto30cm", tilematrix="10", row=357, column=547) assert (tile.info()['Content-Type'] == 'image/jpeg')
def test_wmts_server(ows_server): # Use owslib to confirm that we have a somewhat compliant WCS service wmts = WebMapTileService(url=ows_server.url + "/wmts") assert wmts.identification.type == "OGC WMTS" assert wmts.identification.version == "1.0.0" # Ensure that we have at least some layers available contents = list(wmts.contents) assert contents
def test_wmts_example_build_tile_request(): """ Example for wmts.buildTileRequest """ wmts = WebMapTileService(SERVICE_URL) wmts.buildTileRequest(layer='VIIRS_CityLights_2012', tilematrixset='EPSG4326_500m', tilematrix='6', row=4, column=4) request = 'SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&\
def __init__(self, wmts, layer=None, tms=None, tm=None, fmt=None, pixel_size=_PIXEL_SIZE): # Web Map Tile Service self.wmts = WebMapTileService(wmts) if layer is None: layer = next(iter(self.wmts.contents)) self.layer = self.wmts.contents[layer] if tms is None: tms = next(iter(self.wmts.tilematrixsets)) self.tms = self.wmts.tilematrixsets[tms] if tm is None: tm = next(iter(self.tms.tilematrix)) self.tm = self.tms.tilematrix[tm] # CRS self.crs = pp.CRS.from_user_input(self.tms.crs) self.epsg = ':'.join(self.crs.to_authority()) self._from_wgs = pp.Transformer.from_crs(_WGS84, self.crs) self._to_wgs = pp.Transformer.from_crs(self.crs, _WGS84) self.unit = self.crs.coordinate_system.axis_list[0].unit_name self.ucf = self.crs.coordinate_system.axis_list[ 0].unit_conversion_factor # Tile span(s) self.pixel_size = pixel_size self.scale = self.tm.scaledenominator self.pixel_span = self.scale * self.pixel_size * self.ucf self.tile_width = self.tm.tilewidth self.tile_height = self.tm.tileheight self.tile_span_x = self.tile_width * self.pixel_span self.tile_span_y = self.tile_height * self.pixel_span # Domain self.matrix_width = self.tm.matrixwidth self.matrix_height = self.tm.matrixheight self.x_min, self.y_max = self.tm.topleftcorner self.x_max = self.x_min + self.matrix_width * self.tile_span_x self.y_min = self.y_max - self.matrix_height * self.tile_span_y # Format self.fmt = self.layer.formats[0] if fmt is None else fmt
def test_wmts_example_get_title(): """ Example for wmts.getTitle """ wmts = WebMapTileService(SERVICE_URL) img = wmts.gettile(layer='VIIRS_CityLights_2012', tilematrixset='EPSG4326_500m', tilematrix='6', row=4, column=4) out = open('tile.jpg', 'wb') bytes_written = out.write(img.read()) out.close()
def get_map(lon_min, lon_max, lat_min, lat_max, zoom=19): """ Get an ESRI World Imagery map of the selected region Args: lon_min: Minimum longitude (degrees) lon_max: Maximum longitude (degrees) lat_min: Minimum latitude (degrees) lat_max: Maximum latitude (degrees) zoom: Zoom level Returns: np.array: Numpy array which can be plotted with plt.imshow """ upperleft_tile = mercantile.tile(lon_min, lat_max, zoom) xmin, ymin = upperleft_tile.x, upperleft_tile.y lowerright_tile = mercantile.tile(lon_max, lat_min, zoom) xmax, ymax = lowerright_tile.x, lowerright_tile.y total_image = np.zeros([256 * (ymax - ymin + 1), 256 * (xmax - xmin + 1), 3], dtype='uint8') os.makedirs("tilecache", exist_ok=True) tile_min = mercantile.tile(lon_min, lat_min, zoom) tile_max = mercantile.tile(lon_max, lat_max, zoom) wmts = WebMapTileService("http://server.arcgisonline.com/arcgis/rest/" + "services/World_Imagery/MapServer/WMTS/1.0.0/WMTSCapabilities.xml") for x in range(tile_min.x, tile_max.x + 1): for y in range(tile_max.y, tile_min.y + 1): tilename = os.path.join("tilecache", f"World_Imagery_{zoom}_{x}_{y}.jpg") if not os.path.isfile(tilename): tile = wmts.gettile(layer="World_Imagery", tilematrix=str(zoom), row=y, column=x) out = open(tilename, "wb") out.write(tile.read()) out.close() tile_image = imread(tilename) total_image[(y - ymin) * 256: (y - ymin + 1) * 256, (x - xmin) * 256: (x - xmin + 1) * 256] = tile_image total_llmin = {'lon': mercantile.bounds(xmin, ymax, zoom).west, 'lat': mercantile.bounds(xmin, ymax, zoom).south} total_llmax = {'lon': mercantile.bounds(xmax, ymin, zoom).east, 'lat': mercantile.bounds(xmax, ymin, zoom).north} pix_xmin = int(round(np.interp(lon_min, [total_llmin['lon'], total_llmax['lon']], [0, total_image.shape[1]]))) pix_ymin = int(round(np.interp(lat_min, [total_llmin['lat'], total_llmax['lat']], [0, total_image.shape[0]]))) pix_xmax = int(round(np.interp(lon_max, [total_llmin['lon'], total_llmax['lon']], [0, total_image.shape[1]]))) pix_ymax = int(round(np.interp(lat_max, [total_llmin['lat'], total_llmax['lat']], [0, total_image.shape[0]]))) return total_image[total_image.shape[0] - pix_ymax: total_image.shape[0] - pix_ymin, pix_xmin: pix_xmax]
async def check_wmts(source, session): """ Check WMTS source Parameters ---------- source : dict Source dictionary session : ClientSession aiohttp ClientSession object Returns ------- list: Good messages list: Warning messages list: Error Messages """ error_msgs = [] warning_msgs = [] info_msgs = [] try: wmts_url = source["properties"]["url"] headers = get_http_headers(source) if not validators.url(wmts_url): error_msgs.append("URL validation error: {}".format(wmts_url)) with warnings.catch_warnings(): warnings.simplefilter("ignore") response = await get_url(wmts_url, session, with_text=True, headers=headers) if response.exception is not None: error_msgs.append(response.exception) return info_msgs, warning_msgs, error_msgs xml = response.text wmts = WebMapTileService(wmts_url, xml=xml.encode("utf-8")) info_msgs.append("Good") except Exception as e: error_msgs.append("Exception: {}".format(str(e))) return info_msgs, warning_msgs, error_msgs
def mundi_wmts(self, dataset: str, version: str = "1.0.0") -> WebMapTileService: """ Get a WebMapTileService instance for this collection :param dataset: the target dataset (eg, "L1C" if collection is "Sentinel1" :param version: WMTS version (only 1.0.0 is supported) :return: a WebMapTileService instance """ if version in ["1.0.0"]: return WebMapTileService(self._service_end_point('wmts', dataset), version) else: raise MundiException(ErrorMessages.UNSUPPORTED_SERVICE)
def test_wmts_gettile(ows_server): wmts = WebMapTileService(url=ows_server.url + "/wmts") contents = list(wmts.contents) test_layer_name = contents[0] tile = wmts.gettile(layer=test_layer_name, tilematrixset='WholeWorld_WebMercator', tilematrix='0', row=0, column=0, format="image/png") assert tile assert tile.info()['Content-Type'] == 'image/png'
def test_wmts_tile_caching(): image_cache = WMTSRasterSource._shared_image_cache image_cache.clear() assert len(image_cache) == 0 url = 'https://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi' wmts = WebMapTileService(url) layer_name = 'MODIS_Terra_CorrectedReflectance_TrueColor' source = WMTSRasterSource(wmts, layer_name) gettile_counter = CallCounter(wmts, 'gettile') crs = ccrs.PlateCarree() extent = (-180, 180, -90, 90) resolution = (20, 10) with gettile_counter: source.fetch_raster(crs, extent, resolution) n_tiles = 2 assert gettile_counter.count == n_tiles, ('Too many tile requests - ' 'expected {}, got {}.'.format( n_tiles, gettile_counter.count) ) gc.collect() assert len(image_cache) == 1 assert len(image_cache[wmts]) == 1 tiles_key = (layer_name, '0') assert len(image_cache[wmts][tiles_key]) == n_tiles # Second time around we shouldn't request any more tiles so the # call count will stay the same. with gettile_counter: source.fetch_raster(crs, extent, resolution) assert gettile_counter.count == n_tiles, ('Too many tile requests - ' 'expected {}, got {}.'.format( n_tiles, gettile_counter.count) ) gc.collect() assert len(image_cache) == 1 assert len(image_cache[wmts]) == 1 tiles_key = (layer_name, '0') assert len(image_cache[wmts][tiles_key]) == n_tiles # Once there are no live references the weak-ref cache should clear. del source, wmts, gettile_counter gc.collect() assert len(image_cache) == 0
def update_layers_wmts(service): """ Update layers for an OGC:WMTS service. """ wmts = WebMapTileService(service.url) layer_names = list(wmts.contents) for layer_name in layer_names: ows_layer = wmts.contents[layer_name] print 'Updating layer %s' % ows_layer.name layer, created = Layer.objects.get_or_create(name=ows_layer.name, service=service) if layer.active: links = [['OGC:WMTS', service.url]] layer.type = 'OGC:WMTS' layer.title = ows_layer.title layer.abstract = ows_layer.abstract # keywords for keyword in ows_layer.keywords: layer.keywords.add(keyword) layer.url = service.url layer.page_url = reverse('layer_detail', kwargs={'layer_id': layer.id}) links.append([ 'WWW:LINK', settings.SITE_URL.rstrip('/') + layer.page_url ]) bbox = list(ows_layer.boundingBoxWGS84 or (-179.0, -89.0, 179.0, 89.0)) layer.bbox_x0 = bbox[0] layer.bbox_y0 = bbox[1] layer.bbox_x1 = bbox[2] layer.bbox_y1 = bbox[3] layer.wkt_geometry = bbox2wktpolygon(bbox) layer.xml = create_metadata_record( identifier=layer.id_string, source=service.url, links=links, format='OGC:WMS', type=layer.csw_type, relation=service.id_string, title=ows_layer.title, alternative=ows_layer.name, abstract=layer.abstract, keywords=ows_layer.keywords, wkt_geometry=layer.wkt_geometry ) layer.anytext = gen_anytext(layer.title, layer.abstract, ows_layer.keywords) layer.save() # dates add_mined_dates(layer)
def test_wmts_gettile_wkss(ows_server): wmts = WebMapTileService(url=ows_server.url + "/wmts") contents = list(wmts.contents) test_layer_name = contents[0] tile = wmts.gettile( layer=test_layer_name, tilematrixset="urn:ogc:def:wkss:OGC:1.0:GoogleMapsCompatible", tilematrix="0", row=0, column=0, format="image/png", ) assert tile assert tile.info()["Content-Type"] == "image/png"
def test_wmts_gettile_exception(ows_server): wmts = WebMapTileService(url=ows_server.url + "/wmts") contents = list(wmts.contents) test_layer_name = contents[0] try: # supplying an unsupported tilematrixset wmts.gettile(layer=test_layer_name, tilematrixset='WholeWorld_WebMercatorxxx', tilematrix='0', row=0, column=0, format="image/png") except ServiceException as e: assert 'Invalid Tile Matrix Set:' in str(e) else: assert False
def get_service_obj(self): try: if self.service == "wmts": self.obj = WebMapTileService( url=None, xml=self.xml, version=self.version, ) elif self.service == "wfs": self.obj = WebFeatureService( url=None, xml=self.xml, version=self.version, ) except XMLSyntaxError: # most likely the locally stored xml is corrupt self.err = "{0}: XMLSyntaxError".format(self.domain)
def test_wmts_tile_caching(): image_cache = WMTSRasterSource._shared_image_cache image_cache.clear() assert len(image_cache) == 0 url = 'https://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi' wmts = WebMapTileService(url) layer_name = 'MODIS_Terra_CorrectedReflectance_TrueColor' source = WMTSRasterSource(wmts, layer_name) crs = ccrs.PlateCarree() extent = (-180, 180, -90, 90) resolution = (20, 10) n_tiles = 2 with mock.patch.object(wmts, 'gettile', wraps=wmts.gettile) as gettile_counter: source.fetch_raster(crs, extent, resolution) assert gettile_counter.call_count == n_tiles, ( f'Too many tile requests - expected {n_tiles}, got ' f'{gettile_counter.call_count}.') del gettile_counter gc.collect() assert len(image_cache) == 1 assert len(image_cache[wmts]) == 1 tiles_key = (layer_name, '0') assert len(image_cache[wmts][tiles_key]) == n_tiles # Second time around we shouldn't request any more tiles. with mock.patch.object(wmts, 'gettile', wraps=wmts.gettile) as gettile_counter: source.fetch_raster(crs, extent, resolution) gettile_counter.assert_not_called() del gettile_counter gc.collect() assert len(image_cache) == 1 assert len(image_cache[wmts]) == 1 tiles_key = (layer_name, '0') assert len(image_cache[wmts][tiles_key]) == n_tiles # Once there are no live references the weak-ref cache should clear. del source, wmts gc.collect() assert len(image_cache) == 0
def loadServiceList(self, service_id: int): self.iFace.messageBar().pushMessage('Info: ', 'Please wait loading layers ... ', level=Qgis.Info) self.bar.show() self.iFace.mainWindow().repaint() self.generatedService = WebMapServiceClass(service_id) url = self.generatedService.service_url if self.generatedService.service_type == ServiceType.WebMapService.value: try: wms = WebMapService(url) self.generatedService.setWebMapService(wms) except Exception as e: QMessageBox.information(None, "ERROR:", 'Unable to load this service now.' + str(e)) elif self.generatedService.service_type == ServiceType.WebMapTileService.value: try: wmts = WebMapTileService(url) self.generatedService.setWebMapService(wmts) except Exception as e: QMessageBox.information(None, "ERROR:", 'Unable to load this service now.' + str(e)) self.bar.close()
def main(): # URL of NASA GIBS URL = 'http://gibs.earthdata.nasa.gov/wmts/epsg4326/best/wmts.cgi' wmts = WebMapTileService(URL) # Layers for MODIS true color and snow RGB layers = [ 'MODIS_Terra_SurfaceReflectance_Bands143', 'MODIS_Terra_CorrectedReflectance_Bands367' ] date_str = '2017-12-07' # Plot setup plot_CRS = ccrs.Mercator() geodetic_CRS = ccrs.Geodetic() x0, y0 = plot_CRS.transform_point(3.7, 43.9, geodetic_CRS) x1, y1 = plot_CRS.transform_point(22.5, 50.8, geodetic_CRS) ysize = 8 xsize = 2 * ysize * (x1 - x0) / (y1 - y0) fig = plt.figure(figsize=(xsize, ysize), dpi=100) for layer, offset in zip(layers, [0, 0.5]): ax = plt.axes([offset, 0, 0.5, 1], projection=plot_CRS) ax.set_xlim((x0, x1)) ax.set_ylim((y0, y1)) ax.add_wmts(wmts, layer, wmts_kwargs={'time': date_str}) txt = plt.text(4.7, 43.2, wmts[layer].title, fontsize=18, color='wheat', transform=geodetic_CRS) txt.set_path_effects( [PathEffects.withStroke(linewidth=5, foreground='black')]) state_boundaries = feat.NaturalEarthFeature(category='cultural', name='admin_0_countries', scale='10m', facecolor='none') ax.coastlines(resolution='10m', zorder=1, color='black') ax.add_feature(state_boundaries, zorder=1, edgecolor='black') plt.show()
def get_data(self, element, ranges, style): if WebMapTileService is None: raise SkipRendering('WMTS element requires owslib and PIL ' 'to be installed.') tile_source = None for url in element.data: if isinstance(url, util.basestring): try: tile_source = WebMapTileService(url) break except: pass elif isinstance(url, WebMapTileService): tile_source = url break if tile_source is None: raise SkipRendering("No valid tile source URL found in WMTS " "Element, rendering skipped.") return (tile_source, element.layer), style, {}
def wmts_metadata(wmts_url): """Discover what's available""" from owslib.wmts import WebMapTileService wmts = WebMapTileService(wmts_url) tilematrixsets = {} for identifier, tilematrix in wmts.tilematrixsets.items(): # Store information of identifier and associated crs zooms = [int(key) for key in tilematrix.tilematrix] tilematrixsets[identifier] = { "crs" : tilematrix.crs, "min_zoom" : min(zooms), "max_zoom" : max(zooms), } provider_metadata = {} for name, variant in wmts.contents.items(): d = defaultdict(list) for attribute in ("formats", "layers"): for key in getattr(variant, attribute): d[attribute].append(key) for style in variant.styles: if style is None: d["styles"].append("default") else: d["styles"].append(style) for url in variant.resourceURLs: d["url"].append(url["template"]) for identifier in variant._tilematrixsets: d["tilematrixset"].append(identifier) d["bboxWGS84"] = variant.boundingBoxWGS84 provider_metadata[name] = d return provider_metadata, tilematrixsets
def main_vis(): # URL of NASA GIBS URL = 'http://gibs.earthdata.nasa.gov/wmts/epsg4326/best/wmts.cgi' wmts = WebMapTileService(URL) # Layers for MODIS true color and snow RGB layers = ['MODIS_Terra_SurfaceReflectance_Bands143'] # 'MODIS_Terra_CorrectedReflectance_Bands367' date_str = '2017-12-07' # Plot setup plot_CRS = ccrs.LambertConformal(central_longitude=13, central_latitude=46, standard_parallels=[35]) geodetic_CRS = ccrs.Geodetic() x0, y0 = plot_CRS.transform_point(3.7, 43.9, geodetic_CRS) x1, y1 = plot_CRS.transform_point(22.5, 50.8, geodetic_CRS) ax = plt.axes(projection=plot_CRS) ax.set_xlim((x0, x1)) ax.set_ylim((y0, y1)) ax.add_wmts(wmts, layers[0], wmts_kwargs={'time': date_str})
def check(self): """ Check for availability of a service and provide run metrics. """ from utils import get_esri_service_name success = True start_time = datetime.datetime.utcnow() message = '' print 'Checking service id %s' % self.id try: title = None if self.type == 'OGC_WMS': ows = WebMapService(self.url) title = ows.identification.title if self.type == 'OGC_WMTS': ows = WebMapTileService(self.url) title = ows.identification.title if self.type == 'ESRI_MapServer': esri = ArcMapService(self.url) title = esri.mapName if len(title) == 0: title = get_esri_service_name(self.url) if self.type == 'ESRI_ImageServer': esri = ArcImageService(self.url) title = esri._json_struct['name'] if len(title) == 0: title = get_esri_service_name(self.url) if self.type == 'WM': urllib2.urlopen(self.url) title = 'Harvard WorldMap' if self.type == 'WARPER': urllib2.urlopen(self.url) # update title without raising a signal and recursion if title: Service.objects.filter(id=self.id).update(title=title) except Exception, err: message = str(err) success = False
def __init__(self, url: str, layer: str, tile_system: str, tile_level: Union[str, int], format: str) -> None: """Creates a tile matrix (WMTS layer at fixed zoom level). Args: url: The URL to the Web Map Tile Service (WMTS). layer: The WMTS layer name. tile_system: Name of the tile system (should use the Rijksdriehoek coordinate system, or at least use 1-metre units). tile_level: The zoom level. format: The image format for tiles. Usually either `image/png` or `image/jpeg`. """ self.wmts = WebMapTileService(url) self.layer = layer self.tile_system = tile_system self.tile_level = str(tile_level) self.format = format assert layer in self.wmts.contents, \ 'Layer not found.' assert tile_system in self.wmts.tilematrixsets, \ 'Tile matrix set not found.' assert tile_system in self.wmts.contents[layer].tilematrixsetlinks, \ 'Tile system not found.' assert format in self.wmts.contents[layer].formats, \ 'Unsupported format.' # See: pdf, pp. 8-9 # (Top left corner is min x and max y.) # Note: Rijksdriehoek metric is in metres. This is relevant # because the scaling parameter has been omitted for this # reason. self.matrix = ( self.wmts.tilematrixsets[tile_system].tilematrix[str(tile_level)]) self.pixel_span = self.matrix.scaledenominator * 0.28 * 1e-3 self.span_x = self.matrix.tilewidth * self.pixel_span self.span_y = self.matrix.tileheight * self.pixel_span
def loadServiceList(self, service_id: int): self.generatedService = WebMapServiceClass(service_id) url = self.generatedService.service_url self.bar.show() if self.generatedService.service_type == ServiceType.WebMapService.value: try: wms = WebMapService(url) self.generatedService.setWebMapService(wms) except Exception as e: QMessageBox.information( None, "ERROR:", 'No se puede cargar este servicio en este momento.' + str(e)) elif self.generatedService.service_type == ServiceType.WebMapTileService.value: try: wmts = WebMapTileService(url) self.generatedService.setWebMapService(wmts) except Exception as e: QMessageBox.information( None, "ERROR:", 'No se puede acceder a este servicio en este momento.' + str(e)) self.bar.close()