Skip to content

Commit a7eae78

Browse files
Create buffers around points sample (#425)
Co-authored-by: Shubham Sharma <shubhamsharma@esri.com>
1 parent 1af4af5 commit a7eae78

File tree

9 files changed

+618
-0
lines changed

9 files changed

+618
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Create buffers around points
2+
3+
Generate multiple individual buffers or a single unioned buffer around multiple points.
4+
5+
![Image of create buffers around points](create-buffers-around-points.png)
6+
7+
## Use case
8+
9+
Creating buffers is a core concept in GIS proximity analysis that allows you to visualize and locate geographic features contained within a set distance of a feature. For example, consider an area where wind turbines are proposed. It has been determined that each turbine should be located at least 2 km away from residential premises due to noise pollution regulations, and a proximity analysis is therefore required. The first step would be to generate 2 km buffer polygons around all proposed turbines. As the buffer polygons may overlap for each turbine, unioning the result would produce a single graphic result with a neater visual output. If any premises are located within 2 km of a turbine, that turbine would be in breach of planning regulations.
10+
11+
## How to use the sample
12+
13+
Click/tap on the map to add points. Click the "Create Buffer(s)" button to draw buffer(s) around the points (the size of the buffer is determined by the value entered by the user). Check the check box if you want the result to union (combine) the buffers. Click the "Clear" button to start over. The red dashed envelope shows the area where you can expect reasonable results for planar buffer operations with the North Central Texas State Plane spatial reference.
14+
15+
## How it works
16+
17+
1. Use `GeometryEngine.bufferOrNull(point, radius)` to create a `Polygon` and `GeometryEngine.unionOrNull(polygons)` to union polygons. The parameter `points` are the points to buffer around, `distances` are the buffer distances for each point (in meters).
18+
2. Add the resulting polygons (if not unioned) or single polygon (if unioned) to the map's `GraphicsOverlay` as a `Graphic`.
19+
20+
## Relevant API
21+
22+
* Geometry
23+
* GeometryEngine.bufferOrNull
24+
* GeometryEngine.unionOrNull
25+
* SpatialReference
26+
27+
## Additional information
28+
29+
The properties of the underlying projection determine the accuracy of buffer polygons in a given area. Planar buffers work well when analyzing distances around features that are concentrated in a relatively small area in a projected coordinate system. Inaccurate buffers could still be created by buffering points inside the spatial reference's envelope with distances that move it outside the envelope. On the other hand, geodesic buffers consider the curved shape of the Earth's surface and provide more accurate buffer offsets for features that are more dispersed (i.e., cover multiple UTM zones, large regions, or even the whole globe). See the "Buffer" sample for an example of a geodesic buffer.
30+
31+
For more information about using buffer analysis, see the topic [How Buffer (Analysis) works](https://pro.arcgis.com/en/pro-app/tool-reference/analysis/how-buffer-analysis-works.htm) in the *ArcGIS Pro* documentation.
32+
33+
## Tags
34+
35+
analysis, buffer, geometry, planar
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"category": "Analysis",
3+
"description": "Generate multiple individual buffers or a single unioned buffer around multiple points.",
4+
"formal_name": "CreateBuffersAroundPoints",
5+
"ignore": false,
6+
"images": [
7+
"create-buffers-around-points.png"
8+
],
9+
"keywords": [
10+
"analysis",
11+
"buffer",
12+
"geometry",
13+
"planar",
14+
"Geometry",
15+
"GeometryEngine.bufferOrNull",
16+
"GeometryEngine.unionOrNull",
17+
"SpatialReference"
18+
],
19+
"language": "kotlin",
20+
"redirect_from": "",
21+
"relevant_apis": [
22+
"Geometry",
23+
"GeometryEngine.bufferOrNull",
24+
"GeometryEngine.unionOrNull",
25+
"SpatialReference"
26+
],
27+
"snippets": [
28+
"src/main/java/com/esri/arcgismaps/sample/createbuffersaroundpoints/components/CreateBuffersAroundPointsViewModel.kt",
29+
"src/main/java/com/esri/arcgismaps/sample/createbuffersaroundpoints/MainActivity.kt",
30+
"src/main/java/com/esri/arcgismaps/sample/createbuffersaroundpoints/screens/CreateBuffersAroundPointsScreen.kt"
31+
],
32+
"title": "Create buffers around points"
33+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
alias(libs.plugins.arcgismaps.android.library)
3+
alias(libs.plugins.arcgismaps.android.library.compose)
4+
alias(libs.plugins.arcgismaps.kotlin.sample)
5+
alias(libs.plugins.gradle.secrets)
6+
}
7+
8+
secrets {
9+
// this file doesn't contain secrets, it just provides defaults which can be committed into git.
10+
defaultPropertiesFileName = "secrets.defaults.properties"
11+
}
12+
13+
android {
14+
namespace = "com.esri.arcgismaps.sample.createbuffersaroundpoints"
15+
buildFeatures {
16+
buildConfig = true
17+
}
18+
}
19+
20+
dependencies {
21+
// Only module specific dependencies needed here
22+
}
1.11 MB
Loading
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
6+
<application><activity
7+
android:exported="true"
8+
android:name=".MainActivity"
9+
android:label="@string/create_buffers_around_points_app_name">
10+
11+
</activity>
12+
</application>
13+
14+
</manifest>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Copyright 2025 Esri
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
*/
16+
17+
package com.esri.arcgismaps.sample.createbuffersaroundpoints
18+
19+
import android.os.Bundle
20+
import androidx.activity.ComponentActivity
21+
import androidx.activity.compose.setContent
22+
import androidx.compose.material3.MaterialTheme
23+
import androidx.compose.material3.Surface
24+
import androidx.compose.runtime.Composable
25+
import com.arcgismaps.ApiKey
26+
import com.arcgismaps.ArcGISEnvironment
27+
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
28+
import com.esri.arcgismaps.sample.createbuffersaroundpoints.screens.CreateBuffersAroundPointsScreen
29+
30+
class MainActivity : ComponentActivity() {
31+
32+
override fun onCreate(savedInstanceState: Bundle?) {
33+
super.onCreate(savedInstanceState)
34+
// authentication with an API key or named user is
35+
// required to access basemaps and other location services
36+
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
37+
38+
setContent {
39+
SampleAppTheme {
40+
CreateBuffersAroundPointsApp()
41+
}
42+
}
43+
}
44+
45+
@Composable
46+
private fun CreateBuffersAroundPointsApp() {
47+
Surface(color = MaterialTheme.colorScheme.background) {
48+
CreateBuffersAroundPointsScreen(
49+
sampleName = getString(R.string.create_buffers_around_points_app_name)
50+
)
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)