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.
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
- 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 thanmaxSegmentLength
from the next point. - 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 thanmaxDeviation
. 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. - Note that
maxSegmentLength
andmaxDeviation
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
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.DensifyAndGeneralize.DensifyAndGeneralize"
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">
<RelativeLayout>
<esriUI:MapView x:Name="MyMapView"
BindingContext="{x:Reference Name=ResponsiveFormContainer}"
Style="{StaticResource MapWithFormStyle}" />
<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 Grid.Row="0"
Grid.Column="0"
HorizontalTextAlignment="End"
Style="{StaticResource LabelStyle}"
Text="Generalize" />
<Slider x:Name="DeviationSlider"
Grid.Row="0"
Grid.Column="1"
Maximum="250"
MaximumTrackColor="CadetBlue"
Minimum="1"
MinimumTrackColor="CadetBlue"
Value="1" />
<Label Grid.Row="1"
Grid.Column="0"
HorizontalTextAlignment="End"
Style="{StaticResource LabelStyle}"
Text="Densify" />
<Slider x:Name="SegmentLengthSlider"
Grid.Row="1"
Grid.Column="1"
Maximum="500"
MaximumTrackColor="CadetBlue"
Minimum="100"
MinimumTrackColor="CadetBlue"
Value="100" />
<Label x:Name="ResultLabel"
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="2"
Style="{StaticResource LabelStyle}"
Text="Adjust a slider to start." />
</Grid>
</sampleViewer:ResponsiveFormContainer>
</RelativeLayout>
</ContentPage>