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 can't 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 two 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