Geodesic sectors and ellipses can be used in a wide range of analyses ranging from projectile landing zones to antenna coverage. For example, given the strength and direction of a cellular tower's signal, you could generate cell coverage geometries to identify areas without sufficient connectivity.
How to use the sample
The geodesic sector and ellipse will display with default parameters at the start. Click anywhere on the map to change the center of the geometries. Adjust any of the controls to see how they affect the sector and ellipse on the fly.
How it works
Create GeodesicSectorParameters and GeodesicEllipseParameters using one of the constructors with default values or using each setter individually.
Set the center, axisDirection, semiAxis1Length, and the semiAxis2Length properties to change the general ellipse position, shape, and orientation.
Set the sectorAngle and startDirection angles to change the sector's shape and orientation.
Set the maxPointCount and maxSegmentLength properties to control the complexity of the geometries and the approximation of the ellipse curve.
Specify the geometryType to either POLYGON, POLYLINE, or MULTIPOINT to change the result geometry type.
Pass the parameters to the related static methods: GeometryEngine.ellipseGeodesic(geodesicEllipseParameters) and GeometryEngine.sectorGeodesic(geodesicSectorParameters). The returned value will be a Geometry of the type specified by the geometryType parameter.
Relevant API
GeodesicEllipseParameters
GeodesicSectorParameters
GeometryEngine
GeometryType
Additional information
To create a circle instead of an ellipse, simply set semiAxis2Length to 0.0 and semiAxis1Length to the desired radius of the circle. This eliminates the need to update both parameters to the same value.
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* Copyright 2018 Esri.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/package com.esri.samples.geodesic_sector_and_ellipse;
import javafx.fxml.FXML;
import javafx.geometry.Point2D;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Slider;
import javafx.scene.control.Spinner;
import javafx.scene.input.MouseButton;
import javafx.scene.paint.Color;
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.geometry.GeodesicEllipseParameters;
import com.esri.arcgisruntime.geometry.GeodesicSectorParameters;
import com.esri.arcgisruntime.geometry.Geometry;
import com.esri.arcgisruntime.geometry.GeometryEngine;
import com.esri.arcgisruntime.geometry.GeometryType;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.BasemapStyle;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.Graphic;
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.symbology.FillSymbol;
import com.esri.arcgisruntime.symbology.LineSymbol;
import com.esri.arcgisruntime.symbology.MarkerSymbol;
import com.esri.arcgisruntime.symbology.SimpleFillSymbol;
import com.esri.arcgisruntime.symbology.SimpleLineSymbol;
import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol;
publicclassGeodesicSectorAndEllipseController{
@FXMLprivate MapView mapView;
@FXMLprivate Slider axisDirectionSlider;
@FXMLprivate Spinner<Integer> maxPointCountSpinner;
@FXMLprivate Slider maxSegmentLengthSlider;
@FXMLprivate ComboBox<GeometryType> geometryTypeComboBox;
@FXMLprivate Slider sectorAngleSlider;
@FXMLprivate Slider semiAxis1LengthSlider;
@FXMLprivate Slider semiAxis2LengthSlider;
@FXMLprivate Slider startDirectionSlider;
private Point center;
private Graphic sectorGraphic;
private Graphic ellipseGraphic;
private FillSymbol sectorFillSymbol;
private LineSymbol sectorLineSymbol;
private MarkerSymbol sectorMarkerSymbol;
publicvoidinitialize(){
// authentication with an API key or named user is required to access basemaps and other location services String yourAPIKey = System.getProperty("apiKey");
ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
// create a map with the standard imagery basemap style ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_IMAGERY_STANDARD);
// set the map to the map view mapView.setMap(map);
// set a viewpoint on the map view center = new Point(-13574921.207495, 4378809.903179, SpatialReferences.getWebMercator());
mapView.setViewpoint(new Viewpoint(center, 10000));
// create a graphics overlay for showing the geometries as graphics GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
mapView.getGraphicsOverlays().add(graphicsOverlay);
// create a graphic to show the geodesic sector geometry sectorGraphic = new Graphic();
graphicsOverlay.getGraphics().add(sectorGraphic);
// create green symbols for each sector output geometry type Color transparentLime = Color.web("lime", 0.5);
sectorFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, transparentLime, null);
sectorLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, transparentLime, 3);
sectorMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, transparentLime, 3);
// create a red dotted outline graphic for showing the geodesic ellipse geometry SimpleLineSymbol ellipseLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DOT, Color.RED, 2);
ellipseGraphic = new Graphic();
ellipseGraphic.setSymbol(ellipseLineSymbol);
graphicsOverlay.getGraphics().add(ellipseGraphic);
// set the center of the sector and ellipse where the user clicks on the map mapView.setOnMouseClicked(e -> {
if (e.isStillSincePress() && e.getButton() == MouseButton.PRIMARY) {
Point2D point2D = new Point2D(e.getX(), e.getY());
center = mapView.screenToLocation(point2D);
updateSector();
}
});
// set up the controls with some default parameters GeodesicSectorParameters defaultParameters = new GeodesicSectorParameters(center, 100.0, 100.0, 15.0, 0.0);
axisDirectionSlider.setValue(defaultParameters.getAxisDirection());
maxPointCountSpinner.getValueFactory().setValue(Long.valueOf(defaultParameters.getMaxPointCount()).intValue());
maxSegmentLengthSlider.setValue(defaultParameters.getMaxSegmentLength());
geometryTypeComboBox.getItems().addAll(GeometryType.POLYGON, GeometryType.POLYLINE, GeometryType.MULTIPOINT);
geometryTypeComboBox.getSelectionModel().select(GeometryType.POLYGON);
sectorAngleSlider.setValue(defaultParameters.getSectorAngle());
semiAxis1LengthSlider.setValue(defaultParameters.getSemiAxis1Length());
semiAxis2LengthSlider.setValue(defaultParameters.getSemiAxis2Length());
startDirectionSlider.setValue(defaultParameters.getStartDirection());
// call updateSector when any of the controls change their value axisDirectionSlider.valueProperty().addListener(e -> updateSector());
maxPointCountSpinner.valueProperty().addListener(e -> updateSector());
maxSegmentLengthSlider.valueProperty().addListener(e -> updateSector());
geometryTypeComboBox.valueProperty().addListener(e -> updateSector());
sectorAngleSlider.valueProperty().addListener(e -> updateSector());
semiAxis1LengthSlider.valueProperty().addListener(e -> updateSector());
semiAxis2LengthSlider.valueProperty().addListener(e -> updateSector());
startDirectionSlider.valueProperty().addListener(e -> updateSector());
// update the sector with the default parameters updateSector();
}
/**
* Updates the sector and ellipse graphics using the controls' values.
*/privatevoidupdateSector(){
// create geodesic sector parameters GeodesicSectorParameters geodesicSectorParameters = new GeodesicSectorParameters();
geodesicSectorParameters.setCenter(center);
geodesicSectorParameters.setAxisDirection(axisDirectionSlider.getValue());
geodesicSectorParameters.setMaxPointCount(maxPointCountSpinner.getValue());
geodesicSectorParameters.setMaxSegmentLength(maxSegmentLengthSlider.getValue());
geodesicSectorParameters.setGeometryType(geometryTypeComboBox.getSelectionModel().getSelectedItem());
geodesicSectorParameters.setSectorAngle(sectorAngleSlider.getValue());
geodesicSectorParameters.setSemiAxis1Length(semiAxis1LengthSlider.getValue());
geodesicSectorParameters.setSemiAxis2Length(semiAxis2LengthSlider.getValue());
geodesicSectorParameters.setStartDirection(startDirectionSlider.getValue());
// create the geodesic sector parameter Geometry sectorGeometry = GeometryEngine.sectorGeodesic(geodesicSectorParameters);
// set the sector graphic's geometry to the sector sectorGraphic.setGeometry(sectorGeometry);
// update the graphic's symbol depending on the chosen output geometry typeswitch (sectorGeometry.getGeometryType()) {
case MULTIPOINT:
sectorGraphic.setSymbol(sectorMarkerSymbol);
break;
case POLYGON:
sectorGraphic.setSymbol(sectorFillSymbol);
break;
case POLYLINE:
sectorGraphic.setSymbol(sectorLineSymbol);
break;
}
// create geodesic ellipse parameters using the same values from the geodesic sector parameters// use one of the constructors that sets some defaults for you GeodesicEllipseParameters geodesicEllipseParameters = new GeodesicEllipseParameters(center, semiAxis1LengthSlider
.getValue(), semiAxis2LengthSlider.getValue());
geodesicEllipseParameters.setAxisDirection(axisDirectionSlider.getValue());
// show the geodesic ellipse that the sector is in Geometry ellipseGeometry = GeometryEngine.ellipseGeodesic(geodesicEllipseParameters);
ellipseGraphic.setGeometry(ellipseGeometry);
}
/**
* Disposes of application resources.
*/voidterminate(){
if (mapView != null) {
mapView.dispose();
}
}
}