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:4171 (Pseudo-Mercator)'), (b'epsg:3945', 'EPSG:3945 (CC45)')]), |
|
18 |
), |
|
19 |
] |
passerelle/apps/opengis/models.py | ||
---|---|---|
42 | 42 |
d[attribute_name] = build_dict_from_xml(child) |
43 | 43 |
return d |
44 | 44 | |
45 |
PROJECTIONS = ( |
|
46 |
('epsg:4326', _('EPSG:4326 (WGS 84)')), |
|
47 |
('epsg:2154', _('EPSG:2154 (Lambert-93)')), |
|
48 |
('epsg:3857', _('EPSG:4171 (Pseudo-Mercator)')), |
|
49 |
('epsg:3945', _('EPSG:3945 (CC45)')) |
|
50 |
) |
|
51 | ||
45 | 52 | |
46 | 53 |
class OpenGIS(BaseResource): |
47 | 54 |
category = _('Geographic information system') |
48 | 55 |
wms_service_url = models.URLField(_('Web Map Service (WMS) URL'), max_length=256, blank=True) |
49 | 56 |
wfs_service_url = models.URLField(_('Web Feature Service (WFS) URL'), max_length=256, blank=True) |
50 | 57 |
query_layer = models.CharField(_('Query Layer'), max_length=256) |
58 |
projection = models.CharField(_('GIS projection'), choices=PROJECTIONS, |
|
59 |
default='epsg:3857', max_length=16) |
|
51 | 60 | |
52 | 61 |
class Meta: |
53 | 62 |
verbose_name = _('OpenGIS') |
... | ... | |
134 | 143 |
'J': '0', |
135 | 144 |
'HEIGHT': '500', |
136 | 145 |
'WIDTH': '500', |
137 |
'CRS': 'EPSG:4171',
|
|
146 |
'CRS': self.projection,
|
|
138 | 147 |
'LAYERS': self.query_layer, |
139 | 148 |
'QUERY_LAYERS': self.query_layer, |
140 | 149 |
'BBOX': bbox, |
... | ... | |
165 | 174 |
lat_deg = math.degrees(lat_rad) |
166 | 175 |
return (lon_deg, lat_deg) |
167 | 176 | |
168 |
wgs84 = pyproj.Proj(init='epsg:4326') |
|
169 |
epsg3857 = pyproj.Proj(init='epsg:3857') |
|
170 | 177 |
# lower left |
171 |
ll_lon, ll_lat = pyproj.transform(wgs84, epsg3857, *num2deg(tile_x, tile_y+1, zoom))
|
|
178 |
ll_lon, ll_lat = num2deg(tile_x, tile_y+1, zoom)
|
|
172 | 179 |
# upper right |
173 |
ur_lon, ur_lat = pyproj.transform(wgs84, epsg3857, *num2deg(tile_x+1, tile_y, zoom)) |
|
180 |
ur_lon, ur_lat = num2deg(tile_x+1, tile_y, zoom) |
|
181 | ||
182 |
# convert only when projection system is other than WGS84 |
|
183 |
if self.projection != 'epsg:4326': |
|
184 |
wgs84 = pyproj.Proj(init='epsg:4326') |
|
185 |
target_projection = pyproj.Proj(init=self.projection) |
|
186 |
ll_lon, ll_lat = pyproj.transform(wgs84, target_projection, ll_lon, ll_lat) |
|
187 |
ur_lon, ur_lat = pyproj.transform(wgs84, target_projection, ur_lon, ur_lat) |
|
188 | ||
174 | 189 |
bbox = '%s,%s,%s,%s' % (ll_lon, ll_lat, ur_lon, ur_lat) |
175 | 190 | |
176 | 191 |
params = { |
... | ... | |
183 | 198 |
'TRANSPARENT': 'false', |
184 | 199 |
'HEIGHT': '256', |
185 | 200 |
'WIDTH': '256', |
186 |
'SRS': 'EPSG:3857',
|
|
201 |
'SRS': self.projection,
|
|
187 | 202 |
'BBOX': bbox, |
188 | 203 |
} |
189 | 204 |
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 |
- |