Is it possible to create a raster in QGIS from a CSV file that is a “matrix of coordinates” without transforming it into a vector?

I explain: My data is a matrix of 5500 columns and 175 rows, it is 962500 points. The Columns are the X coordinates and the Rows are the Y coordinates. The values in the matrix are the Z coordinate of each point. The X distance between points is 0,04 cm and the Y distance is 0,80 cm. I could try reorganizing the data in a way that I have just three coordinates in columns X, Y, Z for all the 962500 points. However, it means an additional step and I would have to do it repeatedly as my experiment produces the CSV file described before.

How can I create the raster in QGIS from the original matrix?

  • what you have looks like a "raster to point" output; in order to read it as a csv you have to modify the aspect of your file, so you end up with x, y and z fields, instead of x1...xn, vs y1...yn fields, I would try that in R; then go from point to raster
    – Elio Diaz
    Nov 8 '17 at 22:40
  • 1
    If you add a correct header this could be read in as an ASCI grid, I think
    – Ian Turton
    Nov 9 '17 at 8:49
  • Your data sounds already as a raster in some way, but you need a header to describe its organization, could you provide a exerpt of your data? the first 3 lines for instance
    – Marco
    Nov 9 '17 at 8:50
  • Yes indeed the data is somehow organized as a raster. The original CSV file does not come with the headers. It looks like this: 4.64,4.62,4.64,4.68,4.69,4.76,4.79 4.7,4.71,4.61,4.64,4.64,4.67,4.69 4.33,4.44,4.5,4.48,4.52,4.58,4.61 The delimiters are commas (,). I could include the headers. For columns are the X coordinates and headers for the rows are the Y coordinates.
    – Mandiaz
    Nov 10 '17 at 9:31

You need to create a header for your data. It is plenty of formats, you just need to choose one supported by GDAL (see: http://www.gdal.org/formats_list.html)

Here the description of the GRASS ASCII taken from r.in.ascii., which take into account the different size of X and Y dimensions:

The GRASS ASCII input file has a header section which describes the location and size of the data, followed by the data itself.

The header has 6 lines:

north:   xxxxxx.xx 
south:   xxxxxx.xx 
east:    xxxxxx.xx 
west:    xxxxxx.xx 
rows:    r  
cols:    c 

The north, south, east, and west field values entered are the coordinates of the edges of the geographic region. The rows and cols field values entered describe the dimensions of the matrix of data to follow. The data which follows is r rows of c integers.

Optionally the following parameters can be defined in the header section:

null: nn 
type: float 
multiplier: 2.

"null" defines a string or number to be converted to NULL value (no data). "type" defines the data type (int, float double) and is not required. "multiplier" is an optional parameter to multiply each cell value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.