Currently i am developing a Server Object Extension. On my project i am creating a new line class with LineClass myLine = new LineClass(); and getting a polygon from client as JsonObject than converting this polygon to IPolygon with
JsonObject jsonFieldPolygon;
if (!operationInput.TryGetJsonObject("field", out jsonFieldPolygon))
throw new ArgumentNullException("field");
IPolygon4 fieldGeom = (IPolygon4)Conversion.ToGeometry(jsonFieldPolygon,esriGeometryType.esriGeometryPolygon);
Polygon i have converted from jsonobject is becoming a com object, but line i have created is a class in my own application space.
Thus i cant do operations with these two geometries, i guess both must be com object for operations like intersect and etc.
I am getting an access violation when i try to intersect these 2 geometries.
my code is below
JsonObject jsonFieldPolygon;
if (!operationInput.TryGetJsonObject("field", out jsonFieldPolygon))
throw new ArgumentNullException("field");
IPolygon4 fieldGeom = (IPolygon4)Conversion.ToGeometry(jsonFieldPolygon, esriGeometryType.esriGeometryPolygon);
JsonObject jsonFieldPath;
if (!operationInput.TryGetJsonObject("fieldPath", out jsonFieldPath))
throw new ArgumentNullException("fieldPath");
IPolyline fieldPathGeom = (IPolyline)Conversion.ToGeometry(jsonFieldPath, esriGeometryType.esriGeometryPolyline);
ITopologicalOperator myOp = (ITopologicalOperator)fieldGeom;
IGeometry resultGeom = myOp.Intersect(fieldPathGeom, esriGeometryDimension.esriGeometry1Dimension); // this line works because both geometries are com objects
IPoint startPoint = new PointClass();
IPoint endPoint = new PointClass();
LineClass myLine = new LineClass();
myLine.SpatialReference = fieldGeom.SpatialReference;
endPoint.SetEmpty();
startPoint.SetEmpty();
startPoint.PutCoords(fieldGeom.Envelope.XMin, fieldGeom.Envelope.YMin);
endPoint.PutCoords(fieldGeom.Envelope.XMax, fieldGeom.Envelope.YMax);
myLine.PutCoords(startPoint, endPoint);
IGeometry resultGeom2 = myOp.Intersect(myLine, esriGeometryDimension.esriGeometry1Dimension);// this line throws accessviolation exception because one geometry is com other is a class in my app
I hope there is a way to solve this