[GRASS-user] Export the conversion from Vector to Raster

Greetings
This is probably a very dumb thing but I’m having a few difficulties doing this. I have an SHAPEFILE with classification polygons. And I need to Convert to raster (e.g. TIF) So I thought of using GRASS (of course)

1- Define region with a Landsat image used to create those Training areas outside GRASS
2- Run v.in.gor

v.in.ogr -o dsn=C:\Data\GISDataBase\training_data.shp output=train00
Over-riding projection check
Layer: training_data
Default driver / database set to:
driver: dbf
database: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/
Importanto feições do mapa 448…

Building topology for vector map …
Registering primitives…
448 primitives registered
2903 vertices registered
Building areas…
448 areas built
448 isles built
Attaching islands…
Attaching centroids…
Number of nodes: 448
Number of primitives: 448
Number of points: 0
Number of lines: 0
Number of boundaries: 448
Number of centroids: 0
Number of areas: 448
Number of isles: 448
Number of areas without centroid: 448

Cleaning polygons, result is not guaranteed!
Building topology for vector map …
Number of nodes: 448
Number of primitives: 448
Number of points: 0
Number of lines: 0
Number of boundaries: 448
Number of centroids: 0
Number of areas: -
Number of isles: -

Break polygons:

Remove duplicates:

Break boundaries:

Remove duplicates:

Clean boundaries at nodes:

Change dangles to lines:

Remove bridges:

Building topology for vector map …
Building areas…
448 areas built
448 isles built
Attaching islands…
Number of nodes: 448
Number of primitives: 448
Number of points: 0
Number of lines: 0
Number of boundaries: 448
Number of centroids: 0
Number of areas: 448
Number of isles: 448
Number of areas without centroid: 448
Layer: training_data


Building topology for vector map …
Registering primitives…
896 primitives registered
3351 vertices registered
Building areas…
448 areas built
448 isles built
Attaching islands…
Attaching centroids…
Number of nodes: 896
Number of primitives: 896
Number of points: 0
Number of lines: 0
Number of boundaries: 448
Number of centroids: 448
Number of areas: 448
Number of isles: 448

448 input polygons
Total area: 6.159110e+006 (448 areas)
Overlapping area: 0.000000e+000 (0 areas)
Area without category: 0.000000e+000 (0 areas)

3- It created a vectorial train00. When I open it at GRASS and overlays it with my landsat images they MATCH…
4- I want to create a RASTER exacly with the same characteristics as my landsat images but using Class Field as Raster values. I mean, the pixels inside polygons with class value 12 will have a vlue of 12.
Reading GRASS book I decided to use v.to.rast

v.to.rast input=train00@PERMANENT output=train_raster00 type=area column=Class labelcolumn=cat
Loading data…
Pass 1 of 2:
Reading areas…
Reading features…
Writing raster map…
Pass 2 of 2:
Reading areas…
Writing raster map…
Converted areas: 448 of 448
Converted points/lines: 0 of 0
v.to.rast complete.

5- Open train_raster00 and it seems to be Ok when comparing with Vectorial
6- Metadata from is train_raster00

| Type of Map: raster Number of Categories: 0 |
| Data Type: CELL |
| Rows: 7109 |
| Columns: 7662 |
| Total Cells: 54469158 |
| Projection: x,y |
| N: 23020.21492744 S: -190249.78507256 Res: 30 |
| E: 177696.83076767 W: -52163.16923233 Res: 30 |
| Range of data: min = 1 max = 17 |
And Metadata from Landsat is:

| Type of Map: raster Number of Categories: 0 |
| Data Type: CELL |
| Rows: 7109 |
| Columns: 7662 |
| Total Cells: 54469158 |
| Projection: x,y |
| N: 23020.21492744 S: -190249.78507256 Res: 30 |
| E: 177696.83076767 W: -52163.16923233 Res: 30 |
| Range of data: min = 0 max = 255 |

So it maches :slight_smile:

7- Now, export this raster.Since I want a Geotiff I used:
r.out.tiff input=train_raster00@PERMANENT output=trainraster00a
If I do gdalinfo to the exported file I get:river: GTiff/GeoTIFF
Files: /mnt/GIS/trainraster00a.tif
Size is 7662, 7109
Coordinate System is `’
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 7109.0)
Upper Right ( 7662.0, 0.0)
Lower Right ( 7662.0, 7109.0)
Center ( 3831.0, 3554.5)
Band 1 Block=7662x1 Type=Byte, ColorInterp=Red
Band 2 Block=7662x1 Type=Byte, ColorInterp=Green
Band 3 Block=7662x1 Type=Byte, ColorInterp=Blue

The Size is OK but the Geo information was wipped out
And Why does it create 3 bands? I only need 1 band with Class values.
Can anyone point me out what am I doing wrong?

Thanks
Best regards
Kim~
Sorry for the long EMAIL but I really need to explain what I am doing

Kim Besson wrote:

[snip]

7- Now, export this raster.Since I want a Geotiff I used:
r.out.tiff input=train_raster00@PERMANENT output=trainraster00a

You must use r.out.gdal to get a GeoTIFF, r.out.tiff produces an
ordinary tif image, not a spatial raster dataset.

Markus M

Hi Markus
I did this:
r.out.gdal input=train_raster00@PERMANENT output=C:\Data\GISDataBase\trainraster00b nodata=-1
And I got

<PROJ_INFO> not found for
<PROJ_UNITS> not found for <PT_IGP>
Exporting to GDAL data type: Byte
Unable to set projection
Input raster map contains cells with NULL-value (no-data). The value -1 was used to represent no-data values in the input map. You can specify nodata value by nodata parameter.

It’s strange. Then I decided to do g.region display and I realized that:

projection: 0 (x,y)
zone: 0
north: 23020.21492744
south: -190249.78507256
west: -52163.16923233
east: 177696.83076767
nsres: 30
ewres: 30
rows: 7109
cols: 7662
cells: 54469158
(Fri May 07 10:40:07 2010) Comando terminado (0 sec)
(Fri May 07 10:40:30 2010)
g.region -p
projection: 0 (x,y)
zone: 0
north: 23020.21492744
south: -190249.78507256
west: -52163.16923233
east: 177696.83076767
nsres: 30
ewres: 30
rows: 7109
cols: 7662
cells: 54469158

I have NO PROJECTION :frowning: How come? I have defined my Location from a projected Landsat image the same that I have imported. Any clues of what I did wrong?

2010/5/7 Markus Metz <markus.metz.giswork@googlemail.com>

Kim Besson wrote:

[snip]

7- Now, export this raster.Since I want a Geotiff I used:
r.out.tiff input=train_raster00@PERMANENT output=trainraster00a

You must use r.out.gdal to get a GeoTIFF, r.out.tiff produces an
ordinary tif image, not a spatial raster dataset.

Markus M

Kim Besson wrote:

Hi Markus
I did this:
r.out.gdal input=train_raster00@PERMANENT
output=C:\Data\GISDataBase\trainraster00b nodata=-1

nodata = -1 and type = Byte is no good because the range of Byte is 0
- 255 and -1 gets converted to 255, i.e. all NULL cells will become
255 (all cells that are already 255 stay 255) but nodata is -1 so info
about NULL cells gets lost.

And I got
<PROJ_INFO> not found for <DATA>
<PROJ_UNITS> not found for <PT_IGP>

check the original Landsat data with gdalinfo. They are usually in
UTM. If the original data don't have projection info, the xy location
is correct and you have to manually reproject to a proper location. If
the original data do have projection info, something went wrong while
defining the location, no idea what.

Markus M

Exporting to GDAL data type: Byte
Unable to set projection
Input raster map contains cells with NULL-value (no-data). The value -1 was
used to represent no-data values in the input map. You can specify nodata
value by nodata parameter.
It's strange. Then I decided to do g.region display and I realized that:
projection: 0 (x,y)
zone: 0
north: 23020.21492744
south: -190249.78507256
west: -52163.16923233
east: 177696.83076767
nsres: 30
ewres: 30
rows: 7109
cols: 7662
cells: 54469158
(Fri May 07 10:40:07 2010) Comando terminado (0 sec)

(Fri May 07 10:40:30 2010)

g.region -p

projection: 0 (x,y)
zone: 0
north: 23020.21492744
south: -190249.78507256
west: -52163.16923233
east: 177696.83076767
nsres: 30
ewres: 30
rows: 7109
cols: 7662
cells: 54469158
I have NO PROJECTION :frowning: How come? I have defined my Location from a
projected Landsat image the same that I have imported. Any clues of what I
did wrong?
2010/5/7 Markus Metz <markus.metz.giswork@googlemail.com>

Kim Besson wrote:

[snip]

> 7- Now, export this raster.Since I want a Geotiff I used:
> r.out.tiff input=train_raster00@PERMANENT output=trainraster00a

You must use r.out.gdal to get a GeoTIFF, r.out.tiff produces an
ordinary tif image, not a spatial raster dataset.

Markus M