-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PB-583 : use backend service to get LV03 <> LV95 conversion right #887
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't use the fallback as well here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because if wrong coordinate are given as input, we will end up here (among other cases). And I didn't want to run a
proj4
call on malformed coordinate, as it would require anothertry...catch
wrapping