Hi,
I'm fairly new to ArcGIS, I do a bit of testing to see if we could use it for our application. I have a basic application displaying a map, and I want to draw an ellipse on it. I managed to draw circles, but for whatever reason I can't figure out, I have an arcGISRuntimeException : Invalid argument from the GeometryEngine when I run it with my ellipse.
Here is my code (without my API key):
public class App extends Application {
private MapView mapView;
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage stage) {
stage.setTitle("Carto App");
stage.setWidth(800);
stage.setHeight(700);
stage.show();
StackPane stackPane = new StackPane();
Scene scene = new Scene(stackPane);
stage.setScene(scene);
String yourApiKey =
"";
ArcGISRuntimeEnvironment.setApiKey(yourApiKey);
mapView = new MapView();
stackPane.getChildren().add(mapView);
ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_IMAGERY);
mapView.setMap(map);
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
mapView.getGraphicsOverlays().add(graphicsOverlay);
EllipseFigure ellipse = new EllipseFigure(new Point(0, 0), 100, 100, 0, 0xFF00FF00);
Graphic graphic = new Graphic(ellipse.getGeometry(), ellipse.getSymbol());
graphicsOverlay.getGraphics().add(graphic);
}
/**
* Stops and releases all resources used in application.
*/
@Override
public void stop() {
if (mapView != null) {
mapView.dispose();
}
}
}
public class EllipseFigure {
private final double semiMajorAxis;
private final double semiMinorAxis;
private Point center;
private double rotAngle;
private int color;
public EllipseFigure(Point center, double semiMajorAxis, double semiMinorAxis, double rotAngle, int color) {
this.center = center;
this.semiMajorAxis = semiMajorAxis;
this.rotAngle = rotAngle;
this.semiMinorAxis = semiMinorAxis;
this.color = color;
}
public Geometry getGeometry() {
GeodesicEllipseParameters params =
new GeodesicEllipseParameters(center, semiMajorAxis, semiMinorAxis);
params.setAngularUnit(new AngularUnit(AngularUnitId.RADIANS));
params.setAxisDirection(rotAngle);
return GeometryEngine.ellipseGeodesic(params);
}
public Symbol getSymbol() {
return new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, color, 3);
}
}
I'd really appreciate if someone could help me figure out what's going on here.
Solved! Go to Solution.
Hi @Tone
The ellipseGeodesic method is very fussy about its parameters. You need to make sure you set them all and you also need to pass in a center point which has a known spatial reference.
I've created an example ellipse method which should help you:
private Polygon makeEllipse() {
// create parameters and set all the parameters
GeodesicEllipseParameters parameters = new GeodesicEllipseParameters();
parameters.setCenter(new Point(3,14, SpatialReferences.getWebMercator())); // Note the spatial reference
parameters.setGeometryType(GeometryType.POLYGON);
parameters.setSemiAxis1Length(100);
parameters.setSemiAxis2Length(200);
parameters.setAxisDirection(45);
parameters.setMaxPointCount(100);
parameters.setAngularUnit(new AngularUnit(AngularUnitId.DEGREES));
parameters.setLinearUnit(new LinearUnit(LinearUnitId.METERS));
parameters.setMaxSegmentLength(20);
Polygon ellipsePoly = (Polygon) GeometryEngine.ellipseGeodesic(parameters);
return ellipsePoly;
}
This is how I used the resulting geometry:
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF0063FF, 1);
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0xFF00FF00, lineSymbol);
Graphic graphic = new Graphic(makeEllipse(), fillSymbol);
graphicsOverlay.getGraphics().add(graphic);
Looks like this:
Let me know if this helps
Mark
Hi @Tone
The ellipseGeodesic method is very fussy about its parameters. You need to make sure you set them all and you also need to pass in a center point which has a known spatial reference.
I've created an example ellipse method which should help you:
private Polygon makeEllipse() {
// create parameters and set all the parameters
GeodesicEllipseParameters parameters = new GeodesicEllipseParameters();
parameters.setCenter(new Point(3,14, SpatialReferences.getWebMercator())); // Note the spatial reference
parameters.setGeometryType(GeometryType.POLYGON);
parameters.setSemiAxis1Length(100);
parameters.setSemiAxis2Length(200);
parameters.setAxisDirection(45);
parameters.setMaxPointCount(100);
parameters.setAngularUnit(new AngularUnit(AngularUnitId.DEGREES));
parameters.setLinearUnit(new LinearUnit(LinearUnitId.METERS));
parameters.setMaxSegmentLength(20);
Polygon ellipsePoly = (Polygon) GeometryEngine.ellipseGeodesic(parameters);
return ellipsePoly;
}
This is how I used the resulting geometry:
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF0063FF, 1);
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0xFF00FF00, lineSymbol);
Graphic graphic = new Graphic(makeEllipse(), fillSymbol);
graphicsOverlay.getGraphics().add(graphic);
Looks like this:
Let me know if this helps
Mark
Ah, I knew I had a problem with the parameters but couldn't figure out what it was.
Thank you @MarkBaird !