Geometry Service Project a point

991
3
02-11-2014 11:12 AM
CaseyBentz
Occasional Contributor II
I am trying to project an array of points from a custom coordinate system the web mercator.  I am using the geometry service project method and am coming up blank with how to set the input spatial reference for the geometries. The rest endpoint has a property for input spatial reference and output spatial reference, but the project parameters support class does not.

private function gpResult(event:GeoprocessorEvent):void{
 var geometriesToProject:Array = new Array();
                
 for each(var result:ParameterValue in event.executeResult.results){
  for each(var g:Graphic in result.value.features){
   geometriesToProject.push(g.geometry);                                
  }    
 }
 if(geometriesToProject.length > 0){
  var wkid:Number = 102100; 
  var projectionSR:SpatialReference = new SpatialReference(wkid);
  var projectParams:ProjectParameters = new ProjectParameters();
                    
  projectParams.geometries = geometriesToProject;
  projectParams.outSpatialReference = projectionSR;
  geometryService.project(projectParams);
 }
}
Tags (2)
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus
Casey,

   The input spatial reference is automatically obtained from the SR of the input geometries, thus no need to specify.
0 Kudos
CaseyBentz
Occasional Contributor II
Thanks Robert, but it appears that since I am using a non well-known spatial reference, it was not coming across with the geoprocessing results.  I made a change to my result processing and was able to get it to work.  But the real problem remains, my geoprocessing service will not return the results in the desired spatial reference.  I have a ticket open with Esri, but they don't seem to understand the issue. 

private function gpResult(event:GeoprocessorEvent):void{
 var geometriesToProject:Array = new Array();
 
 var wkid:Number = NaN; 
 var wkt:String = 'PROJCS["IPTM",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.000,298.25722210],TOWGS84[0.0000,0.0000,0.0000,0.000000,0.000000,0.000000,0.00000000]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",1640416.667],PARAMETER["False_Northing",328083.333],PARAMETER["Scale_Factor",0.999600000000],PARAMETER["Central_Meridian",-115.50000000000000],PARAMETER["Latitude_Of_Origin",42.00000000000000],UNIT["Foot_US",0.30480060960122]]';
 var projectionSR:SpatialReference = new SpatialReference(wkid, wkt);
 
 for each(var result:ParameterValue in event.executeResult.results){
  for each(var g:Graphic in result.value.features){
   g.geometry.spatialReference = projectionSR;
   geometriesToProject.push(g.geometry);        
  } 
 }
 if(geometriesToProject.length > 0){
  var projectParams:ProjectParameters = new ProjectParameters();
  
  projectParams.geometries = geometriesToProject;
  projectParams.outSpatialReference = myMap.spatialReference;
  
  geometryService.project(projectParams);
 }
}
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Casey,

   When ever I needed to use a WKT in a geometry service projection it has always worked fine. I do this in my Shapefile widget as there is now way to compare if a WKT from the shapes .prj file is the same as the maps WKID. This is what I am doing. Nothing real different from yours just less lines and if I don't have a WKTstr then just use the maps WKID.

const shpSpatialRef:SpatialReference = (WKTstr) ? new SpatialReference(Number.NaN, WKTstr) : map.spatialReference;
0 Kudos