Mark,
Here is what I have come up with and it does NOT use any ArcObjects. It consists of functions that will buffer an inputted polygon and then use the outputted polygon to perform a spatial query on a layer and return an attribute. Within the example code, you filnd notes explaining what I did, such as storing complex geometries in a text file. Please look at the documentation for the buffer operation, it will explain how to set the units, buffer distances, etc. I hope this is what you are looking for and it helps.
This example creates a 100 foot buffer:
Public Function Buffer_Geometry(ByVal jsonGeom As String) As string
Dim attributeA as string
' where jsonGeom is a serialized json string storing polygon geometry
' add geometryType if it's not already included in the json string
json = "{" + """" + "geometryType" + """" + ":" + """" + "esriGeometryPolygon" + """" + "," + """" + "geometries" + """" + ":[" + jsonGeom + "]}"
' reference a text file to store the json string (solution for very complex geometries)
' this text file should be stored in a folder within the website. Make sure all web users have write access to it.
Dim txtFile = <string: name of text file>
Dim path As String = System.Web.HttpContext.Current.Server.MapPath(<string: path of textfile>)
' write jon to text file
Dim writer As New StreamWriter(path + "/" + txtFile, False, System.Text.Encoding.ASCII)
writer.Write(json)
writer.Close()
' NOTE: instead of passing geometry directly, you are passing in areference to the text file
Dim data As String = "&geometries={" + """" + "url" + """" + ":" + """" + txtFile + """" + " }" + _
"&inSR=3857" + _
"&outSR=3857" + _
"&bufferSR=3857" + _
"&distances=100" + _
"&unit=9002" + _
"&unionResults=true" + _
"&f=json"
' url for buffer operation
Dim bufferURI As String = <string: url of buffer operation>
' calls funcion called PostIt that does a POST
Dim responseString As String = PostIt(bufferURI, data)
Dim jss As New System.Web.Script.Serialization.JavaScriptSerializer()
jss.MaxJsonLength = 1000000
Dim results As IDictionary(Of String, Object) = TryCast(jss.DeserializeObject(responseString), IDictionary(Of String, Object))
If results IsNot Nothing AndAlso results.ContainsKey("geometries") Then
Dim obj As Object = results("geometries")
' output for buffer is geometries, to perform a spatial query, need to input a 'geometry' so grab one form geometries
json2 = jss.Serialize(obj(0))
End If
'call the query function, parameters: mapservice url, layerID (layerid of the layer you are doing query on), geometry
Dim results2 As IEnumerable = DrillDown(<string: mapservice url>, <string: layerID>, json2)
For Each feature As IDictionary(Of String, Object) In results2
Dim attributes As IDictionary(Of String, Object) = TryCast(feature("attributes"), IDictionary(Of String, Object))
attributeA = (attributes.Item(<string: field name attributeA>))
End If
Next
return attributeA
End function
--------------------------------------------------------------------------------------------------------------------------
Private Shared Function PostIt(ByVal baseUrl As String, ByVal input As String) As String
Dim responseString As String
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
Dim byteData() As Byte
Dim postStream As Stream = Nothing
request = DirectCast(WebRequest.Create(baseUrl), HttpWebRequest)
' Set type to POST
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
' Create a byte array of the data we want to send
byteData = UTF8Encoding.UTF8.GetBytes(input)
' Set the content length in the request headers
request.ContentLength = byteData.Length
Try
postStream = request.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)
Finally
If Not postStream Is Nothing Then postStream.Close()
End Try
Try
' Get response
response = DirectCast(request.GetResponse(), HttpWebResponse)
' Get the response stream into a reader
reader = New StreamReader(response.GetResponseStream())
responseString = reader.ReadToEnd
Catch
Finally
If Not response Is Nothing Then response.Close()
End Try
Return responseString
End Function
-------------------------------------------------------------------------------------------------------------------------
Public Shared Function DrillDown(ByVal baseUrl As String, ByVal layerID As Integer, ByVal jsonGeom As String) As IEnumerable
Dim data As String
Dim txtFile = Dim txtFile = <string: name of text file>
Dim path As String = System.Web.HttpContext.Current.Server.MapPath(<string: path of textfile>)
Dim writer As New StreamWriter(path + "/" + txtFile", False, System.Text.Encoding.ASCII)
writer.Write(jsonGeom)
writer.Close()
data = "&geometry=" + jsonGeom + _
"&geometryType=esriGeometryPolygon" + _
"&inSR=" + _
"&spatialRel=esriSpatialRelIntersects" + _
"&relationParam=" + _
"&objectIds=" + _
"&where=" + _
"&time=" + _
"&returnIdsOnly=false" + _
"&returnGeometry=false" + _
"&maxAllowableOffset=" + _
"&outSR=" + _
"&outFields=*" + _
"&f=json"
Dim responseString As String = PostIt(baseUrl.ToString + layerID.ToString + "/query", data)
Dim jss As New System.Web.Script.Serialization.JavaScriptSerializer()
jss.MaxJsonLength = 100000000
Dim results As IDictionary(Of String, Object) = TryCast(jss.DeserializeObject(responseString), IDictionary(Of String, Object))
Dim json As String = ""
Dim DrillDownResult As IEnumerable
If results IsNot Nothing AndAlso results.ContainsKey("features") Then
Dim features As IEnumerable(Of Object) = TryCast(results("features"), IEnumerable(Of Object))
DrillDownResult = features
End If
Return DrillDownResult
End Function