Commit d4c16e8a authored by Jonny Schäfer's avatar Jonny Schäfer
Browse files

Add label independent grid identification

parent e2d15b37
...@@ -4,6 +4,17 @@ import ( ...@@ -4,6 +4,17 @@ import (
"math" "math"
) )
// corner coordinates for projection are defined by the grid type
type grid int
const (
unknownGrid grid = iota
nationalGrid // resolution: 900km * 900km
nationalPictureGrid // resolution: 920km * 920km
extendedNationalGrid // resolution: 900km * 1100km
middleEuropeanGrid // resolution: 1400km * 1500km
)
// values described in [1] // values described in [1]
const ( const (
earthRadius = 6370.04 // km earthRadius = 6370.04 // km
...@@ -12,50 +23,64 @@ const ( ...@@ -12,50 +23,64 @@ const (
junctionEast = 10.0 // E junctionEast = 10.0 // E
) )
// isScaled returns true if the composite can be scaled to the given dimensions // minRes repeatedly bisects the given edges until no further step is possible
// while also maintaining the aspect ratio. // for at least one edge. The resulting dimensions are the returned.
func (c *Composite) isScaled(dx, dy int) bool { func minRes(dx, dy int) (rdx int, rdy int) {
epsilon := 0.00000001 rdx, rdy = dx, dy
return math.Abs(1-float64(c.Dy*dx)/float64(c.Dx*dy)) < epsilon
if rdx == 0 || rdy == 0 {
return
}
for rdx&1 == 0 && rdy&1 == 0 {
rdx >>= 1
rdy >>= 1
}
return
} }
// errNoProjection means that the projection grid could not be identified. // errNoProjection means that the projection grid could not be identified.
var errNoProjection = newError("cornerPoints", "warning: unable to identify grid") var errNoProjection = newError("cornerPoints", "warning: unable to identify grid")
// cornerPoints returns corner coordinates of the national, extended or middle-european grid // detectGrid identifies the used projection grid based on the composite dimensions
// based on the product label or resolution of the composite. The used values are func (c *Composite) detectGrid() grid {
// described in [1], [4] and [5]. dx, dy := minRes(c.Dx, c.Dy)
// If an error is returned, translation methods will not work.
func (c *Composite) cornerPoints() (originTop, originLeft, edgeBottom, edgeRight float64, err error) { if mx, my := minRes(900, 900); dx == mx && dy == my {
// national grid (pg) values described in [4] return nationalGrid
if c.Product == "PG" { }
originTop, originLeft = 54.66218275, 1.900684377 // N, E if mx, my := minRes(920, 920); dx == mx && dy == my {
edgeBottom, edgeRight = 46.98044293, 14.73300934 // N, E return nationalPictureGrid
return
} }
if mx, my := minRes(900, 1100); dx == mx && dy == my {
return extendedNationalGrid
}
if mx, my := minRes(1400, 1500); dx == mx && dy == my {
return middleEuropeanGrid
}
return unknownGrid
}
// national grid values described in [1] // cornerPoints returns corner coordinates of the national, extended or
if c.isScaled(900, 900) { // middle-european grid based on the dimensions of the composite. The used
// values are described in [1], [4] and [5]. If an error is returned,
// translation methods will not work.
func (c *Composite) cornerPoints() (originTop, originLeft, edgeBottom, edgeRight float64, err error) {
switch c.detectGrid() {
case nationalGrid: // described in [1]
originTop, originLeft = 54.5877, 02.0715 // N, E originTop, originLeft = 54.5877, 02.0715 // N, E
edgeBottom, edgeRight = 47.0705, 14.6209 // N, E edgeBottom, edgeRight = 47.0705, 14.6209 // N, E
return case nationalPictureGrid: // (pg) described in [4]
} originTop, originLeft = 54.66218275, 1.900684377 // N, E
edgeBottom, edgeRight = 46.98044293, 14.73300934 // N, E
// extended national grid described in [5] case extendedNationalGrid: // described in [5]
if c.isScaled(900, 1100) {
originTop, originLeft = 55.5482, 03.0889 // N, E originTop, originLeft = 55.5482, 03.0889 // N, E
edgeBottom, edgeRight = 46.1827, 15.4801 // N, E edgeBottom, edgeRight = 46.1827, 15.4801 // N, E
return case middleEuropeanGrid: // described in [5]
}
// middle european grid described in [5]
if c.isScaled(1400, 1500) {
originTop, originLeft = 56.5423, -0.8654 // N, E originTop, originLeft = 56.5423, -0.8654 // N, E
edgeBottom, edgeRight = 43.8736, 18.2536 // N, E edgeBottom, edgeRight = 43.8736, 18.2536 // N, E
return default:
err = errNoProjection
} }
err = errNoProjection
return return
} }
......
...@@ -30,10 +30,10 @@ func TestResolution(t *testing.T) { ...@@ -30,10 +30,10 @@ func TestResolution(t *testing.T) {
NewDummy("SF", 900, 900), NewDummy("SF", 900, 900),
NewDummy("SF", 450, 450), NewDummy("SF", 450, 450),
NewDummy("SF", 225, 225), NewDummy("SF", 225, 225),
NewDummy("SF", 112, 112),
NewDummy("WX", 900, 1100), NewDummy("WX", 900, 1100),
NewDummy("WX", 450, 550), NewDummy("WX", 450, 550),
NewDummy("EX", 1400, 1500), NewDummy("EX", 1400, 1500),
NewDummy("EX", 700, 750),
} }
for _, comp := range dummys { for _, comp := range dummys {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment