Skip to content

Commit

Permalink
fix index bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
wroge committed Nov 23, 2023
1 parent c9b243a commit 5cba3c0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# wgs84 v2 WIP

```sh
go get github.com/wroge/wgs84/v2
<img align="right" src="./logo.png" width="200"/>

## WGS84 - Coordinate Transformations

```
github.com/wroge/wgs84/v2
```


I am currently in the process of rewriting the package. Some things will change and some new features will be added. One of these features is the support of NTv2 grid transformations and other projections, such as Krovak. If you would like to help or have any comments, please report them in the issues.

Expand Down
6 changes: 4 additions & 2 deletions epsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func EPSG(code int) CRS {
crs = Geographic(Helmert(-87, -98, -121, 0, 0, 0, 0), NewSpheroid(6378388, 297))
case 4258:
crs = Geographic(EPSG(4978), NewSpheroid(6378137, 298.257222101))
case 4267:
crs = loadNTv2("NTv2_0.gsb", NewSpheroid(6378206.4, 294.978698213898), EPSG(4326))
// case 4267:
// crs = loadNTv2("NTv2_0.gsb", NewSpheroid(6378206.4, 294.978698213898), EPSG(4326))
case 4269:
crs = Geographic(EPSG(4978), NewSpheroid(6378137, 298.257222101))
case 4277:
Expand Down Expand Up @@ -123,6 +123,8 @@ func EPSG(code int) CRS {
crs = TransverseMercator(EPSG(4312), 16.33333333333333, 0, 1, 750000, 0)
case 31287:
crs = LambertConformalConic2SP(EPSG(4312), 13.33333333333333, 47.5, 49, 46, 400000, 400000)
// case 32024:
// crs = LambertConformalConic2SP(EPSG(4267), -98, 35, 35.5666666666667, 36.7666666666667, 2000000, 0)
case 102109:
crs = TransverseMercator(EPSG(4258), 15, 0, 0.9999, 500000, -5000000)
case 102157:
Expand Down
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 12 additions & 11 deletions wgs84.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ func Transform(from, to CRS) Func {
break
}

if from == to {
return chainFunc(toBase...)
}

toBase = append(toBase, from.ToBase)

from = from.Base()
Expand Down Expand Up @@ -114,11 +110,11 @@ func (errorCRS) Spheroid() Spheroid {
}

func (errorCRS) ToBase(x0, y0, z0 float64) (float64, float64, float64) {
return x0, y0, z0
return math.NaN(), math.NaN(), math.NaN()
}

func (errorCRS) FromBase(x0, y0, z0 float64) (float64, float64, float64) {
return x0, y0, z0
return math.NaN(), math.NaN(), math.NaN()
}

type Spheroid struct {
Expand Down Expand Up @@ -411,8 +407,8 @@ func (n ntv2) Shift(lon, lat float64) (float64, float64) {

ppr := math.Floor((n.wLong-n.eLong)/n.longInc+0.5) + 1
ppc := math.Floor((n.nLat-n.sLat)/n.latInc+0.5) + 1
se := row*ppr + col

se := row*ppr + col
sw := se + 1
ne := se + ppr
nw := ne + 1
Expand All @@ -434,10 +430,15 @@ func (n ntv2) Shift(lon, lat float64) (float64, float64) {
sw = nw
}

sse := n.values[int(se)]
ssw := n.values[int(sw)]
sne := n.values[int(ne)]
snw := n.values[int(nw)]
se_index := min(max(int(se), 0), len(n.values)-1)

Check failure on line 433 in wgs84.go

View workflow job for this annotation

GitHub Actions / lint

undefined: min

Check failure on line 433 in wgs84.go

View workflow job for this annotation

GitHub Actions / lint

undefined: max
sw_index := min(max(int(sw), 0), len(n.values)-1)

Check failure on line 434 in wgs84.go

View workflow job for this annotation

GitHub Actions / lint

undefined: min

Check failure on line 434 in wgs84.go

View workflow job for this annotation

GitHub Actions / lint

undefined: max
ne_index := min(max(int(ne), 0), len(n.values)-1)

Check failure on line 435 in wgs84.go

View workflow job for this annotation

GitHub Actions / lint

undefined: min

Check failure on line 435 in wgs84.go

View workflow job for this annotation

GitHub Actions / lint

undefined: max
nw_index := min(max(int(nw), 0), len(n.values)-1)

Check failure on line 436 in wgs84.go

View workflow job for this annotation

GitHub Actions / lint

undefined: min

Check failure on line 436 in wgs84.go

View workflow job for this annotation

GitHub Actions / lint

undefined: max

sse := n.values[se_index]
ssw := n.values[sw_index]
sne := n.values[ne_index]
snw := n.values[nw_index]

dx := fcol - col
dy := frow - row
Expand Down

0 comments on commit 5cba3c0

Please sign in to comment.