0001-opengis-add-preferred-projection-system-20826.patch
passerelle/apps/opengis/migrations/0004_auto_20180219_1613.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=16, verbose_name='GIS projection', choices=[(b'epsg:4326', 'EPSG:4326 (WGS 84)'), (b'epsg:2154', 'EPSG:2154 (Lambert-93)'), (b'epsg:3857', 'EPSG:3857 (Pseudo-Mercator)'), (b'epsg:3945', 'EPSG:3945 (CC45)')]), |
|
18 |
), |
|
19 |
] |
passerelle/apps/opengis/models.py | ||
---|---|---|
43 | 43 |
d[attribute_name] = build_dict_from_xml(child) |
44 | 44 |
return d |
45 | 45 | |
46 |
PROJECTIONS = ( |
|
47 |
('epsg:4326', _('EPSG:4326 (WGS 84)')), |
|
48 |
('epsg:2154', _('EPSG:2154 (Lambert-93)')), |
|
49 |
('epsg:3857', _('EPSG:3857 (Pseudo-Mercator)')), |
|
50 |
('epsg:3945', _('EPSG:3945 (CC45)')) |
|
51 |
) |
|
52 | ||
46 | 53 | |
47 | 54 |
class OpenGIS(BaseResource): |
48 | 55 |
category = _('Geographic information system') |
49 | 56 |
wms_service_url = models.URLField(_('Web Map Service (WMS) URL'), max_length=256, blank=True) |
50 | 57 |
wfs_service_url = models.URLField(_('Web Feature Service (WFS) URL'), max_length=256, blank=True) |
51 | 58 |
query_layer = models.CharField(_('Query Layer'), max_length=256) |
59 |
projection = models.CharField(_('GIS projection'), choices=PROJECTIONS, |
|
60 |
default='epsg:3857', max_length=16) |
|
52 | 61 | |
53 | 62 |
class Meta: |
54 | 63 |
verbose_name = _('OpenGIS') |
... | ... | |
161 | 170 |
'J': '0', |
162 | 171 |
'HEIGHT': '500', |
163 | 172 |
'WIDTH': '500', |
164 |
'CRS': 'EPSG:4171',
|
|
173 |
'CRS': self.projection,
|
|
165 | 174 |
'LAYERS': self.query_layer, |
166 | 175 |
'QUERY_LAYERS': self.query_layer, |
167 | 176 |
'BBOX': bbox, |
... | ... | |
192 | 201 |
lat_deg = math.degrees(lat_rad) |
193 | 202 |
return (lon_deg, lat_deg) |
194 | 203 | |
195 |
wgs84 = pyproj.Proj(init='epsg:4326') |
|
196 |
epsg3857 = pyproj.Proj(init='epsg:3857') |
|
197 | 204 |
# lower left |
198 |
ll_lon, ll_lat = pyproj.transform(wgs84, epsg3857, *num2deg(tile_x, tile_y+1, zoom))
|
|
205 |
ll_lon, ll_lat = num2deg(tile_x, tile_y+1, zoom)
|
|
199 | 206 |
# upper right |
200 |
ur_lon, ur_lat = pyproj.transform(wgs84, epsg3857, *num2deg(tile_x+1, tile_y, zoom)) |
|
207 |
ur_lon, ur_lat = num2deg(tile_x+1, tile_y, zoom) |
|
208 | ||
209 |
# convert only when projection system is other than WGS84 |
|
210 |
if self.projection != 'epsg:4326': |
|
211 |
wgs84 = pyproj.Proj(init='epsg:4326') |
|
212 |
target_projection = pyproj.Proj(init=self.projection) |
|
213 |
ll_lon, ll_lat = pyproj.transform(wgs84, target_projection, ll_lon, ll_lat) |
|
214 |
ur_lon, ur_lat = pyproj.transform(wgs84, target_projection, ur_lon, ur_lat) |
|
215 | ||
201 | 216 |
bbox = '%s,%s,%s,%s' % (ll_lon, ll_lat, ur_lon, ur_lat) |
202 | 217 | |
203 | 218 |
params = { |
... | ... | |
210 | 225 |
'TRANSPARENT': 'false', |
211 | 226 |
'HEIGHT': '256', |
212 | 227 |
'WIDTH': '256', |
213 |
'SRS': 'EPSG:3857',
|
|
228 |
'SRS': self.projection,
|
|
214 | 229 |
'BBOX': bbox, |
215 | 230 |
} |
216 | 231 |
return HttpResponse( |
tests/test_opengis.py | ||
---|---|---|
130 | 130 |
assert endpoint == '/opengis/test/feature_info' |
131 | 131 |
mocked_get.return_value = utils.FakedResponse(content=FAKE_FEATURE_INFO, status_code=200) |
132 | 132 |
resp = app.get(endpoint, params={'lat': '45.796890', 'lon': '4.784140'}) |
133 |
assert mocked_get.call_args[1]['params']['CRS'] == 'EPSG:3857' |
|
133 | 134 |
assert resp.json['data']['cad_cadastrecadparcelle_layer']['cad_cadastrecadparcelle_feature']['natureproprietaire'] == 'Particulier' |
134 | 135 | |
135 | 136 |
@mock.patch('passerelle.utils.Request.get') |
... | ... | |
138 | 139 |
assert endpoint == '/opengis/test/tile' |
139 | 140 |
mocked_get.return_value = utils.FakedResponse(content='\x89PNG\r\n\x1a\n\x00\x00...', status_code=200) |
140 | 141 |
resp = app.get(endpoint + '/16/33650/23378.png') |
142 |
assert mocked_get.call_args[1]['params']['SRS'] == 'EPSG:3857' |
|
143 |
assert mocked_get.call_args[1]['params']['BBOX'] == '539339.67158,5741338.06856,539951.167806,5741949.56478' |
|
144 |
connector.projection = 'EPSG:4326' |
|
145 |
connector.save() |
|
146 |
resp = app.get(endpoint + '/16/33650/23378.png') |
|
147 |
assert mocked_get.call_args[1]['params']['SRS'] == 'EPSG:4326' |
|
148 |
assert mocked_get.call_args[1]['params']['BBOX'] == '4.84497070312,45.7560261559,4.85046386719,45.7598586879' |
|
141 | 149 |
assert resp.content == '\x89PNG\r\n\x1a\n\x00\x00...' |
142 | 150 | |
143 | 151 | |
144 |
- |