Select to view content in your preferred language

JoinData: Can't create output feature class. the workspaces is not connected.

4278
11
08-08-2011 11:58 PM
SebastianKrings
Frequent Contributor
Hello,

I have a FeatureClass with polylines and one point. I know the point must (almost) lie on one of the polylines.

The Point is stored as shape in a featureClass created by in a scratchworkspace.

To identify which polyline it is I make use of the ISpatialJoin Interface.
The Polyline FeatureClass is set as sourceTable, while the point FeatureClass is set as the JoinTable (both are casted to ITable before)

when now executing
IFeatureClass nearestContour = join.JoinNearest(name, -1);


I will get the Error as in subject:
Can't create output feature class. the workspaces is not connected.


Which workspace is meant? The scratch? Theres no order to close its connection. Is there may another way to create a feature class for a given IPoint, without workspaces?

the whole code:
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.
0 Kudos
11 Replies
SebastianKrings
Frequent Contributor
Hey,

hm your first paragraph I didn't understand right I think.
You mean to store a FeatureClass within a Workspace (FGDB or Scratch? Or Doesnt Matter?) and then assign the returned FeatureClass of the JoinNearest Method (which currently fails) to the new created one? And I shall do this, to define some spatial reference, because NearestJoin could fail due to missing the spatial reference?

And once again, whats about the spatial reference.
FeatureDatasets stores saptial Reference, and FeatureClasses not?
Because FeatureClasses have a Property for Spatial Reference. Because, FeatureClasses gain the SpatialReference of the FeatureDataset or somewhere else and then the spatial Reference is stored? But never assign it youself by using the set property of a FeatureClass?

And because I'm not using a FeatureDataset (which isnt always bad, isnt it?) I shall use IGeometryBag. When I read it correctly, all gemotries referenced in the bag have the same spatial reference, because when adding it to the bag the spatial reference of the featureClass added will be overwritten by the current spatial reference of the baf, right?

So ok, sound nice. But how to add the right spatial reference to the Bag?
Just say Bag.Spatialreference = ContourClass.SpatialReference? (this was going into fail when using for the new(cloned) pointclass.
Or do I have to create a new Spatialreference via SpatialRefernceFactory or something else?

Sorry when I am asking too much and maybe some simple things, but I try to understand it at all.
Have much thanks for your post!
0 Kudos
SebastianKrings
Frequent Contributor
hi

I now did something with the spatial reference.
now boh feature classes have the same coordinate system and a valid spatial reference (factoryCode of both is equal)
but Im still getting the exception.

I am also not able to execute the joinNearest within an testAddin.

Does anybode have a functioning code for the method ISpatialJoin.JoinNeares ?
Doesnt matter which Features and Data is used, does it function at all?

Thanks.
0 Kudos