0

I wonder whether someone may be able to help me please.

I currently use the code below (originating from nearby.org.uk) to allow a user to convert OS Grid Refernces to a Lat & Lng co-ordinate via an HTML form.

function converttolatlng() {
    var gr = document.getElementById('osgridref').value;

    var osgb = new GT_OSGB();


    if (osgb.parseGridRef(gr)) {
        var wgs84 = osgb.getWGS84();

        document.getElementById('osgb36lat').value = wgs84.latitude;
        document.getElementById('osgb36lon').value = wgs84.longitude;
    }
    else {
        document.getElementById('osgb36lat').value = "n/a";
        document.getElementById('osgb36lon').value = "n/a";
    }

}

However on a monthly basis I need to convert an xml list of approx 22,000 OS Grid References. Because of the amount of data involved it's obviously not practical to use an HTML form so I've been working on a way to automate this. The list originates in an XML format, so I've put together the code below to extract the XML data into PHP.

<? 
  $objDOM = new DOMDocument(); 
  $objDOM->load("xmlfile.xml"); 

  $note = $objDOM->getElementsByTagName("Details"); 

  foreach( $note as $value ) 
  { 
    $NGR = $value->getElementsByTagName("NGR"); 
    $ngr  = $NGR->item(0)->nodeValue; 

    echo "$ngr <br>"; 
  } 

I've now come to a point where I'm a little unsure about what to do next. I know that I need to convert the Grid References through the Javascript function and in addition create the Lat & Lng fields that ordinarily would be on my HTML form. I then need to be able to upload this data to a table in a mySQL database.

Could someone perhaps take a look at this please and show me what I need to to convert the Grid References and how I can upload them to my database.

Many thanks

UPDATE

This an extract of the xml file:

 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
- <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <Details>
  <LISTENTRY>1003886</LISTENTRY> 
  <NGR>SS 00000 11111</NGR> 
  </Details>

and please find a link to the 'geotools' file here.

2
  • Cannot be of much help without knowning the structure of the XML file and the code that makes up the getWGS84 Javascript function. Commented Oct 6, 2011 at 15:07
  • Hi, many thanks for replying to my post. I've added an extract of the xml file and the link to the 'geotools' file which the JS function works in conjunction with to my original post. I didn't want to paste the whole file as it's quite a lengthy script. Kind regards Commented Oct 6, 2011 at 15:29

1 Answer 1

1

Passing through a webservice the way you describe should really be your last option, maybe this php code from the Geograph project is what you are looking for. If not I'd suggest you translate the js code to php.

EDIT: how to integrate? I'd start by reading a bit on OSB36 to understand what the 3 elements in <NGR> actually are and how they should be interpreted. The hardest part is the translation of the grid digits to an offset (you need the reverse of osgb36_to_gridref). One way of doing that can be derived from parseGridRef in geotools2.js

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, many thanks for replying to my post. I've had a look at this, and please excuse my beginners ignorance on this. Could you tell me please how I would incorporate this using the variables in my exisitng script? Kind regards
Many thanks for the update. I'll have a look at the geotools JS. Kind regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.