Select to view content in your preferred language

Perform Query with multiple geometries (or one combined geometry)

3480
3
01-12-2011 10:11 AM
RalphPrice
Emerging Contributor
I have a graphics layer with multiple graphics in it and I wish to use all of those geometries to perform a Query.
This following code works fine as far as doing my Query but of course is only using the geometry of the last graphic in my previous buffer results is used.


     
Private Sub GeometryService_BufferCompleted(ByVal sender As Object, ByVal e As GraphicsEventArgs)
Try
       
Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyUserDrawnGraphicsLayer"), GraphicsLayer)
            graphicsLayer.Graphics.Clear()
            Dim iZIndex As Integer = 0
            Dim comboBufferGraphic As New Graphic

            For Each bufferGraphic As Graphic In e.Results
                comboBufferGraphic.Geometry = bufferGraphic.Geometry
                bufferGraphic.Symbol = TryCast(LayoutRoot.Resources("BufferSymbol"), Symbol)
                bufferGraphic.SetZIndex(iZIndex)
                graphicsLayer.Graphics.Add(bufferGraphic)
                iZIndex = iZIndex + 1
            Next

            Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
            query.ReturnGeometry = True
            query.Geometry = comboBufferGraphic.Geometry
            query.OutSpatialReference = MyMap.SpatialReference
            query.OutFields.Add("SUE")
            query.OutFields.Add("LEGAL")
            _queryTask.ExecuteAsync(query)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub



It would seem that a Tasks.Query only accepts one Geometry value as the Geometry property so my question is how do I combine the geometries of all of my graphics?
I have searched for a geometry.add function or aggregate or combine and had no luck.
There is not an obvious way to export the geometries to strings, combine and then create a new geometry from that coord string. If there is I would be glad to have it pointed out to me.

Any thoughts on this would be most appreciated.

Regards

Ralph Price
Application Developer and GIS Analyst
0 Kudos
3 Replies
RalphPrice
Emerging Contributor
Hi to all

The code below shows hows to combine the separate graphic geometries into one to be used in the query task. Amazing how the act of posting a message will prompt inspiration!!
There may be other ways but it is what I am doing for now.


Regards

Ralph Price
Application Developer and GIS Analyst



     
   Private Sub GeometryService_BufferCompleted(ByVal sender As Object, ByVal e As GraphicsEventArgs)
        Try
            Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyUserDrawnGraphicsLayer"), GraphicsLayer)
            graphicsLayer.Graphics.Clear()

            Dim comboBufferGraphic As New Graphic
            Dim myComboPoly As New ESRI.ArcGIS.Client.Geometry.Polygon

            For Each bufferGraphic As Graphic In e.Results
                comboBufferGraphic.Geometry = bufferGraphic.Geometry
                Dim myPoly As ESRI.ArcGIS.Client.Geometry.Polygon = TryCast(bufferGraphic.Geometry, ESRI.ArcGIS.Client.Geometry.Polygon)
                For Each pointColl As ESRI.ArcGIS.Client.Geometry.PointCollection In myPoly.Rings
                    myComboPoly.Rings.Add(pointColl)
                Next
                bufferGraphic.Symbol = TryCast(LayoutRoot.Resources("BufferSymbol"), Symbol)
                bufferGraphic.SetZIndex(1)
                graphicsLayer.Graphics.Add(bufferGraphic)
            Next

            Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
            query.ReturnGeometry = True
            query.Geometry = myComboPoly
            query.OutSpatialReference = MyMap.SpatialReference
            query.OutFields.Add("SUE")
            query.OutFields.Add("LEGAL")
            _queryTask.ExecuteAsync(query)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

0 Kudos
by Anonymous User
Not applicable
Hi to all

The code below shows hows to combine the separate graphic geometries into one to be used in the query task. Amazing how the act of posting a message will prompt inspiration!!
There may be other ways but it is what I am doing for now.


Regards

Ralph Price
Application Developer and GIS Analyst



     
   Private Sub GeometryService_BufferCompleted(ByVal sender As Object, ByVal e As GraphicsEventArgs)
        Try
            Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyUserDrawnGraphicsLayer"), GraphicsLayer)
            graphicsLayer.Graphics.Clear()

            Dim comboBufferGraphic As New Graphic
            Dim myComboPoly As New ESRI.ArcGIS.Client.Geometry.Polygon

            For Each bufferGraphic As Graphic In e.Results
                comboBufferGraphic.Geometry = bufferGraphic.Geometry
                Dim myPoly As ESRI.ArcGIS.Client.Geometry.Polygon = TryCast(bufferGraphic.Geometry, ESRI.ArcGIS.Client.Geometry.Polygon)
                For Each pointColl As ESRI.ArcGIS.Client.Geometry.PointCollection In myPoly.Rings
                    myComboPoly.Rings.Add(pointColl)
                Next
                bufferGraphic.Symbol = TryCast(LayoutRoot.Resources("BufferSymbol"), Symbol)
                bufferGraphic.SetZIndex(1)
                graphicsLayer.Graphics.Add(bufferGraphic)
            Next

            Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
            query.ReturnGeometry = True
            query.Geometry = myComboPoly
            query.OutSpatialReference = MyMap.SpatialReference
            query.OutFields.Add("SUE")
            query.OutFields.Add("LEGAL")
            _queryTask.ExecuteAsync(query)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub




The BufferParameters class has a UnionResults property that will return the result as a single polygon:

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.Buff...
0 Kudos
RalphPrice
Emerging Contributor
Thanks Michael

Isn't always the way that once you post to a forum, you manage to find what you were looking for just after posting.

I did also discover that the first "buffer-select" that I did would work but a second "buffer-select" using the result of the first would error. The way to get that to work was to ensure that spatial references kept getting set for the output graphics. I can now have a single parcel selected, buffer that, select parcels that intersect that buffer, buffer those parcels, select again etc. This is for a mailing list generating tool for planning consents etc.

Thanks again for your assistance

Ralph Price
Application Developer and GIS Analyst
0 Kudos