QueryTask result returns incorrect geometry

1290
6
04-16-2012 07:02 PM
JayGregory
New Contributor III
I'm having this really strange problem with some queries and have tried everything. 
First, I construct a query to retrieve the District of Columbia boundary:
      queryTask = new esri.tasks.QueryTask(districtURL);
  var query = new esri.tasks.Query();
                query.returnGeometry = true;
                query.outFields = ["*"];
  query.where = "CITY_NAME = 'Washington'"
                query.outSpatialReference = map.spatialReference;
  queryTask.execute(query);
  dojo.connect(queryTask, "onComplete", queryResults);

The districtURL variable points to a ArcGIS for Server 10 map server layer, which when displayed on a base map is correctly positioned on the District of Columbia. 
HOWEVER, while the queryTask returns one result (as it should - DC boundary), the geometry of that result is located as if it has no associated projection, off the coast of Africa near Nigeria and Cameroon (I zoom to the results in the following code). 
      
     
function queryResults(featureSet){
 console.log(featureSet.features.length);
 map.setExtent(featureSet.features[0].geometry);


I'm tearing my hair out here - the spatial reference of the layers and map service are all 3857.  Why won't the service return the correct geometry?

Thanks, Jay
6 Replies
StephenLead
Regular Contributor III
Is the districtURL site public-facing? If not, can you show us the results of featureSet.features[0].geometry?

Steve
0 Kudos
JayGregory
New Contributor III
It is public facing:

http://129.2.24.163/ArcGIS/rest/services/Capstone_Projects/JayGregoryStatic/MapServer/7

My code is at home, so can't get the results until this evening, but maybe the map server will help...

Thanks!

Jay
0 Kudos
nicogis
MVP Frequent Contributor
Jay what's the spatialReference of map? you have set in query map.spatialReference but the map.spatialReference  can be <> from spatialReference of your service if you have load in map how first layer (service) another service with spatial reference <> your service.
0 Kudos
JayGregory
New Contributor III
As I've been pretty sure that my problems lie with some spatial reference / projection problems, I've been experimenting with different spatial references, but they've all been either 3857 or 102100 (web mercator). 
When I published my map document, I made sure the data frame and all data layers had the same projection (WGS 1984 Web Mercator - Auxiliary Sphere or just the WGS 1984 Web Mercator.  Sometimes though results may have ended up as 4326 spatial reference, but I don't know how....

So are saying if I load a layer _without_ a spatial reference first then that would overwrite the hard-coded spatial reference of my map when I set the extent?  I think I loaded the basemap first (using map.addLayer), but I may have loaded a generic graphics layer without a spatial reference second....

Jay what's the spatialReference of map? you have set in query map.spatialReference but the map.spatialReference  can be <> from spatialReference of your service if you have load in map how first layer (service) another service with spatial reference <> your service.
0 Kudos
JayGregory
New Contributor III
So I've checked the spatial reference of the queryTask (the one I set equal to map.spatialReference) - it's 102100.  And then, as soon as the query runs, I check the spatial reference of the feature set it returns, using the following code:
function queryResults(featureSet){
 console.log(esri.geometry.webMercatorToGeographic(featureSet.features[0].geometry));
 console.log(featureSet.features[0].geometry);

The first console log has a spatial reference of 4236, and the second has one of 3857.  Yet still the geometry when I use either one (webMercatorToGeographic or original featureSet returned) is wrong, and pans to a location as if it has no projection at all. 
Thanks for your assistance....
Jay

Jay what's the spatialReference of map? you have set in query map.spatialReference but the map.spatialReference  can be <> from spatialReference of your service if you have load in map how first layer (service) another service with spatial reference <> your service.
0 Kudos
SadanandacharB1
New Contributor III

Hi,

Even I am facing the same issue, what Jay has faced.

1. Task : Migrating of Arcgis server from 10.0 to 10.2.1

2. Development : Silverlight application version 5.0

3. All original map service layers render in correct location in the Map control

4. But after the using Query task on route event layer, the result objects are set to wrong projection system, it pans to the coast of Africa near Nigeria and Cameroon.

I have also set outSpatialReference [source from map] on query result features no use,

Any one can help on this, please...

Thanks

Sadanand

0 Kudos