in reply to Lat/Lon to V&H conversion

You should be able to find Geo::Coordinates::VandH::XS on CPAN shortly. It handles both ways.

cheers

tachyon

Replies are listed 'Best First'.
Re^2: Lat/Lon to V&H conversion
by jcoxen (Deacon) on Oct 15, 2004 at 19:44 UTC
    UPDATE - I installed Geo::Coordinates::VandH::XS on my test/development box and put together a quick little test program. After I modified the code to explicitly call Geo::Coordinates::VandH::XS::toVH, the test program worked. Except it gave the wrong answer. The curious thing is, it gave the exact same wrong answer as my converted-over-from-C program.

    All this leads me to think that there's a flaw in the original code somewhere since there's no way I could have made a mistake...unless, or course, I did make a mistake. So, just to make sure, here's my converted code...

      There is an issue with sign I did not really bother to diagnose. I was not sure if it was an error with the toVH or the toLatLon function as the only sample data I found used negative Longitudes (so it looked like toVH was wrong) but toVH agreed with the existing module results. If you enter -104 degrees for the longitude it works exactly as expected.

      V = 7349.7333432988 Latitude = 40.423792190582 H = 5909.05477294282 Longitude = -104.791265047498

      I was to lazy to grok why it should be so. There are comments about the sign for E-W and N-S and also notes that it is US centric. I would be interested in some clarification on the sign issue. Evidently one is 'wrong'. Its easy to fix of course.

      With the XS code (which will be around 100x faster than pure perl) you need to import the functions you want to avoid a fully qualified call. It is good practice with modules not to export by default.

      # import all the available functions specifying by name use Geo::Coordinates::VandH::XS qw( toVH toLatLon distance degrees rad +ians ); # or as documented in the very sparse docs ;-) use Geo::Coordinates::VandH::XS qw( :all );

      cheers

      tachyon

        I figured the sign thing out just a few minutes ago and was turning to PerlMonks to post my stupidity when I saw that you had figured it out ahead of me. The rhythmic thumping sound you hear in the background is me pounding my head against my desk.

        V&H is VERY US centric. It's a Ma Bell invention from the late 50's when they were THE telephone monopoly. My guess is they were throwing in their own obfuscation to keep themselves a monopoly. BTW, if you go here, you'll see a map showing the V&H grid system. Note the relationship of the grid to a North-South axis and how the origin of the grid is upper-right as opposed to the normal lower-left. Add to that the fact that the paper describing the V&H system and the conversion to/from Lat/Lon is 109 freaking pages long and I don't think clarity and ease of use were primary considerations.

        Anyway, thank you VERY much for your module and your help. You've been a life saver.

        Jack

        Cogito cogito, ergo cogito sum
        (I think I think, therefore I think I am)
Re^2: Lat/Lon to V&H conversion
by jcoxen (Deacon) on Oct 15, 2004 at 14:38 UTC
    Could you define "shortly"?

    Never mind. Shortly means now. Just found it.

    Cogito cogito, ergo cogito sum
    (I think I think, therefore I think I am)