Densify and generalize

View inWPFUWPFormsiOSAndroid
View 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.xaml.cs
                                            
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
<?xml version="1.0" encoding="utf-8"?>

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             xmlns:sampleViewer="clr-namespace:Forms.Resources;assembly=ArcGISRuntime"
             x:Class="ArcGISRuntime.Samples.DensifyAndGeneralize.DensifyAndGeneralize">
    <RelativeLayout>
        <esriUI:MapView x:Name="MyMapView" Style="{StaticResource MapWithFormStyle}"
                        BindingContext="{x:Reference Name=ResponsiveFormContainer}" />
        <sampleViewer:ResponsiveFormContainer x:Name="ResponsiveFormContainer">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="{StaticResource DefaultGridRowHeight}" />
                    <RowDefinition Height="{StaticResource DefaultGridRowHeight}" />
                    <RowDefinition Height="{StaticResource DefaultGridRowHeight}" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Label Text="Generalize"
                       Grid.Row="0" Grid.Column="0"
                       Style="{StaticResource LabelStyle}" HorizontalTextAlignment="End" />
                <Slider x:Name="DeviationSlider"
                        Grid.Row="0" Grid.Column="1"
                        MaximumTrackColor="CadetBlue"
                        MinimumTrackColor="CadetBlue"
                        Maximum="250" Minimum="1" Value="1" />
                <Label Text="Densify"
                       Grid.Row="1" Grid.Column="0"
                       Style="{StaticResource LabelStyle}" HorizontalTextAlignment="End" />
                <Slider x:Name="SegmentLengthSlider"
                        Grid.Row="1" Grid.Column="1"
                        MaximumTrackColor="CadetBlue"
                        MinimumTrackColor="CadetBlue"
                        Maximum="500" Minimum="100" Value="100" />
                <Label x:Name="ResultLabel" Text="Adjust a slider to start."
                       Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
                       Style="{StaticResource LabelStyle}" />
            </Grid>
        </sampleViewer:ResponsiveFormContainer>
    </RelativeLayout>
</ContentPage>

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