[geos-commits] r3543 - in branches/3.3: . src/algorithm

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Dec 12 05:09:33 EST 2011


Author: strk
Date: 2011-12-12 02:09:32 -0800 (Mon, 12 Dec 2011)
New Revision: 3543

Modified:
   branches/3.3/NEWS
   branches/3.3/src/algorithm/CGAlgorithms.cpp
Log:
Apply Shoelace formula for area calculation (#485)

Modified: branches/3.3/NEWS
===================================================================
--- branches/3.3/NEWS	2011-12-12 09:59:00 UTC (rev 3542)
+++ branches/3.3/NEWS	2011-12-12 10:09:32 UTC (rev 3543)
@@ -13,6 +13,7 @@
     - Improve buffer robustness by reverting to non-snaprounding noder (#495)
     - Fix C++11 build by avoiding std::pair<auto_ptr> (#491)
     - Add --clibs to geos-config and GEOS_C_LIBS to geos.m4 (#497)
+    - Apply shoelace formula for area calculation (#485)
 
 Changes in 3.3.1
 2011-09-27

Modified: branches/3.3/src/algorithm/CGAlgorithms.cpp
===================================================================
--- branches/3.3/src/algorithm/CGAlgorithms.cpp	2011-12-12 09:59:00 UTC (rev 3542)
+++ branches/3.3/src/algorithm/CGAlgorithms.cpp	2011-12-12 10:09:32 UTC (rev 3543)
@@ -307,18 +307,20 @@
 
 	if (npts<3) return 0.0;
 
+	Coordinate pp;
+	Coordinate cp = ring->getAt(0);
+	Coordinate np = ring->getAt(1);
+	double x0 = cp.x;
+        np.x -= x0;
 	double sum=0.0;
-	Coordinate p = ring->getAt(0);
-	double bx = p.x;
-	double by = p.y;
 	for (size_t i=1; i<npts; ++i)
 	{
-		ring->getAt(i, p);
-		double cx = p.x;
-		double cy = p.y;
-		sum += (bx+cx) * (cy-by);
-		bx = cx;
-		by = cy;
+		pp.y = cp.y;
+		cp.x = np.x;
+		cp.y = np.y;
+		ring->getAt(i, np);
+                np.x -= x0;
+		sum += cp.x * (np.y - pp.y);
 	}
 	return -sum/2.0;
 }



More information about the geos-commits mailing list