I need to perform search on a FeatureClass using ISpatialFilter for a given Point (x,y). I wrote a program in C# to do that and its retrieving the features as expected. But the similar program in C++ is failing for some feature classes and working for some. I am wondering where it went wrong.
The below c++ code works fine for featureclass cbsa. But doesnt work for BlockGroups.
//Create Point IPointPtr ipPoint = NULL; ipPoint.CreateInstance(CLSID_Point); ipPoint->PutCoords( dX, xY); //Create Envelope IEnvelopePtr envelope(CLSID_Envelope); hr = ipPoint->get_Envelope(&envelope); //Open Feature Class IWorkspaceFactoryPtr pWorkspacefactory(CLSID_FileGDBWorkspaceFactory); IFeatureWorkspacePtr featureWorkspace; IWorkspacePtr workspace; hr = pWorkspacefactory->OpenFromFile(CComBSTR(gdbpath,0,&workspace); featureWorkspace = workspace; IFeatureClassPtr featureClass; hr = featureWorkspace->OpenFeatureClass(CComBSTR("CensusBGroups"),&featureClass); // Set ISpatialFilter Properties BSTR shapeFieldName; hr = featureClass->get_ShapeFieldName(&shapeFieldName); ISpatialFilterPtr spatialFilter(CLSID_SpatialFilter); spatialFilter->putref_Geometry(envelope); spatialFilter->put_SpatialRel(esriSpatialRelIntersects); spatialFilter->put_GeometryField(shapeFieldName); // Search IFeatureCursorPtr featureCursor; featureClass->Search(spatialFilter, false, &featureCursor); // featurecursor doesnt contain any featueres IFeaturePtr feature; // Get First Feature hr = featureCursor->NextFeature(&feature); //feature is null IFieldsPtr totalfields; hr = feature->get_Fields(&totalfields);