ArcGIS REST Services Directory Query Function

9042
12
09-11-2014 02:19 PM
GeorgeStrebel
New Contributor III

I have been using the ArcGIS REST Services Directory query function to build a query string step by step so I can then relay the process to our web developer who has limited knowledge of GIS.  I have gotten stuck when I am trying to query a layer using Input Geometry and the Geometry type as a Polygon.

All the features that are being queried are in the same service; polygon for parcel, polygon for fema flood hazards.

The current process is as follows, take a valid address and use the Find Address Candidates operation in a GeocodeService to get the xy, take the address xy and use the Query operation on the parcel polygon to return the xy of the vertex of the associated parcel polygon.  Since HTML doesn't give me a full list of all the vertex that make up the polygon I have to return the JSON which does (see attached jasonXYReturnFromPolyon.txt).  This is where I am getting hung up, I an now trying to take the xy of the returned JSON and use it in the Query operation on the fema flood hazard polygon to return all flood zones that intersect the parcel polygon.  I can get it to work if I use the default Geometry Type: Envelope with Spatial Relationship: Intersect but it does not return accurate data.  When I try and change the Geometry Type to Polygon I get an Invalid or missing input parameters.  My guess is that either my Input Geometry is formatted wrong or the xy that is returned to represent the parcel polygon vertex is not seen as a polygon.  Any help, insight or suggestions on a better way would be appreciated.

0 Kudos
12 Replies
PaulCrickard1
Occasional Contributor II

What do you mean, it does not return accurate data?

What does your input query (geometry) look like?

0 Kudos
PaulCrickard1
Occasional Contributor II

You mention you can't use the HTML, so you have to take the JSON. What are you doing this in? I don't know why you would ever want the HTML response. Parsing all the HTML for the answer would be overly complicated.

0 Kudos
GeorgeStrebel
New Contributor III

Paul,

the data returned using the JSON parsed like below

3141494.4837799999, 10210904.9416,

3141653.99658,10210458.248260001,

3141672.6825700002,10210411.773290001,

3141673.5565800001,10210409.598750001,

3139938.0423400002,10209644.59766,

3139622.1886399998,10209509.99065,

3139561.4069400001,10209485.35421,

3139103.21428,10210640.368629999,

3139023.60421,10210839.482410001,

3139083.6838099998,10210822.509020001,

3139471.08232,10210956.32962,

3140148.4559599999,10210627.96479,

3140200.8761300002,10210650.42275,

3140457.22273,10210608.13871,

3140749.2382200002,10210598.89168,

3140859.1740299999,10210620.211850001,

3141340.4414400002,10210858.245820001,

3141494.4837799999,10210904.9416

using the default Geometry Type: Envelope and Spatial Relationship as Intersects it will return results with the Correct Out Field: information  but it's not what is actually on the ground hence incorrect data.  What I am trying to do is figure out why I can't use the above xy with the Geometry Type of Polygon Spatial Relationship of Intersects to return the correct data. Is it a parsing issue with the xy or maybe the Polygon Geometry Type is not compatible with what I am trying to accomplish.  I am not a programmer or developer and am just trying to make this work so I can turn the process over to someone that is.  I can not find any documentation or example on how to use the Query Operation with the Geometry Type: as Envelope.

0 Kudos
PaulCrickard1
Occasional Contributor II

The REST API docs are here: ArcGIS Server REST API

Envelope is like this:

  • geometryType=esriGeometryEnvelope&geometry={xmin: -104, ymin: 35.6, xmax: -94.32, ymax: 41}
  • geometryType=esriGeometryEnvelope&geometry=-104,35.6,-94.32,41

Here is my working query:

Capture.JPG

0 Kudos
PaulCrickard1
Occasional Contributor II

If you don't specify a geometry, it defaults to envelope.

0 Kudos
GeorgeStrebel
New Contributor III

Paul,

here is what I get when I do the same inputs and you did in your screenshot, I had to use HTML as the return so I could show you the query otherwise it opens on a different page without the query operation dialog.  I am using 10.2, as you can see it returns values for the request output field but it not correct on what is on the ground.

Query: FEMA Flood Hazard Area (ID: 11)

Where:
Text:
Object IDs:
Time:
Input Geometry:
Geometry Type: Envelope
Input Spatial Reference:
Spatial Relationship:
Relation:
Out Fields:
Return Geometry: True  False
Max Allowable Offset:
Geometry Precision:
Output Spatial Reference:
Return IDs Only: True  False
Return Count Only: True  False
Order By Fields:
Group By Fields (For Statistics):
Output Statistics:
ReturnZ: True  False
ReturnM: True  False
Geodatabase Version Name:
Return Distinct Values: True  False
Format:

  # records: 4

FLD_ZONE: AE

Polygon:

[3139873.98177, 1.020943624801E7] , [3139909.01713, 1.020943599571E7] , [3139909.00729, 1.020943203083E7] more...

FLD_ZONE: X

Polygon:

[3140460.33887, 1.020952607624E7] , [3140460.60888, 1.020953236494E7] , [3140460.62069, 1.020953407163E7] more...

FLD_ZONE: AE

Polygon:

[3147925.79506, 1.021805567762E7] , [3147952.21922, 1.021697055315E7] , [3147887.52578, 1.021696978806E7] more...

[3147887.77775, 1.021961688021E7] , [3147838.331, 1.021957684682E7] , [3147667.71159, 1.02195631792E7] more...

[3140234.74549, 1.022370575458E7] , [3140233.96891, 1.022369097705E7] , [3140309.99369, 1.022350997642E7] more...

FLD_ZONE: AE

Polygon:

[3141672.32791, 1.02105661237E7] , [3141668.32202, 1.021056608794E7] , [3141668.29577, 1.02105540732E7] more...

The second screenshot below is of what happens when I change the Geometry Type to Polygon and use the dame Input Geometry, I get the Invalid or missing input parameters

Invalid or missing input parameters.

Where:
Text:
Object IDs:
Time:
Input Geometry:
Geometry Type:   Polygon
Input Spatial Reference:
Spatial Relationship:  
Relation:
Out Fields:
Return Geometry: True   False
Max Allowable Offset:
Geometry Precision:
Output Spatial Reference:
Return IDs Only: True   False
Return Count Only: True   False
Order By Fields:
Group By Fields (For Statistics):
Output Statistics:
ReturnZ: True   False
ReturnM: True   False
Geodatabase Version Name:
Return Distinct Values: True   False
Format:  
0 Kudos
PaulCrickard1
Occasional Contributor II

I don't know why polygon doesn't work, but envelope should only have 4 points. xmin, ymin and xmax, ymax.

Depending on how many FEMA areas you have, you could try to Point in Polygon them (the developer could run the query themselves and ignore the rest if it isn't working right.) Many ways to solve the same problem.

I use this formula:

//+ Jonas Raoni Soares Silva

//@ http://jsfromhell.com/math/is-point-in-poly [rev. #0]

function isPointInPoly(poly, pt){

    for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)

        ((poly.y <= pt.y && pt.y < poly.y) || (poly.y <= pt.y && pt.y < poly.y))

        && (pt.x < (poly.x - poly.x) * (pt.y - poly.y) / (poly.y - poly.y) + poly.x)

        && (c = !c);

    return c;

}

My poly is in a file and looks like this:

var poly=[{x:35.1631035593,y:-106.659880001},

{x:35.1631035458,y:-106.659879999},

{x:35.1631035503,y:-106.659880015},

{x:35.1602168416,y:-106.679432832},

{x:35.1601067583,y:-106.679508129},

{x:35.1600635441,y:-106.679513221},

{x:35.1599856053,y:-106.679510715},

{x:35.1590417964,y:-106.680071918},

{x:35.1581326754,y:-106.680813656},

{x:35.1581325045,y:-106.681021692},

{x:35.1581325837,y:-106.681175784},

{x:35.1581326772,y:-106.681349715},

{x:35.1581324901,y:-106.681449898}]

0 Kudos
GeorgeStrebel
New Contributor III

The best I can figure it is  xy is not parsed correctly so that the corresponding vertex/xy I am providing in the Input Geometry: does not recognize it as a polygon hence I get the Invalid or missing input parameters.  Since the Envelope is only taking the xmin, ymin and xmax, ymax of probably the first four points it returns results but not all the data that the actual polygon covers.  This has been really frustrating to say the least.  The point in polygon could work but I need to use the polygon outline of the parcel to get a valid return and my trigger for this is an address point (single) XY that is associated with the parcel polygon that I then need to intersect the fema polygon to return all values. 

0 Kudos
PaulCrickard1
Occasional Contributor II

Do you really need to use the rest api manually?

what is the developer using to build this application? If they use the ESRI JavaScript API, could they just use the Query() method? It takes a geometry as a spatial filter and handles all the details for you.

Look at this example, it creates a buffer then uses the geometry to grab all census blocks in the buffer. you would get a parcel and select all fema zones in it.

Select with Feature Layer | ArcGIS API for JavaScript

0 Kudos