[GRASS-CVS] markus: grass6/vector/v.in.ascii a2b.c, 1.17,
1.17.2.1 description.html, 1.43, 1.43.2.1 in.c, 1.50,
1.50.2.1 points.c, 1.24, 1.24.2.1
grass at intevation.de
grass at intevation.de
Thu Nov 29 08:34:22 EST 2007
Author: markus
Update of /grassrepository/grass6/vector/v.in.ascii
In directory doto:/tmp/cvs-serv19089
Modified Files:
Tag: releasebranch_6_3
a2b.c description.html in.c points.c
Log Message:
sync to head for layout (indent); Precision for latlong (double to string conversion)
Index: a2b.c
===================================================================
RCS file: /grassrepository/grass6/vector/v.in.ascii/a2b.c,v
retrieving revision 1.17
retrieving revision 1.17.2.1
diff -u -d -r1.17 -r1.17.2.1
--- a2b.c 6 Oct 2007 01:54:22 -0000 1.17
+++ a2b.c 29 Nov 2007 13:34:20 -0000 1.17.2.1
@@ -6,158 +6,164 @@
#define BUFFSIZE 128
-int asc_to_bin(
- FILE *ascii ,
- struct Map_info *Map)
+int asc_to_bin(FILE * ascii, struct Map_info *Map)
{
- char ctype ;
- char buff[BUFFSIZE];
- double *xarray ;
- double *yarray ;
- double *zarray ;
- double *x, *y, *z;
- int i, n_points, n_coors, n_cats ;
- int type;
- int alloc_points ;
- int end_of_file ;
- struct line_pnts *Points;
- struct line_cats *Cats;
- int catn;
- int cat;
+ char ctype;
+ char buff[BUFFSIZE];
+ double *xarray;
+ double *yarray;
+ double *zarray;
+ double *x, *y, *z;
+ int i, n_points, n_coors, n_cats;
+ int type;
+ int alloc_points;
+ int end_of_file;
+ struct line_pnts *Points;
+ struct line_cats *Cats;
+ int catn;
+ int cat;
- /* Must always use this to create an initialized line_pnts structure */
- Points = Vect_new_line_struct ();
- Cats = Vect_new_cats_struct ();
+ /* Must always use this to create an initialized line_pnts structure */
+ Points = Vect_new_line_struct();
+ Cats = Vect_new_cats_struct();
- end_of_file = 0 ;
- /*alloc_points = 1000 ; */
- alloc_points = 1;
- xarray = (double *) G_calloc(alloc_points, sizeof(double)) ;
- yarray = (double *) G_calloc(alloc_points, sizeof(double)) ;
- zarray = (double *) G_calloc(alloc_points, sizeof(double)) ;
+ end_of_file = 0;
+ /*alloc_points = 1000 ; */
+ alloc_points = 1;
+ xarray = (double *)G_calloc(alloc_points, sizeof(double));
+ yarray = (double *)G_calloc(alloc_points, sizeof(double));
+ zarray = (double *)G_calloc(alloc_points, sizeof(double));
- while( G_getl2(buff,BUFFSIZE-1,ascii) != 0 )
- {
- n_cats=0;
- if (buff[0] == '\0') {
- G_debug(3, "a2b: skipping blank line");
- continue;
- }
+ while (G_getl2(buff, BUFFSIZE - 1, ascii) != 0) {
+ n_cats = 0;
+ if (buff[0] == '\0') {
+ G_debug(3, "a2b: skipping blank line");
+ continue;
+ }
- if ( sscanf(buff, "%1c%d%d", &ctype, &n_coors, &n_cats) < 2 || n_coors < 0 || n_cats < 0 ) {
- if (ctype == '#') {
- G_debug(2, "a2b: skipping commented line");
- continue;
- }
- G_fatal_error(_("Error reading ASCII file: (bad type) [%s]"), buff);
- }
+ if (sscanf(buff, "%1c%d%d", &ctype, &n_coors, &n_cats) < 2 ||
+ n_coors < 0 || n_cats < 0) {
if (ctype == '#') {
- G_debug(2, "a2b: Skipping commented line");
+ G_debug(2, "a2b: skipping commented line");
continue;
}
+ G_fatal_error(_("Error reading ASCII file: (bad type) [%s]"), buff);
+ }
+ if (ctype == '#') {
+ G_debug(2, "a2b: Skipping commented line");
+ continue;
+ }
- switch(ctype){
- case 'A':
- type = GV_BOUNDARY ;
- break ;
- case 'B':
- type = GV_BOUNDARY ;
- break ;
- case 'C':
- type = GV_CENTROID ;
- break ;
- case 'L':
- type = GV_LINE ;
- break ;
- case 'P':
- type = GV_POINT ;
- break ;
- case 'F':
- type = GV_FACE ;
- break ;
- case 'K':
- type = GV_KERNEL ;
- break ;
- case 'a':
- case 'b':
- case 'c':
- case 'l':
- case 'p':
- type = 0; /* dead -> ignore */
- break;
- default:
- G_fatal_error(_("Error reading ASCII file: (unknown type) [%s]"), buff);
- }
- G_debug(5, "feature type = %d", type);
+ switch (ctype) {
+ case 'A':
+ type = GV_BOUNDARY;
+ break;
+ case 'B':
+ type = GV_BOUNDARY;
+ break;
+ case 'C':
+ type = GV_CENTROID;
+ break;
+ case 'L':
+ type = GV_LINE;
+ break;
+ case 'P':
+ type = GV_POINT;
+ break;
+ case 'F':
+ type = GV_FACE;
+ break;
+ case 'K':
+ type = GV_KERNEL;
+ break;
+ case 'a':
+ case 'b':
+ case 'c':
+ case 'l':
+ case 'p':
+ type = 0; /* dead -> ignore */
+ break;
+ default:
+ G_fatal_error(_("Error reading ASCII file: (unknown type) [%s]"),
+ buff);
+ }
+ G_debug(5, "feature type = %d", type);
- n_points = 0 ;
- x = xarray ;
- y = yarray ;
- z = zarray ;
+ n_points = 0;
+ x = xarray;
+ y = yarray;
+ z = zarray;
- /* Collect the points */
- for( i=0; i<n_coors; i++)
- {
- if ( G_getl2(buff,BUFFSIZE-1,ascii) == 0 )
- G_fatal_error(_("End of ASCII file reached before end of coordinates")) ;
+ /* Collect the points */
+ for (i = 0; i < n_coors; i++) {
+ if (G_getl2(buff, BUFFSIZE - 1, ascii) == 0)
+ G_fatal_error(_
+ ("End of ASCII file reached before end of coordinates"));
- if (buff[0] == '\0') {
- G_debug(3, "a2b: skipping blank line while reading vertices");
- i--;
- continue;
- }
+ if (buff[0] == '\0') {
+ G_debug(3, "a2b: skipping blank line while reading vertices");
+ i--;
+ continue;
+ }
- *z=0;
- if ( sscanf(buff, "%lf%lf%lf", x, y, z) < 2 )
- G_fatal_error(_("Error reading ASCII file: (bad point) [%s]"), buff);
+ *z = 0;
+ if (sscanf(buff, "%lf%lf%lf", x, y, z) < 2)
+ G_fatal_error(_("Error reading ASCII file: (bad point) [%s]"),
+ buff);
- G_debug( 5, "coor in: %s -> x = %f y = %f z = %f", G_chop(buff), *x, *y, *z);
-
- n_points++;
- x++;
- y++;
- z++;
-
- if (n_points >= alloc_points)
- {
- alloc_points = n_points + 1000 ;
- xarray = (double *) G_realloc((void *)xarray, alloc_points * sizeof(double) );
- yarray = (double *) G_realloc((void *)yarray, alloc_points * sizeof(double) );
- zarray = (double *) G_realloc((void *)zarray, alloc_points * sizeof(double) );
- x = xarray + n_points ;
- y = yarray + n_points ;
- z = zarray + n_points ;
- }
- }
+ G_debug(5, "coor in: %s -> x = %f y = %f z = %f", G_chop(buff), *x,
+ *y, *z);
- /* Collect the cats */
- for( i=0; i<n_cats; i++)
- {
- if ( G_getl2(buff,BUFFSIZE-1,ascii) == 0 )
- G_fatal_error(_("End of ASCII file reached before end of categories"));
+ n_points++;
+ x++;
+ y++;
+ z++;
- if (buff[0] == '\0') {
- G_debug(3, "a2b: skipping blank line while reading category info");
- i--;
- continue;
- }
+ if (n_points >= alloc_points) {
+ alloc_points = n_points + 1000;
+ xarray =
+ (double *)G_realloc((void *)xarray,
+ alloc_points * sizeof(double));
+ yarray =
+ (double *)G_realloc((void *)yarray,
+ alloc_points * sizeof(double));
+ zarray =
+ (double *)G_realloc((void *)zarray,
+ alloc_points * sizeof(double));
+ x = xarray + n_points;
+ y = yarray + n_points;
+ z = zarray + n_points;
+ }
+ }
- if ( sscanf(buff, "%u%u", &catn, &cat) != 2 )
- G_fatal_error(_("Error reading categories: [%s]"), buff);
+ /* Collect the cats */
+ for (i = 0; i < n_cats; i++) {
+ if (G_getl2(buff, BUFFSIZE - 1, ascii) == 0)
+ G_fatal_error(_
+ ("End of ASCII file reached before end of categories"));
- Vect_cat_set ( Cats, catn, cat );
+ if (buff[0] == '\0') {
+ G_debug(3,
+ "a2b: skipping blank line while reading category info");
+ i--;
+ continue;
}
- /* Allocation is handled for line_pnts */
- if (0 > Vect_copy_xyz_to_pnts (Points, xarray, yarray, zarray, n_points))
- G_fatal_error(_("Out of memory"));
+ if (sscanf(buff, "%u%u", &catn, &cat) != 2)
+ G_fatal_error(_("Error reading categories: [%s]"), buff);
- if ( type > 0 )
- Vect_write_line ( Map, type, Points, Cats );
-
- Vect_reset_cats ( Cats );
+ Vect_cat_set(Cats, catn, cat);
}
- return 0;
-}
+ /* Allocation is handled for line_pnts */
+ if (0 > Vect_copy_xyz_to_pnts(Points, xarray, yarray, zarray, n_points))
+ G_fatal_error(_("Out of memory"));
+
+ if (type > 0)
+ Vect_write_line(Map, type, Points, Cats);
+
+ Vect_reset_cats(Cats);
+ }
+ return 0;
+}
Index: description.html
===================================================================
RCS file: /grassrepository/grass6/vector/v.in.ascii/description.html,v
retrieving revision 1.43
retrieving revision 1.43.2.1
diff -u -d -r1.43 -r1.43.2.1
--- description.html 26 Jul 2007 02:34:14 -0000 1.43
+++ description.html 29 Nov 2007 13:34:20 -0000 1.43.2.1
@@ -2,64 +2,61 @@
<em>v.in.ascii</em> converts a vector map in ASCII format to a vector map in
binary format. The module may import two formats:
-<DL>
-<DT><b>standard</b><DD> contains all data types, each coordinate on one row
-<DT><b>point</b><DD> (default) reads only points, each point defined on one row.
- Values are separated by a user definable deliminator. If the 'columns' option is not defined,
- default names are used. It is possible to specify the column order for the
- x,y,z coordinates and category values.
-</DL>
-
+<ul>
+<li><b>standard</b> contains all data types, each coordinate on one row</li>
+<li><b>point</b> (default) reads only points, each point defined on
+ one row. Values are separated by a user definable deliminator. If
+ the <b>columns</b> option is not defined, default names are used. It
+ is possible to specify the column order for the x,y,z coordinates
+ and category values.</li>
+</ul>
-<P>
-The <em><a HREF="v.out.ascii.html">v.out.ascii</a></em> GRASS module
-performs the function of <em>v.in.ascii</em> in reverse;
-i.e., it converts vector maps in binary format to ASCII
-format. These two companion programs are useful both for
-importing and exporting vector maps between GRASS and
-other software, and for transferring data between
+<p>
+The <a HREF="v.out.ascii.html">v.out.ascii</a> GRASS module performs
+the function of <em>v.in.ascii</em> in reverse; i.e., it converts
+vector maps in binary format to ASCII format. These two companion
+programs are useful both for importing and exporting vector maps
+between GRASS and other software, and for transferring data between
machines.
-
<h2>NOTES</h2>
-
-The input is read from the file specified by the <B>input</B> option or
+The input is read from the file specified by the <b>input</b> option or
from standard input.
-<P>
+<p>
The field separator may be a character, the word '<tt>tab</tt>'
(or '<tt>\t</tt>') for tab, or '<tt>space</tt>' (or ' ') for a blank.
-<P>
+<p>
Attribute table is only created if it is needed, i.e. when at
least one attribute column is present in the input file besides
geometry columns. The attribute column will be auto-scanned for type, but
may be explicitly declared along with the geometry columns using the
-<em>columns</em> parameter.
+<b>columns</b> parameter.
-<P>
+<p>
Latitude/Longitude data may be given in a number of ways.
Decimal degrees must be positive or negative instead of using a hemisphere
letter. Mixed coordinates must use a hemisphere letter. Whole minutes and
seconds must always contain two digits (example: use <tt>167:03:04.567</tt>;
and not <tt>167:3:4.567</tt>).
-<BR><BR>
-Acceptable formats:<BR>
+<br><br>
+Acceptable formats:<br>
<i>key: D=Degrees; M=Minutes; S=Seconds; h=Hemisphere (N,S,E,W)</i>
<ul>
-<li><tt>(+/-)DDD.DDDDD</tt>
-<li><tt>DDDh</tt>
-<li><tt>DDD:MMh</tt>
-<li><tt>DDD:MM.MMMMMh</tt>
-<li><tt>DDD:MM:SSh</tt>
-<li><tt>DDD:MM:SS.SSSSSh</tt>
+ <li><tt>(+/-)DDD.DDDDD</tt>
+ <li><tt>DDDh</tt>
+ <li><tt>DDD:MMh</tt>
+ <li><tt>DDD:MM.MMMMMh</tt>
+ <li><tt>DDD:MM:SSh</tt>
+ <li><tt>DDD:MM:SS.SSSSSh</tt>
</ul>
-<P>
-Use the <b>-z</b> flag to convert ASCII data into a 3D map.
+<p>
+Use the <b>-z</b> flag to convert ASCII data into a 3D vector map.
-<P>
+<p>
In special cases of data import, such as the import of large LIDAR datasets
(millions of data points), it may be necessary to disable topology support
(creating a GRASS vector level 1 vector map) due to memory constraints.
@@ -70,35 +67,78 @@
or within a subregion (the <b>-r</b> flag) before resorting the to
disabling of topology.
-<P>
-A GRASS ASCII vector map (in <B>standard</B> mode) may contain a mix of
-primitives including points, lines, boundaries, centroids, areas, faces,
-and kernels. This format is described in the
-<a HREF="http://freegis.org/cgi-bin/viewcvs.cgi/~checkout~/grass6/doc/vector/vector.html#ascii">GRASS Vector ASCII Format Specification</a>.
-On top a header can be defined (see example below).
-The header is not required if the <b>-n</b> flag is used.
+<p>
+A GRASS ASCII vector map (in <B>standard</B> mode) may contain a mix
+of primitives including points, lines, boundaries, centroids, areas,
+faces, and kernels.
+<!--This format is described in the
+<a HREF="http://freegis.org/cgi-bin/viewcvs.cgi/~checkout~/grass6/doc/vector/vector.html#ascii">GRASS
+Vector ASCII Format Specification</a>.--> On top a header can be
+defined (see example below). The header is not required if
+the <b>-n</b> flag is used.
-<P>
+<p>The header is similar as the head file of vector binary format but
+contains bounding box also. Key words are:
+
+<pre>
+ORGANIZATION
+DIGIT DATE
+DIGIT NAME
+MAP NAME
+MAP DATE
+MAP SCALE
+OTHER INFO
+ZONE
+WEST EDGE
+EAST EDGE
+SOUTH EDGE
+NORTH EDGE
+MAP THRESH
+</pre>
+
+<p>The body begins with the row:
+
+<pre>
+VERTI:
+</pre>
+
+followed by records of primitives:
+
+<pre>
+TYPE NUMBER_OF_COORDINATES [NUMBER_OF_CATEGORIES]
+ X Y [Z]
+....
+ X Y [Z]
+[ LAYER CATEGORY]
+....
+[ LAYER CATEGORY]
+</pre>
+
+Everything above in <tt>[ ]</tt> is optional.
+
+<p>
The primitive codes are as follows:
-<UL>
-<LI>'P': point</LI>
-<LI>'L': line</LI>
-<LI>'B': boundary</LI>
-<LI>'C': centroid</LI>
-<LI>'F': face (3D boundary)</LI>
-<LI>'K': kernel (3D centroid)</LI>
-<LI>'A': area (boundary) - better use 'B'; kept only for backward compatibility</LI>
-</UL>
+<ul>
+<li>'P': point</li>
+<li>'L': line</li>
+<li>'B': boundary</li>
+<li>'C': centroid</li>
+<li>'F': face (3D boundary)</li>
+<li>'K': kernel (3D centroid)</li>
+<li>'A': area (boundary) - better use 'B'; kept only for backward
+compatibility</li>
+</ul>
The coordinates are listed following the initial line containing the
primitive code, the total number of vectors in the series, and (optionally)
the number of categories (1 for a single layer, higher for multiple layers).
Below that 1 or several lines follow to indicate the layer number and
the category number (ID).
-<BR>
-The order of coordinates is <BR>
+<br>
+The order of coordinates is
+<pre>
X Y [Z]
-
+</pre>
<h3>Import of files without category ID column</h3>
@@ -109,7 +149,6 @@
(<tt>cat=0</tt>). This is the default action if the <b>cat</b> parameter
is not set.
-
<h3>Importing from a spreadsheet</h3>
Data may be imported from many spreadsheet programs by saving the
@@ -125,7 +164,6 @@
in the header, as defined by the <b>skip</b> parameter, it will be treated as
a header line and written to the history file.
-
<h3>Import of sexagesimal degree (degree, minutes, seconds, DMS)</h3>
The import of DMS formatted degrees is supported (in this case no
@@ -216,12 +254,12 @@
1663709|5102614
</pre></div>
-<P>
+<p>
Import into GRASS:
<div class="code"><pre>
v.in.ascii input=coords.txt output=mymap
</pre></div>
-As the <em>cat</em> option is set to 0 by default, an extra column 'cat'
+As the <b>cat</b> option is set to 0 by default, an extra column 'cat'
containing the IDs will be auto-generated.
<h3>Example 3</h3>
@@ -235,17 +273,16 @@
5|1663709|5102614|mineralni pramen
</pre></div>
-<P>
+<p>
Import into GRASS:
<div class="code"><pre>
cat points.dat | v.in.ascii out=mypoints x=2 y=3 cat=1 \
columns='cat int, x double precision, y double precision, label varchar(20)'
</pre></div>
-<P>
+<p>
The module is reading from standard input, using the default '|' (pipe) delimiter.
-
<h3>Example 4</h3>
Generating a 3D points vector map from DBMS (idcol must be an integer column):<br>
@@ -272,7 +309,7 @@
<P>
Import into GRASS:
<div class="code"><pre>
-#As the <em>cat</em> option is set to 0 by default, an extra column 'cat'
+#As the 'cat' option is set to 0 by default, an extra column 'cat'
#containing the IDs will be auto-generated (no need to define that):
cat points3d.dat | v.in.ascii -z z=3 cat=0 out=mypoints3D \
columns='x double precision, y double precision, z double precision, \
@@ -307,25 +344,25 @@
col='x double precision, y double precision, x_target double precision, \
y_target double precision, ok int'
</pre></div>
-<BR>
-<h2>SEE ALSO</h2>
+<h2>REFERENCES</h2>
-<EM>
-<a HREF="db.execute.html">db.execute</a><BR>
-<a HREF="r.in.ascii.html">r.in.ascii</a><BR>
-<a HREF="r.in.xyz.html">r.in.xyz</a><BR>
-<a HREF="v.db.connect.html">v.db.connect</a><BR>
-<a HREF="v.out.ascii.html">v.out.ascii</a><BR>
-<a HREF="v.info.html">v.info</a><BR>
-<a HREF="v.build.html">v.build</a><BR>
-<a HREF="v.build.polylines.html">v.build.polylines</a><BR>
-<a HREF="v.centroids.html">v.centroids</a><BR>
-<a HREF="v.clean.html">v.clean</a><BR>
-</EM>
-<a HREF="sql.html">SQL command notes</a> for creating databases<BR>
-<a HREF="http://freegis.org/cgi-bin/viewcvs.cgi/~checkout~/grass6/doc/vector/vector.html#ascii">Vector ASCII Format Specification</a>
+<a HREF="sql.html">SQL command notes</a> for creating databases
+<h2>SEE ALSO</h2>
+
+<em>
+<a HREF="db.execute.html">db.execute</a>,
+<a HREF="r.in.ascii.html">r.in.ascii</a>,
+<a HREF="r.in.xyz.html">r.in.xyz</a>,
+<a HREF="v.db.connect.html">v.db.connect</a>,
+<a HREF="v.out.ascii.html">v.out.ascii</a>,
+<a HREF="v.info.html">v.info</a>,
+<a HREF="v.build.html">v.build</a>,
+<a HREF="v.build.polylines.html">v.build.polylines</a>,
+<a HREF="v.centroids.html">v.centroids</a>,
+<a HREF="v.clean.html">v.clean</a>
+</em>
<h2>AUTHORS</h2>
Index: in.c
===================================================================
RCS file: /grassrepository/grass6/vector/v.in.ascii/in.c,v
retrieving revision 1.50
retrieving revision 1.50.2.1
diff -u -d -r1.50 -r1.50.2.1
--- in.c 14 Oct 2007 16:43:29 -0000 1.50
+++ in.c 29 Nov 2007 13:34:20 -0000 1.50.2.1
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: v.in.ascii
@@ -26,474 +27,513 @@
#define A_DIR "dig_ascii"
-int
-main (int argc, char *argv[])
+int main(int argc, char *argv[])
{
- FILE *ascii;
- struct GModule *module;
- struct Option *old, *new, *delim_opt, *columns_opt, *xcol_opt,
- *ycol_opt, *zcol_opt, *catcol_opt, *format_opt, *skip_opt;
- int xcol, ycol, zcol, catcol, format, skip_lines;
- struct Flag *zcoorf, *t_flag, *e_flag, *noheader_flag, *notopol_flag, *region_flag;
- char *table;
- char *fs;
- int zcoor=WITHOUT_Z, make_table;
+ FILE *ascii;
+ struct GModule *module;
+ struct Option *old, *new, *delim_opt, *columns_opt, *xcol_opt,
+ *ycol_opt, *zcol_opt, *catcol_opt, *format_opt, *skip_opt;
+ int xcol, ycol, zcol, catcol, format, skip_lines;
+ struct Flag *zcoorf, *t_flag, *e_flag, *noheader_flag, *notopol_flag,
+ *region_flag;
+ char *table;
+ char *fs;
+ int zcoor = WITHOUT_Z, make_table;
- struct Map_info Map;
+ struct Map_info Map;
- G_gisinit(argv[0]);
+ G_gisinit(argv[0]);
- module = G_define_module();
- module->keywords = _("vector, import");
- module->description =
- _("Creates a vector map from ASCII points file or ASCII vector file.");
+ module = G_define_module();
+ module->keywords = _("vector, import");
+ module->description =
+ _("Creates a vector map from ASCII points file or ASCII vector file.");
- /************************** Command Parser ************************************/
- old = G_define_standard_option (G_OPT_F_INPUT);
- old->required = NO;
- old->description =
- _("ASCII file to be imported, if not given reads from standard input");
+ /************************** Command Parser ************************************/
+ old = G_define_standard_option(G_OPT_F_INPUT);
+ old->required = NO;
+ old->description =
+ _("ASCII file to be imported, if not given reads from standard input");
- new = G_define_standard_option(G_OPT_V_OUTPUT);
+ new = G_define_standard_option(G_OPT_V_OUTPUT);
- format_opt = G_define_option();
- format_opt->key = "format";
- format_opt->type = TYPE_STRING;
- format_opt->required = NO;
- format_opt->multiple = NO;
- format_opt->options = "point,standard";
- format_opt->answer = "point";
- format_opt->description = _("Input file format");
+ format_opt = G_define_option();
+ format_opt->key = "format";
+ format_opt->type = TYPE_STRING;
+ format_opt->required = NO;
+ format_opt->multiple = NO;
+ format_opt->options = "point,standard";
+ format_opt->answer = "point";
+ format_opt->description = _("Input file format");
- delim_opt = G_define_option();
- delim_opt->key = "fs";
- delim_opt->type = TYPE_STRING;
- delim_opt->required = NO;
- delim_opt->description = _("Field separator");
- delim_opt->answer = "|";
+ delim_opt = G_define_standard_option(G_OPT_F_SEP);
- skip_opt = G_define_option();
- skip_opt->key = "skip";
- skip_opt->type = TYPE_INTEGER;
- skip_opt->required = NO;
- skip_opt->multiple = NO;
- skip_opt->answer = "0";
- skip_opt->description =
- _("Number of header lines to skip at top of input file (points mode)");
+ skip_opt = G_define_option();
+ skip_opt->key = "skip";
+ skip_opt->type = TYPE_INTEGER;
+ skip_opt->required = NO;
+ skip_opt->multiple = NO;
+ skip_opt->answer = "0";
+ skip_opt->description =
+ _("Number of header lines to skip at top of input file (points mode)");
- columns_opt = G_define_option();
- columns_opt->key = "columns";
- columns_opt->type = TYPE_STRING;
- columns_opt->required = NO;
- columns_opt->multiple = NO;
- columns_opt->guisection = _("Columns");
- columns_opt->label = _("Column definition in SQL style (points mode)");
- columns_opt->description = _("For example: "
- "'x double precision, y double precision, cat int, name varchar(10)'");
+ columns_opt = G_define_standard_option(G_OPT_COLUMNS);
+ columns_opt->multiple = NO;
+ columns_opt->guisection = _("Columns");
+ columns_opt->label = _("Column definition in SQL style (points mode)");
+ columns_opt->description = _("For example: "
+ "'x double precision, y double precision, cat int, "
+ "name varchar(10)'");
- xcol_opt = G_define_option();
- xcol_opt->key = "x";
- xcol_opt->type = TYPE_INTEGER;
- xcol_opt->required = NO;
- xcol_opt->multiple = NO;
- xcol_opt->answer = "1";
- xcol_opt->guisection = _("Columns");
- xcol_opt->description =
- _("Number of column used as x coordinate (first column is 1) for points mode");
+ xcol_opt = G_define_option();
+ xcol_opt->key = "x";
+ xcol_opt->type = TYPE_INTEGER;
+ xcol_opt->required = NO;
+ xcol_opt->multiple = NO;
+ xcol_opt->answer = "1";
+ xcol_opt->guisection = _("Columns");
+ xcol_opt->description =
+ _
+ ("Number of column used as x coordinate (first column is 1) for points mode");
- ycol_opt = G_define_option();
- ycol_opt->key = "y";
- ycol_opt->type = TYPE_INTEGER;
- ycol_opt->required = NO;
- ycol_opt->multiple = NO;
- ycol_opt->answer = "2";
- ycol_opt->guisection = _("Columns");
- ycol_opt->description =
- _("Number of column used as y coordinate (first column is 1) for points mode");
+ ycol_opt = G_define_option();
+ ycol_opt->key = "y";
+ ycol_opt->type = TYPE_INTEGER;
+ ycol_opt->required = NO;
+ ycol_opt->multiple = NO;
+ ycol_opt->answer = "2";
+ ycol_opt->guisection = _("Columns");
+ ycol_opt->description =
+ _
+ ("Number of column used as y coordinate (first column is 1) for points mode");
- zcol_opt = G_define_option();
- zcol_opt->key = "z";
- zcol_opt->type = TYPE_INTEGER;
- zcol_opt->required = NO;
- zcol_opt->multiple = NO;
- zcol_opt->answer = "0";
- zcol_opt->guisection = _("Columns");
- zcol_opt->label =
- _("Number of column used as z coordinate (first column is 1) for "
- "points mode");
- zcol_opt->description =
- _("If 0, z coordinate is not used");
+ zcol_opt = G_define_option();
+ zcol_opt->key = "z";
+ zcol_opt->type = TYPE_INTEGER;
+ zcol_opt->required = NO;
+ zcol_opt->multiple = NO;
+ zcol_opt->answer = "0";
+ zcol_opt->guisection = _("Columns");
+ zcol_opt->label =
+ _("Number of column used as z coordinate (first column is 1) for "
+ "points mode");
+ zcol_opt->description = _("If 0, z coordinate is not used");
- catcol_opt = G_define_option();
- catcol_opt->key = "cat";
- catcol_opt->type = TYPE_INTEGER;
- catcol_opt->required = NO;
- catcol_opt->multiple = NO;
- catcol_opt->answer = "0";
- catcol_opt->guisection = _("Columns");
- catcol_opt->label =
- _("Number of column used as category (first column is 1) for points mode");
- catcol_opt->description =
- _("If 0, unique category is assigned to each row and written to new column 'cat'");
+ catcol_opt = G_define_option();
+ catcol_opt->key = "cat";
+ catcol_opt->type = TYPE_INTEGER;
+ catcol_opt->required = NO;
+ catcol_opt->multiple = NO;
+ catcol_opt->answer = "0";
+ catcol_opt->guisection = _("Columns");
+ catcol_opt->label =
+ _
+ ("Number of column used as category (first column is 1) for points mode");
+ catcol_opt->description =
+ _
+ ("If 0, unique category is assigned to each row and written to new column 'cat'");
- zcoorf = G_define_flag ();
- zcoorf->key = 'z';
- zcoorf->description = _("Create 3D file");
+ zcoorf = G_define_flag();
+ zcoorf->key = 'z';
+ zcoorf->description = _("Create 3D file");
- e_flag = G_define_flag();
- e_flag->key = 'e';
- e_flag->description =
- _("Create a new empty map and exit. Nothing is read from input");
+ e_flag = G_define_flag();
+ e_flag->key = 'e';
+ e_flag->description =
+ _("Create a new empty map and exit. Nothing is read from input");
- noheader_flag = G_define_flag();
- noheader_flag->key = 'n';
- noheader_flag->description =
- _("Don't expect a header when reading in standard format");
+ noheader_flag = G_define_flag();
+ noheader_flag->key = 'n';
+ noheader_flag->description =
+ _("Don't expect a header when reading in standard format");
- t_flag = G_define_flag();
- t_flag->key = 't';
- t_flag->description = _("Do not create table in points mode");
+ t_flag = G_define_flag();
+ t_flag->key = 't';
+ t_flag->description = _("Do not create table in points mode");
- notopol_flag = G_define_flag();
- notopol_flag->key = 'b';
- notopol_flag->description = _("Do not build topology in points mode");
+ notopol_flag = G_define_flag();
+ notopol_flag->key = 'b';
+ notopol_flag->description = _("Do not build topology in points mode");
- region_flag = G_define_flag();
- region_flag->key = 'r';
- region_flag->description =
- _("Only import points falling within current region (points mode)");
+ region_flag = G_define_flag();
+ region_flag->key = 'r';
+ region_flag->description =
+ _("Only import points falling within current region (points mode)");
- if (G_parser (argc, argv))
- exit(EXIT_FAILURE);
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
- if ( format_opt->answer[0] == 'p' )
- format = FORMAT_POINT;
- else
- format = FORMAT_ALL;
+ if (format_opt->answer[0] == 'p')
+ format = FORMAT_POINT;
+ else
+ format = FORMAT_ALL;
- skip_lines = atoi(skip_opt->answer);
- if(skip_lines < 0)
- G_fatal_error(_("Please specify reasonable number of lines to skip"));
+ skip_lines = atoi(skip_opt->answer);
+ if (skip_lines < 0)
+ G_fatal_error(_("Please specify reasonable number of lines to skip"));
- if (zcoorf->answer && format == FORMAT_POINT && zcol_opt->answer == "0")
- G_fatal_error(_("Please specify z column"));
+ if (zcoorf->answer && format == FORMAT_POINT && !zcol_opt->answer)
+ G_fatal_error(_("Please specify z column"));
- xcol = atoi(xcol_opt->answer) - 1;
- ycol = atoi(ycol_opt->answer) - 1;
- zcol = atoi(zcol_opt->answer) - 1;
+ xcol = atoi(xcol_opt->answer) - 1;
+ ycol = atoi(ycol_opt->answer) - 1;
+ zcol = atoi(zcol_opt->answer) - 1;
- /* specifying zcol= implies that a 3D map is needed */
- if(zcol>=0 && !zcoorf->answer)
- zcoorf->answer = 1;
+ /* specifying zcol= implies that a 3D map is needed */
+ if (zcol >= 0 && !zcoorf->answer)
+ zcoorf->answer = 1;
- if (zcoorf->answer && format == FORMAT_POINT && zcol < 0)
- G_fatal_error(_("Please specify reasonable z column"));
+ if (zcoorf->answer && format == FORMAT_POINT && zcol < 0)
+ G_fatal_error(_("Please specify reasonable z column"));
- catcol = atoi(catcol_opt->answer) - 1;
+ catcol = atoi(catcol_opt->answer) - 1;
- if ( old->answer != NULL ) {
- if ( (ascii = fopen ( old->answer, "r" ) ) == NULL )
- {
- G_fatal_error(_("Unable to open ASCII file <%s>"), old->answer);
- }
- } else {
- ascii = stdin;
- }
+ if (old->answer != NULL) {
+ if ((ascii = fopen(old->answer, "r")) == NULL) {
+ G_fatal_error(_("Unable to open ASCII file <%s>"), old->answer);
+ }
+ }
+ else {
+ ascii = stdin;
+ }
- fs = delim_opt->answer;
- if ( strcmp(fs,"\\t") == 0 ) fs = "\t";
- if ( strcmp(fs,"tab") == 0 ) fs = "\t";
- if ( strcmp(fs,"space") == 0 ) fs = " ";
+ fs = delim_opt->answer;
+ if (strcmp(fs, "\\t") == 0)
+ fs = "\t";
+ if (strcmp(fs, "tab") == 0)
+ fs = "\t";
+ if (strcmp(fs, "space") == 0)
+ fs = " ";
- /* check dimension */
- if (zcoorf->answer) {
- zcoor = 1;
- }
+ /* check dimension */
+ if (zcoorf->answer) {
+ zcoor = 1;
+ }
- Vect_open_new (&Map, new->answer, zcoor);
- Vect_hist_command ( &Map );
+ Vect_open_new(&Map, new->answer, zcoor);
+ Vect_hist_command(&Map);
- if ( e_flag->answer ) {
- Vect_build ( &Map, stdout );
- Vect_close ( &Map );
- exit(EXIT_SUCCESS) ;
+ if (e_flag->answer) {
+ Vect_build(&Map, stdout);
+ Vect_close(&Map);
+ exit(EXIT_SUCCESS);
+ }
+
+ if (format == FORMAT_POINT) {
+ int i, rowlen, ncols, minncols, *coltype, *coltype2, *collen;
+ int n_int = 0, n_double = 0, n_string = 0;
+ char buf[1000];
+ struct field_info *Fi;
+ char *tmp, *key;
+ dbDriver *driver;
+ dbString sql;
+ FILE *tmpascii;
+
+ /* Open temporary file */
+ tmp = G_tempfile();
+ if (NULL == (tmpascii = fopen(tmp, "w+"))) {
+ G_fatal_error(_("Unable to open temporary file <%s>"), tmp);
}
+ unlink(tmp);
- if ( format == FORMAT_POINT ) {
- int i, rowlen, ncols, minncols, *coltype, *coltype2, *collen;
- int n_int = 0, n_double = 0, n_string = 0;
- char buf[1000];
- struct field_info *Fi;
- char *tmp, *key;
- dbDriver *driver;
- dbString sql;
- FILE *tmpascii;
+ points_analyse(ascii, tmpascii, fs, &rowlen, &ncols, &minncols,
+ &coltype, &collen, skip_lines, xcol, ycol,
+ region_flag->answer);
- /* Open temporary file */
- tmp = G_tempfile();
- if (NULL == (tmpascii = fopen(tmp, "w+"))) {
- G_fatal_error(_("Unable to open temporary file <%s>"), tmp);
- }
- unlink(tmp);
+ G_message(_("Maximum input row length: %d"), rowlen);
+ G_message(_("Maximum number of columns: %d"), ncols);
+ G_message(_("Minimum number of columns: %d"), minncols);
- points_analyse ( ascii, tmpascii, fs, &rowlen, &ncols, &minncols,
- &coltype, &collen, skip_lines, xcol, ycol, region_flag->answer);
+ /* check column numbers */
+ if (xcol >= minncols) {
+ Vect_delete(new->answer);
+ G_fatal_error(_
+ ("x column number > minimum last column number\n(incorrect field separator?)"));
+ }
+ if (ycol >= minncols) {
+ Vect_delete(new->answer);
+ G_fatal_error(_
+ ("y column number > minimum last column number\n(incorrect field separator?)"));
+ }
+ if (zcol >= minncols) {
+ Vect_delete(new->answer);
+ G_fatal_error(_("z column number > minimum last column number "
+ "(incorrect field separator?)"));
+ }
+ if (catcol >= minncols) {
+ Vect_delete(new->answer);
+ G_fatal_error(_("cat column number > minimum last column number "
+ "(incorrect field separator?)"));
+ }
- G_message(_("Maximum input row length: %d"), rowlen);
- G_message(_("Maximum number of columns: %d"), ncols);
- G_message(_("Minimum number of columns: %d"), minncols);
+ if (coltype[xcol] == DB_C_TYPE_STRING) {
+ Vect_delete(new->answer);
+ G_fatal_error(_("x column is not of number type"));
+ }
+ if (coltype[ycol] == DB_C_TYPE_STRING) {
+ Vect_delete(new->answer);
+ G_fatal_error(_("y column is not of number type"));
+ }
+ if (zcol >= 0 && coltype[zcol] == DB_C_TYPE_STRING) {
+ Vect_delete(new->answer);
+ G_fatal_error(_("z column is not of number type"));
+ }
+ if (catcol >= 0 && coltype[catcol] == DB_C_TYPE_STRING) {
+ Vect_delete(new->answer);
+ G_fatal_error(_("cat column is not of number type"));
+ }
- /* check column numbers */
- if ( xcol >= minncols ) {
- Vect_delete(new->answer);
- G_fatal_error(_("x column number > minimum last column number\n(incorrect field separator?)"));
- }
- if ( ycol >= minncols ) {
- Vect_delete(new->answer);
- G_fatal_error(_("y column number > minimum last column number\n(incorrect field separator?)"));
- }
- if ( zcol >= minncols ) {
- Vect_delete(new->answer);
- G_fatal_error(_("z column number > minimum last column number\n(incorrect field separator?)"));
+ /* Create table */
+ make_table = 0;
+ for (i = 0; i < ncols; i++) {
+ if (xcol != i && ycol != i && zcol != i && catcol != i) {
+ make_table = 1;
+ break;
}
- if ( catcol >= minncols ) {
+ }
+ if (t_flag->answer) {
+ make_table = 0;
+ }
+
+ if (make_table) {
+ Fi = Vect_default_field_info(&Map, 1, NULL, GV_1TABLE);
+ driver =
+ db_start_driver_open_database(Fi->driver,
+ Vect_subst_var(Fi->database,
+ &Map));
+ if (driver == NULL) {
Vect_delete(new->answer);
- G_fatal_error(_("cat column number > minimum last column number\n(incorrect field separator?)"));
+ G_fatal_error(_("Unavle to open database <%s> by driver <%s>"),
+ Vect_subst_var(Fi->database, &Map), Fi->driver);
}
+ db_begin_transaction(driver);
- if ( coltype[xcol] == DB_C_TYPE_STRING ) {
- Vect_delete(new->answer);
- G_fatal_error(_("x column is not of number type"));
- }
- if ( coltype[ycol] == DB_C_TYPE_STRING ) {
- Vect_delete(new->answer);
- G_fatal_error(_("y column is not of number type"));
- }
- if ( zcol >= 0 && coltype[zcol] == DB_C_TYPE_STRING ) {
- Vect_delete(new->answer);
- G_fatal_error(_("z column is not of number type"));
+ db_init_string(&sql);
+ sprintf(buf, "create table %s ( ", Fi->table);
+ db_append_string(&sql, buf);
+
+ if (catcol < 0) {
+ db_append_string(&sql, "cat integer, ");
}
- if ( catcol >= 0 && coltype[catcol] == DB_C_TYPE_STRING ) {
+
+ for (i = 0; i < ncols; i++) {
+ if (i > 0 && !columns_opt->answer) {
+ db_append_string(&sql, ", ");
+ }
+ if (catcol == i && coltype[i] != DB_C_TYPE_INT) {
Vect_delete(new->answer);
- G_fatal_error(_("cat column is not of number type"));
- }
+ G_fatal_error(_("Category column is not of integer type"));
+ }
- /* Create table */
- make_table = 0;
- for ( i = 0 ; i < ncols; i++ ) {
- if ( xcol != i && ycol != i && zcol != i && catcol != i ) {
- make_table = 1;
+ switch (coltype[i]) {
+ case DB_C_TYPE_INT:
+ G_verbose_message("Column: %d type: integer", i + 1);
+ if (!columns_opt->answer) {
+ sprintf(buf, "int_%d integer", n_int + 1);
+ db_append_string(&sql, buf);
+ if (catcol == i) {
+ sprintf(buf, "int_%d", n_int + 1);
+ key = G_store(buf);
+ }
+ }
+ n_int++;
+ break;
+ case DB_C_TYPE_DOUBLE:
+ G_verbose_message("Column: %d type: double", i + 1);
+ if (!columns_opt->answer) {
+ sprintf(buf, "dbl_%d double precision", n_double + 1);
+ db_append_string(&sql, buf);
+ }
+ n_double++;
+ break;
+ case DB_C_TYPE_STRING:
+ G_verbose_message("Column: %d type: string length: %d",
+ i + 1, collen[i]);
+ if (!columns_opt->answer) {
+ sprintf(buf, "str_%d varchar(%d)", n_string + 1,
+ collen[i]);
+ db_append_string(&sql, buf);
+ }
+ n_string++;
break;
}
}
- if ( t_flag->answer ) {
- make_table = 0;
+ if (columns_opt->answer) {
+ db_append_string(&sql, columns_opt->answer);
}
+ db_append_string(&sql, " )");
- if ( make_table ) {
- Fi = Vect_default_field_info ( &Map, 1, NULL, GV_1TABLE );
- driver = db_start_driver_open_database ( Fi->driver, Vect_subst_var(Fi->database,&Map) );
- if ( driver == NULL ) {
- Vect_delete(new->answer);
- G_fatal_error(_("Cannot open database <%s> by driver <%s>"),
- Vect_subst_var(Fi->database,&Map), Fi->driver );
- }
- db_begin_transaction ( driver );
+ /* this link is added with default 'cat' key, later deleted and replaced by true key name,
+ * otherwise if module crashes when the table exists but link is not written it makes troubles */
+ Vect_map_add_dblink(&Map, 1, NULL, Fi->table, "cat", Fi->database,
+ Fi->driver);
- db_init_string (&sql);
- sprintf ( buf, "create table %s ( ", Fi->table );
- db_append_string ( &sql, buf );
+ /* Create table */
+ G_debug(3, db_get_string(&sql));
+ if (db_execute_immediate(driver, &sql) != DB_OK) {
+ Vect_delete(new->answer);
+ G_fatal_error(_("Unable create table: %s"),
+ db_get_string(&sql));
+ }
- if ( catcol < 0 ) {
- db_append_string ( &sql, "cat integer, " );
- }
+ /* Grant */
+ if (db_grant_on_table
+ (driver, Fi->table, DB_PRIV_SELECT,
+ DB_GROUP | DB_PUBLIC) != DB_OK) {
+ Vect_delete(new->answer);
+ G_fatal_error(_("Unable to grant privileges on table <%s>"),
+ Fi->table);
+ }
- for ( i = 0 ; i < ncols; i++ ) {
- if ( i > 0 && !columns_opt->answer ) {
- db_append_string ( &sql, ", " );
- }
- if ( catcol == i && coltype[i] != DB_C_TYPE_INT ) {
- Vect_delete(new->answer);
- G_fatal_error(_("Category column is not of integer type"));
- }
+ /* Check column types */
+ if (columns_opt->answer) {
+ int nc;
+ dbTable *table;
+ dbColumn *column;
- switch ( coltype[i] ) {
- case DB_C_TYPE_INT:
- G_verbose_message ("Column: %d type: integer", i+1);
- if ( !columns_opt->answer ) {
- sprintf ( buf, "int_%d integer", n_int+1);
- db_append_string ( &sql, buf);
- if ( catcol == i ) {
- sprintf ( buf, "int_%d", n_int+1);
- key = G_store( buf );
- }
- }
- n_int++;
- break;
- case DB_C_TYPE_DOUBLE:
- G_verbose_message ("Column: %d type: double", i+1);
- if ( !columns_opt->answer ) {
- sprintf ( buf, "dbl_%d double precision", n_double+1);
- db_append_string ( &sql, buf);
- }
- n_double++;
- break;
- case DB_C_TYPE_STRING:
- G_verbose_message ("Column: %d type: string length: %d", i+1, collen[i]);
- if ( !columns_opt->answer ) {
- sprintf ( buf, "str_%d varchar(%d)", n_string+1, collen[i]);
- db_append_string ( &sql, buf);
- }
- n_string++;
- break;
- }
- }
- if ( columns_opt->answer ) {
- db_append_string ( &sql, columns_opt->answer );
+ db_set_string(&sql, Fi->table);
+ if (db_describe_table(driver, &sql, &table) != DB_OK) {
+ Vect_delete(new->answer);
+ G_fatal_error(_("Unable to describe table <%s>"),
+ Fi->table);
}
- db_append_string ( &sql, " )" );
- /* this link is added with default 'cat' key, later deleted and replaced by true key name,
- * otherwise if module crashes when the table exists but link is not written it makes troubles */
- Vect_map_add_dblink ( &Map, 1, NULL, Fi->table, "cat", Fi->database, Fi->driver);
+ nc = db_get_table_number_of_columns(table);
- /* Create table */
- G_debug ( 3, db_get_string ( &sql ) );
- if (db_execute_immediate (driver, &sql) != DB_OK ) {
+ if ((catcol >= 0 && nc != ncols) ||
+ (catcol < 0 && (nc - 1) != ncols)) {
Vect_delete(new->answer);
- G_fatal_error(_("Cannot create table: %s"), db_get_string ( &sql ) );
+ G_fatal_error(_
+ ("Number of columns defined (%d) does not match number "
+ "of columns (%d) in input"),
+ catcol < 0 ? nc - 1 : nc, ncols);
}
- /* Grant */
- if (db_grant_on_table (driver, Fi->table, DB_PRIV_SELECT, DB_GROUP|DB_PUBLIC ) != DB_OK ) {
- Vect_delete(new->answer);
- G_fatal_error(_("Cannot grant privileges on table <%s>"), Fi->table );
- }
+ coltype2 = (int *)G_malloc(ncols * sizeof(int));
- /* Check column types */
- if ( columns_opt->answer ) {
- int nc;
- dbTable *table;
- dbColumn *column;
-
- db_set_string ( &sql, Fi->table );
- if(db_describe_table (driver, &sql, &table) != DB_OK) {
- Vect_delete(new->answer);
- G_fatal_error(_("Cannot describe table <%s>"), Fi->table);
- }
-
- nc = db_get_table_number_of_columns(table);
+ for (i = 0; i < ncols; i++) {
+ int dbcol, ctype, length;
- if ( (catcol >= 0 && nc != ncols) || (catcol < 0 && (nc-1) != ncols) ) {
- Vect_delete(new->answer);
- G_fatal_error(_("Number of columns defined (%d) does not match number "
- "of columns (%d) in input"), catcol < 0 ? nc-1 : nc, ncols);
- }
+ if (catcol < 0)
+ dbcol = i + 1; /* first is category */
+ else
+ dbcol = i;
- coltype2 = (int *) G_malloc ( ncols * sizeof(int) );
+ column = db_get_table_column(table, dbcol);
+ ctype = db_sqltype_to_Ctype(db_get_column_sqltype(column));
+ length = db_get_column_length(column);
+ coltype2[i] = ctype;
- for ( i = 0; i < ncols; i++ ) {
- int dbcol, ctype, length;
+ if (catcol == i) { /* if catcol == -1 it cannot be tru */
+ key = G_store(db_get_column_name(column));
+ }
- if ( catcol < 0 ) dbcol = i+1; /* first is category */
- else dbcol = i;
-
- column = db_get_table_column ( table, dbcol );
- ctype = db_sqltype_to_Ctype ( db_get_column_sqltype(column) );
- length = db_get_column_length ( column );
- coltype2[i] = ctype;
-
- if ( catcol == i ) { /* if catcol == -1 it cannot be tru */
- key = G_store(db_get_column_name(column));
+ switch (coltype[i]) {
+ case DB_C_TYPE_INT:
+ if (ctype == DB_C_TYPE_DOUBLE) {
+ G_warning(_("Column number %d defined as double "
+ "has only integer values"), i + 1);
}
-
- switch ( coltype[i] ) {
- case DB_C_TYPE_INT:
- if ( ctype == DB_C_TYPE_DOUBLE ) {
- G_warning(_("Column number [%d] defined as double has only integer values"), i+1);
- } else if ( ctype == DB_C_TYPE_STRING ) {
- G_warning(_("Column number [%d] defined as string has only integer values"), i+1);
- }
- break;
- case DB_C_TYPE_DOUBLE:
- if ( ctype == DB_C_TYPE_INT ) {
- Vect_delete(new->answer);
- G_fatal_error(_("Column number [%d] defined as integer has double values"), i+1);
- } else if ( ctype == DB_C_TYPE_STRING ) {
- G_warning(_("Column number [%d] defined as string has double values"), i+1);
- }
- break;
- case DB_C_TYPE_STRING:
- if ( ctype == DB_C_TYPE_INT ) {
- Vect_delete(new->answer);
- G_fatal_error(_("Column number [%d] defined as integer has string values"), i+1);
- } else if ( ctype == DB_C_TYPE_DOUBLE ) {
- Vect_delete(new->answer);
- G_fatal_error(_("Column number [%d] defined as double has string values"), i+1);
- }
- if ( length < collen[i] ) {
- Vect_delete(new->answer);
- G_fatal_error(_("Length of column [%d] (%d) is less than maximum value "
- "length (%d)"), i+1, length, collen[i]);
- }
- break;
+ else if (ctype == DB_C_TYPE_STRING) {
+ G_warning(_("Column number %d defined as string "
+ "has only integer values"), i + 1);
+ }
+ break;
+ case DB_C_TYPE_DOUBLE:
+ if (ctype == DB_C_TYPE_INT) {
+ Vect_delete(new->answer);
+ G_fatal_error(_
+ ("Column number %d defined as integer "
+ "has double values"), i + 1);
+ }
+ else if (ctype == DB_C_TYPE_STRING) {
+ G_warning(_("Column number %d defined as string "
+ "has double values"), i + 1);
+ }
+ break;
+ case DB_C_TYPE_STRING:
+ if (ctype == DB_C_TYPE_INT) {
+ Vect_delete(new->answer);
+ G_fatal_error(_
+ ("Column number %d defined as integer "
+ "has string values"), i + 1);
+ }
+ else if (ctype == DB_C_TYPE_DOUBLE) {
+ Vect_delete(new->answer);
+ G_fatal_error(_
+ ("Column number %d defined as double "
+ "has string values"), i + 1);
+ }
+ if (length < collen[i]) {
+ Vect_delete(new->answer);
+ G_fatal_error(_
+ ("Length of column %d (%d) is less than "
+ "maximum value " "length (%d)"),
+ i + 1, length, collen[i]);
}
+ break;
}
- } else {
- coltype2 = coltype;
- }
-
- if ( catcol < 0 ) {
- key = "cat";
- } else if ( !columns_opt->answer ) {
-
-
}
+ }
+ else {
+ coltype2 = coltype;
+ }
- if ( db_create_index2(driver, Fi->table, key ) != DB_OK )
- G_warning(_("Cannot create index"));
+ if (catcol < 0) {
+ key = "cat";
+ }
+ else if (!columns_opt->answer) {
- Vect_map_del_dblink ( &Map, 1 );
- Vect_map_add_dblink ( &Map, 1, NULL, Fi->table, key, Fi->database, Fi->driver);
- table = Fi->table;
- } else {
- driver = NULL;
- table = NULL;
}
- points_to_bin ( tmpascii, rowlen, &Map, driver, table, fs, ncols,
- coltype2, xcol, ycol, zcol, catcol, skip_lines );
+ if (db_create_index2(driver, Fi->table, key) != DB_OK)
+ G_warning(_("Unable to create index for table <%s>, key <%s>"),
+ Fi->table, key);
- if ( driver ) {
- G_message(_("Populating table..."));
- db_commit_transaction ( driver );
- db_close_database_shutdown_driver ( driver );
- }
- fclose (tmpascii);
+ Vect_map_del_dblink(&Map, 1);
+ Vect_map_add_dblink(&Map, 1, NULL, Fi->table, key, Fi->database,
+ Fi->driver);
+
+ table = Fi->table;
+ }
+ else {
+ driver = NULL;
+ table = NULL;
}
- else { /* FORMAT_ALL (standard mode) */
- if ( ! noheader_flag->answer )
- read_head(ascii, &Map);
+ points_to_bin(tmpascii, rowlen, &Map, driver, table, fs, ncols,
+ coltype2, xcol, ycol, zcol, catcol, skip_lines);
- asc_to_bin(ascii, &Map) ;
+ if (driver) {
+ G_message(_("Populating table..."));
+ db_commit_transaction(driver);
+ db_close_database_shutdown_driver(driver);
}
+ fclose(tmpascii);
+ }
- if ( old->answer != NULL )
- fclose(ascii);
+ else { /* FORMAT_ALL (standard mode) */
+ if (!noheader_flag->answer)
+ read_head(ascii, &Map);
- if ( notopol_flag->answer ) {
- Vect_close ( &Map );
- }
- else {
- Vect_build ( &Map, stdout );
- Vect_close ( &Map );
- }
+ asc_to_bin(ascii, &Map);
+ }
- G_done_msg("");
+ if (old->answer != NULL)
+ fclose(ascii);
- exit(EXIT_SUCCESS);
+ if (notopol_flag->answer) {
+ Vect_close(&Map);
+ }
+ else {
+ Vect_build(&Map, stdout);
+ Vect_close(&Map);
+ }
+
+ G_done_msg(" ");
+
+ exit(EXIT_SUCCESS);
}
Index: points.c
===================================================================
RCS file: /grassrepository/grass6/vector/v.in.ascii/points.c,v
retrieving revision 1.24
retrieving revision 1.24.2.1
diff -u -d -r1.24 -r1.24.2.1
--- points.c 30 May 2007 13:38:13 -0000 1.24
+++ points.c 29 Nov 2007 13:34:20 -0000 1.24.2.1
@@ -8,51 +8,41 @@
#include <grass/glocale.h>
#include "local_proto.h"
-
-/* Determine if the string is integer, e.g. 123, +123, -123
+/* Determine if the string is integer, e.g. 123, +123, -123,
* return 1 if integer, 0 otherwise */
static int is_int(char *str)
{
- int i = -1;
-
- while (str[++i] != '\0') {
- if (i == 0 && (str[i] == '+' || str[i] == '-'))
- continue;
+ char *tail;
- if (!isdigit(str[i]))
- return 0;
+ if (strtol (str, &tail, 10),
+ tail == str || *tail != '\0') {
+ /* doesn't look like a number,
+ or has extra characters after what looks to be a number */
+ return 0;
}
return 1;
}
-/* Determine if the string is double, e.g. 123.456, +123.456, -123.456
+/* Determine if the string is double, e.g. 123.456, +123.456, -123.456, 1.23456e2
* return 1 if double, 0 otherwise */
static int is_double(char *str)
{
- int i = -1, ndots = 0;
-
- while (str[++i] != '\0') {
- if (i == 0 && (str[i] == '+' || str[i] == '-'))
- continue;
-
- if (str[i] == '.') {
- if (ndots > 0)
- return 0; /* > 1 dot */
-
- ndots++;
- continue;
- }
+ char *tail;
- if (!isdigit(str[i]))
- return 0;
+ if (strtod (str, &tail),
+ tail == str || *tail != '\0') {
+ /* doesn't look like a number,
+ or has extra characters after what looks to be a number */
+ return 0;
}
return 1;
}
+
/* Analyse points ascii file. Determine number of columns and column types.
* ascii_tmp: write copy of tempfile to ascii_tmp:
* rowlength: maximum row length
@@ -91,7 +81,7 @@
tmp_token = (char *)G_malloc(256);
sav_buf = NULL;
- G_message(_("Scanning input for column types ..."));
+ G_message(_("Scanning input for column types..."));
/* fetch projection for LatLong test */
G_get_window(&window);
@@ -160,7 +150,7 @@
if (i == xcol) {
if (G_scan_easting(coorbuf, &easting, window.proj)) {
G_debug(4, "is_latlong east: %f", easting);
- sprintf(tmp_token, "%f", easting);
+ sprintf(tmp_token, "%.12f", easting);
/* replace current DMS token by decimal degree */
tokens[i] = tmp_token;
if (region_flag) {
@@ -175,7 +165,7 @@
if (i == ycol) {
if (G_scan_northing(coorbuf, &northing, window.proj)) {
G_debug(4, "is_latlong north: %f", northing);
- sprintf(tmp_token, "%f", northing);
+ sprintf(tmp_token, "%.12f", northing);
/* replace current DMS token by decimal degree */
tokens[i] = tmp_token;
if (region_flag) {
@@ -217,8 +207,9 @@
G_debug(4, "row %d col %d: '%s' is_int = %d is_double = %d",
row, i, tokens[i], is_int(tokens[i]), is_double(tokens[i]));
- if (is_int(tokens[i]))
+ if (is_int(tokens[i])) {
continue; /* integer */
+ }
if (is_double(tokens[i])) { /* double */
if (coltype[i] == DB_C_TYPE_INT) {
coltype[i] = DB_C_TYPE_DOUBLE;
@@ -254,7 +245,7 @@
G_free(tmp_token);
if (region_flag)
- G_message(_("Skipping [%d] of [%d] rows falling outside of current region"),
+ G_message(_("Skipping %d of %d rows falling outside of current region"),
skipped, row-1);
return 0;
@@ -282,7 +273,7 @@
dbString sql, val;
struct Cell_head window;
- G_message(_("Importing points ..."));
+ G_message(_("Importing points..."));
/* fetch projection for LatLong test */
G_get_window(&window);
@@ -394,7 +385,8 @@
G_debug(3, db_get_string(&sql));
if (db_execute_immediate(driver, &sql) != DB_OK) {
- G_fatal_error(_("Cannot insert values: %s"), db_get_string(&sql));
+ G_fatal_error(_("Unable to insert new record: %s"),
+ db_get_string(&sql));
}
}
More information about the grass-commit
mailing list