From 74061ebb4f01d00e7f2d3182c79430f4d04911cd Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 2 Sep 2013 21:31:31 +0200 Subject: [PATCH] Add method --- .../src/net/osmand/osm/edit/OsmMapUtils.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java b/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java index 399df861cd..53ef219367 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/OsmMapUtils.java @@ -307,6 +307,27 @@ public class OsmMapUtils { } } + /** + * Get the area in pixels + * @param nodes + * @return + */ + public static double polygonAreaPixels(List nodes, int zoom) { + double area = 0.; + double mult = 1 / MapUtils.getPowZoom(Math.max(31 - (zoom + 8), 0)); + int j = nodes.size() - 1; + for (int i = 0; i < nodes.size(); i++) { + Node x = nodes.get(i); + Node y = nodes.get(j); + if(x != null && y != null) { + area += (MapUtils.get31TileNumberX(y.getLongitude()) + (double)MapUtils.get31TileNumberX(x.getLongitude()))* + (MapUtils.get31TileNumberY(y.getLatitude()) - (double)MapUtils.get31TileNumberY(x.getLatitude())); + } + j = i; + } + return Math.abs(area) * mult * mult * .5; + } + /** * Get the area (in m²) of a closed way, represented as a list of nodes *