Select to view content in your preferred language

Buffer Distance

4044
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
JayKappy
Frequent Contributor
......................................
0 Kudos
JayKappy
Frequent Contributor
Jenniferdnery's example early on is what I am going on...

For Each g As var In MyGraphicsLayer.Graphics
 Dim c As MapPoint = g.Geometry.Extent.GetCenter()
 g.Attribute("BUFFER_DISTANCE") = GetDistance(bufferPoint, c)
Next


I converted this to the selectedGraphic

selectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(bp, c)


I was having issues with getting both values (buffer point, and the feature point) in the same location to calculate the distance. I was able to do that below by creating a global varaible and setting that and then retrieveing that in the second sub...

BUT again my problem still lies on this: Where "GetDistance" is not declared...Is this beign done under teh wrong parameters? (QueryEventArgs)

Hopign that soemone has some thoughts....Guess this is not going to work....keeps telling me that the variable that I am setting: Value type Strign cannot be converted to MapPoint

selectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(_XYLocationBuffer, c)




    Private _XYLocation As String = ""




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

        _pointAndBufferGraphicsLayer.Graphics.Add(bufferGraphic)

       ' Find the Center point of the buffer       
          Dim bp As ESRI.ArcGIS.Client.Geometry.MapPoint = bufferGraphic.Geometry.Extent.GetCenter()
 ' Set the Buffer Variable for the Center Point of the buffer       
        _XYLocation = Nothing
        _XYLocation = bp.ToString

        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

        ' Set the Buffer Variable for the Center Point of the buffer        
         Dim _XYLocationBuffer As String = Nothing
        _XYLocationBuffer = _XYLocation.ToString


        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()
            MessageBox.Show(c.ToString)
            selectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(_XYLocationBuffer, c)

        Next selectedGraphic

    End Sub





Also tryign this example: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/util_distance....

            Dim distParams = New ESRI.tasks.DistanceParameters()
            distParams.distanceUnit = ESRI.tasks.GeometryService.UNIT_STATUTE_MILE
            distParams.geometry1 = pointA  '<--- your Point A geometry
            distParams.geometry2 = pointB  '<--- your Point B geometry
            distParams.geodesic = True

            GeometryService.distance(distParams,function(distance))
0 Kudos
JayKappy
Frequent Contributor
I am now getting is results back, right now I dont care if the value is not correct distance or not...

The MessageBox below shows a value...but for some reason I cant Bind the value to the Listbox...
The BUFFER_DISTANCE is not a field or anything....It does not exist...I am just trying to create this temporarly to hold the distance value....
Can I do this....Does this make sence....
Any thoughts on why the value is not reflecting in the Listbox?
The other two attributes show up fine...


    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()
            MessageBox.Show(c.ToString)

            selectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(_XYLocationBuffer, c)

            MessageBox.Show(selectedGraphic.Attributes("BUFFER_DISTANCE"))

        Next selectedGraphic


<ListBox.ItemTemplate>
   <DataTemplate>
       <StackPanel Orientation="Horizontal" VerticalAlignment="Center" >
           <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[NAME], StringFormat='Name:    \{0\}'}" />
                  <TextBlock Foreground="White" Text="{Binding BUFFER_DISTANCE, StringFormat='Distance: \{0\}'}" />
            </StackPanel>
         </StackPanel>
      </DataTemplate>
   </ListBox.ItemTemplate>
</ListBox>
0 Kudos
JayKappy
Frequent Contributor
Got it...think to syntax I was using was incorrect.....

Not Working:
<TextBlock Foreground="White" Text="{Binding BUFFER_DISTANCE, StringFormat='Distance: \{0\}'}" >


Working
<TextBlock Foreground="White" Text="{Binding Attributes[BUFFER_DISTANCE], StringFormat='Distance: \{0\}'}" >


ANYONE INTERESTED IN WHAT I DID OR WANT THE CODE PLEASE FEEL FREE TO CONTACT ME.

THANK YOU ALL FOR YOUR HELP.......SORRY FOR THE BARAGE OF QUESTIONS....KNOW THAT THIS IS NOT A FORUM FOR EVERYONE WRITE CODE FOR ANOTHER PERSON....BUT I DO APPRECIATE ALL YOUR THOUGHTS AND COMMENTS.....

Outline of what I did if anyone is interested...

User Input Box for Parcel
Finds Parcel and highlights it, zooms to it, populates list box with Parcel Info
In the mean time it Does a Buffer on the Parcels geomoetry
Finds features (users choosing) that are within that buffer and creates graphics on the map
The values from these found features in the buffer are also displayed in a listbox with their Attrbiutes and the DISTANCE FROM THE BUFFER CENTER.

The VERY last part of the explination above is what this entry was for....To simply calculate the DISTANCE from the center of the BUFFER.
0 Kudos
RobChouinard
Frequent Contributor
I have a similar issue where I want to get distance from a point to multiple points. Where did you find the GetDistance() method listed on your posts? I'm thinking this method isn't built into the API. Did you have to use the GeometryService for each point you wanted to get the distance to?

Thanks,
Rob
0 Kudos
JenniferNery
Esri Regular Contributor
GetDistance() in this post is not yet implemented.
        private double GetDistance(MapPoint a, MapPoint b)
        {
            if (a == null || b == null) return 0;
            return Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2));
        }
0 Kudos
JayKappy
Frequent Contributor
I have a similar issue where I want to get distance from a point to multiple points. Where did you find the GetDistance() method listed on your posts? I'm thinking this method isn't built into the API. Did you have to use the GeometryService for each point you wanted to get the distance to?

Thanks,
Rob


This is what I used:

Not you can change and return from Double to Integer on the Function (  As Integer,   As Double)

    Private Function GetDistance(ByVal start As MapPoint, ByVal [end] As MapPoint) As Integer
        Dim deltaX As Double = 0
        Dim deltaY As Double = 0

        deltaX = start.X - [end].X
        deltaY = start.Y - [end].Y

        Return Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY))

    End Function


Yes on the Geometry service.....I can give you my code...but here is what I did...

I do a search
it finds a parcel (polygon)
Zooms to that parcel.
Creates a Buffer graphic based ont he geomoetry of that Parcel (set the buffer point to global variable, very important)
Queries for the points that fall in that buffer
in a for each loop passes the location and buffer center point to the function which calculates distance
Finally bind the results to a listbox.

If you want help...contact me....jaykappy@yahoo.com
0 Kudos
RobChouinard
Frequent Contributor
Thanks, I used the C# code that jenniferdnery posted. I didn't realize it would be that simple 🙂
0 Kudos