Coder Social home page Coder Social logo

go-elevations's Introduction

SRTM parser for golang

go-elevations is a parser for "The Shuttle Radar Topography Mission" data.

It is based on the existing library for python srtm.py

Usage

package main

import (
	"fmt"
	"net/http"

	"github.com/tkrajina/go-elevations/geoelevations"
)

func main() {
	srtm, err := geoelevations.NewSrtm(http.DefaultClient)
	if err != nil {
		panic(err.Error())
	}
	elevation, err := srtm.GetElevation(http.DefaultClient, 45.2775, 13.726111)
	if err != nil {
		panic(err.Error())
	}
	fmt.Println("Višnjan elevation is", elevation)
}

go-elevations is a parser for "The Shuttle Radar Topography Mission" data.

It is based on the existing library for python srtm.py

License

This library is licensed under the Apache License, Version 2.0

go-elevations's People

Contributors

dave avatar tkrajina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-elevations's Issues

Elevation returns NaN

I'm getting lots of NaNs from this point...

An example:

Lat: 30.404229
Lon: 79.547245

Locals in the debugger at that point are:

row = {int} 714
column = {int} 656
i = {int} 858170
byte1 = {uint8} 128
byte2 = {uint8} 0
result = {int} 32768

Any ideas why?

Code doesn't run- missing client

Cool library, but unfortunately doesn't seem to run as stated in README.md (called example.go), here are the errors

./example.go:10:39: not enough arguments in call to geoelevations.NewSrtm
	have ()
	want (*http.Client)
./example.go:14:40: not enough arguments in call to srtm.GetElevation
	have (number, number)
	want (*http.Client, float64, float64)```

Downloads broken?

Hi, I was using the library for quite some time and it always worked seamlessly.
Thank you for all your work.

Today, when I wanted to get the elevation of some coordinates, I got 2024/03/21 21:46:33 Invalid file N45E013 in the logs and the result was NaN.
Maybe the mirror changed again?

When I find some time, I might look into it myself.
Thanks again.

SRTM Website No Longer Providing Data

I think the USGS https://dds.cr.usgs.gov/srtm/ is no longer delivering data non-authenticated HTTP requests.
Every request seems to return a 404 not found.
Example: https://dds.cr.usgs.gov/srtm/version2_1/SRTM1//Region_01/N40W114.hgt.zip returns a 404.

Looks like the tests are failing because of this. Granted, am just running go test and didn't really debug further.

--- FAIL: TestGetElevation (0.00s) srtm_test.go:51: Invalid elevation for (45.277500, 13.726111): NaN, but should be 246.000000 srtm_test.go:51: Invalid elevation for (-26.400000, 146.250000): NaN, but should be 301.000000 srtm_test.go:51: Invalid elevation for (-12.100000, -77.016667): NaN, but should be 133.000000 srtm_test.go:51: Invalid elevation for (40.750000, -111.883333): NaN, but should be 1298.000000

My current solution is to download the data from https://search.earthdata.nasa.gov/ (NASA Shuttle Radar Topography Mission Global 3 arc second V003) and putting it into the cache directory with the filename that the go-elevations library is looking for. The earthdata does require a free account to access the downloads.

Earthdata produces a script that downloads each file individually.
Here's an example of one of the new download links.
https://e4ftl01.cr.usgs.gov//DP133/SRTM/SRTMGL3.003/2000.02.11/S34W059.SRTMGL3.hgt.zip
The script itself is just a bash script that uses curl to retrieve the data. It's authentication is archieved via a netrc file, so just basic authentication it looks like.

Here is some highlights from the script:

setup_auth_curl() {
    # Firstly, check if it require URS authentication
    status=$(curl -s -z "$(date)" -w %{http_code} https://e4ftl01.cr.usgs.gov//DP133/SRTM/SRTMGL3.003/2000.02.11/S34W059.SRTMGL3.hgt.zip | tail -1)
    if [[ "$status" -ne "200" && "$status" -ne "304" ]]; then
        # URS authentication is required. Now further check if the application/remote service is approved.
        detect_app_approval
    fi

fetch_urls() {
  if command -v curl >/dev/null 2>&1; then
      setup_auth_curl
      while read -r line; do
        # Get everything after the last '/'
        filename="${line##*/}"

        # Strip everything after '?'
        stripped_query_params="${filename%%\?*}"

        curl -f -b "$cookiejar" -c "$cookiejar" -L --netrc-file "$netrc" -g -o $stripped_query_params -- $line && echo || exit_with_error "Command failed with error. Please retrieve the data manually."
      done;
  fi
}

So in theory, I guess the library could be updated to use a new urls.json, and with a username + password configured in the client creation helper? But I'm unsure of this host being active all the time: e4ftl01.cr.usgs.gov

Anyway, just posting my findings. Hopefully what I wrote makes sense! Definitely a bummer if they did take down the SRTM service, the library has worked great thus far!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.