Select to view content in your preferred language

convert WGS84 to 27700 using geometry service - what datum transformation?

4177
11
04-08-2014 07:28 AM
MikeSteven
Regular Contributor
Hi,

I'm trying to convert coordinates from WGS84 to British National Grid using the geometry service but when I do this, the points all seem to be a bit out (maybe 100m or so). From reading up on this it seems that the reason is probably I'm not doing a datum transformation to the coordinates. However, I can't find out what value to put in for the datum transformation.

The starting coordinates come from the geolocation API so are in WKID 4326, so the starting datum should be WGS1984 I think. The output spatial reference is British National Grid (WKID 27700) so it's datum is OSGB_1936. I've been searching to find out what the value for the datum transformation should be and the closest I've come is EPSG::1314 which is for WGS1984_To_OSGB_1936. I've tried specifying this as the datum transformation value but the output point is in the same location as if I leave this datum transformation parameter blank.

Has anyone else come across this?

   function zoomToLocation(location) {
    var pt = new Point(location.coords.longitude, location.coords.latitude, new SpatialReference({
     wkid : 4236
    }));
    var outSR = new SpatialReference({
     wkid : 27700
    });

    var PrjParams = new ProjectParameters();
    PrjParams.geometries = [pt];
    PrjParams.outSR = outSR;
    var datumtrans = 1314;
    PrjParams.transformation = datumtrans;

    geometryService.project(PrjParams, function(projectedPoints) {
     console.log('Conversion completed. Datum Transformation: ' + datumtrans + '.');
     pt = projectedPoints[0];
     map.centerAndZoom(pt, 8);
    });
   }
0 Kudos
11 Replies
JohnGravois
Deactivated User
your methodology seems correct to me and i can see by adding and removing the datum transformation in the request below that the output x and y are affected by about 100 units.
http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer/project...

are you sure your own geometry service supports adding a transformation?  this capability wasn't added until 10.1
http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Project/02r3000000pv000000/

HowTo:  Select the correct geographic (datum) transformation when projecting between datums
http://support.esri.com/fr/knowledgebase/techarticles/detail/21327
0 Kudos
MikeSteven
Regular Contributor
Thanks for your reply. Yeah I had been using ArcGIS Server 10.0 without thinking about it. We've also got a server running ArcGIS Server v10.2 and I've put the code into a javascript map on that server and when I put in the datum transformation as 1314 it shifts the results further to the west (they should be getting shifted to the east).

In your link

http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer/project

I've just seen the transform forward parameter and notice that when I change it there it changes the values. How do I change this parameter in my code? I've tried playing about with something along the lines of

PrjParams.transformationForward = true;

or

PrjParams.transformationForward = false;

but it doesn't change the output value.

Cheers,
Mike
0 Kudos
JohnGravois
Deactivated User
unfortunately thats a bug:

[NIM090102: When projecting using geometry service in a JavaScript application, the transformationForward parameter is not passed to the request parameters even it is defined in the code.]

you might want to try using something like esriRequest.setRequestPreCallback() until the issue is resolved.
0 Kudos
MikeSteven
Regular Contributor
Sorry you've lost me here, how can I use esriRequest.setRequestPreCallback() to set the transformationForward boolean? (it's false I need to set the transformationForward boolean to)
0 Kudos
JohnGravois
Deactivated User
setRequestPreCallback() is a generic method which gives you an opportunity to manipulate parameters in any AJAX request before it is sent.

if you'd like to take a stab at writing up a simple sample and incorporating the technique, i would happy to provide additional assistance if you get stuck.
0 Kudos
MikeSteven
Regular Contributor
Erm, callbacks are not something I've worked with much so I'm struggling a bit. I've tried a few different things but I can't see how I should use the callback to set the parameters, sorry.

   function zoomToLocation(location) {
    console.debug(location);
    var pt = new Point(location.coords.longitude, location.coords.latitude, new SpatialReference({
     wkid : 4236
    }));
    //alert("input x = " + location.coords.longitude + " , y = " + location.coords.latitude);
    var outSR = new SpatialReference({
     wkid : 27700
    });

    PrjParams = esriRequest.setRequestPreCallback(setTransformationForward);
    alert("prjParams datumtrans = " + PrjParams.transformation);
    /*geometryService.project(PrjParams, function(projectedPoints) {
     console.log('Conversion completed. Datum Transformation: ' + PrjParams.transformationForward + '.');
     pt = projectedPoints[0];
     map.centerAndZoom(pt, 8);
     });*/
   }

   function setTransformationForward() {
    alert("got here");
    var PrjParams = new ProjectParameters();
    PrjParams.geometries = [pt];
    PrjParams.outSR = outSR;
    var datumtrans = 1314;
    PrjParams.transformation = datumtrans;
    PrjParams.transformationForward = false;

    return PrjParams;
   }
0 Kudos
JohnGravois
Deactivated User
the crux of this issue is that setting the property on your ProjectParms object doesn't have the effect it should.  because of this we need to be listening for the AJAX request all the time and modify it manually.

//we call this method once when the application loads so that it will execute afterwards when AJAX requests are fired.
esriRequest.setRequestPreCallback(addTransformationForward);
...
var params = new ProjectParameters();
params.geometries = [point];
...          
//setting this parameter is not working (because of NIM090102)
params.transformationForward = false;

gsvc.project(params, function(projectedPoints) {
    ...
});

function addTransformationForward(ioArgs) {
    //lets add the parameter when we catch an AJAX request aimed at our geometry service
    if (ioArgs.url == "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer/project")

        //add the request parameter manually
        ioArgs.content = ioArgs.content || {};
        ioArgs.content.transformForward = false;

    // don't forget to return ioArgs.
    return ioArgs;
}



heres a working fiddle
http://jsfiddle.net/jagravois/9WXDx/
AdrianMarsden
Honored Contributor

Many thanks for that fiddle -  I've just hit a similar issue (user collects in google maps, want to display in our 27700 maps) and a slightly modified version of your code works a treat.

0 Kudos
MikeSteven
Regular Contributor
Thanks John, that's it working now.

That's greatly appreciated.
Cheers,
Mike
0 Kudos