Skip to content

Commit

Permalink
[Fixes #4487] Issue adding remote services - FAILED - could not conve…
Browse files Browse the repository at this point in the history
…rt string to float: EPSG:4326
  • Loading branch information
afabiani committed Jun 13, 2019
1 parent b63db8d commit d194c72
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 162 deletions.
4 changes: 2 additions & 2 deletions geonode/layers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def data_objects(self):

@property
def ows_url(self):
if self.remote_service is not None and self.remote_service.method == INDEXED:
if self.remote_service is not None:
result = self.remote_service.service_url
else:
result = "{base}ows".format(
Expand All @@ -200,7 +200,7 @@ def ptype(self):

@property
def service_typename(self):
if self.remote_service is not None and self.remote_service.method == INDEXED:
if self.remote_service is not None:
return "%s:%s" % (self.remote_service.name, self.alternate)
else:
return self.alternate
Expand Down
11 changes: 6 additions & 5 deletions geonode/services/serviceprocessors/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def __init__(self, url):
self.indexing_method = (
INDEXED if self._offers_geonode_projection() else CASCADED)
# self.url = self.parsed_service.url
# TODO: Check if the name already esists
self.name = slugify(self.url)[:255]

def create_cascaded_store(self):
Expand Down Expand Up @@ -322,19 +321,20 @@ def _get_cascaded_layer_fields(self, geoserver_resource):
"name": name,
"workspace": workspace,
"store": store.name,
"typename": "{}:{}".format(workspace, name),
"alternate": "{}:{}".format(workspace, name),
"storeType": "remoteStore", # store.resource_type,
"typename": "{}:{}".format(workspace, name) if workspace not in name else name,
"alternate": "{}:{}".format(workspace, name) if workspace not in name else name,
"storeType": "remoteStore",
"title": geoserver_resource.title,
"abstract": geoserver_resource.abstract,
"bbox_x0": bbox[0],
"bbox_x1": bbox[1],
"bbox_y0": bbox[2],
"bbox_y1": bbox[3],
"srid": bbox[4] if len(bbox) > 4 else "EPSG:4326",
}

def _get_indexed_layer_fields(self, layer_meta):
bbox = utils.decimal_encode(layer_meta.boundingBoxWGS84)
bbox = utils.decimal_encode(layer_meta.boundingBox)
return {
"name": layer_meta.name,
"store": self.name,
Expand All @@ -348,6 +348,7 @@ def _get_indexed_layer_fields(self, layer_meta):
"bbox_x1": bbox[2],
"bbox_y0": bbox[1],
"bbox_y1": bbox[3],
"srid": bbox[4] if len(bbox) > 4 else "EPSG:4326",
"keywords": [keyword[:100] for keyword in layer_meta.keywords],
}

Expand Down
316 changes: 161 additions & 155 deletions geonode/services/utils.py
Original file line number Diff line number Diff line change
@@ -1,155 +1,161 @@
#########################################################################
#
# Copyright (C) 2018 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################

import re
import math
import logging
from decimal import Decimal

logger = logging.getLogger(__name__)


def flip_coordinates(c1, c2):
if c1 > c2:
logger.debug('Flipping coordinates %s, %s' % (c1, c2))
temp = c1
c1 = c2
c2 = temp
return c1, c2


def format_float(value):
if value is None:
return None
try:
value = float(value)
if value > 999999999:
return None
return value
except ValueError:
return None


def bbox2wktpolygon(bbox):
"""
Return OGC WKT Polygon of a simple bbox list of strings
"""

minx = float(bbox[0])
miny = float(bbox[1])
maxx = float(bbox[2])
maxy = float(bbox[3])
return 'POLYGON((%.2f %.2f, %.2f %.2f, %.2f %.2f, %.2f %.2f, %.2f %.2f))' \
% (minx, miny, minx, maxy, maxx, maxy, maxx, miny, minx, miny)


def inverse_mercator(xy):
"""
Given coordinates in spherical mercator, return a lon,lat tuple.
"""
lon = (xy[0] / 20037508.34) * 180
lat = (xy[1] / 20037508.34) * 180
lat = 180 / math.pi * (2 * math.atan(math.exp(lat * math.pi / 180)) - math.pi / 2)
return (lon, lat)


def mercator_to_llbbox(bbox):
minlonlat = inverse_mercator([bbox[0], bbox[1]])
maxlonlat = inverse_mercator([bbox[2], bbox[3]])
return [minlonlat[0], minlonlat[1], maxlonlat[0], maxlonlat[1]]


def get_esri_service_name(url):
"""
A method to get a service name from an esri endpoint.
For example: http://example.com/arcgis/rest/services/myservice/mylayer/MapServer/?f=json
Will return: myservice/mylayer
"""
result = re.search('rest/services/(.*)/[MapServer|ImageServer]', url)
if result is None:
return url
else:
return result.group(1)


def get_esri_extent(esriobj):
"""
Get the extent of an ESRI resource
"""

extent = None
srs = None

try:
if 'fullExtent' in esriobj._json_struct:
extent = esriobj._json_struct['fullExtent']
except Exception as err:
logger.error(err, exc_info=True)

try:
if 'extent' in esriobj._json_struct:
extent = esriobj._json_struct['extent']
except Exception as err:
logger.error(err, exc_info=True)

try:
srs = extent['spatialReference']['wkid']
except Exception as err:
logger.error(err, exc_info=True)

return [extent, srs]


def decimal_encode(bbox):
_bbox = []
for o in [float(coord) for coord in bbox]:
if isinstance(o, Decimal):
o = (str(o) for o in [o])
_bbox.append("{0:.15f}".format(round(o, 2)))
return _bbox


def test_resource_table_status(test_cls, table, is_row_filtered):
tbody = table.find_elements_by_tag_name('tbody')
rows = tbody[0].find_elements_by_tag_name('tr')
visible_rows_count = 0
filter_row_count = 0
hidden_row_count = 0
for row in rows:
attr_name = row.get_attribute('name')
val = row.value_of_css_property('display')

if attr_name == "filter_row":
filter_row_count = filter_row_count + 1
if val == "none":
hidden_row_count = hidden_row_count + 1
else:
visible_rows_count = visible_rows_count + 1
result = {"filter_row_count": filter_row_count,
"visible_rows_count": visible_rows_count,
"hidden_row_count": hidden_row_count}

if is_row_filtered:
test_cls.assertTrue(result["filter_row_count"] > 0)
test_cls.assertEqual(result["visible_rows_count"], result["filter_row_count"])
test_cls.assertEqual(result["hidden_row_count"], 20)
else:
test_cls.assertEqual(result["filter_row_count"], 0)
test_cls.assertEqual(result["visible_rows_count"], 20)
test_cls.assertEqual(result["hidden_row_count"], 0)
#########################################################################
#
# Copyright (C) 2018 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################

import re
import math
import logging

logger = logging.getLogger(__name__)


def flip_coordinates(c1, c2):
if c1 > c2:
logger.debug('Flipping coordinates %s, %s' % (c1, c2))
temp = c1
c1 = c2
c2 = temp
return c1, c2


def format_float(value):
if value is None:
return None
try:
value = float(value)
if value > 999999999:
return None
return value
except ValueError:
return None


def bbox2wktpolygon(bbox):
"""
Return OGC WKT Polygon of a simple bbox list of strings
"""

minx = float(bbox[0])
miny = float(bbox[1])
maxx = float(bbox[2])
maxy = float(bbox[3])
return 'POLYGON((%.2f %.2f, %.2f %.2f, %.2f %.2f, %.2f %.2f, %.2f %.2f))' \
% (minx, miny, minx, maxy, maxx, maxy, maxx, miny, minx, miny)


def inverse_mercator(xy):
"""
Given coordinates in spherical mercator, return a lon,lat tuple.
"""
lon = (xy[0] / 20037508.34) * 180
lat = (xy[1] / 20037508.34) * 180
lat = 180 / math.pi * (2 * math.atan(math.exp(lat * math.pi / 180)) - math.pi / 2)
return (lon, lat)


def mercator_to_llbbox(bbox):
minlonlat = inverse_mercator([bbox[0], bbox[1]])
maxlonlat = inverse_mercator([bbox[2], bbox[3]])
return [minlonlat[0], minlonlat[1], maxlonlat[0], maxlonlat[1]]


def get_esri_service_name(url):
"""
A method to get a service name from an esri endpoint.
For example: http://example.com/arcgis/rest/services/myservice/mylayer/MapServer/?f=json
Will return: myservice/mylayer
"""
result = re.search('rest/services/(.*)/[MapServer|ImageServer]', url)
if result is None:
return url
else:
return result.group(1)


def get_esri_extent(esriobj):
"""
Get the extent of an ESRI resource
"""

extent = None
srs = None

try:
if 'fullExtent' in esriobj._json_struct:
extent = esriobj._json_struct['fullExtent']
except Exception as err:
logger.error(err, exc_info=True)

try:
if 'extent' in esriobj._json_struct:
extent = esriobj._json_struct['extent']
except Exception as err:
logger.error(err, exc_info=True)

try:
srs = extent['spatialReference']['wkid']
except Exception as err:
logger.error(err, exc_info=True)

return [extent, srs]


def decimal_encode(bbox):
_bbox = []
_srid = None
for o in bbox:
try:
o = float(o)
except BaseException:
o = None if 'EPSG' not in o else o
if o and isinstance(o, float):
_bbox.append("{0:.15f}".format(round(o, 2)))
elif o and 'EPSG' in o:
_srid = o
_bbox = _bbox if not _srid else _bbox + [_srid]
return _bbox


def test_resource_table_status(test_cls, table, is_row_filtered):
tbody = table.find_elements_by_tag_name('tbody')
rows = tbody[0].find_elements_by_tag_name('tr')
visible_rows_count = 0
filter_row_count = 0
hidden_row_count = 0
for row in rows:
attr_name = row.get_attribute('name')
val = row.value_of_css_property('display')

if attr_name == "filter_row":
filter_row_count = filter_row_count + 1
if val == "none":
hidden_row_count = hidden_row_count + 1
else:
visible_rows_count = visible_rows_count + 1
result = {"filter_row_count": filter_row_count,
"visible_rows_count": visible_rows_count,
"hidden_row_count": hidden_row_count}

if is_row_filtered:
test_cls.assertTrue(result["filter_row_count"] > 0)
test_cls.assertEqual(result["visible_rows_count"], result["filter_row_count"])
test_cls.assertEqual(result["hidden_row_count"], 20)
else:
test_cls.assertEqual(result["filter_row_count"], 0)
test_cls.assertEqual(result["visible_rows_count"], 20)
test_cls.assertEqual(result["hidden_row_count"], 0)

0 comments on commit d194c72

Please sign in to comment.