2

I would like to set up a lat/long graticule in QGIS with output being a line shapefile with values in Degrees and Minutes, and grid lines shown at every even 1 minute (e.g. 13°23' W, 13°24' W, 13°25' W ..., and likewise for the other axis), and if possible have these values written in this exact format in the attribute table of the output file.

It seems that there are more ways to how to set up the graticule, e.g. in the program itself (Vector -> Research Tools -> Vector Grid, or via MMQGIS plugin) or in the Print Composer, however none of these methods provide a straight forward output as desired; only in decimal numbers.

How can I do it?

QGIS version 2.18.14 and my project and its layers are in EPSG:3857.

  • 1
    I understand you asked for an actual line feature, but I'd like to point out it is possible to get a grid spacing every minute in the composer, I just tested it: just set the grid to a geographic CRS and enter the decimal value of 1/60 in the grid spacing. In my example, the map projection is EPSG:32187 and the grid is EPSG:4326. – Gabriel C. Nov 8 '18 at 16:03
  • This works well and at first glance it is a more straight forward method than doing it via the Toolbox menu. Unlike the other method it automatically creates the grid at even minutes (which is welcome), but a downside for me would be that the output grid lies on top of all other layers, and can't be moved e.g. under labels. But a valid and well working method, thank you very much. – Granko Nov 16 '18 at 16:14
  • That's why I didn't put it as an answer as I suspected you wanted a line layer precisely for this reason. – Gabriel C. Nov 16 '18 at 17:50
3

I would use the processing toolbox->QGIS->Vector Creation tools->Create Grid for this as it allows you to specify the CRS of the grid, but it seems to work best if you also have your project projection in EPSG:4326 too for this step. For the grid spacing I put 1/60 to get minutes. Since you want lines the first grid type (rectangle (line)) is fine.

enter image description here

Once you have run this you need to add the DSM label to each line, for this we will need to add a new column called label and then calculate the DSM value for the line's position.

I borrowed an expression from this question and generated two new columns leftdms and topdms using:

(CASE WHEN "left" < 0 THEN '-' ELSE '' END) || floor (abs("left")) || '° ' || floor(((abs("left")) - floor (abs("left"))) * 60) ||'\'' || substr( (tostring((((abs("left")) - floor (abs("left"))) * 60) - floor(((abs("left")) - floor (abs("left"))) * 60)) * 60),1,5) || '"'

and

(CASE WHEN "top" < 0 THEN '-' ELSE '' END) || floor (abs("top")) || '° ' || floor(((abs("top")) - floor (abs("top"))) * 60) ||'\'' || substr( (tostring((((abs("top")) - floor (abs("top"))) * 60) - floor(((abs("top")) - floor (abs("top"))) * 60)) * 60),1,5) || '"'

Then by using rule based labeling (top=bottom or left=right) for horizontal and vertical lines you end up with:

enter image description here

Note my grid values aren't even numbers as I just picked the canvas extents for my grid bounds.

  • This works! I would add two observations. Running the 'create grid' function in CRS other than 4326 makes QGIS crash (no error message). Then to have the grid lines starting at even minutes, I select the grid extent on screen then correct it manually in the box to even degrees. The result is a grid with an extent much larger than I need but it is easy to delete the redundant lines. Probably not the smoothest of methods but works. I have yet to fine tune the expression to round up/down the figures in the 'label' attribute to have even minutes there. Many thanks! – Granko Nov 16 '18 at 16:10

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.