0001-opengis-add-preferred-projection-system-20826.patch
passerelle/apps/opengis/migrations/0004_auto_20180219_1400.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
from __future__ import unicode_literals |
|
3 | ||
4 |
from django.db import migrations, models |
|
5 | ||
6 | ||
7 |
class Migration(migrations.Migration): |
|
8 | ||
9 |
dependencies = [ |
|
10 |
('opengis', '0003_auto_20171220_1058'), |
|
11 |
] |
|
12 | ||
13 |
operations = [ |
|
14 |
migrations.AddField( |
|
15 |
model_name='opengis', |
|
16 |
name='projection', |
|
17 |
field=models.CharField(default=b'EPSG:3857', max_length=256, verbose_name='Preferred projection'), |
|
18 |
), |
|
19 |
] |
passerelle/apps/opengis/models.py | ||
---|---|---|
48 | 48 |
wms_service_url = models.URLField(_('Web Map Service (WMS) URL'), max_length=256, blank=True) |
49 | 49 |
wfs_service_url = models.URLField(_('Web Feature Service (WFS) URL'), max_length=256, blank=True) |
50 | 50 |
query_layer = models.CharField(_('Query Layer'), max_length=256) |
51 |
projection = models.CharField(_('Preferred projection'), default='EPSG:3857', max_length=256) |
|
51 | 52 | |
52 | 53 |
class Meta: |
53 | 54 |
verbose_name = _('OpenGIS') |
... | ... | |
134 | 135 |
'J': '0', |
135 | 136 |
'HEIGHT': '500', |
136 | 137 |
'WIDTH': '500', |
137 |
'CRS': 'EPSG:4171',
|
|
138 |
'CRS': self.projection,
|
|
138 | 139 |
'LAYERS': self.query_layer, |
139 | 140 |
'QUERY_LAYERS': self.query_layer, |
140 | 141 |
'BBOX': bbox, |
... | ... | |
165 | 166 |
lat_deg = math.degrees(lat_rad) |
166 | 167 |
return (lon_deg, lat_deg) |
167 | 168 | |
168 |
wgs84 = pyproj.Proj(init='epsg:4326') |
|
169 |
epsg3857 = pyproj.Proj(init='epsg:3857') |
|
170 | 169 |
# lower left |
171 |
ll_lon, ll_lat = pyproj.transform(wgs84, epsg3857, *num2deg(tile_x, tile_y+1, zoom))
|
|
170 |
ll_lon, ll_lat = num2deg(tile_x, tile_y+1, zoom)
|
|
172 | 171 |
# upper right |
173 |
ur_lon, ur_lat = pyproj.transform(wgs84, epsg3857, *num2deg(tile_x+1, tile_y, zoom)) |
|
172 |
ur_lon, ur_lat = num2deg(tile_x+1, tile_y, zoom) |
|
173 | ||
174 |
# convert only when projection system is other than WGS84 |
|
175 |
if self.projection.strip().upper() != 'EPSG:4326': |
|
176 |
wgs84 = pyproj.Proj(init='EPSG:4326') |
|
177 |
target_projection = pyproj.Proj(init=self.projection) |
|
178 |
ll_lon, ll_lat = pyproj.transform(wgs84, target_projection, ll_lon, ll_lat) |
|
179 |
ur_lon, ur_lat = pyproj.transform(wgs84, target_projection, ur_lon, ur_lat) |
|
180 | ||
174 | 181 |
bbox = '%s,%s,%s,%s' % (ll_lon, ll_lat, ur_lon, ur_lat) |
175 | 182 | |
176 | 183 |
params = { |
... | ... | |
183 | 190 |
'TRANSPARENT': 'false', |
184 | 191 |
'HEIGHT': '256', |
185 | 192 |
'WIDTH': '256', |
186 |
'SRS': 'EPSG:3857',
|
|
193 |
'SRS': self.projection,
|
|
187 | 194 |
'BBOX': bbox, |
188 | 195 |
} |
189 | 196 |
return HttpResponse( |
tests/test_opengis.py | ||
---|---|---|
118 | 118 |
assert endpoint == '/opengis/test/feature_info' |
119 | 119 |
mocked_get.return_value = utils.FakedResponse(content=FAKE_FEATURE_INFO, status_code=200) |
120 | 120 |
resp = app.get(endpoint, params={'lat': '45.796890', 'lon': '4.784140'}) |
121 |
assert mocked_get.call_args[1]['params']['CRS'] == 'EPSG:3857' |
|
121 | 122 |
assert resp.json['data']['cad_cadastrecadparcelle_layer']['cad_cadastrecadparcelle_feature']['natureproprietaire'] == 'Particulier' |
122 | 123 | |
123 | 124 |
@mock.patch('passerelle.utils.Request.get') |
... | ... | |
126 | 127 |
assert endpoint == '/opengis/test/tile' |
127 | 128 |
mocked_get.return_value = utils.FakedResponse(content='\x89PNG\r\n\x1a\n\x00\x00...', status_code=200) |
128 | 129 |
resp = app.get(endpoint + '/16/33650/23378.png') |
130 |
assert mocked_get.call_args[1]['params']['SRS'] == 'EPSG:3857' |
|
131 |
assert mocked_get.call_args[1]['params']['BBOX'] == '539339.67158,5741338.06856,539951.167806,5741949.56478' |
|
132 |
connector.projection = 'EPSG:4326' |
|
133 |
connector.save() |
|
134 |
resp = app.get(endpoint + '/16/33650/23378.png') |
|
135 |
assert mocked_get.call_args[1]['params']['SRS'] == 'EPSG:4326' |
|
136 |
assert mocked_get.call_args[1]['params']['BBOX'] == '4.84497070312,45.7560261559,4.85046386719,45.7598586879' |
|
129 | 137 |
assert resp.content == '\x89PNG\r\n\x1a\n\x00\x00...' |
130 | 138 | |
131 | 139 | |
132 |
- |