Skip to content

Commit

Permalink
Merge pull request #3197 from Geoportail-Luxembourg/fix_esri_rest_tim…
Browse files Browse the repository at this point in the history
…e_layers

Manage esri bug with timestamp and rest service
  • Loading branch information
rmichaelis authored Nov 13, 2024
2 parents adb4c45 + ff0e9e4 commit d521b9d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -707,14 +707,20 @@ exports.prototype.singleclickEvent_ = function(evt, infoMymaps) {
var layers = this.map_.getLayers().getArray();
var layersList = [];
var layerLabel = {};

var layersTimeList = [];
for (var i = layers.length - 1; i >= 0; i--) {
var metadata = layers[i].get('metadata');
if (metadata !== undefined && metadata !== null) {
if (metadata['is_queryable'] && layers[i].getVisible() && layers[i].getOpacity() > 0) {
var queryableId = layers[i].get('queryable_id');
layersList.push(queryableId);
layerLabel[queryableId] = layers[i].get('label');
//const time = layers[i].get('time');
//layersTimeList.push(time.minValue+"/"+time.maxValue);
const time = layers[i].get('current_time');
if (time !== undefined) {
layersTimeList.push(time);
}
}
}
}
Expand Down Expand Up @@ -743,7 +749,8 @@ exports.prototype.singleclickEvent_ = function(evt, infoMymaps) {
'box1': big_box.join(),
'box2': small_box.join(),
'srs': 'EPSG:3857',
'zoom': this.map_.getView().getZoom()
'zoom': this.map_.getView().getZoom(),
'time': layersTimeList.join()
};
if (!this.map_.get('ol3dm').is3dEnabled()) {
var size = this.map_.getSize();
Expand Down
32 changes: 22 additions & 10 deletions geoportal/geoportailv3_geoportal/views/getfeatureinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def get_feature_info(self):
fids = self.request.params.get('fids', None)
query_limit = self.request.params.get('max_features', '20')
offset = self.request.params.get('start_index', None)

time = self.request.params.get('time', None)
fids_array = []
if fids is not None:
fids_array = fids.split(',')
Expand All @@ -275,7 +275,7 @@ def get_feature_info(self):
layers, fid = fid.split('_', 1)
if layers is None or fid is None:
return HTTPBadRequest()
self.get_info(fid, None, None, results, layers, None, None, zoom, query_limit, offset)
self.get_info(fid, None, None, results, layers, None, None, zoom, query_limit, offset, time)
return results

layers = self.request.params.get('layers', None)
Expand All @@ -294,7 +294,7 @@ def get_feature_info(self):
if geometry is not None and len(geometry) > 0:
fc = self.get_info(
fid, None,
None, results, layers, None, geometry, zoom, query_limit, offset)
None, results, layers, None, geometry, zoom, query_limit, offset, time)
if len(fc) > 0 and 'features' in fc[0]:
s = shape(wkt_loads(geometry))
for feature in fc[0]['features']:
Expand All @@ -319,7 +319,7 @@ def get_feature_info(self):
return HTTPBadRequest("Wrong box2 value : " + small_box)
return self.get_info(
fid, coordinates_big_box,
coordinates_small_box, results, layers, big_box, None, zoom, query_limit, offset)
coordinates_small_box, results, layers, big_box, None, zoom, query_limit, offset, time)

def is_zoom_ok(self, cur_zoom, zoom_definition):
if cur_zoom is None or len(cur_zoom) == 0:
Expand All @@ -340,7 +340,7 @@ def is_zoom_ok(self, cur_zoom, zoom_definition):
return False

def get_info(self, fid, coordinates_big_box, coordinates_small_box,
results, layers, big_box, p_geometry=None, p_zoom=None, p_query_limit='20', offset=None):
results, layers, big_box, p_geometry=None, p_zoom=None, p_query_limit='20', offset=None, time=None):
rows_cnt = 0
luxgetfeaturedefinitions = self.get_lux_feature_definition(layers)
for luxgetfeaturedefinition in luxgetfeaturedefinitions:
Expand All @@ -367,7 +367,7 @@ def get_info(self, fid, coordinates_big_box, coordinates_small_box,
None, None, None, None,
None,
use_auth=luxgetfeaturedefinition.use_auth,
p_geometry=the_box.centroid.wkt, srs_geometry="2169")
p_geometry=the_box.centroid.wkt, srs_geometry="2169", time=time)
if len(features) > 0:
f.append(self.to_feature(luxgetfeaturedefinition.layer, None,
geometry,
Expand Down Expand Up @@ -614,23 +614,23 @@ def get_info(self, fid, coordinates_big_box, coordinates_small_box,
None, None, None, None,
luxgetfeaturedefinition.columns_order,
use_auth=luxgetfeaturedefinition.use_auth,
p_geometry=p_geometry, srs_geometry=self.request.params.get('srs', self.request.params.get('geometry_srs', '2169')))
p_geometry=p_geometry, srs_geometry=self.request.params.get('srs', self.request.params.get('geometry_srs', '2169')), time=time)
else :
features = self._get_external_data(
luxgetfeaturedefinition.layer,
luxgetfeaturedefinition.rest_url,
luxgetfeaturedefinition.id_column,
big_box, None, None, None,
luxgetfeaturedefinition.columns_order,
use_auth=luxgetfeaturedefinition.use_auth)
use_auth=luxgetfeaturedefinition.use_auth, time=time)
else:
features = self._get_external_data(
luxgetfeaturedefinition.layer,
luxgetfeaturedefinition.rest_url,
luxgetfeaturedefinition.id_column,
None, fid, None, None,
luxgetfeaturedefinition.columns_order,
use_auth=luxgetfeaturedefinition.use_auth)
use_auth=luxgetfeaturedefinition.use_auth, time=time)

if len(features) > 0:
if (luxgetfeaturedefinition.additional_info_function
Expand Down Expand Up @@ -1464,7 +1464,7 @@ def get_additional_external_data(
def _get_external_data(self, layer_id, url, id_column='objectid',
bbox=None, featureid=None, cfg=None,
attributes_to_remove=None, columns_order=None,
where_clause=None, use_auth=False, p_geometry=None, srs_geometry=None):
where_clause=None, use_auth=False, p_geometry=None, srs_geometry=None, time=None):
# ArcGIS Server REST API:
# http://help.arcgis.com/en/arcgisserver/10.0/apis/rest/query.html
# form example:
Expand Down Expand Up @@ -1506,6 +1506,18 @@ def _get_external_data(self, layer_id, url, id_column='objectid',
'where': '',
'outFields': '*',
'objectIds': ''}
if time is not None and len(time) > 0:
# WMS time format is <start_date>/<end_date>
# this shall be parsed into <start_millisec>,<end_millisec> for arcgis REST
time_values = time.split("/")
str_time_integers = [
str(int(dateutil.parser.parse(time_val).timestamp()*1000))
for time_val in time_values
]
# Bypass arcgis bug when time layers are queried with timestamp
if len(str_time_integers) == 1:
str_time_integers.append(str(int(str_time_integers[0]) + 3600000))
body['time'] = ",".join(str_time_integers)
splitted_url = url.split('f=geojson')
url = splitted_url[0]
if id_column is None:
Expand Down
9 changes: 8 additions & 1 deletion geoportal/geoportailv3_geoportal/views/luxthemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,19 @@ def _wms_layers_internal(self):
ti = data["timeInfo"]
start = datetime.fromtimestamp(ti['timeExtent'][0]/1000)
end = datetime.fromtimestamp(ti['timeExtent'][1]/1000)
if ti['defaultTimeIntervalUnits'] in ESRI_TIME_CONSTANTS:
if 'defaultTimeIntervalUnits' in ti and ti['defaultTimeIntervalUnits'] in ESRI_TIME_CONSTANTS:
layer_dict['timepositions'] = ['%s/%s/%s'
% (start.isoformat(),
end.isoformat(),
ESRI_TIME_CONSTANTS[ti['defaultTimeIntervalUnits']]
% ti['defaultTimeInterval'])]
elif 'timeIntervalUnits' in ti and ti['timeIntervalUnits'] in ESRI_TIME_CONSTANTS:
layer_dict['timepositions'] = ['%s/%s/%s'
% (start.isoformat(),
end.isoformat(),
ESRI_TIME_CONSTANTS[ti['timeIntervalUnits']]
% ti['timeInterval'])]

layers[layer.name + '__' + sublayer] = layer_dict
# if no esri time layer defined => standard WMS server
else:
Expand Down
3 changes: 3 additions & 0 deletions geoportal/geoportailv3_geoportal/views/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def _process_arcgis_server(self, internal_wms: LuxLayerInternalWMS) -> str:
str(int(dateutil.parser.parse(time_val).timestamp()*1000))
for time_val in time_values
]
# Bypass arcgis bug when time layers are queried with timestamp
if len(str_time_integers) == 1:
str_time_integers.append(str(int(str_time_integers[0]) + 3600000))
query_params["time"] = ",".join(str_time_integers)
elif lparam == 'layers':
query_params["layers"] = 'show:' + internal_wms.layers
Expand Down

0 comments on commit d521b9d

Please sign in to comment.