web service for buffering?

Discussion created by hbdong on Jul 30, 2013
   I'm testing out the below web service sample to get a buffer of a giving point but have problem retrieving buffer points.  I'm new to this and not sure whether I'm using the correct APIs for it.   My goal is to pass in a lat/lon point or a line and to get back a buffer around that point or line.   Please let me know what's the correct way for doing this.  Thanks


import com.esri.arcgisws.EnvelopeN;
import com.esri.arcgisws.GeographicCoordinateSystem;
import com.esri.arcgisws.Geometry;
import com.esri.arcgisws.GeometryServerBindingStub;
import com.esri.arcgisws.LinearUnit;
import com.esri.arcgisws.Point;
import com.esri.arcgisws.PointN;
import com.esri.arcgisws.PolygonN;
import com.esri.arcgisws.ProjectedCoordinateSystem;
import com.esri.arcgisws.Ring;
import com.esri.arcgisws.SpatialReference;

    String serviceURL = "http://localhost:6080/arcgis/services/Utilities/Geometry/GeometryServer?wsdl";
    GeometryServerBindingStub geometryService = new GeometryServerBindingStub(serviceURL);
    SpatialReference inputSpatialReference = new GeographicCoordinateSystem();
    //Set buffer spatial reference
    SpatialReference bufferSpatialReference = new ProjectedCoordinateSystem();

    //Set output spatial reference
    SpatialReference outputSpatialReference = inputSpatialReference;

    //Input points

    PointN inputPoint1 = new PointN();
    Geometry[] inputGeometry = new Geometry[] { inputPoint1};   
    //Distance for buffer for each point

    double[] distances = new double[] { 1000 }; 
    LinearUnit linearUnit = new LinearUnit();
    boolean bUnionResults = false;
    Geometry[] outputGeometry = geometryService.buffer(inputSpatialReference, bufferSpatialReference, outputSpatialReference,distances, linearUnit, bUnionResults, inputGeometry);
    for (Geometry geom : outputGeometry) {
           if (geom instanceof PolygonN){
                 PolygonN polygon = (PolygonN) geom;                
                 EnvelopeN extent = (EnvelopeN) polygon.getExtent();                
                 System.out.println("Extent - XMin,YMin: " + extent.getXMin() + "," + extent.getYMin() + " XMax,YMax: " + extent.getXMax() + "," + extent.getYMax());
                 Ring[] ring = polygon.getRingArray();
                 for (int i=0 ;i<ring.length;i++) {
                  Point[] point = ring[i].getPointArray();                   
                  for (int j=0; j< point.length; j++) {
                   System.out.println("point: " + point[j]);

     }   // end of for