Results 1 to 1 of 1

Thread: OSTN02.pas

  1. #1
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    OSTN02.pas

    Hi all,

    It's been a while since I've posted anything up here.. Things have been pretty busy over the last couple years with uni and other projects taking up most of my time. Recently, I've spent a lot of time working on some guidance systems and came across one heck of an annoying problem: converting Ordnance Survey grid references to gps co-ordinates. For those of you not aware of OS maps, in the UK we have an organization that likes making lots of maps. Unfortunately, they feel above what the rest of the world (or europe) use and don't provide their data in ETRS89 (european version of WGS84) or WGS84 (think GPS). They say that the conversion is to go from their grid reference to OSGB36 to ETRS89 before doing the final WGS84 conversion.

    Now, why would I ever spend time doing such a conversion? Well, they produce a whole lot of good data on the geography of the UK - and are pretty liberal with how you can use it. Looking around there are a fair few libraries out there for java, javacript and stranger languages. (it is worth noting a lot of these use the mathematical transform and are accurate down to ~5M). With more digging I found a nice little C library up on github: https://github.com/jawj/OSTN02C. In this instance I needed pascal bindings to make use of this in an existing project, and having considered either re-implementing it, or just creating bindings, I decided I may as well do the latter since it'd be a lot quicker and wouldn't require me to re-validate the code.

    I've attached the bindings and relevant source files to this post. The build process is rather simple;
    Code:
    gcc -c crc32.c
    gcc -c OSTN02.c
    fpc pastn02c.pas
    This is a pretty quick and dirty job, and all the credit goes to the original author of the library, but if you want to use my OSTN02.pas file however you like go right ahead (I forget which of the BSD licences is the sane one which is effectively 'hey I did something, go use it however').

    I've included a very quick test program (pastn02c.pas) which converts an example northing/easting value to GPS co-ordinates (ETRS89) and prints the output of its little test function (which I have renamed given the rather annoying name for use in other stuff). Hopefully someone might find this useful for making the next pokemon go, flightsim game or whatever that may need to work with some funky co-ordinate systems...
    Attached Files Attached Files
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •