I am trying to calculate the 2D area of a polygon created from vertices defined by latitude and longitude coordinates using the following dependencies:
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.Polygon;
import com.esri.core.geometry.SpatialReference;
I have initialized the vertices using latitude and longitude coordinates and assuming that they are in the wgs84 spatial reference system. In the documentation, it is also stated that "In case of Geographic Coordinate Systems, the X coordinate is the longitude and the Y is the latitude."
SpatialReference wgs84 = SpatialReference.create(4326);
Point kassel = new Point(9.49, 51.29);
Point bamberg = new Point (10.90, 49.88);
Point gotha = new Point(10.70,50.93);
Now the polygon is formed without any problems:
Polygon polygon = new Polygon();
polygon.startPath(kassel);
polygon.lineTo(bamberg);
polygon.lineTo(gotha);
polygon.closePathWithLine();
If I use the method polygon.calculateArea2D(), then the result is negative. It is explained that "If the spatial reference is a Geographic Coordinate System (WGS84) then the 2D area calculation is defined in angular units."
After some research, it seems to me that the polygon should be projected to another spatial reference system (Web Mercator), so that the measurement can be done in proper units (meters and square meters):
SpatialReference webMercator= SpatialReference.create(3857);
Polygon newPolygon = GeometryEngine.project(polygon,wgs84,webMercator);
However, I receive an error that the method is not found. I have seen several examples use this method to project a geometry from one spatial reference system to another. I also could not find this method in the documentation of the GeometryEngine class. Does anyone have any ideas what went wrong here? Your help would be much appreciated.