Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
    
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
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
    
thanks a lot, i was banging my head to walls because of this –  bahadir Jun 6 '12 at 15:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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