Opened 14 years ago

Last modified 8 years ago

#1124 new defect

v.to.rast inconsistency in importing label

Reported by: cmbarton Owned by: grass-dev@…
Priority: major Milestone: 6.4.6
Component: Raster Version: svn-develbranch6
Keywords: v.to.rast Cc:
CPU: All Platform: All

Description

We just ran into a strange inconsistency in the behavior of v.to.rast. This happens if you are trying to use vector attributes to populate the cat and label fields of a new raster.

If you have a float (double precision) attribute to use for the raster cat and string attribute to use for the raster label, the float is imported into the raster cat fine. But the string is imported from the vector attribute to the raster label ONLY if the value in the corresponding attribute to use for the cat has no decimals. For example:

here is a vector attribute table with 2 attributes and 4 records:

float_attr     str_attr
=========     =======
1.5           "first line"
2             "second line"
2.5           "third line"
3             "fourth line"

v.to.rast is run as follows:

v.to.rast input=vectorfile output=newraster use=attr type=point column=floatattr labelcolumn=strattr

The result is that raster cells with values 2 and 3 have labels, but the cells with values 1.5 and 2.5 do not have labels.

Change History (7)

comment:1 by hamish, 14 years ago

see also #175, "v.to.rast labelcol= SegFaults and ignored".

Hamish

comment:2 by hamish, 14 years ago

Keywords: v.to.rast added

in reply to:  1 comment:3 by cmbarton, 14 years ago

Replying to hamish:

see also #175, "v.to.rast labelcol= SegFaults and ignored".

Hamish

This does indeed look suspicious and possibly related.

Michael

comment:4 by neteler, 8 years ago

Milestone: 6.4.06.4.6

in reply to:  description comment:5 by mlennert, 8 years ago

Replying to cmbarton:

We just ran into a strange inconsistency in the behavior of v.to.rast. This happens if you are trying to use vector attributes to populate the cat and label fields of a new raster.

If you have a float (double precision) attribute to use for the raster cat and string attribute to use for the raster label, the float is imported into the raster cat fine. But the string is imported from the vector attribute to the raster label ONLY if the value in the corresponding attribute to use for the cat has no decimals. For example:

here is a vector attribute table with 2 attributes and 4 records:

float_attr     str_attr
=========     =======
1.5           "first line"
2             "second line"
2.5           "third line"
3             "fourth line"

v.to.rast is run as follows:

v.to.rast input=vectorfile output=newraster use=attr type=point column=floatattr labelcolumn=strattr

The result is that raster cells with values 2 and 3 have labels, but the cells with values 1.5 and 2.5 do not have labels.

I would actually consider this logical: what does a label for an arbitrary precision number mean ? In my eyes, labels only make sense for CELL maps, not really for DCELL or FCELL, or it should be range labels, not exact value label.

comment:6 by cmbarton, 8 years ago

There is no reason why only a map with integer values should have labels and a map with float values should not. Sometimes discrete data are coded with real numbers for a variety of reasons. Having labels for these values should not be arbitrarily prohibited.

in reply to:  6 comment:7 by mmetz, 8 years ago

Replying to cmbarton:

There is no reason why only a map with integer values should have labels and a map with float values should not. Sometimes discrete data are coded with real numbers for a variety of reasons. Having labels for these values should not be arbitrarily prohibited.

According to the manual of r.category, floating point values are fine. The problem is a bug in v.to.rast which writes out ranges for labels instead of unique labels. The cats file contains something like

1.5:2:first line
2:2.5:second line
2.5:3:third line

that is, 3 ranges for 4 values, and the last label got lost. v.to.rast should instead write out unique labels as

1.5:first line
2:second line
2.5:third line
3:fourth line

Further on, v.to.rast should remove duplicate values before creating raster categories, otherwise the result could be something like

1.5:first line
1.5:first line
2:second line
1.5:first line
2.5:third line
1.5:first line
3:fourth line
1.5:first line
Note: See TracTickets for help on using tickets.