Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:

  1. 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
  2. Start editor

  3. Using arcobjects open layer1 from workspace opened using workspacefactory
    • ((IFeatureWorkspace)workspace).OpenFeatureClass("name of layer1);
  4. Find feature from layer1
  5. layer1 feature geometry has spatial reference WGS
  6. use geometry to find (spatial query) other object FAILS
  7. Edit the geometry using editor and save edits
  8. repeat steps 2-3
  9. layer1 feature geometry has spatial reference EUREF
  10. use geometry to find (spatial query) other object SUCCEEDS
  11. Stop editor & Repeat from 1. (always repeatable)
share|improve this question
    
What arcobjects methods are you using for steps 4 and 6? –  Kirk Kuykendall Oct 16 '12 at 13:20
    
For step 4 I'm not sure, but for step it's table.Search(filter, false); (ITable and IQueryFilter). –  kor_ Oct 31 '12 at 8:49

1 Answer 1

up vote 2 down vote accepted

You must project the geometry of the search feature to the spatial reference of the selection layer. This way you ensures that the query is done in the correct CRS. This is how i'll do it:

IGeometry searchGeometry = searchFeature.Shape;
searchGeometry.Project(((IGeoDataset)selectionLayer.featureClass).SpatialReference);

ISpatialFilter spatialFilter = new SpatialFilterClass();
spatialFilter.Geometry = searchGeometry;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

IFeatureSelection featureSelection = (IFeatureSelection)selectionLayer; 
featureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false); 

I hope this will help you.

share|improve this answer
    
Thanks for the answer. This may become a serious overhead if I have alot of features. Isn't there an easier way to "automate" this or something, because the issue only happens before the user has edited something (and after that everything is fine)? –  kor_ Oct 31 '12 at 9:15
    
+1 Another alternative is when fetching the searchGeometry, you might try setting ISpatialFilter.OutputSpatialReference before calling IFeatureClass.Search. Not sure if it performs any faster though. –  Kirk Kuykendall Oct 31 '12 at 16:52
    
Ok, thanks. I will mark the answer as accepted even though it's not excatly what I need (but it resolves the main issue). –  kor_ Nov 9 '12 at 10:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.