Select to view content in your preferred language

Buffer Distance

4036
17
01-25-2011 09:22 AM
JayKappy
Frequent Contributor
I have a buffer working off of a Query.
A query runs finding a Parcel
That selected feature then is used to run a buffer that selects another set of Feature within that buffer
It then returns them to a listbox

NOTE: everything works great...Just trying to figure out how if I can retrieve the distance each feature is to the buffer centerpoint.

How do I return the Buffer distance for each feature and put the distance in the listbox.
Is there something that I can do in the xaml below, or do I have to get the value in the vb code first?
Once that is gotten can I sort the values in the listbox Ascending via this buffer distance?

<TextBlock Foreground="White" Margin="0,4,0,0" VerticalAlignment="Center" Text="{Binding BUFFER_DISTANCE}" SORT="ASCENDING"  />

Is this even possible with the Buffer? I assume that its measuring the distance in order to determine if its inside the Buffer specified distance.....

Thanks

<ListBox.ItemTemplate>
     <DataTemplate>
           <StackPanel Orientation="Horizontal" VerticalAlignment="Center" >
                    <!-- QUERY -->
                    <StackPanel Margin="1">
                            <TextBlock Foreground="White" Margin="0,4,0,0" VerticalAlignment="Center" Text="{Binding Attributes[TYPE]}"/>
                     </StackPanel>
                     <StackPanel Margin="5,0,0,0" Orientation="Vertical">
                             <TextBlock Foreground="White" Text="{Binding Attributes[CITY_NAME], StringFormat='City Name: \{0\}'}" >
                                      <TextBlock.Effect>
                                              <DropShadowEffect/>
                                      </TextBlock.Effect>
                             </TextBlock>
                             <TextBlock Foreground="White" Text="{Binding Attributes[POP1990], StringFormat='Population: \{0\}'}"  >
                                      <TextBlock.Effect>
                                              <DropShadowEffect/>
                                      </TextBlock.Effect>
                             </TextBlock>
                        </StackPanel>
                    </StackPanel>
              </DataTemplate>
       </ListBox.ItemTemplate>
</ListBox>
0 Kudos
17 Replies
JenniferNery
Esri Regular Contributor
This Text="{Binding BUFFER_DISTANCE}"  will work if you add graphic Attribute with Key 'BUFFER_DISTANCE.' Yes, this need to be added in code-behind.

You can iterate through the graphics in your GraphicsLayer and calculate the Eucledian distance between buffer point and graphic.Geometry.Extent.GetCenter() and store into the graphic Attribute.
For Each g As var In MyGraphicsLayer.Graphics
 Dim c As MapPoint = g.Geometry.Extent.GetCenter()
 g.Attribute("BUFFER_DISTANCE") = GetDistance(bufferPoint, c)
Next


There is no Sort property on TextBox. If you wish to sort the ListBox contents against this Attribute, you can sort using Linq before setting ItemSource or use CollectionViewSource.
0 Kudos
JayKappy
Frequent Contributor
What you are saying makes sense.....I think my application is a bit different...

The user clicks a button that does a search on a value from a textblock.
The Parcel is located adn zoomed to
A buffer is created from that found parcel geometry
The buffer then selects the points within that buffer and returns the results to a listbox.

I am not seeing the location to place the code to calculate the Buffer Distance


            ' DRAW THE BUFFER AND USE THE PARCEL TO CREATE THE INITIAL POINT OF THE BUFFER
            _geometryService = New GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer")
            AddHandler _geometryService.BufferCompleted, AddressOf GeometryService_BufferCompleted2
            AddHandler _geometryService.Failed, AddressOf GeometryService_Failed2

            _queryTask = New QueryTask("http://gis.logis.org/arcgis/rest/services/MG_Test_WGS84/MapServer/1")
            AddHandler _queryTask.ExecuteCompleted, AddressOf QueryTask_ExecuteCompletedBuffer2
            AddHandler _queryTask.Failed, AddressOf QueryTask_Failed2



It seems I would put it here:
For Each selectedGraphic As Graphic In args.FeatureSet.Features
selectedGraphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
_resultsGraphicsLayer.Graphics.Add(selectedGraphic)
Next selectedGraphic

But then I get confused because I am binding the imagelistbuffer (listbox) here
imageListBuffer.ItemsSource = args.FeatureSet.Features

    Private Sub GeometryService_BufferCompleted2(ByVal sender As Object, ByVal args As GraphicsEventArgs)
        Dim bufferGraphic As New Graphic()
        bufferGraphic.Geometry = args.Results(0).Geometry
        bufferGraphic.Symbol = TryCast(LayoutRoot.Resources("BufferSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
        bufferGraphic.SetZIndex(1)

        _pointAndBufferGraphicsLayer.Graphics.Add(bufferGraphic)

        Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
        query.ReturnGeometry = True
        query.OutSpatialReference = MyMap.SpatialReference
        query.Geometry = bufferGraphic.Geometry
        query.OutFields.Add("*")
        _queryTask.ExecuteAsync(query)
    End Sub


    Private Sub QueryTask_ExecuteCompletedBuffer2(ByVal sender As Object, ByVal args As QueryEventArgs)

         ' Bind the results to the listbox
        Dim featureSet As FeatureSet = args.FeatureSet
        imageListBuffer.ItemsSource = args.FeatureSet.Features

        If args.FeatureSet.Features.Count < 1 Then
            MessageBox.Show("No features found")
            Return
        End If
        For Each selectedGraphic As Graphic In args.FeatureSet.Features
            selectedGraphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
            _resultsGraphicsLayer.Graphics.Add(selectedGraphic)
        Next selectedGraphic
    End Sub
0 Kudos
JayKappy
Frequent Contributor
I tried this but nothing going on the: GetDistance(bufferPoint,c)

    Private Sub QueryTask_ExecuteCompletedBuffer2(ByVal sender As Object, ByVal args As QueryEventArgs)

        Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayerBufferResults"), GraphicsLayer)

        For Each g As Graphic In graphicsLayer.Graphics
            Dim c As MapPoint = g.Geometry.Extent.GetCenter()
            g.Attributes("BUFFER_DISTANCE") = GetDistance(bufferPoint, c)
        Next

        Dim featureSet As FeatureSet = args.FeatureSet
        imageListBuffer.ItemsSource = args.FeatureSet.Features

        If args.FeatureSet.Features.Count < 1 Then
            MessageBox.Show("No features found")
            Return
        End If
        For Each selectedGraphic As Graphic In args.FeatureSet.Features
            selectedGraphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
            _resultsGraphicsLayer.Graphics.Add(selectedGraphic)

        Next selectedGraphic

    End Sub
0 Kudos
dotMorten_esri
Esri Notable Contributor
Isn't it the args.FeatureSet.Features that you want to add the attribute to, and not the graphics layer? (since this is what you bind to the listbox).
0 Kudos
JayKappy
Frequent Contributor
I tried this as well just didnt put it in the forum...
I am having a problem I think because the params on the Sub are args As QueryEvent and geometry is not a member of ESRI Tasks.QueryEventArgs
So I cant see how to get teh geometry from the center of each feature

Do I need to do this in a different method or change the Sub Params?
This the only sub tht I can think of placing this data as this is where i am binding the results to the listbox..

    Private Sub QueryTask_ExecuteCompletedBuffer2(ByVal sender As Object, ByVal args As QueryEventArgs)
        Dim featureSet As FeatureSet = args.FeatureSet
        imageListBuffer.ItemsSource = args.FeatureSet.Features

        If args.FeatureSet.Features.Count < 1 Then
            MessageBox.Show("No features found")
            Return
        End If
        For Each selectedGraphic As Graphic In args.FeatureSet.Features
            selectedGraphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
            _resultsGraphicsLayer.Graphics.Add(selectedGraphic)

            Dim c As MapPoint = args.Geometry.Extent.GetCenter()
            args.Attributes("BUFFER_DISTANCE") = GetDistance(bufferPoint, c)

        Next selectedGraphic



Then tried this: But the GetDistance errors out saying that GetDistance and bufferPoint are not declared...

        For Each selectedGraphic As Graphic In args.FeatureSet.Features
            selectedGraphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
            _resultsGraphicsLayer.Graphics.Add(selectedGraphic)

            Dim c As MapPoint = selectedGraphic.Geometry.Extent.GetCenter()
            selectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(bufferPoint, c)

        Next selectedGraphic



.I cannot see the solution here..anyone? THanks

uggggggggggggggggggggg
0 Kudos
JayKappy
Frequent Contributor
Am I wasting my time by doing this here in the ... if I am even tryign this in the righ location....or even trying to do it correctly

    Private Sub QueryTask_ExecuteCompletedBuffer2(ByVal sender As Object, ByVal args As QueryEventArgs)

It seems that GetDistance is not an option
0 Kudos
JayKappy
Frequent Contributor
I tried this as well....adding
ESRI.ArcGIS.Client.Geometry.MapPoint

instead of just MapPoint...keeps telling me that GetDistance and bufferPoint not defined.

    Private Sub QueryTask_ExecuteCompletedBuffer2(ByVal sender As Object, ByVal args As QueryEventArgs)

        Dim featureSet As FeatureSet = args.FeatureSet
        imageListBuffer.ItemsSource = args.FeatureSet.Features

        If args.FeatureSet.Features.Count < 1 Then
            MessageBox.Show("No features found")
            Return
        End If
        For Each selectedGraphic As Graphic In args.FeatureSet.Features
            selectedGraphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
            _resultsGraphicsLayer.Graphics.Add(selectedGraphic)

            Dim c As ESRI.ArcGIS.Client.Geometry.MapPoint = selectedGraphic.Geometry.Extent.GetCenter()
            selectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(bufferPoint, c)
        Next selectedGraphic

    End Sub


Is GetDistance supposed to be a function that I am passing 'c' to in order find the distance?
Seems the way I have things set up it cant find the Buffer Point???? only the c (the parcel center point) is defined.
The center point of the buffer was defined in an ealier sub routine...
0 Kudos
JayKappy
Frequent Contributor
I take it I hit my question limit....wish I had another location to ask questions....I know that I am close here...thanks anyway...although still open for help
0 Kudos
JayKappy
Frequent Contributor
Io think that I can get the Buffer Graphics center like this: See RED below, BUT its not in the correct Sub Routine...
I need to get that center location to the Private Sub QueryTask_ExecuteCompletedBuffer2 in order to calculate the Distance from the Buffer center to the features found inside the buffer.


    Private Sub GeometryService_BufferCompleted2(ByVal sender As Object, ByVal args As GraphicsEventArgs)
        Dim bufferGraphic As New Graphic()
        bufferGraphic.Geometry = args.Results(0).Geometry
        bufferGraphic.Symbol = TryCast(LayoutRoot.Resources("BufferSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
        bufferGraphic.SetZIndex(1)

        _pointAndBufferGraphicsLayer.Graphics.Add(bufferGraphic)

        Dim bp As ESRI.ArcGIS.Client.Geometry.MapPoint = bufferGraphic.Geometry.Extent.GetCenter()        

        Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
        query.ReturnGeometry = True
        query.OutSpatialReference = MyMap.SpatialReference
        query.Geometry = bufferGraphic.Geometry
        query.OutFields.Add("*")
        _queryTask.ExecuteAsync(query)
    End Sub

    Private Sub QueryTask_ExecuteCompletedBuffer2(ByVal sender As Object, ByVal args As QueryEventArgs)

        Dim featureSet As FeatureSet = args.FeatureSet
        imageListBuffer.ItemsSource = args.FeatureSet.Features

        If args.FeatureSet.Features.Count < 1 Then
            MessageBox.Show("No features found")
            Return
        End If
        For Each selectedGraphic As Graphic In args.FeatureSet.Features
            selectedGraphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
            _resultsGraphicsLayer.Graphics.Add(selectedGraphic)

            Dim c As ESRI.ArcGIS.Client.Geometry.MapPoint = selectedGraphic.Geometry.Extent.GetCenter()
            selectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(bp, c)

        Next selectedGraphic

    End Sub
0 Kudos