[GRASS-SVN] r59596 - in grass/branches/releasebranch_7_0: include/defs lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 6 01:20:34 PDT 2014


Author: mmetz
Date: 2014-04-06 01:20:34 -0700 (Sun, 06 Apr 2014)
New Revision: 59596

Modified:
   grass/branches/releasebranch_7_0/include/defs/vector.h
   grass/branches/releasebranch_7_0/lib/vector/Vlib/area.c
Log:
Vlib: fix area perimeter

Modified: grass/branches/releasebranch_7_0/include/defs/vector.h
===================================================================
--- grass/branches/releasebranch_7_0/include/defs/vector.h	2014-04-06 08:14:59 UTC (rev 59595)
+++ grass/branches/releasebranch_7_0/include/defs/vector.h	2014-04-06 08:20:34 UTC (rev 59596)
@@ -277,11 +277,11 @@
 int Vect_get_node_line(const struct Map_info *, int, int);
 float Vect_get_node_line_angle(const struct Map_info *, int, int);
 
-double Vect_area_perimeter(const struct line_pnts *);
 int Vect_get_area_points(const struct Map_info *, int, struct line_pnts *);
 int Vect_get_area_centroid(const struct Map_info *, int);
 int Vect_get_area_num_isles(const struct Map_info *, int);
 int Vect_get_area_isle(const struct Map_info *, int, int);
+double Vect_get_area_perimeter(const struct Map_info *, int);
 double Vect_get_area_area(const struct Map_info *, int);
 int Vect_get_area_boundaries(const struct Map_info *, int, struct ilist *);
 

Modified: grass/branches/releasebranch_7_0/lib/vector/Vlib/area.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/vector/Vlib/area.c	2014-04-06 08:14:59 UTC (rev 59595)
+++ grass/branches/releasebranch_7_0/lib/vector/Vlib/area.c	2014-04-06 08:20:34 UTC (rev 59596)
@@ -279,20 +279,47 @@
     return (Isle->area);
 }
 
-
 /*!
-   \brief Calculate area perimeter
+   \brief Returns perimeter of area with perimeter of isles
 
-   \param Points list of points defining area boundary
+   \param Map pointer to Map_info structure
+   \param area area id
 
-   \return area perimeter
+   \return perimeter of area with perimeters of isles in meters
  */
-double Vect_area_perimeter(const struct line_pnts *Points)
+
+double Vect_get_area_perimeter(const struct Map_info *Map, int area)
 {
-    return Vect_line_length(Points);
+    const struct Plus_head *Plus;
+    struct P_area *Area;
+    struct line_pnts *Points;
+    double d;
+    int i;
+
+    G_debug(3, "Vect_get_area_perimeter(): area = %d", area);
+
+    Points = Vect_new_line_struct();
+    Plus = &(Map->plus);
+    Area = Plus->Area[area];
+
+    Vect_get_area_points(Map, area, Points);
+    Vect_line_prune(Points);
+    d = Vect_line_geodesic_length(Points);
+
+    /* adding island perimeters */
+    for (i = 0; i < Area->n_isles; i++) {
+	Vect_get_isle_points(Map, Area->isles[i], Points);
+	Vect_line_prune(Points);
+	d += Vect_line_geodesic_length(Points);
+    }
+
+    Vect_destroy_line_struct(Points);
+
+    G_debug(3, "    perimeter = %f", d);
+
+    return (d);
 }
 
-
 /*!
    \brief Check if point is in area
 
@@ -363,11 +390,13 @@
     Area = Plus->Area[area];
 
     Vect_get_area_points(Map, area, Points);
+    Vect_line_prune(Points);
     size = G_area_of_polygon(Points->x, Points->y, Points->n_points);
 
-    /* substructing island areas */
+    /* substracting island areas */
     for (i = 0; i < Area->n_isles; i++) {
 	Vect_get_isle_points(Map, Area->isles[i], Points);
+	Vect_line_prune(Points);
 	size -= G_area_of_polygon(Points->x, Points->y, Points->n_points);
     }
 



More information about the grass-commit mailing list