Select to view content in your preferred language

Geo Point Converter? (WGS84 to Web Mercator)

5522
2
Jump to solution
10-02-2013 11:18 AM
StephenBaier
Occasional Contributor
Does the API have a function for converting WGS84 lat/lon points to Web Mercator (as expected by the JMap / ArcGISLocalTiledLayer)? I have been unable to locate such...

Thanks
0 Kudos
1 Solution

Accepted Solutions
JeremieJoalland1
Deactivated User
I've done a Utility Class with a function to reproject on the fly... so in case I need to reproject a Geometry (Point, Polyline, ...) from WGS 84 to the map's Spatial Reference, I'm using GeometryEngine !

Here is one solution :

private static final SpatialReference SPATIAL_REF_WGS84 = SpatialReference.create(4326);  ...  public static Geometry projectGeometryWGS84ToMap(Geometry geometryWGS84, SpatialReference spatialRefMap)  throws ReprojectException {  Geometry result;   try {   if (spatialRefMap != null && SPATIAL_REF_WGS84.getID() != spatialRefMap.getID()) {    // reproject here    result = GeometryEngine.project(geometryWGS84, SPATIAL_REF_WGS84, spatialRefMap);    }   else {    // map is already in WGS 84    result = geometryWGS84;   }  }  catch (ArrayIndexOutOfBoundsException e) {   // In case of Polygon, I face this kind of Exception sometimes... but don't know why   throw new ReprojectException ...  }   return result; }


You can obtain your map Spatial Reference by jMap.getSpatialReference()

View solution in original post

0 Kudos
2 Replies
JeremieJoalland1
Deactivated User
I've done a Utility Class with a function to reproject on the fly... so in case I need to reproject a Geometry (Point, Polyline, ...) from WGS 84 to the map's Spatial Reference, I'm using GeometryEngine !

Here is one solution :

private static final SpatialReference SPATIAL_REF_WGS84 = SpatialReference.create(4326);  ...  public static Geometry projectGeometryWGS84ToMap(Geometry geometryWGS84, SpatialReference spatialRefMap)  throws ReprojectException {  Geometry result;   try {   if (spatialRefMap != null && SPATIAL_REF_WGS84.getID() != spatialRefMap.getID()) {    // reproject here    result = GeometryEngine.project(geometryWGS84, SPATIAL_REF_WGS84, spatialRefMap);    }   else {    // map is already in WGS 84    result = geometryWGS84;   }  }  catch (ArrayIndexOutOfBoundsException e) {   // In case of Polygon, I face this kind of Exception sometimes... but don't know why   throw new ReprojectException ...  }   return result; }


You can obtain your map Spatial Reference by jMap.getSpatialReference()
0 Kudos
StephenBaier
Occasional Contributor
Thanks for the response.

I hadn't seen that particular interface, I had tried using the GE.project( x, y, spatialRef ). When I used that it took minutes to do the conversion of a few thousand points, which was no acceptable at all. Using the method you mentioned it took only 523ms for about 13000 data points (30ms if I put them all in one line and do a "bulk" projection).

Thanks! +1
0 Kudos