Plotting points in lat-long on map or converting WKID:4326 to XY WKID:102100 in bulk.

7774
7
01-12-2013 12:40 AM
NiranjanBorawake
New Contributor
Hi,

My problem seems to be more common but the solutions provided don't apply in my case. I googled a lot and finally decided to post a question.
Let me start by explaining what I am trying to do:
I have a large set of points (around 40 to 50 thousand) to be plotted which are in latitudes and longitudes.
I created a map with following intialExtent  and base layer:
var initExtent = new esri.geometry.Extent({
                    "xmin" : -9025716.63,
                    "ymin" :4428892.14,
                    "xmax" : -8888129.98,
                    "ymax" : 4520616.57,
                    "spatialReference" : {
                        "wkid" : 102100
                    }
                });
var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");

Spatial Reference (SR) for the map is WKID:102100 which does not allow me to plot my points in lat-long (as lat-long can be plotted on a map with SR WKID:4326, "I think so..Please correct if this is not the case " ). So I need to transform these lat-long to X-Y coordinates i.e. in SR WKID:102100. I could find the arcgis's GeometryService to do this but only for points less than 15 at a time, obviously on the arcgis's public server. So there is no way i could transform all those 40-50 thousand points this way.

I tried following things:

  1. Creating the map with SR WKID:4326 and plotting the points in lat-long itself, no conversion required. This plots the points correctly but the map images are not fetched, the images saying "NO map data available" are shown on the map. Is there any relation between type of layer used and SR? I mean is it a case, that certain types of layers support only certain SRs.

  2. Tried to create map with SR WKID:102100 and another layer with WKID:4326 and then plot points on this layer. But this doesn't work, from the api reference of the arcgis I feel all other layers extend the SR of the map/base layer. So there is no way i could have layers with different SR WKIDs.

  3. So finally I came to a conclusion that I need to convert those points from WKID 4326 to WKID 102100. The Geometry service api ref http://resources.arcgis.com/en/help/rest/apiref/ has an option to provide URL based geometries where URL points to a  file with all the points to be converted in JSON format. I could not get this working :(. When I hit the REST API URL http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/project?inSR=4326... it takes me to the HTML page. How can I make use of this option and convert all those points in bulk.

Please answer following questions :

  1. Is there a way in which I could plot all those points in lat-long itself by creating a map with WKID:4326? If yes, any example?

  2. How can I convert all those points in bulk from SR WKID 4326 to SR WKID 102100? This way I am planning to convert all lat-longs offline and then use them to plot.

Thanks in advance.
Niranjan
0 Kudos
7 Replies
JohnnyPenet
New Contributor
Hi  niranjan,

I did some work on converting between projected systems in javascript. I put this information into a blog http://jpenet.blogspot.be/2012/08/transformation-between-datums-in.html , including JavaScript code that bypass the use of geometry services for transformation of projections. First document explains the conversions needed, the second illustrate this with javascript code.
I hope this can help you.

Johnny
0 Kudos
NiranjanBorawake
New Contributor
Hi Johnny,

Thanks a lot for such a quick reply.
I have gone through your blog and it seems this is going to help me.

Thanks,
Niranjan
0 Kudos
NiranjanBorawake
New Contributor
Hi Jhonny,

I could make things work with the help of functions you have defined. I gave input point as

var point = {
  lng : -80.430123,
  lat : 37.2447239
};


and got the converted point as

{"x":-5991744.271143372,"y":2592441.1643744702} 


All the functions woked correctly.

But I am not interested in converting into Lambert 72.

I need to convert points from

Well-known ID Name
4326                 GCS_WGS_1984
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]


TO

Well-known ID Name
102100          WGS_1984_Web_Mercator_Auxiliary_Sphere
PROJCS["WGS_1984_Web_Mercator_Auxiliary_Sphere",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Mercator_Auxiliary_Sphere"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",0.0],PARAMETER["Standard_Parallel_1",0.0],PARAMETER["Auxiliary_Sphere_Type",0.0],UNIT["Meter",1.0]]

.

This is an example of what I need to do : http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/project?inSR=4326...

All these coordinate systems are too confusing 😞 . Can you please give some pointers in what all parameters i need to add/modify to

CoordTransform.ellipse and
CoordTransform.datumTransform


properties and what new functions i need to add to get this done.

I appreciate your help a lot. Eagerly waiting for your reply.

Thanks in advance again.

Niranjan
0 Kudos
NiranjanBorawake
New Contributor
Hi Jhonny,

Finally, got what I was looking for. Was going through rest of the links on your blog and came across http://jpenet.blogspot.be/2012/07/using-different-projections-within.html.

2.     TRANSFORMATION BETWEEN WGS84 AND WEBMERCATOR (102100/3857)

This has a function

function toWebMercator(xlon, ylat) {
  if ((Math.abs(mercatorX_lon) > 180 || Math.abs(mercatorY_lat) > 90))
    return null;
  var num = xlon * 0.017453292519943295;
  var x = 6378137.0 * num;
  var a = ylat * 0.017453292519943295;
  var y = 3189068.5 * Math.Log((1.0 + Math.Sin(a)) / (1.0 - Math.Sin(a)));
  return {
     x: x,
     y: y
  }
}


which is what i was looking for. This converts exactly the way i needed. You have saved my lot of time ( time to get this solved and the arcgis Geometry service response time 🙂 ).

Thanks a lot again.

Regards,
Niranjan
0 Kudos
JeffJacobson
Occasional Contributor III
The ArcGIS JavaScript API has a method for doing this conversion.
0 Kudos
NiranjanBorawake
New Contributor
Thanks Jeff, for pointing out the exact ArcGIS api for doing this. This will definitely help.

But I need to plot points in thousands, doing these conversions during plotting won't be a good idea. The function 'toWebMercator' mentioned above in the thread does this conversion. So its better to get those points already converted to WEBMERCATOR and then its just a matter of plotting them directly on the map.

Thanks,
Niranjan
0 Kudos
JeffPace
MVP Alum
function (lat,lon) {
  //code completely borrowed from Dr Bill Hazelton's HP-33S calculator
    // http://homepage.mac.com/nwjh/HP-33S/ 10-Feb-10

var num = lon * 0.017453292519943295;
var x = 6378137.0 * num;
var a = lat * 0.017453292519943295;

var mercatorX = x;
var mercatorY = 3189068.5*Math.log((1.0 + Math.sin(a))/(1.0 - Math.sin(a)));


    return [mercatorX,mercatorY];
    }
0 Kudos