Skip to content

Commit

Permalink
Reproject: Enhance performance of multiple reprojections.
Browse files Browse the repository at this point in the history
  • Loading branch information
geofurlong committed Jun 8, 2024
1 parent eaff1cb commit cc7a32e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/builder/precompute.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func precompute(cfg GeofurlongConfig, resolution int) { //
geocode.Check(err)

// Set up projection conversion from OSGB planar (EPSG:27700) to geographic longitude / latitude (EPSG:4326).
pj := geocode.OSGBtoLongLat()
pj := geocode.OSGBToLonLat()

file, err := os.Create(fmt.Sprintf("%s/geofurlong_precomputed_%.4dy.csv", cfg["precompute_dir"], resolution))
geocode.Check(err)
Expand Down
8 changes: 3 additions & 5 deletions pkg/geocode/reproject.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const (
GeographicCRS = "EPSG:4326"
)

// OSGBtoLongLat returns a pointer to the transformer from projected OSGB36 (EPSG:27700) to geographic Longitude / Latitude (EPSG:4326).
func OSGBtoLongLat() *proj.PJ {
// OSGBToLonLat returns a pointer to the transformer from projected OSGB36 (EPSG:27700) to geographic Longitude / Latitude (EPSG:4326).
func OSGBToLonLat() *proj.PJ {
pj, err := proj.NewCRSToCRS(ProjectedCRS, GeographicCRS, nil)
Check(err)

Expand All @@ -33,10 +33,8 @@ func Reproject(point orb.Point, pj *proj.PJ) orb.Point {
}

// ReprojectMulti takes a slice of projected Easting / Northing points and returns the corresponding Longitude / Latitude points slice.
func ReprojectMulti(points []orb.Point) []orb.Point {
func ReprojectMulti(points []orb.Point, pj *proj.PJ) []orb.Point {
latLons := make([]orb.Point, len(points))
pj, err := proj.NewCRSToCRS(ProjectedCRS, GeographicCRS, nil)
Check(err)

for i, point := range points {
latLon, err := pj.Forward(proj.Coord{point.X(), point.Y()})
Expand Down
7 changes: 4 additions & 3 deletions pkg/geocode/reproject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestReproject(t *testing.T) {
planarPoints = append(planarPoints, orb.Point{float64(testPlace.easting), float64(testPlace.northing)})
}

geoPoints := ReprojectMulti(planarPoints)
geoPoints := ReprojectMulti(planarPoints, OSGBToLonLat())
for i, testPlace := range testPlaces {
deltaX := geoPoints[i].Point().X() - testPlace.lonLat.X()
deltaY := geoPoints[i].Point().Y() - testPlace.lonLat.Y()
Expand All @@ -28,9 +28,9 @@ func TestReproject(t *testing.T) {
}
}

pj := OSGBtoLongLat()
pjToGeo := OSGBToLonLat()
for _, testPlace := range testPlaces {
geoPoint := Reproject(orb.Point{float64(testPlace.easting), float64(testPlace.northing)}, pj)
geoPoint := Reproject(orb.Point{float64(testPlace.easting), float64(testPlace.northing)}, pjToGeo)
deltaX := geoPoint.X() - testPlace.lonLat.X()
deltaY := geoPoint.Y() - testPlace.lonLat.Y()

Expand All @@ -39,4 +39,5 @@ func TestReproject(t *testing.T) {
t.Fail()
}
}

}

0 comments on commit cc7a32e

Please sign in to comment.