2

I have a CSV file with the following output

id, x min, y min, x max, y max, value
1 , 0    , 0    , 100  , 100  , 5
2 , 0,   , 100  , 100  , 200  , 10
3 , 100  , 100  , 200  , 200  , 15
4 , 100  , 0    , 200  , 100  , 20

I can plot the co-ordinate points onto my basemap fine. What I'm trying to do is tell QGIS that row 1 of the CSV has the bottom left and top right corners of a square, to draw it, and to assign it a value of 5.

I'm not even sure this is the right way to achieve my goal - which is to display a grid with different values attached to each square, and then produce a heat-map based on those values.

Thanks.

  • 2
    Do you need a vector "grid" of square-shaped polygons? I think that you instead want a raster (often referred to as a grid), which stores values in cells (almost always square-shaped). – Erica Jun 11 '14 at 16:27
  • I don't specifically need a vector. Your raster technique sounds like a good solution, but how to implement it? – Ben Mayo Jun 11 '14 at 17:37
  • This question may help you as a starting point. I don't honestly know QGIS as well as I should, so hopefully a more qualified answerer can expand on the actual implementation :) – Erica Jun 11 '14 at 19:45
1

I would go through WKT way. You could edit your data a bit and build polygons as WKT from the corners of your boxes and save the result into csv file which you can finally import with the CSV plugin. See documentation http://docs.qgis.org/2.0/en/docs/user_manual/introduction/general_tools.html#add-delimited-text-layer

However, it is more fun to do the conversion with SQL within Spatialite. Install spatialite-gui, create an empty database and copy and execute the following SQL statements one by one in the SQL box.

create table text_to_box  (id,  x_min, y_min, x_max, y_max, value);
insert into text_to_box values (1,0,0,100,100,5);
insert into text_to_box values (2,0,100,100,200,10);
insert into text_to_box values (3,100,100,200,200,15);
insert into text_to_box values (4,100,0,200,100,20);
SELECT AddGeometryColumn('text_to_box','geometry',4326,'POLYGON',2);
update text_to_box set geometry = geomfromtext('POLYGON(('||x_min||' '||y_min||','||x_min||' '||y_max||','||x_max||' '||y_max||','||x_max||' '||y_min||','||x_min||' '||y_min||'))',4326)

When you are ready you can connect your database with QGIS and import the table. Note that I used EPSG:4326 as the coordinate system. Edit it if needed.

If you decide to build WKT without Spatialite/SQLite you can do it with Excel or OpenOffice by using the text string functions. The result should be like this (square has four corners but WKT polygon must be closed and therefore the first point must be repeated as the last point)

POLYGON((0 0,0 100,100 100,100 0,0 0))
POLYGON((0 100,0 200,100 200,100 100,0 100))
POLYGON((100 100,100 200,200 200,200 100,100 100))
POLYGON((100 0,100 100,200 100,200 0,100 0))
1

If your grid is regular, think of calculating xmean and ymean:

xmean = (xmax+xmin) / 2
ymean = (ymax+ymin) / 2

for every line, then import this text file:

id, xmean, ymean, value
1 , 50   , 50   , 5
2 , 50   , 150  , 10
3 , 150  , 150  , 15
4 , 150  , 50   , 20

And run a contour or heatmap algorithm on it.

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.