Pergunta

I was trying to obtain a gpx file with some coordinates by drawing on an Openlayers map with an ArcGIS baseMap.

When I draw the polyline and create the gpx, if I open it on Google Earth, what I see is not what I drawed before, the line is totally different from the original and not positioned where I drawed it. I know it's a projection problem, I've tried trasforming the geometry object from Mercator to Geographic, also getting directly the geographic coordinates from the map coordinates, but nothing. I tried to set "spatialReference" to 4362 and then to 3857, but nothing changes.

I'm going to use that .gpx on a gps device (the next week I'll go to the Svalbard islands and I need some gps tracks to go around Longyearbyen by snowmobile, there there aren't any sign of life out the town, so I must be prepared to it), when I'll be there I'll adjust the output right for the device they will rent to me, but now I need to save on the .gpx file almost the right coordinates.

I'm getting from the map those coordinates: lat: 61.22582068741976 lon: 4.684820015391338 when I'm expecting instead something around 78. lat and 15. lon.

This is some of the code I use to create the map (I'm not pasting the code I know it's not responsible of my problems):

    var initialExtent = new esri.geometry.Extent({"xmin":505615.5801124362,"ymin":8678955.717187276,"xmax":525935.6207525175,"ymax":8689168.654279819,"spatialReference":{"wkid":32633,"latestWkid":32633}});

    map = map = new esri.Map("map", {extent: initialExtent, logo : false});
    basemapURL = "http://geodata.npolar.no/ArcGIS/rest/services/inspire1/NP_TopoSvalbard_U33_CHL/MapServer/";
    map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer(basemapURL));

Here I'm using wkid 32633 that is the default for that map, tried to change with known ones, but nothing happened.

And now the code I use to get the coordinates:

        dojo.connect(tb, "onDrawEnd", getCoords);
        function getCoords(geo) {
            var r=confirm("Salvare tracciato?");
            if (r==true) {
                geo = esri.geometry.webMercatorToGeographic(geo);   
                for ( var path = 0; path < geo.paths.length; path ++ ) {                   
                    for ( var pt = 0; pt < geo.paths[path].length; pt++ ) {
                        tra += '<wpt lat="'+geo.paths[path][pt][1]+'" lon="'+geo.paths[path][pt][0]+'"></wpt>';
                    }   
                }
            }
        }

"tra" is a variable that stores all the code I'll insert into the gpx file with an other function. The "webMercatorToGeographic" function transform the map coordinates to geographic ones.

Foi útil?

Solução

Thanks to Devdatta Tengshe on GIS.stackexchange I got what I need:

Use the proj4js library in your application. To do this, follow these steps:

Download the latest library from https://github.com/proj4js/proj4js/releases In your HTML file use You'll need to define the projections before you can use it. You can do this by using the following lines of code: var UTM33N= "+proj=utm +zone=33 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"; var GCS84="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";

When you need to transform, you can use the following line: var transformed=proj4(UTM33N,GCS84,[x,y]); where x & y are the coordinates in your given projection. As output you'll get an array with two elements, the longitude, & the Latitude

That worked fine.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top