[GRASS-dev] v.in.dxf patch

Huidae Cho grass4u at gmail.com
Fri Apr 10 21:07:43 EDT 2009


Ben,

You mean we can store *any* data in the handle group as long as
applications do not complain about it?  Even if stored values do not
conform to the DXF specification (text string of 16 hexadecimal digits)?
I'm not comfortable with breaking standards there.  Having integer or
double *numbers* in the handle column might be useful, but you could
also typecast text handles to whatever data type you want.  Or we could
implement the partial solution (uint32 column) that I mentioned below, but
I'm not sure about double type handles...

The reason I added the handle column is that I see entity handles as
object IDs uniquely identifying corresponding entities, not just
arbitrary user data.  Without the entity handle, there is no direct way
to identify which entity in DXF is which feature in GRASS after import.

I could be mistaken for how you *abuse* the handle.

Thanks,
Huidae


On Fri, Apr 10, 2009 at 11:28:42AM +0000, Benjamin Ducke wrote:
> Hi Huidae,
> 
> thanks for clarifying this. The patch I sent in does essentially the same thing,
> except that it has "-r" and "-n" flags which allow the user to force conversion
> of the entity field to a double or integer number. Do you think that makes sense?
> My idea was that the entity field is one of the few consistent DXF fields that
> can be "abused" for passing numeric data between an application that produces
> DXF and GRASS. Having the contents of that field directly imported as double
> or integer values seemed to make data processing easier for me.
> 
> Thanks,
> 
> Ben
> 
> ----- Original Message -----
> From: "Huidae Cho" <grass4u at gmail.com>
> To: "Benjamin Ducke" <benjamin.ducke at oxfordarch.co.uk>
> Cc: grass-dev at lists.osgeo.org
> Sent: Friday, April 10, 2009 10:39:09 AM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
> Subject: Re: [GRASS-dev] v.in.dxf patch
> 
> Ben,
> 
> Thanks for the patch.  The entity handle is a 64-bit integer (up to 16
> hexadecimal digits), which is not supported by GRASS database drivers
> (correct me if I'm wrong).  When the entity handle is represented as a
> decimal number, theoretically, it can be too long for identification
> purposes.  No body may want to type or read 20-digit decimal integers
> (up to 2^64=1.84467440737096e+19).  I know this situation is
> unrealistic.  I doubt any DXF files have this many entities in them, so
> a *partial* approach to the entity handle could be to use the biggest
> integer type that GRASS supports and warn the user if the
> handle number is truncated to this integer type.
> 
> In recent updates, I added the "handle" column as varchar(16) for the
> sake of safety and removed lowercase conversion for attribute values.
> 
> Best,
> Huidae
> 
> 
> On Thu, Apr 09, 2009 at 02:13:38PM +0000, Benjamin Ducke wrote:
> > Dear all,
> > 
> > I have attached a little patch for v.in.dxf. This just makes a small but
> > useful addition:
> > 
> > it allows parsing of the 'handle' field which exists for every DXF
> > entity and provides a way for transporting small bits of data in the DXF
> > file.
> > 
> > The patch is against the current sources in:
> > 
> > http://trac.osgeo.org/grass/browser/grass/trunk
> > 
> > I am not sure which version of GRASS this should go into,
> > as it does add a new feature (but really just a tiny one).
> > 
> > Cheers,
> > 
> > Ben
> > 
> > -- 
> > Benjamin Ducke
> > Senior Geospatial Consultant
> > 
> > Oxford Archaeology
> > Janus House
> > Osney Mead
> > OX2 0ES
> > Oxford, U.K.
> > 
> > Tel: +44 (0)1865 263 800 (switchboard)
> > Tel: +44 (0)1865 980 758 (direct)
> > Fax :+44 (0)1865 793 496
> > benjamin.ducke at oxfordarch.co.uk
> > 
> > 
> > 
> > 
> > 
> > ------
> > Files attached to this email may be in ISO 26300 format (OASIS Open Document Format). If you have difficulty opening them, please visit http://iso26300.info for more information.
> 
> > diff -urB old/add_3dface.c new/add_3dface.c
> > --- old/add_3dface.c	2009-04-09 09:39:49.000000000 +0100
> > +++ new/add_3dface.c	2009-04-09 09:52:26.000000000 +0100
> > @@ -12,21 +12,30 @@
> >      int yflag = 0;		/* indicates if a y value has been found */
> >      int zflag = 0;		/* indicates if a z value has been found */
> >      int arr_size = 0;
> > +    char handle[DXF_BUF_SIZE];	/* read in from dxf file */
> > +    char *handle_ptr = NULL;
> > +    
> >  
> >      strcpy(layer, UNIDENTIFIED_LAYER);
> >  
> >      /* read in lines and process information until a 0 is read in */
> >      while ((code = dxf_get_code(dxf)) != 0) {
> >  	if (code == -2)
> > -	    return -1;
> > +	    return -1;	
> >  
> >  	switch (code) {
> > +	case 5:		/* handle value (int) */
> > +	    strcpy(handle, dxf_buf);
> > +	    handle_ptr = &handle[0];
> > +	    break;		    
> >  	case 8:		/* layer name */
> >  	    if (!layer_flag && *dxf_buf) {
> >  		if (flag_list) {
> >  		    if (!is_layer_in_list(dxf_buf)) {
> >  			add_layer_to_list(dxf_buf);
> >  			print_layer(dxf_buf);
> > +			fprintf(stdout, _("Layer %d: %s\n"), num_layers,
> > +				dxf_buf);
> >  		    }
> >  		    return 0;
> >  		}
> > @@ -116,7 +125,7 @@
> >  	if (xpnts[2] == xpnts[3] && ypnts[2] == ypnts[3] &&
> >  	    zpnts[2] == zpnts[3])
> >  	    arr_size--;
> > -	write_face(Map, layer, arr_size);
> > +	write_face(Map, layer, handle_ptr, arr_size);
> >      }
> >  
> >      return 0;
> > diff -urB old/add_arc.c new/add_arc.c
> > --- old/add_arc.c	2009-04-09 09:40:07.000000000 +0100
> > +++ new/add_arc.c	2009-04-09 09:53:06.000000000 +0100
> > @@ -19,6 +19,9 @@
> >      float start_angle = 0;	/* read in from dxf file */
> >      float finish_angle = 0;	/* read in from dxf file */
> >      int arr_size = 0;
> > +    char handle[DXF_BUF_SIZE];	/* read in from dxf file */
> > +    char *handle_ptr = NULL;
> > +    
> >  
> >      strcpy(layer, UNIDENTIFIED_LAYER);
> >  
> > @@ -28,12 +31,18 @@
> >  	    return -1;
> >  
> >  	switch (code) {
> > +	case 5:		/* handle value (int) */
> > +	    strcpy(handle, dxf_buf);
> > +	    handle_ptr = &handle[0];
> > +	    break;	    
> >  	case 8:		/* layer name */
> >  	    if (!layer_flag && *dxf_buf) {
> >  		if (flag_list) {
> >  		    if (!is_layer_in_list(dxf_buf)) {
> >  			add_layer_to_list(dxf_buf);
> >  			print_layer(dxf_buf);
> > +			fprintf(stdout, _("Layer %d: %s\n"), num_layers,
> > +				dxf_buf);
> >  		    }
> >  		    return 0;
> >  		}
> > @@ -78,7 +87,7 @@
> >  	arr_size =
> >  	    make_arc(0, centerx, centery, radius, start_angle, finish_angle,
> >  		     zcoor);
> > -	write_line(Map, layer, arr_size);
> > +	write_line(Map, layer, handle_ptr, arr_size);
> >      }
> >  
> >      return 0;
> > diff -urB old/add_circle.c new/add_circle.c
> > --- old/add_circle.c	2009-04-09 09:40:18.000000000 +0100
> > +++ new/add_circle.c	2009-04-09 09:53:25.000000000 +0100
> > @@ -15,6 +15,9 @@
> >      double radius = 0;		/* read in from dxf file */
> >      double zcoor = 0;		/* read in from dxf file */
> >      int arr_size = 0;
> > +    char handle[DXF_BUF_SIZE];	/* read in from dxf file */
> > +    char *handle_ptr = NULL;
> > +    
> >  
> >      strcpy(layer, UNIDENTIFIED_LAYER);
> >  
> > @@ -24,12 +27,18 @@
> >  	    return -1;
> >  
> >  	switch (code) {
> > +	case 5:		/* handle value (int) */
> > +	    strcpy(handle, dxf_buf);
> > +	    handle_ptr = &handle[0];
> > +	    break;	    
> >  	case 8:		/* layer name */
> >  	    if (!layer_flag && *dxf_buf) {
> >  		if (flag_list) {
> >  		    if (!is_layer_in_list(dxf_buf)) {
> >  			add_layer_to_list(dxf_buf);
> >  			print_layer(dxf_buf);
> > +			fprintf(stdout, _("Layer %d: %s\n"), num_layers,
> > +				dxf_buf);
> >  		    }
> >  		    return 0;
> >  		}
> > @@ -64,7 +73,7 @@
> >  
> >      if (xflag && yflag && rflag) {
> >  	arr_size = make_arc(0, centerx, centery, radius, 0.0, 360.0, zcoor);
> > -	write_line(Map, layer, arr_size);
> > +	write_line(Map, layer, handle_ptr, arr_size);
> >      }
> >  
> >      return 0;
> > diff -urB old/add_line.c new/add_line.c
> > --- old/add_line.c	2009-04-09 09:40:30.000000000 +0100
> > +++ new/add_line.c	2009-04-09 10:10:03.000000000 +0100
> > @@ -11,6 +11,9 @@
> >      int yflag = 0;		/* indicates if a y value has been found */
> >      int zflag = 0;		/* indicates if a z value has been found */
> >      int arr_size = 0;
> > +    char handle[DXF_BUF_SIZE];	/* read in from dxf file */
> > +    char *handle_ptr = NULL;
> > +    
> >  
> >      strcpy(layer, UNIDENTIFIED_LAYER);
> >  
> > @@ -21,12 +24,18 @@
> >  	    return -1;
> >  
> >  	switch (code) {
> > +	case 5:		/* handle value (int) */
> > +	    strcpy(handle, dxf_buf);
> > +	    handle_ptr = &handle[0];
> > +	    break;	    
> >  	case 8:		/* layer name */
> >  	    if (!layer_flag && *dxf_buf) {
> >  		if (flag_list) {
> >  		    if (!is_layer_in_list(dxf_buf)) {
> >  			add_layer_to_list(dxf_buf);
> >  			print_layer(dxf_buf);
> > +			fprintf(stdout, _("Layer %d: %s\n"), num_layers,
> > +				dxf_buf);
> >  		    }
> >  		    return 0;
> >  		}
> > @@ -76,8 +85,8 @@
> >  	}
> >      }
> >  
> > -    if (arr_size == 2)	/* have both start and stop */
> > -	write_line(Map, layer, arr_size);
> > +    if (arr_size == 2) /* have both start and stop */
> > +	write_line(Map, layer, handle_ptr, arr_size);
> >  
> >      return 0;
> >  }
> > diff -urB old/add_lwpolyline.c new/add_lwpolyline.c
> > --- old/add_lwpolyline.c	2009-04-09 09:40:41.000000000 +0100
> > +++ new/add_lwpolyline.c	2009-04-09 09:54:54.000000000 +0100
> > @@ -11,6 +11,8 @@
> >      int xflag = 0;		/* indicates if a x value has been found */
> >      int yflag = 0;		/* indicates if a y value has been found */
> >      int arr_size = 0;
> > +    char handle[DXF_BUF_SIZE];	/* read in from dxf file */
> > +    char *handle_ptr = NULL;
> >  
> >      /* variables to create arcs */
> >      double bulge = 0.0;		/* for arc curves */
> > @@ -25,12 +27,18 @@
> >  	    return -1;
> >  
> >  	switch (code) {
> > +	case 5:		/* handle value (int) */
> > +	    strcpy(handle, dxf_buf);
> > +	    handle_ptr = &handle[0];
> > +	    break;	    
> >  	case 8:		/* layer name */
> >  	    if (!layer_flag && *dxf_buf) {
> >  		if (flag_list) {
> >  		    if (!is_layer_in_list(dxf_buf)) {
> >  			add_layer_to_list(dxf_buf);
> >  			print_layer(dxf_buf);
> > +			fprintf(stdout, _("Layer %d: %s\n"), num_layers,
> > +				dxf_buf);
> >  		    }
> >  		    return 0;
> >  		}
> > @@ -105,7 +113,7 @@
> >  	    zpnts[i] = 0.0;
> >      }
> >  
> > -    write_line(Map, layer, arr_size);
> > +    write_line(Map, layer, handle_ptr, arr_size);
> >  
> >      return 0;
> >  }
> > diff -urB old/add_point.c new/add_point.c
> > --- old/add_point.c	2009-04-09 09:40:52.000000000 +0100
> > +++ new/add_point.c	2009-04-09 10:17:18.000000000 +0100
> > @@ -9,6 +9,8 @@
> >      int layer_flag = 0;		/* indicates if a layer name has been found */
> >      int xflag = 0;		/* indicates if a x value has been found */
> >      int yflag = 0;		/* indicates if a y value has been found */
> > +    char handle[DXF_BUF_SIZE];	/* read in from dxf file */
> > +    char *handle_ptr = NULL;
> >  
> >      strcpy(layer, UNIDENTIFIED_LAYER);
> >  
> > @@ -19,12 +21,18 @@
> >  	    return -1;
> >  
> >  	switch (code) {
> > +	case 5:		/* handle value (int) */
> > +	    strcpy(handle, dxf_buf);
> > +	    handle_ptr = &handle[0];
> > +	    break;	    
> >  	case 8:		/* layer name */
> >  	    if (!layer_flag && *dxf_buf) {
> >  		if (flag_list) {
> >  		    if (!is_layer_in_list(dxf_buf)) {
> >  			add_layer_to_list(dxf_buf);
> >  			print_layer(dxf_buf);
> > +			fprintf(stdout, _("Layer %d: %s\n"), num_layers,
> > +				dxf_buf);
> >  		    }
> >  		    return 0;
> >  		}
> > @@ -61,7 +69,7 @@
> >  	 * ypnts[1] = ypnts[0];
> >  	 * zpnts[1] = zpnts[0];
> >  	 */
> > -	write_point(Map, layer);
> > +	write_point(Map, layer, handle_ptr);
> >      }
> >  
> >      return 0;
> > diff -urB old/add_polyline.c new/add_polyline.c
> > --- old/add_polyline.c	2009-04-09 09:41:04.000000000 +0100
> > +++ new/add_polyline.c	2009-04-09 10:16:55.000000000 +0100
> > @@ -2,7 +2,7 @@
> >  #include <string.h>
> >  #include "global.h"
> >  
> > -static void write_pnts(struct Map_info *, char *, int, int, int);
> > +static void write_pnts(struct Map_info *, char *, char *, int, int, int);
> >  
> >  int add_polyline(struct dxf_file *dxf, struct Map_info *Map)
> >  {
> > @@ -17,6 +17,8 @@
> >      int yflag = 0;		/* indicates if a y value has been found */
> >      int zflag = 0;		/* indicates if a z value has been found */
> >      int arr_size = 0;
> > +    char handle[DXF_BUF_SIZE];	/* read in from dxf file */
> > +    char *handle_ptr = NULL;
> >  
> >      /* variables to create arcs */
> >      double bulge = 0.0;		/* for arc curves */
> > @@ -31,7 +33,9 @@
> >      double *mesh_ypnts = NULL;
> >      double *mesh_zpnts = NULL;
> >  
> > +
> >      strcpy(layer, UNIDENTIFIED_LAYER);
> > +    
> >  
> >      /* read in lines and process information until a 0 is read in */
> >      while ((code = dxf_get_code(dxf)) != 0) {
> > @@ -67,8 +71,8 @@
> >  	    if (polyline_flag & (8 | 16 | 32))
> >  		if (warn_flag70) {
> >  		    if (!flag_list)
> > -			G_warning(_("3-d data in dxf file. Polyline_flag: %d"),
> > -				  polyline_flag);
> > +		        G_warning(_("3-d data in dxf file. Polyline_flag: %d"),
> > +			          polyline_flag);
> >  		    warn_flag70 = 0;
> >  		}
> >  	    break;
> > @@ -91,6 +95,10 @@
> >  		    return -1;
> >  
> >  		switch (code) {
> > +		case 5:		/* handle value (int) */
> > +	    	    strcpy(handle, dxf_buf);
> > +	    	    handle_ptr = &handle[0];
> > +	    	    break;		    
> >  		case 8:	/* layer name */
> >  		    /* if no layer previously assigned */
> >  		    if (!layer_flag && *dxf_buf) {
> > @@ -98,6 +106,8 @@
> >  			    if (!is_layer_in_list(dxf_buf)) {
> >  				add_layer_to_list(dxf_buf);
> >  				print_layer(dxf_buf);
> > +				fprintf(stdout, _("Layer %d: %s\n"),
> > +					num_layers, dxf_buf);
> >  			    }
> >  			    return 0;
> >  			}
> > @@ -201,11 +211,11 @@
> >  			    arr_size++;
> >  			    if (flag_frame) {
> >  				set_entity("POLYFACE FRAME");
> > -				write_line(Map, layer, arr_size);
> > +				write_line(Map, layer, handle_ptr, arr_size);
> >  			    }
> >  			    else {
> >  				set_entity("POLYFACE");
> > -				write_face(Map, layer, arr_size);
> > +				write_face(Map, layer, handle_ptr, arr_size);
> >  			    }
> >  			    arr_size = 0;
> >  			}
> > @@ -235,13 +245,14 @@
> >  	G_free(mesh_ypnts);
> >  	G_free(mesh_zpnts);
> >      }
> > -    else
> > -	write_pnts(Map, layer, polyline_flag, zflag, arr_size);
> > +    else {
> > +       write_pnts(Map, layer, handle_ptr, polyline_flag, zflag, arr_size);
> > +    }
> >  
> >      return 0;
> >  }
> >  
> > -static void write_pnts(struct Map_info *Map, char *layer, int polyline_flag,
> > +static void write_pnts(struct Map_info *Map, char *layer, char *handle, int polyline_flag,
> >  		       int zflag, int arr_size)
> >  {
> >      /* done reading vertices */
> > @@ -271,8 +282,8 @@
> >  	for (i = 0; i < arr_size; i++)
> >  	    zpnts[i] = 0.0;
> >      }
> > -
> > -    write_line(Map, layer, arr_size);
> > +    
> > +    write_line(Map, layer, handle, arr_size);
> >  
> >      return;
> >  }
> > diff -urB old/add_text.c new/add_text.c
> > --- old/add_text.c	2009-04-09 09:41:13.000000000 +0100
> > +++ new/add_text.c	2009-04-09 09:57:27.000000000 +0100
> > @@ -13,6 +13,9 @@
> >      double angle = 0.0;		/* read in from dxf file */
> >      char label[DXF_BUF_SIZE];	/* read in from dxf file */
> >      int label_len = 0;
> > +    char handle[DXF_BUF_SIZE];	/* read in from dxf file */
> > +    char *handle_ptr = NULL;
> > +    
> >  
> >      strcpy(layer, UNIDENTIFIED_LAYER);
> >  
> > @@ -27,12 +30,18 @@
> >  	    label_len = strlen(dxf_buf);
> >  	    strcpy(label, dxf_buf);
> >  	    break;
> > +	case 5:		/* handle value (int) */
> > +	    strcpy(handle, dxf_buf);
> > +	    handle_ptr = &handle[0];
> > +	    break;	    
> >  	case 8:		/* layer name */
> >  	    if (!layer_flag && *dxf_buf) {
> >  		if (flag_list) {
> >  		    if (!is_layer_in_list(dxf_buf)) {
> >  			add_layer_to_list(dxf_buf);
> >  			print_layer(dxf_buf);
> > +			fprintf(stdout, _("Layer %d: %s\n"), num_layers,
> > +				dxf_buf);
> >  		    }
> >  		    return 0;
> >  		}
> > @@ -110,9 +119,9 @@
> >  	ypnts[3] = ypnts[0] + (length * sin(theta));
> >  	zpnts[3] = zpnts[0];
> >  
> > -	write_line(Map, layer, 5);
> > +	write_line(Map, layer, handle_ptr, 5);
> >  #endif
> > -	write_text(Map, layer, label);
> > +	write_text(Map, layer, handle_ptr, label);
> >      }
> >  
> >      return 0;
> > diff -urB old/dxf_to_vect.c new/dxf_to_vect.c
> > --- old/dxf_to_vect.c	2009-04-09 09:41:25.000000000 +0100
> > +++ new/dxf_to_vect.c	2009-04-07 15:34:22.000000000 +0100
> > @@ -172,8 +172,11 @@
> >  void set_entity(char *str)
> >  {
> >      strcpy(entity, str);
> > -    for (str = entity; *str; str++)
> > -	*str = tolower(*str);
> > +    
> > +    if ( flag_to_lower ) {
> > +       for (str = entity; *str; str++)
> > +	  *str = tolower(*str);
> > +    }
> >  
> >      return;
> >  }
> > diff -urB old/global.h new/global.h
> > --- old/global.h	2009-04-09 09:41:35.000000000 +0100
> > +++ new/global.h	2009-04-09 10:00:19.000000000 +0100
> > @@ -20,7 +20,7 @@
> >  #define DXF_BUF_SIZE 256
> >  
> >  extern int flag_list, flag_extent, flag_table, flag_topo, flag_invert,
> > -    flag_one_layer, flag_frame;
> > +    flag_one_layer, flag_frame, flag_int_handles, flag_real_handles, flag_to_lower;
> >  extern int num_layers, found_layers;
> >  extern char **layers;
> >  extern char dxf_buf[DXF_BUF_SIZE], entity[DXF_BUF_SIZE];
> > @@ -76,11 +76,11 @@
> >  int add_text(struct dxf_file *, struct Map_info *);
> >  
> >  /* write_vect.c */
> > -#define write_point(a, b) write_vect(a, b, entity, "", 1, GV_POINT)
> > -#define write_line(a, b, c) write_vect(a, b, entity, "", c, GV_LINE)
> > -#define write_face(a, b, c) write_vect(a, b, entity, "", c, GV_FACE)
> > -#define write_text(a, b, c) write_vect(a, b, entity, c, 1, GV_POINT)
> > -void write_vect(struct Map_info *, char *, char *, char *, int, int);
> > +#define write_point(a, b, c) write_vect(a, b, entity, c, "", 1, GV_POINT)
> > +#define write_line(a, b, c, d) write_vect(a, b, entity, c, "", d, GV_LINE)
> > +#define write_face(a, b, c, d) write_vect(a, b, entity, c, "", d, GV_FACE)
> > +#define write_text(a, b, c, d) write_vect(a, b, entity, c, d, 1, GV_POINT)
> > +void write_vect(struct Map_info *, char *, char *, char*, char *, int, int);
> >  void write_done(struct Map_info *);
> >  
> >  #endif
> > diff -urB old/main.c new/main.c
> > --- old/main.c	2009-04-09 09:41:56.000000000 +0100
> > +++ new/main.c	2009-04-09 10:22:02.000000000 +0100
> > @@ -14,10 +14,12 @@
> >   *
> >   *               Rewrite for GRASS 6:
> >   *               Huidae Cho <grass4u gmail.com>
> > + *		 Small enhancements:
> > + *		 Benjamin Ducke <benjamin.ducke at oadigital.net>
> >   *
> >   * PURPOSE:      Import DXF file
> >   *
> > - * COPYRIGHT:    (C) 1999-2006 by the GRASS Development Team
> > + * COPYRIGHT:    (C) 1999-2009 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
> > @@ -30,7 +32,7 @@
> >  #include "global.h"
> >  
> >  int flag_list, flag_extent, flag_table, flag_topo, flag_invert,
> > -    flag_one_layer, flag_frame;
> > +    flag_one_layer, flag_frame, flag_int_handles, flag_real_handles, flag_to_lower;
> >  int num_layers, found_layers;
> >  char **layers;
> >  char dxf_buf[DXF_BUF_SIZE], entity[DXF_BUF_SIZE];
> > @@ -53,6 +55,9 @@
> >  	struct Flag *topo;
> >  	struct Flag *invert;
> >  	struct Flag *one_layer;
> > +	struct Flag *int_handles;
> > +	struct Flag *real_handles;
> > +	struct Flag *to_lower;
> >  	struct Flag *frame;
> >      } flag;
> >      struct
> > @@ -84,6 +89,18 @@
> >      flag.frame = G_define_flag();
> >      flag.frame->key = 'f';
> >      flag.frame->description = _("Import polyface meshes as 3D wire frame");
> > +    
> > +    flag.int_handles = G_define_flag();
> > +    flag.int_handles->key = 'n';
> > +    flag.int_handles->description = _("Import handles as integer values");
> > +
> > +    flag.real_handles = G_define_flag();
> > +    flag.real_handles->key = 'r';
> > +    flag.real_handles->description = _("Import handles as floating point values");
> > +
> > +    flag.to_lower = G_define_flag();
> > +    flag.to_lower->key = 'c';
> > +    flag.to_lower->description = _("Convert DXF entity names to lower case");
> >  
> >      flag.list = G_define_flag();
> >      flag.list->key = 'l';
> > @@ -100,7 +117,7 @@
> >      flag.one_layer->key = '1';
> >      flag.one_layer->description = _("Import all objects into one layer");
> >      flag.one_layer->guisection = _("DXF layers");
> > -
> > +    
> >      opt.input = G_define_standard_option(G_OPT_F_INPUT);
> >      opt.input->description = _("Name of input DXF file");
> >  
> > @@ -124,11 +141,18 @@
> >      flag_invert = flag.invert->answer;
> >      flag_one_layer = flag.one_layer->answer;
> >      flag_frame = flag.frame->answer;
> > +    flag_int_handles = flag.int_handles->answer;
> > +    flag_real_handles = flag.real_handles->answer;
> > +    flag_to_lower = flag.to_lower->answer;
> >  
> >      /* open DXF file */
> >      if (!(dxf = dxf_open(opt.input->answer)))
> >  	G_fatal_error(_("Unable to open DXF file <%s>"), opt.input->answer);
> >  
> > +    if ( flag_real_handles && flag_int_handles ) {
> > +        G_fatal_error(_("Please specify either '-n' or '-r'") );
> > +    }
> > +
> >      if (flag_list) {
> >  	num_layers = 0;
> >  	layers = NULL;
> > Only in new: main.c~
> > diff -urB old/v.in.dxf.html new/v.in.dxf.html
> > --- old/v.in.dxf.html	2009-04-09 09:42:37.000000000 +0100
> > +++ new/v.in.dxf.html	2009-04-09 10:06:55.000000000 +0100
> > @@ -1,6 +1,6 @@
> >  <h2>DESCRIPTION</h2>
> >  
> > -Standard DXF is imported. The following graphical objects are supported:
> > +Converts DXF format CAD files to GRASS vector format. The following graphical objects (DXF entities) are supported:
> >  
> >  <ul>
> >  <li>GRASS point type:</li>
> > @@ -23,13 +23,28 @@
> >   </ul></li>
> >  </ul>
> >  
> > -Capital column names are changed to lowercase characters as for easier
> > +Capital column names are changed to lowercase characters for easier
> >  SQL usage (lowercase column names avoid the need to quote them if the
> >  attribute table is stored in a SQL DBMS such as PostgreSQL).
> >  
> > +For text type entities, the text value will be stored in a column
> > +"label" of the GRASS vector output map. The "layer" field will contain
> > +the name(s) of the DXF input layer(s). The DXF entity type string will
> > +be stored in "entity". DXF specification suggest upper case spelling
> > +for entity names. Use the <b>-c</b> flag to store them as lower case.
> > +<p>
> > +The "handle" column can be used to store small bits of data associated with any entity 
> > +in the DXF file. The DXF specification is not clear about whether this
> > +is supposed to be a text string or a number. You can force numeric interpretation
> > +by using the <b>-n</b> and <b>-r</b> flags. Most applications that read DXF files
> > +seem to be relaxed about the contents of this column.
> > +<p>
> > +Neither the "label" nor the "handle" columns are mandatory. 
> > +
> >  <H2>REFERENCES</H2>
> >  
> > -<a href="http://en.wikipedia.org/wiki/AutoCAD_DXF">AutoCad DXF</a> (from Wikipedia, the free encyclopedia)
> > +<a href="http://en.wikipedia.org/wiki/AutoCAD_DXF">AutoCad DXF</a> (from Wikipedia, the free encyclopedia)<br>
> > +<a href="http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=12272454&linkID=10809853">DXF Reference</a> (Autodesk-supplied documentation)
> >  
> >  <H2>SEE ALSO</H2>
> >  
> > @@ -43,6 +58,7 @@
> >  Revised by Dave Gerdes, 12/1989<BR>
> >  US Army Construction Engineering Research Lab
> >  <P>
> > -Updated for GRASS 6 and 3D support. Huidae Cho, 3/2006
> > +Updated for GRASS 6 and 3D support. Huidae Cho, 3/2006<BR>
> > +With minor additions by Benjamin Ducke (Oxford Archaeology), 4/2009 
> >  
> > -<P><I>Last changed: $Date$</I>
> > +<P><I>Last changed: $Date: 2009-04-09 10:00:00 (Thu, 09 Apr 2009) $</I>
> > diff -urB old/write_vect.c new/write_vect.c
> > --- old/write_vect.c	2009-04-09 09:42:50.000000000 +0100
> > +++ new/write_vect.c	2009-04-09 10:15:24.000000000 +0100
> > @@ -11,7 +11,7 @@
> >  static dbString sql, str;
> >  static char buf[1000];
> >  
> > -void write_vect(struct Map_info *Map, char *layer, char *entity, char *label,
> > +void write_vect(struct Map_info *Map, char *layer, char *entity, char *handle, char *label,
> >  		int arr_size, int type)
> >  {
> >      struct line_cats *Cats;
> > @@ -30,6 +30,7 @@
> >  	sprintf(buf, "insert into %s (%s"
> >  		", layer"
> >  		", entity"
> > +		", handle"
> >  		", label" ") values (%d, '", Fi[i]->table, Fi[i]->key, cat);
> >  
> >  	if (layer) {
> > @@ -42,20 +43,38 @@
> >  	if (entity) {
> >  	    db_set_string(&str, entity);
> >  	    db_double_quote_string(&str);
> > -	    strcat(buf, db_get_string(&str));
> > +	    strcat(buf, db_get_string(&str));	    
> >  	}
> > -	strcat(buf, "', '");
> > +	strcat(buf, "', ");
> >  
> > -	if (label) {
> > +	if (handle) {
> > +	    if ( !flag_int_handles && !flag_real_handles ) {
> > +	        strcat(buf, "'");
> > +	    }
> > +	    if ( !flag_int_handles && !flag_real_handles ) {
> > +	        db_double_quote_string(&str);
> > +	    }	    	
> > +	    db_set_string(&str, handle);
> > +	    strcat(buf, db_get_string(&str));
> > +	    if ( !flag_int_handles && !flag_real_handles ) {
> > +	        strcat(buf, "'");
> > +	    }	    
> > +	} else {
> > +	    strcat(buf, "NULL"); /* no handle? Set to NULL value */
> > +	}
> > +	strcat(buf, ", '");
> > +	
> > +	if ( label ) {	
> >  	    db_set_string(&str, label);
> >  	    db_double_quote_string(&str);
> >  	    strcat(buf, db_get_string(&str));
> >  	}
> > -	strcat(buf, "')");
> > +	
> > +	strcat(buf, "' )");
> >  
> >  	db_set_string(&sql, buf);
> >  	if (db_execute_immediate(driver, &sql) != DB_OK)
> > -	    G_fatal_error(_("Unable to insert new record: %s"),
> > +	    G_fatal_error(_("Unable to insert new record: %s"), 
> >  			  db_get_string(&sql));
> >  	db_free_string(&sql);
> >      }
> > @@ -133,11 +152,11 @@
> >       */
> >      strcpy(field_name, layer);
> >      if (field_name[0] >= '0' && field_name[0] <= '9')
> > -	x = field_name[0];
> > +       x = field_name[0];
> >      G_str_to_sql(field_name);
> >      if (x)
> >          field_name[0] = x;
> > -
> > +	
> >      for (i = 0; i < num_fields; i++) {
> >  	/* field name already exists */
> >  	if (strcmp(field_name, field_names[i]) == 0) {
> > @@ -208,11 +227,34 @@
> >  
> >      /* capital table names are a pain in SQL */
> >      G_str_to_lower(Fi[i]->table);
> > -    sprintf(buf, "create table %s (cat integer"
> > +    
> > +    if ( flag_int_handles ) {
> > +        sprintf(buf, "create table %s (cat integer"
> > +	    ", layer varchar(%d)"
> > +	    ", entity varchar(%d)"
> > +	    ", handle integer"
> > +	    ", label varchar(%d)"
> > +	    ")", Fi[i]->table, DXF_BUF_SIZE, DXF_BUF_SIZE, DXF_BUF_SIZE);
> > +    }
> > +    
> > +    if ( flag_real_handles ) {
> > +        sprintf(buf, "create table %s (cat integer"
> >  	    ", layer varchar(%d)"
> >  	    ", entity varchar(%d)"
> > +	    ", handle double"
> >  	    ", label varchar(%d)"
> >  	    ")", Fi[i]->table, DXF_BUF_SIZE, DXF_BUF_SIZE, DXF_BUF_SIZE);
> > +    }
> > +    
> > +    if ( !flag_int_handles && !flag_real_handles ) {
> > +        sprintf(buf, "create table %s (cat integer"
> > +	    ", layer varchar(%d)"
> > +	    ", entity varchar(%d)"
> > +	    ", handle varchar(%d)"
> > +	    ", label varchar(%d)"
> > +	    ")", Fi[i]->table, DXF_BUF_SIZE, DXF_BUF_SIZE, DXF_BUF_SIZE, DXF_BUF_SIZE);
> > +    }    
> > +    
> >      db_set_string(&sql, buf);
> >  
> >      if (db_execute_immediate(driver, &sql) != DB_OK)
> > @@ -221,7 +263,7 @@
> >  
> >      if (db_grant_on_table
> >  	(driver, Fi[i]->table, DB_PRIV_SELECT, DB_GROUP | DB_PUBLIC) != DB_OK)
> > -	G_fatal_error(_("Unable to grant privileges on table <%s>"),
> > +	G_fatal_error(_("Unable to grant privileges on table <%s>"), 
> >  		      Fi[i]->table);
> >      if (db_create_index2(driver, Fi[i]->table, Fi[i]->key) != DB_OK)
> >  	G_warning(_("Unable to create index for table <%s>, key <%s>"),
> 
> > _______________________________________________
> > grass-dev mailing list
> > grass-dev at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/grass-dev
> 
> 
> 
> 
> ------
> Files attached to this email may be in ISO 26300 format (OASIS Open Document Format). If you have difficulty opening them, please visit http://iso26300.info for more information.
> 
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev


More information about the grass-dev mailing list