2

I have polygon data as:

POLYGON ((1645481.0939999996 6124506.9885, 1645470.0473999996 6124473.5406, 1645475.7094 6124440.1391,1645481.0939999996 6124506.9885))

in wkid=2193

I want to project this polygon using geometry service with new spatial reference wkid= 3857.

I was able to project point using similar data on new spatial reference wkid=3857, but that is not happening with polygon.

Which method should I use to project polygon using geometry service?

 function addGraphic() {
 var wkt = new Wkt.Wkt(); 
 wkt.read("POLYGON ((1645481.0939999996 6124506.9885, 1645470.0473999996 6124473.5406, 1645475.7094 6124440.1391,1645481.0939999996 6124506.9885))");
 var polygon = wkt.toObject();
 //set the spatialreference
 polygon.SpatialReference = new esri.SpatialReference({wkid: 2193});
 var outSR = new esri.SpatialReference({ wkid: 3857 });
 var gsvc = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
 var projPoly;
 gsvc.project([polygon], outSR, function (outGeom) {
 projPoly = outGeom[0];
 var symbol = new esri.symbol.SimpleFillSymbol().setStyle(esri.symbol.SimpleFillSymbol.STYLE_SOLID);
 var polygonGraphic = new esri.Graphic(projPoly, symbol);
 map.graphics.add(polygonGraphic);
 });
 }
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Oct 3, 2014 at 6:55
1
  • user esri.symbol.SimpleFillSymbol.STYLE_NULL Commented Sep 15, 2015 at 11:19

1 Answer 1

2

There are two issues that you need to solve.

  • Firstly, the polygon that you have, is in a format that is called the WKT. You will have to convert it to a geometry in the ESRI's JavaScript format. I have used Wicket in the past to do this conversation for me.
  • Once you have an ESRI Polygon, you can use the project operator on the GeometryService. You should make sure that you set the spatialreference on the polygon, before you send it to the service.

You can use code similar to this:

 function projectToWebMercator() {
 var wkt = new Wkt.Wkt();
 wkt.read("POLYGON ((1645481.0939999996 6124506.9885, 1645470.0473999996 6124473.5406, 1645475.7094 6124440.1391,1645481.0939999996 6124506.9885))");
 var polygon = wkt.toObject();
 //set the spatialreference
 polygon.setSpatialReference(new SpatialReference({
 wkid : 2193
 }));
 var outSR = new SpatialReference({
 wkid : 102100
 });
 var gsvc = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
 gsvc.project([polygon], outSR, function (outGeom) {
 console.dir(outGeom); //<-- Do whatever you want with the projected Polygon here
 });
 }
answered Oct 3, 2014 at 14:46
7
  • I've tried to convert WKT to a geometry using arthur-e.github.io/Wicket/sandbox-arcgis.html, but its not showing up anything. Can you please send me some sampple code? I had similar coordinates for point, but when I project them using new spatial reference and geometry service, it worked. Please guide me. Commented Oct 6, 2014 at 1:30
  • @Dips: I've added the code. Don't forget to add the two scripts from Wicket in you HTML file. Commented Oct 6, 2014 at 2:05
  • hey..Thanks for the code, but still not getting those two scripts to add from Wicket, please guide me. Commented Oct 6, 2014 at 3:26
  • What do you mean when you say 'not getting those scripts' did you download those scripts from github? Commented Oct 6, 2014 at 3:28
  • I've added scripts and modified code as per your directions, but still its not showing up polygon on the map. Please check my above edited code. If I modify polygon data i.e. add more coordinates to it around 40 coordinates, it doesn't call gsvc.project method. Commented Oct 6, 2014 at 5:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.