[GRASS-dev] problem with parse_command python

Glynn Clements glynn at gclements.plus.com
Wed Dec 29 18:44:31 EST 2010


Luca Delucchi wrote:

> > This isn't correct. Without -g, the blank line occurs betwen the
> > Layer: and Category: lines and the rest of the per-layer information.
> 
> I don't know if this is correct, look the answer of  "fields =
> grass.read_command('v.what',flags = 'a', map = map_tiles, east_north =
> pointslist)"

This breaks down as follows:

Header:

> print fields
> 
> East: 636280
> North: 5079748
> 
> Map: test_tile
> Mapset: ortofoto_baldo
> Type: Area
> Sq Meters: 770560.000
> Hectares: 77.056
> Acres: 190.410
> Sq Miles: 0.2975

First category:

> Layer: 1
> Category: 1
> 
> Driver: dbf
> Database: /grassdata/patUTM32/ortofoto_baldo/dbf/
> Table: test_tile
> Key column: cat
> cat : 1
> location : /grassdata/patUTM32/ortofoto_baldo/cellhd/22_1683_tagliata

Second category:

> Layer: 1
> Category: 13
> 
> Driver: dbf
> Database: /grassdata/patUTM32/ortofoto_baldo/dbf/
> Table: test_tile
> Key column: cat
> cat : 13
> location : /grassdata/patUTM32/ortofoto_baldo/cellhd/24a_3001_tagliata

Third category:

> Layer: 2
> Category: 2

The code which generates this output is in vector/v.what/what.c:

	if (Cats->n_cats > 0) {
	    int j;
	    char *formbuf1, *formbuf2;

	    for (j = 0; j < Cats->n_cats; j++) {
		G_debug(2, "field = %d  category = %d\n", Cats->field[j],
			Cats->cat[j]);
		if (script) {
		    fprintf(stdout, "Layer=%d\nCategory=%d\n", Cats->field[j],
			    Cats->cat[j]);
		}
		else {
		    fprintf(stdout, _("Layer: %d\nCategory: %d\n"),
			    Cats->field[j], Cats->cat[j]);
		}
		Fi = Vect_get_field(&(Map[i]), Cats->field[j]);
		if (Fi != NULL && showextra) {
		    if (script) {
			fprintf(stdout,
				"Driver=%s\nDatabase=%s\nTable=%s\nKey_column=%s\n",
				Fi->driver, Fi->database, Fi->table, Fi->key);
		    }
		    else {
			fprintf(stdout,
				_("\nDriver: %s\nDatabase: %s\nTable: %s\nKey column: %s\n"),
				Fi->driver, Fi->database, Fi->table, Fi->key);
		    }
		    F_generate(Fi->driver, Fi->database, Fi->table,
			       Fi->key, Cats->cat[j], &form);

		    if (script) {
			formbuf1 = G_str_replace(form, " : ", "=");
			formbuf2 = G_str_replace(formbuf1, " ", "_");
			fprintf(stdout, "%s", formbuf2);
			G_free(formbuf1);
			G_free(formbuf2);
		    }
		    else
			fprintf(stdout, "%s", form);
		    G_free(form);
		    G_free(Fi);
		}
	    }
	}

> I think the first word of new feature is Driver, I wrong?

I think that you're getting confused by the fact that the second layer
doesn't appear to have attribute data attached, and the extra blank
line being inserted between the data from the map itself and the
associated attribute data.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list