[GRASS-SVN] r50353 - grass-addons/grass7/vector/v.out.ply
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jan 21 09:08:27 EST 2012
Author: mmetz
Date: 2012-01-21 06:08:27 -0800 (Sat, 21 Jan 2012)
New Revision: 50353
Added:
grass-addons/grass7/vector/v.out.ply/body.c
grass-addons/grass7/vector/v.out.ply/header.c
grass-addons/grass7/vector/v.out.ply/v.out.ply.html
Removed:
grass-addons/grass7/vector/v.out.ply/v.out.ascii.html
Modified:
grass-addons/grass7/vector/v.out.ply/Makefile
grass-addons/grass7/vector/v.out.ply/args.c
grass-addons/grass7/vector/v.out.ply/local_proto.h
grass-addons/grass7/vector/v.out.ply/main.c
Log:
new module v.out.ply
Modified: grass-addons/grass7/vector/v.out.ply/Makefile
===================================================================
--- grass-addons/grass7/vector/v.out.ply/Makefile 2012-01-21 14:06:13 UTC (rev 50352)
+++ grass-addons/grass7/vector/v.out.ply/Makefile 2012-01-21 14:08:27 UTC (rev 50353)
@@ -1,6 +1,6 @@
MODULE_TOPDIR = ../..
-PGM = v.out.ascii
+PGM = v.out.ply
LIBES = $(VECTORLIB) $(DBMILIB) $(GISLIB)
DEPENDENCIES = $(VECTORDEP) $(DBMIDEP) $(GISDEP)
Modified: grass-addons/grass7/vector/v.out.ply/args.c
===================================================================
--- grass-addons/grass7/vector/v.out.ply/args.c 2012-01-21 14:06:13 UTC (rev 50352)
+++ grass-addons/grass7/vector/v.out.ply/args.c 2012-01-21 14:08:27 UTC (rev 50353)
@@ -8,55 +8,37 @@
#include "local_proto.h"
void parse_args(int argc, char **argv,
- char **input, char**output, int *format, int *dp, char **delim,
- char **field, char ***columns, char **where, int *region,
- int *old_format, int *header, struct cat_list **clist, int *type)
+ char **input, char**output, int *format, int *dp,
+ char **field, char ***columns, int *region)
{
- struct Option *input_opt, *output_opt, *format_opt, *dp_opt, *delim_opt,
- *field_opt, *column_opt, *where_opt, *cats_opt, *type_opt;
- struct Flag *old_flag, *header_flag, *region_flag;
+ struct Option *input_opt, *output_opt, *dp_opt,
+ *field_opt, *column_opt /* , *format_opt */;
+ struct Flag *region_flag;
input_opt = G_define_standard_option(G_OPT_V_INPUT);
field_opt = G_define_standard_option(G_OPT_V_FIELD);
- field_opt->guisection = _("Selection");
- type_opt = G_define_standard_option(G_OPT_V3_TYPE);
- type_opt->guisection = _("Selection");
-
output_opt = G_define_standard_option(G_OPT_F_OUTPUT);
- output_opt->label = _("Name for output ASCII file "
- "or ASCII vector name if '-o' is defined");
+ output_opt->label = _("Name for output PLY file");
output_opt->description = _("'-' for standard output");
output_opt->required = NO;
output_opt->answer = "-";
column_opt = G_define_standard_option(G_OPT_DB_COLUMNS);
- column_opt->description = _("Name of attribute column(s) to be exported (point mode)");
- column_opt->guisection = _("Points");
+ column_opt->description = _("Name of attribute column(s) to be exported");
- cats_opt = G_define_standard_option(G_OPT_V_CATS);
- cats_opt->guisection = _("Selection");
-
- where_opt = G_define_standard_option(G_OPT_DB_WHERE);
- where_opt->guisection = _("Selection");
-
+/*
format_opt = G_define_option();
format_opt->key = "format";
format_opt->type = TYPE_STRING;
format_opt->required = YES;
format_opt->multiple = NO;
- format_opt->options = "point,standard,wkt";
- format_opt->answer = "point";
- format_opt->description = _("Output format");
- format_opt->descriptions = _("point;Simple point format (point per row);"
- "standard;GRASS ASCII vector format;"
- "wkt;OGC well-known text;");
+ format_opt->options = "ascii,binary";
+ format_opt->answer = "ascii";
+ format_opt->description = _("Output PLY file format");
+*/
- delim_opt = G_define_standard_option(G_OPT_F_SEP);
- delim_opt->description = _("Field separator (points mode)");
- delim_opt->guisection = _("Points");
-
dp_opt = G_define_option();
dp_opt->key = "dp";
dp_opt->type = TYPE_INTEGER;
@@ -65,17 +47,7 @@
dp_opt->answer = "8"; /* This value is taken from the lib settings in G_format_easting() */
dp_opt->description =
_("Number of significant digits (floating point only)");
- dp_opt->guisection = _("Points");
- old_flag = G_define_flag();
- old_flag->key = 'o';
- old_flag->description = _("Create old (version 4) ASCII file");
-
- header_flag = G_define_flag();
- header_flag->key = 'c';
- header_flag->description = _("Include column names in output (points mode)");
- header_flag->guisection = _("Points");
-
region_flag = G_define_flag();
region_flag->key = 'r';
region_flag->description =
@@ -87,60 +59,29 @@
*input = G_store(input_opt->answer);
*output = G_store(output_opt->answer);
- if (format_opt->answer[0] == 'p')
- *format = GV_ASCII_FORMAT_POINT;
- else if (format_opt->answer[0] == 's')
- *format = GV_ASCII_FORMAT_STD;
+
+/*
+ if (format_opt->answer[0] == 'b')
+ *format = PLY_BINARY;
else
- *format = GV_ASCII_FORMAT_WKT;
+ *format = PLY_ASCII;
+*/
+
if (sscanf(dp_opt->answer, "%d", dp) != 1)
G_fatal_error(_("Failed to interpret 'dp' parameter as an integer"));
- /* the field separator */
- if (strcmp(delim_opt->answer, "\\t") == 0)
- *delim = G_store("\t");
- else if (strcmp(delim_opt->answer, "tab") == 0)
- *delim = G_store("\t");
- else if (strcmp(delim_opt->answer, "space") == 0)
- *delim = G_store(" ");
- else if (strcmp(delim_opt->answer, "comma") == 0)
- *delim = G_store(",");
- else
- *delim = G_store(delim_opt->answer);
*field = G_store(field_opt->answer);
- *type = Vect_option_to_types(type_opt);
- if (*type & GV_AREA) {
- *type |= GV_BOUNDARY;
- *type |= GV_CENTROID;
- }
+
*columns = NULL;
if (column_opt->answer) {
int i, nopt;
nopt = 0;
- while(column_opt->answers[nopt++])
- ;
+ while(column_opt->answers[nopt++]);
+
*columns = (char **) G_malloc(nopt * sizeof(char *));
for (i = 0; i < nopt - 1; i++)
(*columns)[i] = G_store(column_opt->answers[i]);
(*columns)[nopt - 1] = NULL;
}
- *where = NULL;
- if (where_opt->answer) {
- *where = G_store(where_opt->answer);
- }
- *clist = NULL;
- if (cats_opt->answer) {
- int ret;
-
- *clist = Vect_new_cat_list();
- (*clist)->field = atoi(field_opt->answer);
- if ((*clist)->field < 1)
- G_fatal_error(_("Option <%s> must be > 0"), field_opt->key);
- ret = Vect_str_to_cat_list(cats_opt->answer, *clist);
- if (ret > 0)
- G_fatal_error(_("%d errors in cat option"), ret);
- }
*region = region_flag->answer ? 1 : 0;
- *old_format = old_flag->answer ? 1 : 0;
- *header = header_flag->answer ? 1 : 0;
}
Added: grass-addons/grass7/vector/v.out.ply/body.c
===================================================================
--- grass-addons/grass7/vector/v.out.ply/body.c (rev 0)
+++ grass-addons/grass7/vector/v.out.ply/body.c 2012-01-21 14:08:27 UTC (rev 50353)
@@ -0,0 +1,214 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <grass/gis.h>
+#include <grass/vector.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+
+int write_ply_body_ascii(FILE *fp, struct Map_info *Map,
+ int dp, int region, int field,
+ const char **columns, struct bound_box *box)
+{
+ int type, i, cat, n_lines, line;
+ static struct line_pnts *Points;
+ struct line_cats *Cats, *ACats;
+ char *fs = G_store(" ");
+ struct ilist *fcats;
+
+ /* columns */
+ struct field_info *Fi = NULL;
+ dbDriver *driver = NULL;
+ dbValue value;
+ dbHandle handle;
+ int ncats, more;
+ dbTable *Table;
+ dbString dbstring;
+ dbColumn *Column;
+ dbValue *Value;
+ char buf[2000];
+ dbCursor cursor;
+ int *coltypes = NULL;
+
+ n_lines = ncats = 0;
+
+ G_zero(&value, sizeof(dbValue));
+ db_init_string(&dbstring);
+
+ if (columns) {
+ Fi = Vect_get_field(Map, field);
+ if (!Fi) {
+ G_fatal_error(_("Database connection not defined for layer %d"),
+ field);
+ }
+
+ driver = db_start_driver(Fi->driver);
+ if (!driver)
+ G_fatal_error(_("Unable to start driver <%s>"), Fi->driver);
+
+ db_init_handle(&handle);
+ db_set_handle(&handle, Fi->database, NULL);
+
+ if (db_open_database(driver, &handle) != DB_OK)
+ G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+ Fi->database, Fi->driver);
+
+ i = 0;
+ while (columns[i++]);
+
+ coltypes = G_malloc(i * sizeof(int));
+
+ i = 0;
+ while (columns[i]) {
+ coltypes[i] = db_column_Ctype(driver, Fi->table, columns[i]);
+ i++;
+ }
+
+
+ }
+
+ Points = Vect_new_line_struct();
+ Cats = Vect_new_cats_struct();
+ ACats = Vect_new_cats_struct();
+ fcats = Vect_new_list();
+
+ /* by default, read_next_line will NOT read Dead lines */
+ /* but we can override that (in Level I only) by specifying */
+ /* the type -1, which means match all line types */
+
+ Vect_rewind(Map);
+
+ line = 0;
+ while (TRUE) {
+ type = Vect_read_next_line(Map, Points, Cats);
+ if (type == -1 ) { /* failure */
+ if (columns) {
+ db_close_database(driver);
+ db_shutdown_driver(driver);
+ }
+
+ return -1;
+ }
+
+ if (type == -2) { /* EOF */
+ if (columns) {
+ db_close_database(driver);
+ db_shutdown_driver(driver);
+ }
+ break;
+ }
+ if (!(type & GV_POINT))
+ continue;
+
+ if (region &&
+ !Vect_point_in_box(Points->x[0], Points->y[0],
+ Points->z[0], box))
+ continue;
+
+ if (field > 0 && !(Vect_cat_get(Cats, field, &cat)))
+ continue;
+
+ line++;
+
+ sprintf(buf, "%.*f", dp, Points->x[0]);
+ G_trim_decimal(buf);
+ fprintf(fp, "%s", buf);
+
+ sprintf(buf, "%.*f", dp, Points->y[0]);
+ G_trim_decimal(buf);
+ fprintf(fp, "%s%s", fs, buf);
+
+ /* z coord */
+ if (Map->head.with_z) {
+ sprintf(buf, "%.*f", dp, Points->z[0]);
+ G_trim_decimal(buf);
+ fprintf(fp, "%s%s", fs, buf);
+ }
+
+ Vect_reset_list(fcats);
+ Vect_field_cat_get(Cats, field, fcats);
+
+ if (fcats->n_values > 1) {
+ G_warning(_("Feature has more categories. Only first category (%d) "
+ "is exported."), fcats->value[0]);
+ }
+
+ /* print attributes */
+ if (columns) {
+
+ for(i = 0; columns[i]; i++) {
+
+ sprintf(buf, "SELECT %s FROM %s WHERE %s = %d",
+ columns[i], Fi->table, Fi->key, fcats->value[0]);
+ G_debug(2, "SQL: %s", buf);
+ db_set_string(&dbstring, buf);
+
+ /* original
+ if (db_select_value(driver, Fi->table, Fi->key, fcats->value[0],
+ columns[i], &value) < 0)
+ G_fatal_error(_("Unable to select record from table <%s> (key %s, column %s)"),
+ Fi->table, Fi->key, columns[i]);
+ */
+
+ if (db_open_select_cursor
+ (driver, &dbstring, &cursor, DB_SEQUENTIAL) != DB_OK) {
+ G_fatal_error(_("Cannot select attributes for cat = %d"),
+ fcats->value[0]);
+ }
+ if (db_fetch(&cursor, DB_NEXT, &more) != DB_OK)
+ G_fatal_error(_("Unable to fetch data from table"));
+
+ Table = db_get_cursor_table(&cursor);
+ Column = db_get_table_column(Table, 0);
+ Value = db_get_column_value(Column);
+
+ if (db_test_value_isnull(Value)) {
+ fprintf(fp, "%s", fs);
+ }
+ else {
+ switch(coltypes[i])
+ {
+ case DB_C_TYPE_INT: {
+ if (strcmp(columns[i], "red") == 0 ||
+ strcmp(columns[i], "green") == 0 ||
+ strcmp(columns[i], "blue") == 0 ||
+ strcmp(columns[i], "alpha") == 0)
+
+ fprintf(fp, "%s%d", fs, db_get_value_int(Value));
+ else
+ fprintf(fp, "%s%d", fs, db_get_value_int(Value));
+ break;
+ }
+ case DB_C_TYPE_DOUBLE: {
+ fprintf(fp, "%s%.*f", fs, dp, db_get_value_double(Value));
+ break;
+ }
+ case DB_C_TYPE_STRING: {
+ break;
+ }
+ case DB_C_TYPE_DATETIME: {
+ break;
+ }
+ case -1:
+ G_fatal_error(_("Column <%s> not found in table <%s>"),
+ columns[i], Fi->table);
+ default: G_fatal_error(_("Column <%s>: unsupported data type"),
+ columns[i]);
+ }
+ }
+ db_close_cursor(&cursor);
+ }
+ }
+
+ fprintf(fp, "\n");
+ n_lines++;
+ }
+
+ db_free_string(&dbstring);
+ Vect_destroy_line_struct(Points);
+ Vect_destroy_cats_struct(Cats);
+ Vect_destroy_cats_struct(ACats);
+
+ return n_lines;
+}
Property changes on: grass-addons/grass7/vector/v.out.ply/body.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Added: grass-addons/grass7/vector/v.out.ply/header.c
===================================================================
--- grass-addons/grass7/vector/v.out.ply/header.c (rev 0)
+++ grass-addons/grass7/vector/v.out.ply/header.c 2012-01-21 14:08:27 UTC (rev 50353)
@@ -0,0 +1,108 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <grass/gis.h>
+#include <grass/vector.h>
+#include <grass/dbmi.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+void write_ply_header(FILE *fp, const struct Map_info *Map,
+ const char *input_opt, const char *field_opt,
+ const char **columns, int n_vertices, int dp)
+{
+ int num_dblinks, i;
+
+ struct field_info *fi;
+ dbDriver *driver = NULL;
+ dbHandle handle;
+ dbString table_name;
+ dbTable *table;
+ char *dbltype;
+
+ if (dp > 7)
+ dbltype = G_store("double");
+ else
+ dbltype = G_store("float");
+
+ fprintf(fp, "ply\n");
+ fprintf(fp, "format ascii 1.0\n");
+ fprintf(fp, "comment GRASS generated\n");
+ fprintf(fp, "element vertex %d\n", n_vertices);
+ fprintf(fp, "property %s x\n", dbltype);
+ fprintf(fp, "property %s y\n", dbltype);
+ if (Map->head.with_z)
+ fprintf(fp, "property %s z\n", dbltype);
+
+
+ if (columns) {
+ num_dblinks = Vect_get_num_dblinks(Map);
+
+ if (num_dblinks <= 0) {
+ G_fatal_error(_("Database connection for map <%s> is not defined in DB file"),
+ input_opt);
+ }
+
+ if ((fi = Vect_get_field2(Map, field_opt)) == NULL)
+ G_fatal_error(_("Database connection not defined for layer <%s>"),
+ field_opt);
+ driver = db_start_driver(fi->driver);
+ if (driver == NULL)
+ G_fatal_error(_("Unable to open driver <%s>"),
+ fi->driver);
+ db_init_handle(&handle);
+ db_set_handle(&handle, fi->database, NULL);
+ if (db_open_database(driver, &handle) != DB_OK)
+ G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+ fi->database, fi->driver);
+ db_init_string(&table_name);
+ db_set_string(&table_name, fi->table);
+ if (db_describe_table(driver, &table_name, &table) != DB_OK)
+ G_fatal_error(_("Unable to describe table <%s>"),
+ fi->table);
+
+ for (i = 0; columns[i]; i++) {
+
+ switch(db_column_Ctype(driver, fi->table, columns[i]))
+ {
+ case DB_C_TYPE_INT: {
+ if (strcmp(columns[i], "red") == 0 ||
+ strcmp(columns[i], "green") == 0 ||
+ strcmp(columns[i], "blue") == 0 ||
+ strcmp(columns[i], "alpha") == 0)
+
+ fprintf(fp, "property uchar %s\n", columns[i]);
+ else
+ fprintf(fp, "property int %s\n", columns[i]);
+ break;
+ }
+ case DB_C_TYPE_DOUBLE: {
+ fprintf(fp, "property %s %s\n", dbltype, columns[i]);
+ break;
+ }
+ case DB_C_TYPE_STRING: {
+ break;
+ }
+ case DB_C_TYPE_DATETIME: {
+ break;
+ }
+ case -1:
+ G_fatal_error(_("Column <%s> not found in table <%s>"),
+ columns[i], fi->table);
+ default: G_fatal_error(_("Column <%s>: unsupported data type"),
+ columns[i]);
+ }
+
+ }
+
+ db_close_database(driver);
+ db_shutdown_driver(driver);
+ }
+
+ fprintf(fp, "element face 0\n");
+ fprintf(fp, "property list uchar int vertex_indices\n");
+ fprintf(fp, "end_header\n");
+
+}
Property changes on: grass-addons/grass7/vector/v.out.ply/header.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass7/vector/v.out.ply/local_proto.h
===================================================================
--- grass-addons/grass7/vector/v.out.ply/local_proto.h 2012-01-21 14:06:13 UTC (rev 50352)
+++ grass-addons/grass7/vector/v.out.ply/local_proto.h 2012-01-21 14:08:27 UTC (rev 50353)
@@ -1,5 +1,11 @@
/* args.c */
-void parse_args(int, char **,
- char **, char**, int *, int *, char **,
- char **, char ***, char **, int *, int *, int *,
- struct cat_list **, int *);
+void parse_args(int, char **, char **, char**, int *, int *, char **,
+ char ***, int *);
+
+/* body.c */
+int write_ply_body_ascii(FILE *, struct Map_info *, int, int, int,
+ const char **, struct bound_box *);
+
+/* header.c */
+void write_ply_header(FILE *, const struct Map_info *, const char *,
+ const char *, const char **, int, int);
Modified: grass-addons/grass7/vector/v.out.ply/main.c
===================================================================
--- grass-addons/grass7/vector/v.out.ply/main.c 2012-01-21 14:06:13 UTC (rev 50352)
+++ grass-addons/grass7/vector/v.out.ply/main.c 2012-01-21 14:08:27 UTC (rev 50353)
@@ -1,21 +1,18 @@
-/*
- ****************************************************************************
+/*****************************************************************************
*
- * MODULE: v.out.ascii
- * AUTHOR(S): Michael Higgins, U.S. Army Construction Engineering Research Laboratory
- * James Westervelt, U.S. Army Construction Engineering Research Laboratory
- * Radim Blazek, ITC-Irst, Trento, Italy
- * Martin Landa, CTU in Prague, Czech Republic (v.out.ascii.db merged & update (OGR) for GRASS7)
+ * MODULE: v.out.ply
+ * AUTHOR(S): Markus Metz
+ * based on v.out.ascii
*
- * PURPOSE: Writes GRASS vector data as ASCII files
- * COPYRIGHT: (C) 2000-2009, 2011 by the GRASS Development Team
+ * PURPOSE: Writes GRASS vector data as PLY files
+ *
+ * COPYRIGHT: (C) 2011 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>
@@ -32,113 +29,78 @@
struct GModule *module;
struct Map_info Map;
- FILE *ascii, *att;
- char *input, *output, *delim, **columns, *where, *field_name;
- int format, dp, field, ret, region, old_format, header, type;
- int ver, pnt;
-
- struct cat_list *clist;
+ FILE *fp = NULL;
+ char *input, *output, **columns, *field_name;
+ int format, dp, field, region, type;
+ int pnts, cat;
+ struct Cell_head window;
+ struct bound_box box;
+ struct line_pnts *Points;
+ struct line_cats *Cats;
G_gisinit(argv[0]);
module = G_define_module();
G_add_keyword(_("vector"));
G_add_keyword(_("export"));
- G_add_keyword(_("ascii"));
+ G_add_keyword(_("ply"));
module->description =
_("Exports a vector map to a GRASS ASCII vector representation.");
- parse_args(argc, argv, &input, &output, &format, &dp, &delim,
- &field_name, &columns, &where, ®ion, &old_format, &header,
- &clist, &type);
-
- if (format == GV_ASCII_FORMAT_STD && columns) {
- G_warning(_("Parameter 'column' ignored in standard mode"));
- }
+ parse_args(argc, argv, &input, &output, &format, &dp,
+ &field_name, &columns, ®ion);
- ver = 5;
- pnt = 0;
- if (old_format)
- ver = 4;
+ /* topology not needed */
+ Vect_set_open_level(1);
+ if (Vect_open_old2(&Map, input, "", field_name) < 0)
+ G_fatal_error(_("Unable to open vector map <%s>"), input);
- if (ver == 4 && format == GV_ASCII_FORMAT_POINT) {
- G_fatal_error(_("Format 'point' is not supported for old version"));
- }
-
- if (ver == 4 && strcmp(output, "-") == 0) {
- G_fatal_error(_("'output' must be given for old version"));
- }
-
- /* open with topology only if needed */
- if (format == GV_ASCII_FORMAT_WKT || (format == GV_ASCII_FORMAT_STD &&
- (where || clist))) {
- if (Vect_open_old2(&Map, input, "", field_name) < 2) /* topology required for areas */
- G_warning(_("Unable to open vector map <%s> at topology level. "
- "Areas will not be processed."),
- input);
- }
- else {
- Vect_set_open_level(1); /* topology not needed */
- if (Vect_open_old2(&Map, input, "", field_name) < 0)
- G_fatal_error(_("Unable to open vector map <%s>"), input);
- }
-
field = Vect_get_field_number(&Map, field_name);
if (strcmp(output, "-") != 0) {
- if (ver == 4) {
- ascii = G_fopen_new("dig_ascii", output);
- }
- else if (strcmp(output, "-") == 0) {
- ascii = stdout;
- }
- else {
- ascii = fopen(output, "w");
- }
-
- if (ascii == NULL) {
+ if ((fp = fopen(output, "w")) == NULL) {
G_fatal_error(_("Unable to open file <%s>"), output);
}
}
else {
- ascii = stdout;
+ fp = stdout;
}
- if (format == GV_ASCII_FORMAT_STD) {
- Vect_write_ascii_head(ascii, &Map);
- fprintf(ascii, "VERTI:\n");
- }
+ /* get the region */
+ G_get_window(&window);
+ Vect_region_box(&window, &box);
- /* Open dig_att */
- att = NULL;
- if (ver == 4 && !pnt) {
- if (G_find_file("dig_att", output, G_mapset()) != NULL)
- G_fatal_error(_("dig_att file already exist"));
+ /* count points */
+ Points = Vect_new_line_struct();
+ Cats = Vect_new_cats_struct();
+ pnts = 0;
+ while ((type = Vect_read_next_line(&Map, Points, Cats)) > 0) {
+ if (type == GV_POINT) {
+ if (field > 0 && !(Vect_cat_get(Cats, field, &cat)))
+ continue;
+ if (region &&
+ !Vect_point_in_box(Points->x[0], Points->y[0],
+ Points->z[0], &box))
+ continue;
- if ((att = G_fopen_new("dig_att", output)) == NULL)
- G_fatal_error(_("Unable to open dig_att file <%s>"),
- output);
+ pnts++;
+ }
}
+ if (pnts < 1)
+ G_fatal_error(_("No points found, nothing to be exported"));
- if (where || columns || clist)
+ /* write ply header */
+ write_ply_header(fp, &Map, input, field_name, (const char **)columns, pnts, dp);
+
+ if (columns)
G_message(_("Fetching data..."));
- ret = Vect_write_ascii(ascii, att, &Map, ver, format, dp, delim,
- region, type, field, clist, (const char *)where,
- (const char **)columns, header);
- if (ret < 1) {
- if (format == GV_ASCII_FORMAT_POINT) {
- G_warning(_("No points found, nothing to be exported"));
- }
- else {
- G_warning(_("No features found, nothing to be exported"));
- }
- }
+ write_ply_body_ascii(fp, &Map, dp, region, field,
+ (const char **)columns, &box);
+
- if (ascii != NULL)
- fclose(ascii);
- if (att != NULL)
- fclose(att);
+ if (fp != NULL)
+ fclose(fp);
Vect_close(&Map);
Deleted: grass-addons/grass7/vector/v.out.ply/v.out.ascii.html
===================================================================
--- grass-addons/grass7/vector/v.out.ply/v.out.ascii.html 2012-01-21 14:06:13 UTC (rev 50352)
+++ grass-addons/grass7/vector/v.out.ply/v.out.ascii.html 2012-01-21 14:08:27 UTC (rev 50353)
@@ -1,136 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>v.out.ascii</em> converts a GRASS vector map in binary format to a
-GRASS vector map in <a href="vectorascii.html">ASCII format</a>. Using
-flag <b>-o</b> <em>v.out.ascii</em> output will be in old (version 4)
-ASCII format.
-
-<p>If the <b>output</b> parameter is not given then the coordinates of any
-<em>point</em> data within the vector map is sent to stdout.
-
-<h2>NOTES</h2>
-
-The <em><a href="v.in.ascii.html">v.in.ascii</a></em> module performs
-the function of <em>v.out.ascii</em> in reverse; i.e. it converts
-vector maps in ASCII format to their binary format. These two
-companion module are useful both for importing and exporting vector
-maps between GRASS and other software, and for transferring data
-between machines.
-
-<p>If old version is requested, the <b>output</b> files from <em>v.out.ascii</em> is placed
-in the <tt>$LOCATION/$MAPSET/dig_ascii/</tt> and <tt>$LOCATION/$MAPSET/dig_att</tt> directory.
-
-<p>Only features with a category number will be
-exported. Use <em><a href="v.category.html">v.category</a></em> to add
-them if needed.
-
-<p><em>v.out.ascii</em> does not copy the <tt>dig_cats</tt> file
-associated with the binary vector <b>input</b> map to the
-new <b>output</b> file name. The user must copy the <tt>dig_cats</tt>
-file to the new <b>output</b> name if this is desired (e.g. using the
-UNIX <em>cp</em> command).
-
-<p>It is possible to output the coordinates of vertices in a non-points vector
-feature by first converting the vector feature to a points map with
-<em><a href="v.to.points.html">v.to.points</a></em> and then exporting
-with <em>v.out.ascii</em> in
-<b>points</b> mode.
-
-<h2>EXAMPLES</h2>
-
-<h3>Standard mode</h3>
-
-<p><div class="code"><pre>
-v.out.ascii input=quads format=standard
-
-ORGANIZATION: US Army Const. Eng. Rsch. Lab
-DIGIT DATE: May 1987
-DIGIT NAME: grass
-MAP NAME: Quads
-MAP DATE: May 1987
-MAP SCALE: 24000
-OTHER INFO:
-ZONE: 13
-MAP THRESH: 18.288000
-VERTI:
-B 4
- 599587.1820962 4914067.53414294
- 589639.15126831 4913922.5687301
- 589440.96838162 4927803.62500018
- 599375.87959179 4927959.83330436
-B 2
- 599375.87959179 4927959.83330436
- 599587.1820962 4914067.53414294
-B 4
- 599587.1820962 4914067.53414294
- 609541.5508239 4914236.0597482
- 609316.10665227 4928116.8490555
- 599375.87959179 4927959.83330436
-C 1 1
- 594125.63 4921115.58
- 1 1
-C 1 1
- 604433.84 4921087.1
- 1 2
-</pre></div>
-
-<h3>Point mode</h3>
-
-<div class="code"><pre>
-v.out.ascii input=quads format=point
-
-594125.63|4921115.58|1
-604433.84|4921087.1|2
-</pre></div>
-
-<div class="code"><pre>
-v.out.ascii input=archsites format=point where="cat > 5 and cat <= 8" columns=str1
-
-600375|4925235|6|Prairie Site
-606635|4920773|7|Jensen Pass
-595755|4925300|8|No Name
-</pre></div>
-
-<h3>WKT mode</h3>
-
-WKT is abbreviation
-for <a href="http://en.wikipedia.org/wiki/Well-known_text">Well-known
-text</a>.
-
-<div class="code"><pre>
-v.out.ascii input=quads format=wkt
-
-POLYGON((599587.18209620 4914067.53414294, 589639.15126831 4913922.56873010,
- 589440.96838162 4927803.62500018, 599375.87959179 4927959.83330436,
- 599587.18209620 4914067.53414294))
-POLYGON((599587.18209620 4914067.53414294, 599375.87959179 4927959.83330436,
- 609316.10665227 4928116.84905550, 609541.55082390 4914236.05974820,
- 599587.18209620 4914067.53414294))
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="v.category.html">v.category</a>,
-<a href="v.in.ascii.html">v.in.ascii</a>,
-<a href="v.to.points.html">v.to.points</a><br>
-<a href="vectorascii.html">GRASS ASCII vector format</a> specification<br>
-<a href="sql.html">GRASS SQL interface</a>
-</em>
-
-<h2>AUTHORS</h2>
-
-Michael Higgins,
-U.S. Army Construction Engineering
-Research Laboratory
-<br>
-James Westervelt,
-U.S. Army Construction Engineering
-Research Laboratory
-<br>
-Radim Blazek, ITC-Irst, Trento, Italy
-<br>
-Attribute selection added by Martin Landa, Czech Technical University
-in Prague, Czech Republic (2008/12)
-
-<p><i>Last changed: $Date$</i>
Copied: grass-addons/grass7/vector/v.out.ply/v.out.ply.html (from rev 50352, grass-addons/grass7/vector/v.out.ply/v.out.ascii.html)
===================================================================
--- grass-addons/grass7/vector/v.out.ply/v.out.ply.html (rev 0)
+++ grass-addons/grass7/vector/v.out.ply/v.out.ply.html 2012-01-21 14:08:27 UTC (rev 50353)
@@ -0,0 +1,32 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.out.ply</em> converts a GRASS vector map in binary format to an
+ASCII file in PLY format>. Currently supported is points export only.
+<em>v.out.ply</em> is designed for large point clouds and fairly fast
+if only coordinates are exported. The export of attributes with the
+option <b>columns</b> can slow down the export considerably.
+
+<p>If the <b>output</b> parameter is not given then the coordinates of
+any <em>point</em> data within the vector map is sent to stdout.
+
+
+<h2>REFERENCES</h2>
+
+<a href="http://paulbourke.net/dataformats/ply/">http://paulbourke.net/dataformats/ply/</a>
+<br>
+<a href="http://www.cc.gatech.edu/projects/large_models/ply.html">http://www.cc.gatech.edu/projects/large_models/ply.html</a>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="v.out.ascii.html">v.out.ascii</a>,
+<a href="v.in.ply.html">v.in.ply</a>,
+</em>
+
+<h2>AUTHORS</h2>
+
+Markus Metz
+<br>
+based on <a href="v.out.ascii.html">v.out.ascii</a>
+
+<p><i>Last changed: $Date$</i>
More information about the grass-commit
mailing list