Comments (9)
Hi Dan,
Right now, I'm at the office rather than at home, so don't have a lot of time to look at something that I know works, but off the top of my head, it looks like you're using geographic coordinates rather than radian coordinates.
The .Net Math trig functions use radians, so there's some helper functions in the API you can use to convert the values of a GeoGoord to valid radian values which are needed for things to work.
double DegreesToRadians(double degrees)
double RadiansToDegrees(double radians)
If you dig into the codebase a little, there's a currently public function in H3Net.Code.GeoCoord called setGeoDegs
public static void setGeoDegs(ref GeoCoord p, double latDegs, double lonDegs)
{
_setGeoRads(ref p, degsToRads(latDegs), degsToRads(lonDegs));
}
You would use it like so:
var dgc = new GeoCoord();
H3Net.Code.GeoCoord.setGeoDegs(ref dgc, 37.775661, -122.417972);
from h3netold.
In regards to why 3.5, it's primarily because Unity3d for mobile likes it.
I'm currently in the process of catching the bugs that cropped up in the refactoring, but the unit tests are slowly becoming green.
As soon as the 3.5 version is working, I'll likely be forking this to Standard as well, maintaining both versions, keeping the 3.5 for my mobile app, and Standard for desktop management of the environment.
from h3netold.
Thanks!
I'll take a look at that in depth as I get things more developed with the refactoring I'm working on.
Question: Was one of the inaccuracies that you found, a deviation in values after 10 significant digits or so? I'm going to place that on the fact that the Math namespace trig functions use double instead of float.
When I mapped out some few thousand hexes though, spot checks showed that the vertices were in the correct spot, and they looked just fine as the attached pic shows:
There's still more to do on my conversion, and since it needs to conform to .Net 3.5 initially, it's going to be a little weird internally, but I'm shooting for keeping the initial API i've set up to stay the same.
from h3netold.
Here's one example, using the location of Uber's HQ. I got the H3 index values from the original H3 library's h3ToGeo.exe test app.
// 37.775661, -122.417972
string[] uberh3 = new string[]
{
"8029fffffffffff", // 0
"81283ffffffffff", // 1
"822837fffffffff", // 2
"832830fffffffff", // 3
"8428309ffffffff", // 4
"85283083fffffff", // 5
"86283082fffffff", // 6
"872830828ffffff", // 7
"8828308281fffff", // 8
"8928308280fffff", // 9
"8a28308280f7fff", // 10
"8b28308280f5fff", // 11
"8c28308280f53ff", // 12
"8d28308280f507f", // 13
"8e28308280f53a7", // 14
"8f28308280f53a4", // 15
};
[Test]
public void TestLocation_GeoToH3()
{
for (int i = 0; i < uberh3.Length; i++)
{
var h3expected = new H3Index(ulong.Parse(uberh3[i], NumberStyles.HexNumber));
var g = new GeoCoord(37.775661, -122.417972);
var h3actual = H3Index.geoToH3(ref g, i);
Assert.AreEqual(h3expected.value.ToString("X"), h3actual.value.ToString("X"),
$"unexpected geoToH3 output at res {i}");
}
}
unexpected geoToH3 output at res 0
Expected: "8029FFFFFFFFFFF"
But was: "8071FFFFFFFFFFF"
When I send 8071FFFFFFFFFFF to H3's h3ToGeo.exe, it gives a latitude and longitude of (4.7796854525, -170.3596184978), which is in the South Pacific Ocean.
from h3netold.
Here's the test running the other direction, from H3 to GeoCoord.
[Test]
public void TestLocation_h3ToGeo()
{
for (int i = 0; i < uberh3.Length; i++)
{
var h3 = new H3Index(ulong.Parse(uberh3[i], NumberStyles.HexNumber));
var g = new GeoCoord();
H3Index.h3ToGeo(h3, ref g);
const double epsilon = 0.0001 * Constants.M_PI_180;
var expected = new GeoCoord(37.775661, -122.417972);
Assert.True(GeoCoord.geoAlmostEqualThreshold(expected, g, epsilon),
$"unexpected h3ToGeo output at res {i}");
}
}
from h3netold.
Regarding your refactoring project, I started my own H3 port to C# not knowing you were already working on it. While I'm not as far along as you are here, I couldn't help but start that same refactoring process, even before moving it all over. It's quite the process. Feel free to borrow or steal anything you see there. The fluent style interface with all the converters cleans up the code really nice, makes it easier to read IMO.
I'm scratching my head over whether to continue my porting efforts, or to adopt your library. But if you're staying on .NET Framework 3.5, and I want to use .NET Standard 2.0+, I'm not sure how practical it'll be. What kind of environment are you targeting that you're constrained to 3.5?
from h3netold.
That was my error. Forgot about the radian degree measurements.
Thank you!
from h3netold.
from h3netold.
@danvanderboom Glad you got it to work.
from h3netold.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from h3netold.