Query using geometry(polygon) and js api 3.7

1947
7
11-06-2013 05:32 AM
AndersonCarneiro
New Contributor
Hi,

I'm trying to do a query over a feature layer, using a geometry as filter. The geometry is a polygon, so it has rings and the json format should be like in the API reference examples: (http://sampleserver3.arcgisonline.com/ArcGIS/SDK/REST/index.html?query.html)

1) {"rings" : [
[ [<x11>, <y11>], [<x12>, <y12>], ..., [<x11>, <y11>] ],
[ [<x21>, <y21>], [<x22>, <y22>], ..., [<x21>, <y21>] ]
],
"spatialReference" : {<spatialReference>}
}

But, instead of that, the json built by the API is diferent, like this:

2){ "rings" : " [
[ [<x11>, <y11>], [<x12>, <y12>], ..., [<x11>, <y11>] ],
[ [<x21>, <y21>], [<x22>, <y22>], ..., [<x21>, <y21>] ]
]",
"spatialReference" : {<spatialReference>}
}

Trying to submit a query using this geometry to a AGS 10.1 , I've got this error: Invalid or missing input parameters
I also tried to submit a query using the same geometry to a AGS 10.2 and the result was ok, with no error.

My question is: if the documentation says the correct json format is like 1), why is theAPI building a json with extra double quotes?
Is it a bug?

Thanks in advance!

Anderson
0 Kudos
7 Replies
JohnGravois
Frequent Contributor
welcome to our forum!

how did you get a reference to the polygon geometry object in question?  from another query?

in general, if you need to validate/correct a geometry object, you can use the simplify method of a geometry service, but i'd definitely be curious to know what returned the problematic geometry to you in the first place.

a simplified app or code snippet (wrapped in code tags) would also be helpful.
0 Kudos
AndersonCarneiro
New Contributor
jgravois,

Yes, the geometry comes from another query. It's a simple query and I'm not simplifying the geometry.

        ...
        this.query.returnGeometry = true;
        this.query.where =  "NUM_RESERVAT_AARE="+id;
        this.query.outFields=['*'];
        this.queryTask.execute(this.query, function (results){            
        if (results.features.length){
                areainfluencia.geometry = results.features[0].geometry;
            }
        }


After this, I try to make a selecion in a feature layer, using the geometry:

               ....               
        if (areainfluencia.geometry != null){ 
            selectQuery.geometry = areainfluencia.geometry;
        }
        myFeatureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW);


I know the geometry is quite complex, but it used to work fine in 2.8 version, however, with 3.7 it doesn't work anymore.

Any idea?

Thanks!!
0 Kudos
JohnGravois
Frequent Contributor
what is the benefit of using QueryTask in this case?  (in other words, why not just fire the SQL query against the FeatureLayer directly?)
0 Kudos
AndersonCarneiro
New Contributor
Hi,

With the first query, I get the geometry (polygon) to use with the feature layer to select all points inside the polygon...

I don't know if I understood, but maybe it would be possible to create just one query against the feature layer, and in the where clause I would have something like this:

               query.where = "ID IN(SELECT A.ID FROM TABLE_POINT A, TABLE POLYGON B 
                                    WHERE SDE.ST_INTERSECTS(A.SHAPE, B.SHAPE) = 1
                                   AND B.ID_POLYGON = " + ID_POLYGON + ")"


I'll try to run this query tomorrow and after I'll post the results...

Thanks!!
0 Kudos
JohnGravois
Frequent Contributor
sounds good.

you can pass a query which filters both based on a SQL expression and spatial relationship to FeatureLayer.queryFeatures(query) by setting query.geometry as well as query.where
0 Kudos
AndersonCarneiro
New Contributor
Hi,

It worked! Using the sde.st_intersects inside the query solved the problem.
In my opinion, there is a bug in 3.7 api (and maybe in earlier versions)when the polygon is used as a filter in a query. The extra double quotes generated by the api cause the error in Arcgis Sever 10.1 sp1, even with simple polygons. In 10.2(I've used the arcgis online servers), it works with both formats(with ou without the extra double quotes).

Anyway, I'd like to say thank you so much for your help, jgravois!
0 Kudos
JohnGravois
Frequent Contributor
glad to hear you got yourself sorted.  i finally got a chance to take a deeper look at this and i wasn't able to reproduce the error you described when a spatial query is passed to a feature layer in selection mode that returns a multipart polygon geometry.

check out this fiddle and if possible, let me know what needs to change to show the problem.
0 Kudos