Create planar and geodetic buffers

View on GitHub

Create a buffer around a map point and display the results as a graphic.

Image of create planar and geodetic buffers

Use case

Creating buffers is a core concept in GIS proximity analysis that allows you to visualize and locate geographic features contained within a polygon. For example, suppose you wanted to visualize areas of your city where alcohol sales are prohibited because they are within 500 meters of a school. The first step in this proximity analysis would be to generate 500 meter buffer polygons around all schools in the city. Any such businesses you find inside one of the resulting polygons are violating the law.

How to use the sample

  1. Tap on the map.
  2. A planar and a geodetic buffer will be created at the tap location using the distance (miles) specified.
  3. Continue tapping to create additional buffers. Notice that buffers closer to the equator appear similar in size. As you move north or south from the equator, however, the geodetic polygons become much larger. Geodetic polygons are in fact a better representation of the true shape and size of the buffer.
  4. Tap Clear to remove all buffers and start again.

How it works

  1. The map ArcGISPoint for a tap on the display is captured.
  2. The static method GeometryEngine.buffer is called to create a planar buffer polygon from the map location and distance.
  3. Another static method, GeometryEngine.bufferGeodetic, is called to create a geodetic buffer polygon using the same inputs.
  4. The polygon results (and tap location) are displayed in the map view with different symbols in order to highlight the difference between the buffer techniques due to the spatial reference used in the planar calculation.

Relevant API

  • GeometryEngine.buffer
  • GeometryEngine.bufferGeodetic
  • GraphicsOverlay

Additional information

Buffers can be generated as either planar (flat - coordinate space of the map's spatial reference) or geodetic (technique that considers the curved shape of the Earth's surface, which is generally a more accurate representation). In general, distortion in the map increases as you move away from the standard parallels of the spatial reference's projection. This map is in Web Mercator so areas near the equator are the most accurate. As you move the buffer location north or south from that line, you'll see a greater difference in the polygon size and shape. Planar operations are generally faster, but performance improvement may only be noticeable for large operations (buffering a great number or complex geometry).

For more information about using buffer analysis, see the topic How Buffer (Analysis) works in the ArcGIS Pro documentation.

Tags

analysis, buffer, euclidean, geodetic, geometry, planar

Sample Code

create_planar_and_geodetic_buffers.dart
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
//
// Copyright 2024 Esri
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import 'dart:math';
import 'package:arcgis_maps/arcgis_maps.dart';
import 'package:flutter/material.dart';

import '../../utils/sample_state_support.dart';

class CreatePlanarAndGeodeticBuffers extends StatefulWidget {
  const CreatePlanarAndGeodeticBuffers({super.key});

  @override
  State<CreatePlanarAndGeodeticBuffers> createState() =>
      _CreatePlanarAndGeodeticBuffersState();
}

class _CreatePlanarAndGeodeticBuffersState
    extends State<CreatePlanarAndGeodeticBuffers> with SampleStateSupport {
  // Create a controller for the map view.
  final _mapViewController = ArcGISMapView.createController();
  // The graphics overlay for the geodetic buffers.
  final _geodeticOverlay = GraphicsOverlay();
  // The graphics overlay for the planar buffers.
  final _planarOverlay = GraphicsOverlay();
  // The graphics overlay for the tapped points.
  final _pointOverlay = GraphicsOverlay();
  // A flag for when the map view is ready and controls can be used.
  var _ready = false;
  // A flag for when the settings bottom sheet is visible.
  var _settingsVisible = false;
  // The buffer radius in miles.
  var _bufferRadius = 500.0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        top: false,
        child: Stack(
          children: [
            Column(
              children: [
                Expanded(
                  // Add a map view to the widget tree and set a controller.
                  child: ArcGISMapView(
                    controllerProvider: () => _mapViewController,
                    onMapViewReady: onMapViewReady,
                    onTap: onTap,
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    // A button to show the Settings bottom sheet.
                    ElevatedButton(
                      onPressed: () => setState(() => _settingsVisible = true),
                      child: const Text('Settings'),
                    ),
                    // A button to clear the buffers.
                    ElevatedButton(
                      onPressed: clear,
                      child: const Text('Clear'),
                    ),
                  ],
                ),
              ],
            ),
            // Display a progress indicator and prevent interaction until state is ready.
            Visibility(
              visible: !_ready,
              child: SizedBox.expand(
                child: Container(
                  color: Colors.white30,
                  child: const Center(child: CircularProgressIndicator()),
                ),
              ),
            ),
          ],
        ),
      ),
      // The Settings bottom sheet.
      bottomSheet: _settingsVisible ? buildSettings(context) : null,
    );
  }

  // The build method for the Settings bottom sheet.
  Widget buildSettings(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(
        20.0,
        20.0,
        20.0,
        max(
          20.0,
          View.of(context).viewPadding.bottom /
              View.of(context).devicePixelRatio,
        ),
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Row(
            children: [
              Text(
                'Settings',
                style: Theme.of(context).textTheme.titleLarge,
              ),
              const Spacer(),
              IconButton(
                icon: const Icon(Icons.close),
                onPressed: () => setState(() => _settingsVisible = false),
              ),
            ],
          ),
          Row(
            children: [
              const Text('Buffer Radius (miles)'),
              const Spacer(),
              Text(
                _bufferRadius.round().toString(),
                textAlign: TextAlign.right,
              ),
            ],
          ),
          Row(
            children: [
              Expanded(
                // A slider to adjust the buffer radius.
                child: Slider(
                  value: _bufferRadius,
                  min: 200.0,
                  max: 2000.0,
                  onChanged: (value) => setState(() => _bufferRadius = value),
                ),
              ),
            ],
          ),
          Row(
            children: [
              SizedBox(
                width: 30.0,
                height: 30.0,
                child: Container(
                  decoration: const BoxDecoration(
                    shape: BoxShape.circle,
                    color: Colors.green,
                  ),
                  child: Container(
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      border: Border.all(color: Colors.black, width: 2.0),
                      color: Colors.red.withAlpha(127),
                    ),
                  ),
                ),
              ),
              const SizedBox(width: 10.0),
              const Text('Planar Buffer'),
            ],
          ),
          const SizedBox(height: 10.0),
          Row(
            children: [
              SizedBox(
                width: 30.0,
                height: 30.0,
                child: Container(
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    border: Border.all(color: Colors.black, width: 2.0),
                    color: Colors.green,
                  ),
                ),
              ),
              const SizedBox(width: 10.0),
              const Text('Geodetic Buffer'),
            ],
          ),
        ],
      ),
    );
  }

  void onMapViewReady() {
    // Configure the graphics overlay for the geodetic buffers.
    _geodeticOverlay.renderer = SimpleRenderer(
      symbol: SimpleFillSymbol(
        style: SimpleFillSymbolStyle.solid,
        color: Colors.green,
        outline: SimpleLineSymbol(
          style: SimpleLineSymbolStyle.solid,
          color: Colors.black,
          width: 2.0,
        ),
      ),
    );
    _geodeticOverlay.opacity = 0.5;

    // Configure the graphics overlay for the planar buffers.
    _planarOverlay.renderer = SimpleRenderer(
      symbol: SimpleFillSymbol(
        style: SimpleFillSymbolStyle.solid,
        color: Colors.red,
        outline: SimpleLineSymbol(
          style: SimpleLineSymbolStyle.solid,
          color: Colors.black,
          width: 2.0,
        ),
      ),
    );
    _planarOverlay.opacity = 0.5;

    // Configure the graphics overlay for the tapped points.
    _pointOverlay.renderer = SimpleRenderer(
      symbol: SimpleMarkerSymbol(
        style: SimpleMarkerSymbolStyle.cross,
        color: Colors.white,
        size: 14.0,
      ),
    );

    // Add the overlays to the map view.
    _mapViewController.graphicsOverlays.addAll(
      [
        _geodeticOverlay,
        _planarOverlay,
        _pointOverlay,
      ],
    );

    // Create a map with the topographic basemap style and set to the map view.
    final map = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISTopographic);
    _mapViewController.arcGISMap = map;

    // Set the ready state variable to true to enable the sample UI.
    setState(() => _ready = true);
  }

  void onTap(Offset screenPoint) {
    // Capture the tapped point and convert it to a map point.
    final mapPoint = _mapViewController.screenToLocation(screen: screenPoint);
    if (mapPoint == null) return;

    // Create a geodetic buffer around the tapped point at the specified distance.
    final geodeticGeometry = GeometryEngine.bufferGeodetic(
      geometry: mapPoint,
      distance: _bufferRadius,
      distanceUnit: LinearUnit(unitId: LinearUnitId.miles),
      maxDeviation: double.nan,
      curveType: GeodeticCurveType.geodesic,
    );
    // Create and add a graphic to the geodetic overlay.
    final geodeticGraphic = Graphic(geometry: geodeticGeometry);
    _geodeticOverlay.graphics.add(geodeticGraphic);

    // Create a planar buffer around the tapped point at the specified distance.
    final planarGeometry = GeometryEngine.buffer(
      geometry: mapPoint,
      distance: _bufferRadius * 1609.344, // Convert miles to meters.
    );
    // Create and add a graphic to the planar overlay.
    final planarGraphic = Graphic(geometry: planarGeometry);
    _planarOverlay.graphics.add(planarGraphic);

    // Create and add a graphic to the point overlay.
    final pointGraphic = Graphic(geometry: mapPoint);
    _pointOverlay.graphics.add(pointGraphic);
  }

  // Clear the graphics overlays.
  void clear() {
    _geodeticOverlay.graphics.clear();
    _planarOverlay.graphics.clear();
    _pointOverlay.graphics.clear();
  }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.