Skip to content

Commit 35a0305

Browse files
Update samples to use GeometryEngine static extension methods (#1178)
1 parent 2211e75 commit 35a0305

File tree

145 files changed

+248
-248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+248
-248
lines changed

src/MAUI/Maui.Samples/Samples/Analysis/LineOfSightGeoElement/LineOfSightGeoElement.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private void AnimationTimer_Elapsed(object sender, EventArgs e)
176176
_taxiGraphic.Geometry = intermediatePoint;
177177

178178
// Update the taxi rotation.
179-
GeodeticDistanceResult distance = GeometryEngine.DistanceGeodetic(starting, ending, LinearUnits.Meters, AngularUnits.Degrees, GeodeticCurveType.Geodesic);
179+
GeodeticDistanceResult distance = starting.DistanceGeodetic(ending, LinearUnits.Meters, AngularUnits.Degrees, GeodeticCurveType.Geodesic);
180180
((ModelSceneSymbol)_taxiGraphic.Symbol).Heading = distance.Azimuth1;
181181
}
182182

src/MAUI/Maui.Samples/Samples/Analysis/ViewshedGeoElement/ViewshedGeoElement.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ private void AnimateTank()
149149

150150
// Get current location and distance from the destination.
151151
MapPoint location = (MapPoint)_tank.Geometry;
152-
GeodeticDistanceResult distance = GeometryEngine.DistanceGeodetic(
153-
location, _tankEndPoint, _metersUnit, _degreesUnit, GeodeticCurveType.Geodesic);
152+
GeodeticDistanceResult distance = location.DistanceGeodetic(_tankEndPoint, _metersUnit, _degreesUnit,
153+
GeodeticCurveType.Geodesic);
154154

155155
// Move the tank a short distance.
156156
location = GeometryEngine.MoveGeodetic(new List<MapPoint>() { location }, 1.0, _metersUnit, distance.Azimuth1, _degreesUnit,

src/MAUI/Maui.Samples/Samples/Data/AddFeatures/AddFeatures.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private async void MapView_Tapped(object sender, Esri.ArcGISRuntime.Maui.GeoView
7474
ArcGISFeature feature = (ArcGISFeature)_damageFeatureTable.CreateFeature();
7575

7676
// Get the normalized geometry for the tapped location and use it as the feature's geometry.
77-
MapPoint tappedPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(e.Location);
77+
MapPoint tappedPoint = (MapPoint)e.Location.NormalizeCentralMeridian();
7878
feature.Geometry = tappedPoint;
7979

8080
// Set feature attributes.

src/MAUI/Maui.Samples/Samples/Data/AddFeaturesWithContingentValues/AddFeaturesWithContingentValues.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private async Task QueryAndBufferFeatures()
129129
foreach (Feature feature in results.ToList())
130130
{
131131
double bufferDistance = Convert.ToDouble(feature.GetAttributeValue("BufferSize"));
132-
Geometry buffer = GeometryEngine.Buffer(feature.Geometry, bufferDistance);
132+
Geometry buffer = feature.Geometry.Buffer(bufferDistance);
133133
MyMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(buffer));
134134
}
135135
}
@@ -147,7 +147,7 @@ private async Task CreateNewEmptyFeature(Esri.ArcGISRuntime.Maui.GeoViewInputEve
147147
_newFeature = (ArcGISFeature)_geodatabaseFeatureTable.CreateFeature();
148148

149149
// Get the normalized geometry for the tapped location and use it as the feature's geometry.
150-
MapPoint tappedPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(e.Location);
150+
MapPoint tappedPoint = (MapPoint)e.Location.NormalizeCentralMeridian();
151151
_newFeature.Geometry = tappedPoint;
152152

153153
// Add the feature to the table.

src/MAUI/Maui.Samples/Samples/Data/EditFeatureLinkedAnnotation/EditFeatureLinkedAnnotation.xaml.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Maui.GeoV
7272
else
7373
{
7474
// Project the user selected point.
75-
MapPoint projPoint = GeometryEngine.Project(e.Location, _selectedFeature.Geometry.SpatialReference) as MapPoint;
75+
MapPoint projPoint = e.Location.Project(_selectedFeature.Geometry.SpatialReference) as MapPoint;
7676

7777
// Update the geometry of the selected feature.
7878
_ = UpdateGeometry(projPoint);
@@ -122,7 +122,7 @@ private async Task UpdateGeometry(MapPoint point)
122122
if (_selectedFeature.Geometry is Polyline line)
123123
{
124124
// Get the nearest point on the selected line.
125-
ProximityResult nearestVertex = GeometryEngine.NearestVertex(line, point);
125+
ProximityResult nearestVertex = line.NearestVertex(point);
126126

127127
// Create a new polyline.
128128
PolylineBuilder polylineBuilder = new PolylineBuilder(line);
@@ -132,7 +132,7 @@ private async Task UpdateGeometry(MapPoint point)
132132
part.SetPoint(nearestVertex.PointIndex, point);
133133

134134
// Update the geometry of the feature.
135-
_selectedFeature.Geometry = GeometryEngine.Project(polylineBuilder.ToGeometry(), _selectedFeature.Geometry.SpatialReference);
135+
_selectedFeature.Geometry = polylineBuilder.ToGeometry().Project(_selectedFeature.Geometry.SpatialReference);
136136
await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);
137137
}
138138
else if (_selectedFeature.Geometry is MapPoint)

src/MAUI/Maui.Samples/Samples/Data/UpdateGeometries/UpdateGeometries.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private async void MoveSelectedFeature(Esri.ArcGISRuntime.Maui.GeoViewInputEvent
9292
MapPoint destinationPoint = tapEventDetails.Location;
9393

9494
// Normalize the point - needed when the tapped location is over the international date line.
95-
destinationPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(destinationPoint);
95+
destinationPoint = (MapPoint)destinationPoint.NormalizeCentralMeridian();
9696

9797
// Load the feature.
9898
await _selectedFeature.LoadAsync();

src/MAUI/Maui.Samples/Samples/Geometry/Buffer/Buffer.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Mau
9595
double bufferInMeters = LinearUnits.Miles.ToMeters(bufferInMiles);
9696

9797
// Create a planar buffer graphic around the input location at the specified distance.
98-
Geometry bufferGeometryPlanar = GeometryEngine.Buffer(userTapPoint, bufferInMeters);
98+
Geometry bufferGeometryPlanar = userTapPoint.Buffer(bufferInMeters);
9999
Graphic planarBufferGraphic = new Graphic(bufferGeometryPlanar);
100100

101101
// Create a geodesic buffer graphic using the same location and distance.
102-
Geometry bufferGeometryGeodesic = GeometryEngine.BufferGeodetic(userTapPoint, bufferInMeters, LinearUnits.Meters, double.NaN, GeodeticCurveType.Geodesic);
102+
Geometry bufferGeometryGeodesic = userTapPoint.BufferGeodetic(bufferInMeters, LinearUnits.Meters, double.NaN, GeodeticCurveType.Geodesic);
103103
Graphic geodesicBufferGraphic = new Graphic(bufferGeometryGeodesic);
104104

105105
// Create a graphic for the user tap location.

src/MAUI/Maui.Samples/Samples/Geometry/Buffer/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Creating buffers is a core concept in GIS proximity analysis that allows you to
1818
## How it works
1919

2020
1. The `MapPoint` for a tap on the display is captured.
21-
2. The static method `GeometryEngine.Buffer` is called to create a planar buffer polygon from the map location and distance.
22-
3. Another static method, `GeometryEngine.BufferGeodetic` is called to create a geodesic buffer polygon using the same inputs.
21+
2. The static extension method `GeometryEngine.Buffer` is called to create a planar buffer polygon from the map location and distance.
22+
3. Another static extension method, `GeometryEngine.BufferGeodetic` is called to create a geodesic buffer polygon using the same inputs.
2323
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.
2424

2525
## Relevant API

src/MAUI/Maui.Samples/Samples/Geometry/BufferList/BufferList.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private void Initialize()
5656
new MapPoint(-94.00, 31.720, SpatialReferences.Wgs84)
5757
};
5858
_spatialReferenceArea = new Polygon(spatialReferenceExtentCoords);
59-
_spatialReferenceArea = GeometryEngine.Project(_spatialReferenceArea, statePlaneNorthCentralTexas) as Polygon;
59+
_spatialReferenceArea = _spatialReferenceArea.Project(statePlaneNorthCentralTexas) as Polygon;
6060

6161
// Create a map that uses the North Central Texas state plane spatial reference.
6262
Map bufferMap = new Map(statePlaneNorthCentralTexas);
@@ -108,7 +108,7 @@ private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
108108
MapPoint tapMapPoint = e.Location;
109109

110110
// Check if the point coordinates are within the spatial reference envelope.
111-
bool withinValidExent = GeometryEngine.Contains(_spatialReferenceArea, tapMapPoint);
111+
bool withinValidExent = _spatialReferenceArea.Contains(tapMapPoint);
112112

113113
// If the input point is not within the valid extent for the spatial reference, warn the user and return.
114114
if (!withinValidExent)

src/MAUI/Maui.Samples/Samples/Geometry/BufferList/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Click/tap on the map to add points. Tap the "Create Buffer(s)" button to draw bu
1414

1515
## How it works
1616

17-
1. Use `GeometryEngine.Buffer(points, distances, union)` to create a `Polygon`. The parameter `points` are the points to buffer around, `distances` are the buffer distances for each point (in meters) and `union` is a boolean for whether the results should be unioned.
17+
1. Use `points.Buffer(distances, union)` to create a `Polygon`. The parameter `points` are the points to buffer around, `distances` are the buffer distances for each point (in meters) and `union` is a boolean for whether the results should be unioned.
1818
2. Add the resulting polygons (if not unioned) or single polygon (if unioned) to the map's `GraphicsOverlay` as a `Graphic`.
1919

2020
## Relevant API

src/MAUI/Maui.Samples/Samples/Geometry/ClipGeometry/ClipGeometry.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private void ClipGraphics()
151151
// Perform the clip operation. The first parameter of the clip operation will always be the Colorado graphic.
152152
// The second parameter of the clip operation will be one of the 3 different clip geometries (_outsideGraphic,
153153
// _containedGraphic, or _intersectingGraphic).
154-
Geometry myGeometry = GeometryEngine.Clip(_coloradoGraphic.Geometry, (Envelope)graphic.Geometry);
154+
Geometry myGeometry = _coloradoGraphic.Geometry.Clip((Envelope)graphic.Geometry);
155155

156156
// Only work on returned geometries that are not null.
157157
if (myGeometry != null)

src/MAUI/Maui.Samples/Samples/Geometry/ClipGeometry/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Tap the "Clip" button to clip the blue graphic with the red dashed envelopes.
1414

1515
## How it works
1616

17-
1. Use the static method `GeometryEngine.Clip()` to generate a clipped `Geometry`, passing in an existing `Geometry` and an `Envelope` as parameters. The existing geometry will be clipped where it intersects an envelope.
17+
1. Use the static extension method `GeometryEngine.Clip()` to generate a clipped `Geometry`, passing in an existing `Geometry` and an `Envelope` as parameters. The existing geometry will be clipped where it intersects an envelope.
1818
2. Create a new `Graphic` from the clipped geometry and add it to a `GraphicsOverlay` on the `MapView`.
1919

2020
## Relevant API

src/MAUI/Maui.Samples/Samples/Geometry/ConvexHull/ConvexHull.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
6464
try
6565
{
6666
// Normalize the tapped point.
67-
var centralizedPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(e.Location);
67+
var centralizedPoint = (MapPoint)e.Location.NormalizeCentralMeridian();
6868

6969
// Add the map point to the list that will be used by the GeometryEngine.ConvexHull operation.
7070
_inputPointCollection.Add(centralizedPoint);
@@ -104,7 +104,7 @@ private void ConvexHullButton_Clicked(object sender, EventArgs e)
104104
Multipoint inputMultipoint = new Multipoint(_inputPointCollection);
105105

106106
// Get the returned result from the convex hull operation.
107-
Geometry convexHullGeometry = GeometryEngine.ConvexHull(inputMultipoint);
107+
Geometry convexHullGeometry = inputMultipoint.ConvexHull();
108108

109109
// Create a simple line symbol for the outline of the convex hull graphic(s).
110110
SimpleLineSymbol convexHullSimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Blue, 4);

src/MAUI/Maui.Samples/Samples/Geometry/ConvexHull/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Tap on the map to add points. Tap the "Create Convex Hull" button to generate th
1515
## How it works
1616

1717
1. Create an input geometry such as a `Multipoint` object.
18-
2. Use `GeometryEngine.ConvexHull(inputGeometry)` to create a new `Geometry` object representing the convex hull of the input points. The returned geometry will either be a `Point`, `Polyline`, or `Polygon` based on the number of input points.
18+
2. Use `inputGeometry.ConvexHull()` to create a new `Geometry` object representing the convex hull of the input points. The returned geometry will either be a `Point`, `Polyline`, or `Polygon` based on the number of input points.
1919

2020
## Relevant API
2121

src/MAUI/Maui.Samples/Samples/Geometry/ConvexHullList/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Tap the 'Create Convex Hull' button to create convex hull(s) from the polygon gr
1616

1717
1. Create an `Map` and display it in a `MapView`.
1818
2. Create two input polygon graphics and add them to a `GraphicsOverlay`.
19-
3. Call `GeometryEngine.ConvexHull(inputGeometries, boolean)`, specifying a list of geometries for which to generate the convex hull. Set the boolean parameter to `true` to generate a convex hull for the union of the geometries. Set it to `false` to create a convex hull for each individual geometry.
19+
3. Call `inputGeometries.ConvexHull(boolean)`, specifying a list of geometries for which to generate the convex hull. Set the boolean parameter to `true` to generate a convex hull for the union of the geometries. Set it to `false` to create a convex hull for each individual geometry.
2020
4. Loop through the returned geometries and add them as graphics for display on the map.
2121

2222
## Relevant API

src/MAUI/Maui.Samples/Samples/Geometry/CutGeometry/CutGeometry.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void CutButton_Clicked(object sender, EventArgs e)
9898
private void Cut()
9999
{
100100
// Cut the polygon geometry with the polyline, expect two geometries.
101-
Geometry[] cutGeometries = GeometryEngine.Cut(_lakeSuperiorPolygonGraphic.Geometry, (Polyline)_countryBorderPolylineGraphic.Geometry);
101+
Geometry[] cutGeometries = _lakeSuperiorPolygonGraphic.Geometry.Cut((Polyline)_countryBorderPolylineGraphic.Geometry);
102102

103103
// Create a simple line symbol for the outline of the Canada side of Lake Superior.
104104
SimpleLineSymbol canadaSideSimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Null, System.Drawing.Color.Blue, 0);

src/MAUI/Maui.Samples/Samples/Geometry/CutGeometry/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Tap the "Cut" button to cut the polygon with the polyline and see the resulting
1414

1515
## How it works
1616

17-
1. Pass the geometry and polyline to `GeometryEngine.Cut` to cut the geometry along the polyline.
17+
1. Pass the polyline to the static extension method `GeometryEngine.Cut()` to cut the geometry along the polyline.
1818
2. Loop through the returned list of part geometries. Some of these geometries may be multi-part.
1919

2020
## Relevant API

src/MAUI/Maui.Samples/Samples/Geometry/DensifyAndGeneralize/DensifyAndGeneralize.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private void UpdateGeometry(string operation, double segmentLength, double devia
9595
// Reset the other slider.
9696
SegmentLengthSlider.Value = 100;
9797

98-
polyline = (Polyline)GeometryEngine.Generalize(polyline, deviation, true);
98+
polyline = (Polyline)polyline.Generalize(deviation, true);
9999

100100
// Update the result label.
101101
ResultLabel.Text = $"Generalize- deviation: {deviation:f}";
@@ -105,7 +105,7 @@ private void UpdateGeometry(string operation, double segmentLength, double devia
105105
// Reset the other slider.
106106
DeviationSlider.Value = 1;
107107

108-
polyline = (Polyline)GeometryEngine.Densify(polyline, segmentLength);
108+
polyline = (Polyline)polyline.Densify(segmentLength);
109109

110110
// Update the result label.
111111
ResultLabel.Text = $"Densify- segment length: {segmentLength:f}";

src/MAUI/Maui.Samples/Samples/Geometry/DensifyAndGeneralize/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Use the sliders to control the parameters of the densify and generalize methods.
1616

1717
## How it works
1818

19-
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.
20-
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.
19+
1. Use the static extension method `polyline.Densify(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.
20+
2. Use the static extension method `polyline.Generalize(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.
2121
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.
2222

2323
## Relevant API

src/MAUI/Maui.Samples/Samples/Geometry/GeodesicOperations/GeodesicOperations.xaml.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void Initialize()
7575
private void MyMapViewOnGeoViewTapped(object sender, Esri.ArcGISRuntime.Maui.GeoViewInputEventArgs geoViewInputEventArgs)
7676
{
7777
// Get the tapped point, projected to WGS84.
78-
MapPoint destination = (MapPoint)GeometryEngine.Project(geoViewInputEventArgs.Location, SpatialReferences.Wgs84);
78+
MapPoint destination = (MapPoint)geoViewInputEventArgs.Location.Project(SpatialReferences.Wgs84);
7979

8080
// Update the destination graphic.
8181
_endLocationGraphic.Geometry = destination;
@@ -91,13 +91,13 @@ private void MyMapViewOnGeoViewTapped(object sender, Esri.ArcGISRuntime.Maui.Geo
9191
Polyline routeLine = new Polyline(polylinePoints);
9292

9393
// Densify the polyline to show the geodesic curve.
94-
Geometry pathGeometry = GeometryEngine.DensifyGeodetic(routeLine, 1, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);
94+
Geometry pathGeometry = routeLine.DensifyGeodetic(1, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);
9595

9696
// Apply the curved line to the path graphic.
9797
_pathGraphic.Geometry = pathGeometry;
9898

9999
// Calculate and show the distance.
100-
double distance = GeometryEngine.LengthGeodetic(pathGeometry, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);
100+
double distance = pathGeometry.LengthGeodetic(LinearUnits.Kilometers, GeodeticCurveType.Geodesic);
101101
ResultsLabel.Text = $"{(int)distance} kilometers";
102102
}
103103
}

src/MAUI/Maui.Samples/Samples/Geometry/GeodesicOperations/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Tap anywhere on the map. A line graphic will display the geodesic line between t
1717
1. A `Point` is created in New York City and displayed as a `Graphic`.
1818
2. When a tap occurs on the `MapView`, a new `Point` is obtained from the mouse click. This `Point` is added as a `Graphic`.
1919
3. A `Polyline` is created with the two `Point` objects.
20-
4. `GeometryEngine.DensifyGeodetic` is executed by passing in the `Polyline` object, and the returned `Geometry` is added as a `Graphic`.
21-
5. `GeometryEngine.LengthGeodetic` is executed by passing in the two `Point` objects, and the returned number is displayed on the screen.
20+
4. `GeometryEngine.DensifyGeodetic` is called from the `Polyline` object, and the returned `Geometry` is stored as `pathGeometry`.
21+
5. `GeometryEngine.LengthGeodetic` is called from `pathGeometry`, and the returned number is displayed on the screen.
2222

2323
## Relevant API
2424

0 commit comments

Comments
 (0)