Select to view content in your preferred language

Value accumulation with buffers (using Flex)

809
3
05-13-2013 01:11 AM
KarlBarker-Ottley
Emerging Contributor
Hi,

I have a table of values associated with geographic positions. What I'm trying to do is use the result of an address search as the centre point of a few buffers (50 metres, 100 metres and 250 metres) and sum up the values of the geographic positions that fall within the respective buffers.

I am scripting this in Flex. Any help here is greatly appreciated.
(I'm using FlexAPI 3.2 & ArcGIS 10.1)

Thanks,
Karl
Tags (2)
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus
Karl,

   It is a pretty straight forward work flow you does the addressToLocations method on the locateTask and take the map points from the result and then send them to a buffering operation on the Geometry Server then use the polygons from the buffers as the geometry for a QueryTask on the features you are looking for inside the buffers.

Addrress Result Snippet:

                function onResult(candidates:Array, token:Object=null):void
                {
                    var addressCandidate:AddressCandidate;
                    for (var i:int=0; i < candidates.length; i++)
                    {
                        addressCandidate=candidates;
                        if (addressCandidate.score > 80)
                        {
                            var pGeom:Geometry=addressCandidate.location;
                            pGeom.spatialReference=map.spatialReference;
                            var pArray:Array=[addressCandidate.location, addressCandidate.address, addressCandidate.score];
                            tpoints.push(pArray);
                        }
                    }
                    if (tpoints.length > 0)
                    {
                        qDistrict(); //Your buffering function
                    }


A Buffering Function Snippet:

            private function bufferGeometries(geomArr:Array, sr:SpatialReference, dist:Array, unit:Number):void
            {
                if (geomArr)
                {
                    showMessage("Buffering...",true);
                    var bufferParameters:BufferParameters = new BufferParameters();
                    var resultEvent:Polygon = new Polygon;
                    bufferParameters.geometries = geomArr;
                    bufferParameters.bufferSpatialReference = sr;
                    bufferParameters.unit = unit;
                    bufferParameters.distances = dist;
                    bufferParameters.unionResults = dischk.selected;
                    bufferParameters.outSpatialReference = map.spatialReference;
                    geometryService.buffer(bufferParameters,new AsyncResponder(bufferCompleteHandler,bufferFault));
                    
                    function bufferCompleteHandler(event:Array, token:Object):void
                    {
                        for each(resultEvent in event)
                        {
                            try
                            {
                                var graphic:Graphic = new Graphic();
                                graphic.geometry = resultEvent;
                                graphic.symbol = sfs;
                                var attribs:Object =
                                {
                                    distance: textInputBuffer.text,
                                    unit: configBufferUnits[cboBufferUnit.selectedIndex].name
                                }
                                graphic.attributes = attribs;
                                graphicsLayerBuffer.add(graphic);
                                clearMessage();
                            }
                            catch (error:Error)
                            {
                                showMessage(error.message, false, true);
                            }
                        }                        
                    }
                    
                    function bufferFault(event:Fault, token:Object):void
                    {
                        showMessage(event.message, false, true);
                    }
                }
            }
0 Kudos
KarlBarker-Ottley
Emerging Contributor
Hi Robert,

Thanks for providing guidance with this issue - I'm still fairly new to Flex, so am still a little unclear on utilising and implementing your buffering snippet.

My address search is based on the code from the ESRI Flex Samples (http://resources.arcgis.com/en/help/flex-api/samples/index.html#/Geocode_an_address/01nq000000680000...). Are you able / willing to offer a sample of some mxml that defines the various properties (eg. configBufferUnits, cboBufferUnit etc)?

Appreciate any help you can offer here, and apologies for missing anything obvious!

Thanks,
Karl
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Karl,

   I don't do very much coding in MXML as this actually get turned into Action Script when you compile anyway. But the two arryas you are speaking of are just things that were specific to my implementation of the function and can easily be hard coded to the distance unit you will be using:

unit: configBufferUnits[cboBufferUnit.selectedIndex].name
change to:
unit: "Miles"
0 Kudos