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;

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

  • i guess i need to use a function like ESRI.ArcGIS.ADF.ArcGISServer.Converter.ComObjectToValueObject, but i dont have and use adf on my soe, any ideas or similar function for soe?
    – bahadir
    Jun 6 '12 at 9:16

All the geometry objects you have created (either by deserializing from JSON or instantiating them with new) are COM objects and are created in the same process space.

Your issue probably stems from the fact that the ITopologicalOperator.Intersect method works only on high-level geometries (see the Remarks section in the link). Line is not a high-level geometry, whereas Polyline is, that's why your first call of Intersect works and the other does not. You will need to represent your line with a Polyline instance instead.

  • thanks a lot, i was banging my head to walls because of this
    – bahadir
    Jun 6 '12 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.