[GRASS-SVN] r56977 - grass/trunk/scripts/r.in.wms
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jul 2 06:30:21 PDT 2013
Author: turek
Date: 2013-07-02 06:30:21 -0700 (Tue, 02 Jul 2013)
New Revision: 56977
Modified:
grass/trunk/scripts/r.in.wms/wms_base.py
grass/trunk/scripts/r.in.wms/wms_drv.py
grass/trunk/scripts/r.in.wms/wms_gdal_drv.py
Log:
r.in.wms: added support for CRS projections (WMS 1.3.0)
Modified: grass/trunk/scripts/r.in.wms/wms_base.py
===================================================================
--- grass/trunk/scripts/r.in.wms/wms_base.py 2013-07-02 11:53:39 UTC (rev 56976)
+++ grass/trunk/scripts/r.in.wms/wms_base.py 2013-07-02 13:30:21 UTC (rev 56977)
@@ -61,12 +61,6 @@
for key in ['url', 'layers', 'styles', 'method']:
self.params[key] = options[key].strip()
- self.params['wms_version'] = options['wms_version']
- if self.params['wms_version'] == "1.3.0":
- self.params['proj_name'] = "CRS"
- else:
- self.params['proj_name'] = "SRS"
-
self.flags = flags
if self.flags['o']:
@@ -97,7 +91,18 @@
self.params['srs'] = int(options['srs'])
if self.params['srs'] <= 0 and not 'srs' in driver_props['ignored_params']:
grass.fatal(_("Invalid EPSG code %d") % self.params['srs'])
+
+ self.params['wms_version'] = options['wms_version']
+ if "CRS" in GetSRSParamVal(self.params['srs']) and self.params['wms_version'] == "1.1.1":
+ self.params['wms_version'] = "1.3.0"
+ grass.warning(_("WMS version <1.3.0> will be used, because version <1.1.1> does not support <%s>projection")
+ % GetSRSParamVal(self.params['srs']))
+ if self.params['wms_version'] == "1.3.0":
+ self.params['proj_name'] = "CRS"
+ else:
+ self.params['proj_name'] = "SRS"
+
# read projection info
self.proj_location = grass.read_command('g.proj',
flags ='jf').rstrip('\n')
@@ -111,7 +116,7 @@
else:
self.proj_srs = grass.read_command('g.proj',
flags = 'jf',
- epsg = str(self.params['srs']) ).rstrip('\n')
+ epsg = str(GetEpsg(self.params['srs']))).rstrip('\n')
self.proj_srs = self._modifyProj(self.proj_srs)
@@ -530,6 +535,9 @@
# form for request
self.formats = ["image/geotiff", "image/tiff", "image/png", "image/jpeg", "image/gif"]
+ self.srs = ("epsg", "crs")
+
+
def GetDrvProperties(self, driver):
"""!Get information about driver parameters.
"""
@@ -594,3 +602,36 @@
if label in self.f_labels:
return self.formats[self.f_labels.index(label)]
return None
+
+ def GetSrs(self):
+ """!Get supported srs prefixes (e.g. epsg/crs)
+
+ @todo filter according to version and driver params
+ """
+ return self.srs
+
+
+
+#TODO move to utils?
+def GetSRSParamVal(srs):
+ """!Decides whether to use CRS or EPSG prefix according to srs number.
+ """
+
+ if srs in [84, 83, 27]:
+ return "CRS:%d" % srs
+ else:
+ return "EPSG:%d" % srs
+
+def GetEpsg(srs):
+ """
+ @return EPSG number
+ If srs is CRS number, return EPSG number which corresponds to CRS number.
+ """
+ if srs == 84:
+ return 4326
+ if srs == 83:
+ return 4269
+ if srs == 27:
+ return 4267
+
+ return srs
Modified: grass/trunk/scripts/r.in.wms/wms_drv.py
===================================================================
--- grass/trunk/scripts/r.in.wms/wms_drv.py 2013-07-02 11:53:39 UTC (rev 56976)
+++ grass/trunk/scripts/r.in.wms/wms_drv.py 2013-07-02 13:30:21 UTC (rev 56977)
@@ -38,7 +38,7 @@
except ImportError: # < Python 2.7
from xml.parsers.expat import ExpatError as ParseError
-from wms_base import WMSBase
+from wms_base import WMSBase, GetSRSParamVal
from wms_cap_parsers import WMTSCapabilitiesTree, OnEarthCapabilitiesTree
@@ -97,9 +97,9 @@
wms_data = self._fetchDataFromServer(query_url, self.params['username'], self.params['password'])
except (IOError, HTTPException), e:
if HTTPError == type(e) and e.code == 401:
- grass.fatal(_("Authorization failed to '%s' when fetching data.") % self.params['url'])
+ grass.fatal(_("Authorization failed to '%s' when fetching data.\n%s") % (self.params['url'], str(e)))
else:
- grass.fatal(_("Unable to fetch data from: '%s'") % self.params['url'])
+ grass.fatal(_("Unable to fetch data from: '%s'\n%s") % (self.params['url'], str(e)))
temp_tile = self._tempfile()
@@ -335,7 +335,9 @@
"""!Initialize data needed for iteration through tiles.
"""
self.version = params['wms_version']
- proj = params['proj_name'] + "=EPSG:"+ str(params['srs'])
+ self.srs_param = params['srs']
+
+ proj = params['proj_name'] + "=" + GetSRSParamVal(params['srs'])
self.url = params['url'] + ("SERVICE=WMS&REQUEST=GetMap&VERSION=%s&LAYERS=%s&WIDTH=%s&HEIGHT=%s&STYLES=%s&BGCOLOR=%s&TRANSPARENT=%s" % \
(params['wms_version'], params['layers'], tile_size['cols'], tile_size['rows'], params['styles'], \
params['bgcolor'], params['transparent']))
@@ -411,10 +413,7 @@
if self.i_y == self.num_tiles_y - 1 and self.last_tile_y:
tile_ref['sizeY'] = self.last_tile_y_size
- if self._isGeoProj(self.proj_srs) and self.version == "1.3.0":
- query_bbox = self._flipBbox(self.tile_bbox, self.proj_srs, self.version)
- else:
- query_bbox = self.tile_bbox
+ query_bbox = self._getQueryBbox(self.tile_bbox, self.proj_srs, self.srs_param, self.version)
query_url = self.url + "&" + "BBOX=%s,%s,%s,%s" % ( query_bbox['minx'], query_bbox['miny'], query_bbox['maxx'], query_bbox['maxy'])
tile_ref['t_cols_offset'] = int(self.tile_cols * self.i_x)
@@ -431,12 +430,23 @@
return query_url, tile_ref
- def _flipBbox(self, bbox, proj, version):
+ def _getQueryBbox(self, bbox, proj, srs_param, version):
+ """!Creates query bbox (used in request URL)
+
+ Mostly bbox is not modified but if WMS standard is 1.3.0 and
+ projection is geographic, the bbox x and y are in most cases flipped.
+ """
+ # CRS:84 and CRS:83 are exception (CRS:83 and CRS:27 need to be tested)
+ if srs_param in [84, 83] or version != '1.3.0':
+ return bbox
+ elif self._isGeoProj(proj):
+ return self._flipBbox(bbox)
+
+ return bbox
+
+ def _flipBbox(self, bbox):
"""
- Flips coordinates if WMS standard is 1.3.0 and
- projection is geographic.
-
- value flips between this keys:
+ Flips bbox values between this keys:
maxy -> maxx
maxx -> maxy
miny -> minx
@@ -453,7 +463,6 @@
return new_bbox
-
class WMTSRequestMgr(BaseRequestMgr):
def __init__(self, params, bbox, region, proj_srs, cap_file = None):
"""!Initializes data needed for iteration through tiles.
Modified: grass/trunk/scripts/r.in.wms/wms_gdal_drv.py
===================================================================
--- grass/trunk/scripts/r.in.wms/wms_gdal_drv.py 2013-07-02 11:53:39 UTC (rev 56976)
+++ grass/trunk/scripts/r.in.wms/wms_gdal_drv.py 2013-07-02 13:30:21 UTC (rev 56977)
@@ -24,7 +24,7 @@
import xml.etree.ElementTree as etree
-from wms_base import WMSBase
+from wms_base import WMSBase, GetSRSParamVal
class NullDevice():
def write(self, s):
@@ -50,7 +50,7 @@
server_url.text =self.params['url']
srs = etree.SubElement(service, self.params['proj_name'])
- srs.text = 'EPSG:' + str(self.params['srs'])
+ srs.text = GetSRSParamVal(self.params['srs'])
image_format = etree.SubElement(service, "ImageFormat")
image_format.text = self.params['format']
@@ -65,7 +65,7 @@
styles.text = self.params['styles']
data_window = etree.SubElement(gdal_wms, "DataWindow")
-
+
upper_left_x = etree.SubElement(data_window, "UpperLeftX")
upper_left_x.text = str(self.bbox['minx'])
@@ -115,8 +115,8 @@
if ("+proj=latlong" in self.proj_srs or \
"+proj=longlat" in self.proj_srs) and \
self.params['wms_version'] == "1.3.0":
- grass.warning(_("If module will not be able to fetch the data in this\
- geographic projection, \n try 'WMS_GRASS' driver or use WMS version 1.1.1."))
+ grass.warning(_("If module will not be able to fetch the data in this " +
+ "geographic projection, \n try 'WMS_GRASS' driver or use WMS version 1.1.1."))
self._debug("_download", "started")
More information about the grass-commit
mailing list