I'm using ArcMap 10 and Bing Maps Road as base map. Then we have our adding which is programmed using C#. What I'm trying to do is to select a feature (A) that intersects another feature (B, from a different feature class). I can achieve this with ArcMap's Select By Location function.
But when I try to do the same with ArcObjects, I cannot find anything because feature A seems to have a different coordinate system than feature B! Bing Maps Road uses WGS 1984 and my feature classes should use EUREF_FIN_TM35_FIN.
An interesting thing is, that when I manually modify feature class' geometry and save it, then both features are using EUREF (as they should in the first place)!
If I right click the Layers and take Data Frame Properties, it shows "WGS_1984_Web_Mercator_Auxiliary_Sphere" (and this is when error happens). If I change it to EUREF_FIN_TM35_FIN then everything works.
Code sample:
IFeatureClass featureClass = ((IFeatureWorkspace)m_workspace).OpenFeatureClass(name) as IDataset;
// Here I can see the feature.Shape.SpatialRef changes
IFeature feature = featureClass.GetFeature(oid.Value);
Now I would like to know is this a bug in ArcObjects or am I doing something wrong? I'm quite new to GIS and ArcMap, so there might be some simple thing I don't get.
In a nutshell:
- I want to select feature B that intersects feature A
- When I try to do that in ArcMap, it works
- In ArcObjects it doesn't, except when I modify a geometry and save
- It has something to do with the base map's coordinate system
Edit: Here's how to reproduce this issue:
Preparation On the map and in same data frame (data frame spatial ref wgs)
- layer1 (from fgdb) - spatial reference EUREF
- layer2 (bing maps) - spatial reference wgs
Start editor
- Using arcobjects open layer1 from workspace opened using workspacefactory
- ((IFeatureWorkspace)workspace).OpenFeatureClass("name of layer1);
- Find feature from layer1
- layer1 feature geometry has spatial reference WGS
- use geometry to find (spatial query) other object FAILS
- Edit the geometry using editor and save edits
- repeat steps 2-3
- layer1 feature geometry has spatial reference EUREF
- use geometry to find (spatial query) other object SUCCEEDS
- Stop editor & Repeat from 1. (always repeatable)