-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #887 from geoadmin/feat_PB-583_use_backend_to_get_…
…lv03 PB-583 : use backend service to get LV03 <> LV95 conversion right
- Loading branch information
Showing
4 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import axios from 'axios' | ||
import proj4 from 'proj4' | ||
|
||
import { LV03, LV95 } from '@/utils/coordinates/coordinateSystems' | ||
import log from '@/utils/logging' | ||
|
||
const REFRAME_BASE_URL = 'https://geodesy.geo.admin.ch/reframe/' | ||
|
||
/** | ||
* Re-frames LV95 coordinate taking all LV03 -> LV95 deformation into account (they are not stable, | ||
* so using "simple" proj4 matrices isn't enough to get a very accurate result) | ||
* | ||
* @param {[Number, Number]} lv95coordinate LV95 coordinate that we want expressed in LV03 | ||
* @returns {Promise<[Number, Number]>} Input LV95 coordinate re-framed by the backend service into | ||
* LV03 coordinate | ||
* @see https://www.swisstopo.admin.ch/en/rest-api-geoservices-reframe-web | ||
* @see https://github.com/geoadmin/mf-geoadmin3/blob/master/src/components/ReframeService.js | ||
*/ | ||
export default function reframe(lv95coordinate) { | ||
return new Promise((resolve, reject) => { | ||
if (!Array.isArray(lv95coordinate) || lv95coordinate.length !== 2) { | ||
reject(new Error('lv95coordinate must be an array with length of 2')) | ||
} | ||
axios({ | ||
method: 'GET', | ||
url: `${REFRAME_BASE_URL}lv95tolv03`, | ||
params: { | ||
easting: lv95coordinate[0], | ||
northing: lv95coordinate[1], | ||
}, | ||
}) | ||
.then((response) => { | ||
if (response.data?.coordinates) { | ||
resolve(response.data.coordinates) | ||
} else { | ||
log.error( | ||
'Error while re-framing coordinate', | ||
lv95coordinate, | ||
'fallback to proj4' | ||
) | ||
resolve(proj4(LV95.epsg, LV03.epsg, lv95coordinate)) | ||
} | ||
}) | ||
.catch((error) => { | ||
log.error('Error while re-framing coordinate', lv95coordinate, error) | ||
reject(error) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters