You can calculate the area of a surface with one of these three methods:
-
TLcdEllipsoidUtil.geodesicArea(ILcdShape, ILcdEllipsoid)
for shapes with longitude/latitude coordinates -
TLcdSphereUtil.geodesicArea(ILcdShape, double)
for shapes with longitude/latitude coordinates -
TLcdCartesian.area(ILcdShape)
for shapes with Cartesian (X/Y) coordinates
In Program: Area calculation for a shapefile, we calculate and output the area of the elements of a shapefile.
Program: Area calculation for a shapefile
String countriesFile = "Data/Shp/NaturalEarth/50m_cultural/ne_50m_admin_0_countries_lakes.shp";
ILcdModel model = new TLcdSHPModelDecoder2().decode(countriesFile);
ILcdEllipsoid ellipsoid = ((ILcdGeodeticReference) model.getModelReference()).getGeodeticDatum().getEllipsoid();
Enumeration elements = model.elements();
while (elements.hasMoreElements()) {
Object element = elements.nextElement();
String countryName = (String) ((ILcdDataObject) element).getValue("ADMIN");
double countryAreaSqM = TLcdEllipsoidUtil.geodesicArea((ILcdShape) element, ellipsoid);
System.out.println(String.format("%s: %.2f km2", countryName, countryAreaSqM / 1e6));
}
See the API reference documentation for more details and limitations.
Figure 1. An example of the area of a complex polygon