[GRASS-SVN] r41279 - in grass/trunk/misc: . m.measure

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Mar 3 22:48:14 EST 2010


Author: glynn
Date: 2010-03-03 22:48:13 -0500 (Wed, 03 Mar 2010)
New Revision: 41279

Added:
   grass/trunk/misc/m.measure/
   grass/trunk/misc/m.measure/Makefile
   grass/trunk/misc/m.measure/m.measure.html
   grass/trunk/misc/m.measure/main.c
Modified:
   grass/trunk/misc/Makefile
Log:
Add m.measure


Modified: grass/trunk/misc/Makefile
===================================================================
--- grass/trunk/misc/Makefile	2010-03-04 01:47:10 UTC (rev 41278)
+++ grass/trunk/misc/Makefile	2010-03-04 03:48:13 UTC (rev 41279)
@@ -1,7 +1,8 @@
 MODULE_TOPDIR = ..
 
 SUBDIRS = \
-	m.cogo
+	m.cogo \
+	m.measure
 
 include $(MODULE_TOPDIR)/include/Make/Dir.make
 


Property changes on: grass/trunk/misc/m.measure
___________________________________________________________________
Added: svn:ignore
   + OBJ.*


Added: grass/trunk/misc/m.measure/Makefile
===================================================================
--- grass/trunk/misc/m.measure/Makefile	                        (rev 0)
+++ grass/trunk/misc/m.measure/Makefile	2010-03-04 03:48:13 UTC (rev 41279)
@@ -0,0 +1,10 @@
+MODULE_TOPDIR = ../..
+
+PGM = m.measure
+
+LIBES     = $(DISPLAYLIB) $(GISLIB)
+DEPENDENCIES= $(DISPLAYDEP) $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd

Added: grass/trunk/misc/m.measure/m.measure.html
===================================================================
--- grass/trunk/misc/m.measure/m.measure.html	                        (rev 0)
+++ grass/trunk/misc/m.measure/m.measure.html	2010-03-04 03:48:13 UTC (rev 41279)
@@ -0,0 +1,20 @@
+<H2>DESCRIPTION</H2>
+
+<EM>m.measure</EM> provides the user with a
+way to measure the lengths and areas of lines and polygons.
+Areas can be stated in hectares, square miles, square meters and
+square kilometers.
+
+<H2>AUTHORS</H2>
+
+Glynn Clements
+<BR>
+Derived from d.measure, by:
+<BR>
+James Westervelt, 
+<BR>
+Michael Shapiro, <BR>
+U.S. Army Construction Engineering 
+Research Laboratory
+
+<p><i>Last changed: $Date: 2008-08-15 07:16:42 +0100 (Fri, 15 Aug 2008) $</i>

Added: grass/trunk/misc/m.measure/main.c
===================================================================
--- grass/trunk/misc/m.measure/main.c	                        (rev 0)
+++ grass/trunk/misc/m.measure/main.c	2010-03-04 03:48:13 UTC (rev 41279)
@@ -0,0 +1,87 @@
+
+/****************************************************************************
+ *
+ * MODULE:       m.measure
+ * AUTHOR(S):    Created from d.measure by Glynn Clements, 2010
+ *               James Westervelt and Michael Shapiro 
+ *                (CERL - original contributors)
+ *               Markus Neteler <neteler itc.it>, 
+ *               Reinhard Brunzema <r.brunzema at web.de>, 
+ *               Bernhard Reiter <bernhard intevation.de>, 
+ *               Huidae Cho <grass4u gmail.com>, 
+ *               Eric G. Miller <egm2 jps.net>, 
+ *               Glynn Clements <glynn gclements.plus.com>, 
+ *               Hamish Bowman <hamish_b yahoo.com>, 
+ *               Jan-Oliver Wagner <jan intevation.de>
+ * PURPOSE:      distance and area measurement
+ * COPYRIGHT:    (C) 1999-2006,2010 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *               License (>=v2). Read the file COPYING that comes with GRASS
+ *               for details.
+ *
+ *****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <grass/gis.h>
+#include <grass/display.h>
+#include <grass/glocale.h>
+
+int main(int argc, char **argv)
+{
+    struct GModule *module;
+    struct Option *coords;
+    double *x, *y;
+    double length, area;
+    int npoints;
+    int i;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->description = _("Measures the lengths and areas of features.");
+
+    coords = G_define_option();
+    coords->key = "coords";
+    coords->description = _("Vertex coordinates");
+    coords->type = TYPE_DOUBLE;
+    coords->required = YES;
+    coords->multiple = YES;
+    coords->key_desc = "x,y";
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    npoints = 0;
+    for (i = 0; coords->answers[i]; i += 2)
+	npoints++;
+    x = G_malloc(npoints * sizeof(double));
+    y = G_malloc(npoints * sizeof(double));
+
+    for (i = 0; i < npoints; i++)
+    {
+	x[i] = atof(coords->answers[2*i+0]);
+	y[i] = atof(coords->answers[2*i+1]);
+    }
+
+    G_begin_distance_calculations();
+    length = 0;
+    for (i = 1; i < npoints; i++)
+	length += G_distance(x[i-1], y[i-1], x[i], y[i]);
+
+    printf("LEN:   %10.2f meters\n", length);
+    printf("LEN:   %10.4f kilometers\n", length / 1e3);
+    printf("LEN:   %10.4f miles\n", length / 1609.344);
+
+    if (npoints > 3) {
+	G_begin_polygon_area_calculations();
+	area = G_area_of_polygon(x, y, npoints);
+	printf("AREA:  %10.2f square meters\n", area);
+	printf("AREA:  %10.2f hectares\n", area / 1e4);
+	printf("AREA:  %10.4f square kilometers\n", area / 1e6);
+	printf("AREA:  %10.4f square miles\n", area / 2589988.11);
+    }
+
+    exit(EXIT_SUCCESS);
+}



More information about the grass-commit mailing list