I do not know why my tool no longer functions properly when working in a file geodatabase (FGDB), as opposed to the personal geodatabases (PGDB) used in the past. The tool is used to find feature in a point feature class (point_fc) that intersect features in a line feature class (line_fc).
The tool splits a selected line_fc feature at midpoints between vertices that intersect point_fc features. This still works as designed.
The issue arises when a spatial filter is used to find point_fc features that intersect the new 'split' features. The results of the spatial filter are not consistent as when using a PGDB. I don't believe anything is fundamentally wrong with my code, since it works with PGDB, but I may have overlooked something. I've included some code below:
// loop through selected line_fc features
IEnumFeat _enumFeat = _editor.EditSelection; // an enumeration of selected features
IFeature _feature;
while ((_feature = _enumFeat.Next()) != null)
{
// storage for midpoints
IGeometry midpointMultipoint = new Multipoint() as IGeometry;
midpointMultipoint.SpatialReference = map.SpatialReference; // <-----PCS
IPointCollection midpointCollection = midpointMultipoint as IPointCollection;
// storage for point_fc geometry
IGeometry multipoint = new Multipoint() as IGeometry;
multipoint.SpatialReference = _feature.Shape.SpatialReference; //<----PCS
IPointCollection intersectingPoints = (IPointCollection)multipoint;
// get intersecting point_fc
sFilter.Geometry = (IGeometry)_feature.Shape;
sFilter.GeometryField = point_fc.ShapeFieldName;
sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
sFilter.WhereClause = string.Format("{0}{1}{2} = {3}", fieldPreffixDelim, "subtype", fieldSuffixDelim, "12345"); // the specific subtype i'm interested in
IFeatureCursor fCursor = point_fc.Search(sFilter, false);
IFeature thisFeature;
object Missing = Type.Missing;
while ((thisFeature = fCursor.NextFeature()) != null)
{
IPoint pnt = thisFeature.Shape as IPoint;
pnt.Project(_feature.Shape.SpatialReference); // GCS --> PCS
intersectingPoints.AddPoint(pnt, ref Missing, ref Missing);
}
// split _feature polyline at intersecting points into individual polyline objects
IPolycurve2 polyCurve = _feature.ShapeCopy as IPolycurve2;
IEnumVertex splitPoints = intersectingPoints.EnumVertices;
IEnumSplitPoint enumSplitPoint = polyCurve.SplitAtPoints(splitPoints, true, true, 0.1);
// check if split occurred
if (!enumSplitPoint.SplitHappened)
{
continue; // go to next _feature
}
// new geoCol for polycurve
IGeometryCollection geoColl = (IGeometryCollection)polyCurve;
for (int i = 0; i < geoColl.GeometryCount; i++)
{
IGeometryCollection polyline = new Polyline() as IGeometryCollection;
IGeometry geom = (IGeometry)polyline;
geom.SpatialReference = _feature.Shape.SpatialReference;
polyline.AddGeometries(1, geoColl.get_Geometry(i));
// query points that intersect line
sFilter.Geometry = (IGeometry)polyline;
// not all lines will intersect 2 points, so we skip those that don't
// check for 2 points
int pointCount = point_fc.FeatureCount(sFilter);
if (pointCount != 2) //<----TODO: determine why we are getting inconsistent results with FGDB
{
continue; // go to next polyline feature
}
// use fCursor to get intersecting point_fc (also inconsistent results)
...
// do something here with 2 point_fc features
...
}
}
The same schema is used on both the PGDB and FGDB, and all feature classes/datasets are in GCS. Map document is in PCS (WGS84 UTM).
Why would a spatial filter return varying results when using a PGDB vs FGDB?
It is recommended at ArcObjects SpatialFilter not working well to use a buffer when querying point/line intersections, however my points are snapped to my lines at vertices. I will try this if all else fails.