Skip to content

Commit

Permalink
Feature/sir 1144 (#221)
Browse files Browse the repository at this point in the history
* SIR-1144 adding a OSGB to WGS84 point transform

* sonarcloud issue
  • Loading branch information
teddmason authored Nov 15, 2024
1 parent 217f529 commit e5049bc
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
8 changes: 8 additions & 0 deletions server/routes/__tests__/smell/location-map.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ describe(url, () => {
...baseAnswer,
answerId: question.answers.northing.answerId,
otherDetails: '343015'
}, {
...baseAnswer,
answerId: question.answers.lng.answerId,
otherDetails: '-2.511745'
}, {
...baseAnswer,
answerId: question.answers.lat.answerId,
otherDetails: '52.983397'
}])
})
it('Sad: errors on no point provided', async () => {
Expand Down
8 changes: 8 additions & 0 deletions server/routes/__tests__/water-pollution/location-map.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ describe(url, () => {
...baseAnswer,
answerId: question.answers.northing.answerId,
otherDetails: '343015'
}, {
...baseAnswer,
answerId: question.answers.lng.answerId,
otherDetails: '-2.511745'
}, {
...baseAnswer,
answerId: question.answers.lat.answerId,
otherDetails: '52.983397'
}])
})
it('Sad: errors on no point provided', async () => {
Expand Down
16 changes: 14 additions & 2 deletions server/routes/smell/location-map.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import constants from '../../utils/constants.js'
import bngToNgr from '../../utils/bng-to-ngr.js'
import { questionSets } from '../../utils/question-sets.js'
import { oSGBToWGS84 } from '../../utils/transform-point.js'

const question = questionSets.SMELL.questions.SMELL_LOCATION_MAP
const baseAnswer = {
Expand All @@ -27,7 +28,9 @@ const handlers = {
})
}

request.yar.set(constants.redisKeys.SMELL_LOCATION_MAP, buildAnswers(point))
const lngLat = oSGBToWGS84(point)

request.yar.set(constants.redisKeys.SMELL_LOCATION_MAP, buildAnswers(point, lngLat))

// handle redirects
return h.redirect(constants.routes.SMELL_PREVIOUS)
Expand All @@ -40,8 +43,9 @@ const getContext = () => {
}
}

const buildAnswers = point => {
const buildAnswers = (point, lngLat) => {
const ngr = bngToNgr(point).text
const six = 6
return [{
...baseAnswer,
answerId: question.answers.nationalGridReference.answerId,
Expand All @@ -54,6 +58,14 @@ const buildAnswers = point => {
...baseAnswer,
answerId: question.answers.northing.answerId,
otherDetails: Math.floor(point[1]).toString()
}, {
...baseAnswer,
answerId: question.answers.lng.answerId,
otherDetails: lngLat[0].toFixed(six)
}, {
...baseAnswer,
answerId: question.answers.lat.answerId,
otherDetails: lngLat[1].toFixed(six)
}]
}

Expand Down
16 changes: 14 additions & 2 deletions server/routes/water-pollution/location-map.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import constants from '../../utils/constants.js'
import bngToNgr from '../../utils/bng-to-ngr.js'
import { questionSets } from '../../utils/question-sets.js'
import { oSGBToWGS84 } from '../../utils/transform-point.js'

const question = questionSets.WATER_POLLUTION.questions.WATER_POLLUTION_LOCATION_MAP
const baseAnswer = {
Expand All @@ -27,7 +28,9 @@ const handlers = {
})
}

request.yar.set(constants.redisKeys.WATER_POLLUTION_LOCATION_MAP, buildAnswers(point))
const lngLat = oSGBToWGS84(point)

request.yar.set(constants.redisKeys.WATER_POLLUTION_LOCATION_MAP, buildAnswers(point, lngLat))

// handle redirects
return h.redirect(constants.routes.WATER_POLLUTION_WHEN)
Expand All @@ -40,8 +43,9 @@ const getContext = () => {
}
}

const buildAnswers = point => {
const buildAnswers = (point, lngLat) => {
const ngr = bngToNgr(point).text
const six = 6
return [{
...baseAnswer,
answerId: question.answers.nationalGridReference.answerId,
Expand All @@ -54,6 +58,14 @@ const buildAnswers = point => {
...baseAnswer,
answerId: question.answers.northing.answerId,
otherDetails: Math.floor(point[1]).toString()
}, {
...baseAnswer,
answerId: question.answers.lng.answerId,
otherDetails: lngLat[0].toFixed(six)
}, {
...baseAnswer,
answerId: question.answers.lat.answerId,
otherDetails: lngLat[1].toFixed(six)
}]
}

Expand Down
Binary file added server/utils/OSTN15_NTv2_OSGBtoETRS.gsb
Binary file not shown.
12 changes: 12 additions & 0 deletions server/utils/question-sets.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ const questionSets = {
},
northing: {
answerId: 2703
},
lng: {
answerId: 2704
},
lat: {
answerId: 2705
}
}
},
Expand Down Expand Up @@ -453,6 +459,12 @@ const questionSets = {
},
northing: {
answerId: 2703
},
lng: {
answerId: 2704
},
lat: {
answerId: 2705
}
}
},
Expand Down
14 changes: 14 additions & 0 deletions server/utils/transform-point.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import proj4 from 'proj4'
import { readFileSync } from 'fs'

const oSTN15 = readFileSync('./server/utils/OSTN15_NTv2_OSGBtoETRS.gsb').buffer

proj4.nadgrid('OSTN15_NTv2_OSGBtoETRS', oSTN15)
proj4.defs('EPSG:27700', '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs +nadgrids=OSTN15_NTv2_OSGBtoETRS')
// proj4.defs('EPSG:27700', '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs')

const oSGBToWGS84 = point => proj4('EPSG:27700', 'EPSG:4326', point)

export {
oSGBToWGS84
}

0 comments on commit e5049bc

Please sign in to comment.