Densify and generalize

View inAndroidFormsUWPWPFWinUIiOSView on GitHub

A multipart geometry can be densified by adding interpolated points at regular intervals. Generalizing multipart geometry simplifies it while preserving its general shape. Densifying a multipart geometry adds more vertices at regular intervals.

Image of densify and generalize

Use case

The sample shows a polyline representing a ship's location at irregular intervals. The density of vertices along the ship's route is appropriate to represent the path of the ship at the sample map view's initial scale. However, that level of detail may be too great if you wanted to show a polyline of the ship's movement down the whole of the Willamette river. Then, you might consider generalizing the polyline to still faithfully represent the ship's passage on the river without having an overly complicated geometry.

Densifying a multipart geometry can be used to more accurately represent curved lines or to add more regularity to the vertices making up a multipart geometry.

How to use the sample

Use the sliders to control the parameters of the densify and generalize methods.

How it works

  1. Use the static method GeometryEngine.Densify(polyline, maxSegmentLength) to densify the polyline object. The resulting polyline object will have more points along the line, so that there are no points greater than maxSegmentLength from the next point.
  2. Use the static method GeometryEngine.Generalize(polyline, maxDeviation, true) to generalize the polyline object. The resulting polyline object will have points shifted from the original line to simplify the shape. None of these points can deviate farther from the original line than maxDeviation. The last parameter, removeDegenerateParts, will clean up extraneous parts of a multipart geometry. This will have no effect in this sample as the polyline does not contain extraneous parts.
  3. Note that maxSegmentLength and maxDeviation are in the units of the geometry's coordinate system. In this example, a cartesian coordinate system is used and at a small enough scale that geodesic distances are not required.

Relevant API

  • GeometryEngine
  • Multipoint
  • Point
  • PointCollection
  • Polyline
  • SimpleLineSymbol
  • SpatialReference

Tags

data, densify, generalize, simplify

Sample Code

DensifyAndGeneralize.xamlDensifyAndGeneralize.xamlDensifyAndGeneralize.xaml.cs
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
<UserControl x:Class="ArcGISRuntime.WinUI.Samples.DensifyAndGeneralize.DensifyAndGeneralize"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <Grid>
        <esriUI:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0"
                           FontWeight="SemiBold"
                           Text="Adjust the sliders to see the resulting generalized or densified polyline."
                           TextWrapping="Wrap" />
                <TextBlock Grid.Row="1"
                           FontWeight="Bold"
                           Text="Max. Deviation (Generalize)" />
                <Slider x:Name="DeviationSlider"
                        Grid.Row="2"
                        Margin="5"
                        Maximum="250"
                        Minimum="1"
                        Value="10" />
                <TextBlock Grid.Row="3"
                           FontWeight="Bold"
                           Text="Max. Segment length (Densify)" />
                <Slider x:Name="SegmentLengthSlider"
                        Grid.Row="4"
                        Margin="5"
                        Maximum="500"
                        Minimum="100"
                        Value="100" />
                <TextBlock x:Name="ResultLabel"
                           Grid.Row="5"
                           FontWeight="SemiBold"
                           Foreground="RoyalBlue"
                           Text="Adjust a slider to start"
                           TextWrapping="Wrap" />
            </Grid>
        </Border>
    </Grid>
</UserControl>

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