Select to view content in your preferred language

FeatureLayer - geometries from QueryTask overlay in different location than source

1164
9
06-08-2010 09:10 AM
DavidLowther
Deactivated User
I have a map defined with four layers in this order: TiledBaseMap (ArcMapTiledMapServiceLayer), Sample Locations (FeatureLayer), MyGraphicsLayer (GraphicsLayer), and MySelectionGraphicsLayer (GraphicsLayer). The TiledBaseMap service WKID is 3735. The Sample Locations service WKID is 3734.

I am executing a QueryTask against Sample Locations passing in a Geometry object with SpatialReference WKID=3735. When the call to QueryTask.ExecuteAsync returns the features in the QueryEventArgs.FeatureSet specify that their SpatialReference WKID=3735. However, when I add these features to MyGraphicsLayer they do not overlay with the features from Sample Locations.

I have tried specifying QueryTask.OutSpatialReference as 3735 (though this should be the default according to my understanding) and 3734 - and even though the features in the featureset report the WKID I specify, the actual coordinates are the same.

I have tried setting MyGraphicsLayer.SpatialReference to 3735 and 3734 in combination with the QueryTask OutSpatialReference with no change in the overlay.

Can you help me understand what is going on here?

And, I guess the simple question is: Is there any way to return geometry from a QueryTask that is not in the SpatialReference of the map? If not, do I need to reproject each feature using the GeometryService in order to overlay them, or is there some better way to get where I am trying to go (which is to highlight the selected features).

Thanks,
0 Kudos
9 Replies
dotMorten_esri
Esri Notable Contributor
When doing a query for features that you want to overlay on the map, you should ALWAYS set
query.OutSpatialReference = MyMap.SpatialReference.

To answer your question: "Is there any way to return geometry from a QueryTask that is not in the SpatialReference of the map":
Yes. Remember that the QueryTask and the server has no idea what spatial reference your map is in. All it knows to return is the spatial reference you ask it to return it in (if you don't specify any, it will default to the spatial reference of >service< you are querying). Hence the above line of code is VERY important.
0 Kudos
DavidLowther
Deactivated User
Morten,

I've verified that the OutSpatialReference performs as described with my layers when no Query.Geometry is present. A Query with only Where specified will return what I ask. However, when I do specify Query.Geometry I get features back in the SpatialReference of the input Geometry. Does that sound right?
0 Kudos
dotMorten_esri
Esri Notable Contributor
Are you saying that the spatial reference of the geometry you use to query is different than that of your map? (although that should technically still work, but its a very rare usecase and most likely the reason why you are seeing something different than you expect).
0 Kudos
DavidLowther
Deactivated User
No, the spatial reference of the geometry I use to query is the same as that of the map. I am saying that when I use a geometry in the query the out spatial reference does not seem to be honored.
0 Kudos
dotMorten_esri
Esri Notable Contributor
Can you get it to work if you use the REST endpoint's HTML interface?
0 Kudos
DavidLowther
Deactivated User
No. I see the same results in the REST HTML interface.

query geometry inSR 3735 - outSR 3734

http://www.coordinatesolutions.com/ArcGIS/rest/services/SampleLoc3734/MapServer/0/query?text=&geomet...

MiR0051
Point:
X: 1965181.74994861
Y: 395641.406268179

query geometry inSR 3735 - outSR 3735

http://www.coordinatesolutions.com/ArcGIS/rest/services/SampleLoc3734/MapServer/0/query?text=&geomet...

MiR0051
Point:
X: 1965181.75005963
Y: 395641.406089559

query no geometry outsr 3734

http://www.coordinatesolutions.com/ArcGIS/rest/services/SampleLoc3734/MapServer/0/query?text=MiR0051...

MiR0051
Point:
X: 1965181.74994861
Y: 395641.406268179

query no geometry outsr 3735

http://www.coordinatesolutions.com/ArcGIS/rest/services/SampleLoc3734/MapServer/0/query?text=MiR0051...

MiR0051
Point:
X: 1965180.86160997
Y: 1002668.97155955
0 Kudos
DavidLowther
Deactivated User
Any ideas on this one?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Sorry, no idea.

It looks like the issue is coming from the REST API and is not related to the FLEX API since we can reproduce the strange behavior just by requesting the REST End points.
At first glance I will say that there is a bug (or a behavior I can't explain!) in the REST or the server API.
I suggest you post a message to the REST API forum.
0 Kudos