AnsweredAssumed Answered

Points to Polyline - How to the spatial reference?

Question asked by shaningesri on Jan 16, 2014
Latest reply on Jan 16, 2014 by shaningesri
In a project, I created a polyline through a collection of points. The related code is below:
// Create and add segments
ISegmentCollection path = new ESRI.ArcGIS.Geometry.PathClass();
object obj = Type.Missing;
for (int i = 1; i < pointsCollection.Count; i++) {
ILine pLine = CreateLine(pointsCollection[i - 1], pointsCollection[i]);
path.AddSegment((ISegment)pLine, ref obj, ref obj);
}

// Get the Polyline
ESRI.ArcGIS.Geometry.IPolyline pSegPoly = new ESRI.ArcGIS.Geometry.PolylineClass();
ESRI.ArcGIS.Geometry.IGeometryCollection pGeoColl = pSegPoly as IGeometryCollection;
pGeoColl.AddGeometry((IGeometry)path, ref obj, ref obj);
pGeoColl.GeometriesChanged();

// Get json results
JsonObject onSegment = Conversion.ToJsonObject((IPolyline)pGeoColl);
List<JsonObject> jsonGeometry = new List<JsonObject>();
jsonGeometry.Add(onSegment);
JsonObject resultJsonObject = new JsonObject();
resultJsonObject.AddArray("Geometry", jsonGeometry.ToArray());

// Get byte array of json and return results, which will be the output of ArcGIS Server SOE service
byte[] result = Encoding.UTF8.GetBytes(resultJsonObject.ToJson());
return result;

The data from my ArcGIS Server's service call looks like:
{ "Geometry": [ {
"paths": [ [
[-8575118.2321458999,4707114.1745275566], ... [-8575820.374931246,4707389.1788524361] ] ]
} ] }
Ideally, after the { } block, there should be
"spatialReference":{"wkid":102100}}, which is the same as that of the points in the point collection.

How can the SR information be added to the polyline?

Outcomes