Giter Club home page Giter Club logo

h3netold's Introduction

Nothing here yet

h3netold's People

Contributors

richardvasquez avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

h3netold's Issues

unit test for conversions between H3 index and lat/long coordinates

I was able to get this project to build in Visual Studio 2017, but only after upgrading the target framework. Didn't want to issue a pull request with such a big framework change, but after noticing that conversions between H3 and latitude/longitude were incorrect and that geo boundaries were not being generated correctly, I wrote this unit test for these conversions using the res0#ic.txt files in the input directory:

public static string[] ICFileNameStrings() => new [] { "res00ic.txt", "res01ic.txt", "res02ic.txt", "res03ic.txt", "res04ic.txt" };

    [Test, Sequential]
    public async Task Conversions_H3Index_GeoCoord([ValueSource("ICFileNameStrings")] string filename)
    {
        for (int i = 0; i <= 4; i++)
        {
            var fileName = $"res0{i}ic.txt";
            var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "input", fileName);

            using (var sr = new StreamReader(path))
            {
                while (!sr.EndOfStream)
                {
                    var line = await sr.ReadLineAsync();
                    var match = Regex.Match(line, 
                        @"(?<h3>\w+)\s(?<lat>[-+]?([0-9]*\.[0-9]+|[0-9]+))\s(?<lon>[-+]?([0-9]*\.[0-9]+|[0-9]+))");

                    var h3str = match.Groups["h3"].Value;
                    var lat = double.Parse(match.Groups["lat"].Value);
                    var lon = double.Parse(match.Groups["lon"].Value);

                    var h3index = new H3Index(ulong.Parse(h3str, NumberStyles.HexNumber));

                    var coord = new GeoCoord(lat, lon);

                    assertExpected(h3index, ref coord);
                }
            }
        }
    }`

H3Index differs between .Net version and JS version.

I was testing H3.Net and wanted to cross check it against Javascript version of the api at 3.2.0. I realized that the H3Index generated by .Net version and JS version differs even though they both are returned as valid index.

.Net code
GeoCoord gc = new GeoCoord(27.700769, 85.300140);
var index = Api.GeoToH3(gc, 7);
Console.WriteLine(index);
Console.WriteLine(Api.H3IsValid(index));

Result:
873F512E5FFFFFF
1

JavaScript code: (npm install [email protected])
const h3 = require("h3-js");
const h3Index = h3.geoToH3(27.700769, 85.300140, 7);
console.log(h3Index);
console.log(h3.h3IsValid(h3Index));

Result:
873c02992ffffff
true

Note: JS will produce same index for newer version of H3.

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.