IFeatureClass nearestContour = join.JoinNearest(name, -1);
Can't create output feature class. the workspaces is not connected.
private double getheightAtPoint(IFeatureClass contourClass, IPoint point) { try { IScratchWorkspaceFactory2 scratchWorkspaceFactory = (IScratchWorkspaceFactory2)new FileGDBScratchWorkspaceFactory(); IWorkspace scratchWorkspace = (IWorkspace)scratchWorkspaceFactory.CreateNewScratchWorkspace(); IFeatureClass pointClass = Utilities.Instance.CreateFeatureClassInWorkspace("tmpPoint", (IFeatureWorkspace)scratchWorkspace); IFeature pointFeature = pointClass.CreateFeature(); pointFeature.Shape = point; IFeatureCursor contourCursor = contourClass.Search(null, false); IFeature contourFeature = contourCursor.NextFeature(); IPolyline pPolyline = contourFeature.Shape as IPolyline; double height = 0; ISpatialJoin join = new SpatialJoinClass(); join.SourceTable = contourClass as ITable; join.JoinTable = pointClass as ITable; IName name = new FeatureClassName(); name.NameString = "nearestContour"; IFeatureClass nearestContour = join.JoinNearest(name, -1); int index = nearestContour.Fields.FindField("Contour"); if (index != -1) { height = (Double)(nearestContour as IRow).get_Value(index); } else { throw new NullReferenceException("Es konnte kein Contour-Feld gefunden werden!"); } return height; } catch (Exception e) { throw e; } Thanks for any help and ideas.
IFeatureClass pointClass = Utilities.Instance.CreateFeatureClassInWorkspace("tmpPoint", (IFeatureWorkspace)scratchWorkspace);
IFeature pointFeature = pointClass.CreateFeature(); pointFeature.Shape = point as IGeometry;
IPoint testPoint2 = new Point(); testPoint2.PutCoords(point.X, point.Y);
IFeatureCursor testCursor = pointClass.Search(null, true); IFeature testFeature = testCursor.NextFeature(); IGeometry testGeom = testFeature.Shape; IPoint testPoint = testGeom as IPoint;
Yes of course I do.Exception is connected with scratchWorkspace.
Within the method
IFeatureClass pointClass = Utilities.Instance.CreateFeatureClassInWorkspace("tmpPoint", (IFeatureWorkspace)scratchWorkspace);
there is an edit session created and the featureClass stored.
After the shape is set, the references within the point of OID, X, Y, M Z will have an entry that an exception was thrown.Is your edit session closed after returning fromUtilities.Instance.CreateFeatureClassInWorkspace?
The testPoint has the exceptions as well.Parameter IPoint point memeber could be geometry element from another feature. If yes, you didn't created it or cloned, you should clone or create new PointClass object.
IScratchWorkspaceFactory2 scratchWorkspaceFactory = (IScratchWorkspaceFactory2)new FileGDBScratchWorkspaceFactory(); IWorkspace scratchWorkspace = (IWorkspace)scratchWorkspaceFactory.CreateNewScratchWorkspace(); IFeatureClass pointClass = Utilities.Instance.CreateFeatureClassInWorkspace("tmpPoint", (IFeatureWorkspace)scratchWorkspace); IWorkspaceEdit scratchWorkspaceEdit = (IWorkspaceEdit)scratchWorkspace; scratchWorkspaceEdit.StartEditing(false); scratchWorkspaceEdit.StartEditOperation(); IFeature pointFeature = pointClass.CreateFeature(); pointFeature.Shape = point as IGeometry; scratchWorkspaceEdit.StartEditOperation(); scratchWorkspaceEdit.StopEditing(true);
IPoint point1 (as parameter) IPoint point2 = point; IPoint point3 = new Point(); point3.X = point.X; point3.Y = point.Y; point3.SpatialReference = point.SpatialReference; IPoint point4 = new Point(); point4.X = point.X; point4.Y = point.Y;
pointFeature.Shape = point as IGeometry;You should clone this point or create new one before using this point
testPoint2.PutCoords(point.X, point.Y);is just fine because you created new Point
IPoint newPoint = new PointClass();
newPoint.PutCoords(point.X, point.Y);
IFeatureClass nearestContour = join.JoinNearest(name, -1);
newPoint.PutCoords(point.X, point.Y);Exception there would be if point object is null or newPoint is null. Can't imagine other scenario.
IPoint newPoint = new PointClass();
newPoint.PutCoords(point.X, point.Y);
IFeatureClass nearestContour = join.JoinNearest(name, -1);
ISpatialJoin join = new SpatialJoinClass(); join.SourceTable = contourClass as ITable; join.JoinTable = point as ITable; IName name = new FeatureClassName(); name.NameString = "nearestContour"; IFeatureClass nearestContour = join.JoinNearest(name, -1);