geometryService.Project() with polygons

1447
6
08-24-2011 08:35 AM
MikeAdams
New Contributor II
Does the geometryService.Project() method work with polygons?  According to the documentation, it should work for any geometries, but I can only get it to work with points.  When I try using it to reproject a polygon, it returns nothing.
0 Kudos
6 Replies
JeffPace
MVP Alum
Does the geometryService.Project() method work with polygons?  According to the documentation, it should work for any geometries, but I can only get it to work with points.  When I try using it to reproject a polygon, it returns nothing.


Yes it works with all geometry types.  Please paste an email of your code.  You can also try the rest service directly to make sure you are getting the syntax right.
0 Kudos
MikeAdams
New Contributor II
Here is a portion of the code:

  {
    // Create the spatial reference objects:
    m_spref_In = new SpatialReference(4326); // GCS_WGS_1984
    m_spref_Out = new SpatialReference(102113); // WGS_1984_Web_Mercator                       

    shpPolygon = ac_Polygons[i_ShapeNum]

    // Create the graphic object:
    myGraphic = new Graphic();
    myGraphic.geometry = shpPolygon.toPolygon();

    geometryService.project([ myGraphic ], m_spref_Out);
  }

  private function projectCompleteHandler(event:GeometryServiceEvent):void
  {
      /* DEBUG */
      Alert.show("#1001: event.graphics.length = " + event.graphics.length.toString());
  }

The event.graphics.length is ALWAYS zero.
0 Kudos
KellyHutchins
Esri Frequent Contributor
Starting at version 2.0 of the API the input to the project method was switched from a graphic to a geometry. In your code it looks like you are attempting to project the graphic, try this instead:
   geometryService.project([ shpPolygon ], m_spref_Out);

However, it looks like you are projecting from geographic to web mercator. If so you do not need to use project. The API contains client-side utility objects that allow you to project from geographic to web mercator and vice-versa. Here's an example:


var geom = esri.geometry.geographicToWebMercator(geometryToProject);


Here is a portion of the code:

  {
    // Create the spatial reference objects:
    m_spref_In = new SpatialReference(4326); // GCS_WGS_1984
    m_spref_Out = new SpatialReference(102113); // WGS_1984_Web_Mercator                       

    shpPolygon = ac_Polygons[i_ShapeNum]

    // Create the graphic object:
    myGraphic = new Graphic();
    myGraphic.geometry = shpPolygon.toPolygon();
   geometryService.project([ myGraphic ], m_spref_Out);

  }

  private function projectCompleteHandler(event:GeometryServiceEvent):void
  {
      /* DEBUG */
      Alert.show("#1001: event.graphics.length = " + event.graphics.length.toString());
  }

The event.graphics.length is ALWAYS zero.
0 Kudos
MikeAdams
New Contributor II
We are still using version 1.3 of the API.  The client had been using geographicToWebMercator, but now wants to be able to use other projections in addition to Web Mercator.
0 Kudos
KellyHutchins
Esri Frequent Contributor
I just took another look at your code and I think you are using the Flex API? If so you might want to post this question in the flex forum:


http://forums.arcgis.com/forums/18-ArcGIS-API-for-Flex
0 Kudos
MikeAdams
New Contributor II
Thank you -- I have reposted it in the ArcGIS API for Flex forum.
0 Kudos