0

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.

2
  • You are not using the API and it's library contains it, pro.arcgis.com/en/pro-app/latest/sdk/api-reference/… Commented Jun 16, 2023 at 3:18
  • Note: with api's use documentation "index" link at the top of the javadoc page and press ctrl + F for find on page and enter the method or class name then click your way through to find if it exists. Commented Jun 16, 2023 at 3:21

1 Answer 1

0

The Project method only takes two parameters: the geometry and the desired spatial reference. The original spatial reference is stored on the original geometry. I suspect the examples you are looking at are old and the three parameter version has been deprecated.

I would also use an Equal-area projection system like Albers (https://en.wikipedia.org/wiki/Equal-area_projection) rather then Web Mercator. Web Mercator is designed to preserve compass bearings, and it will wildly distort areas the farther away you get from the equator. It's really not suitable for anything other than driving directions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.