2

Objective: Extract the four Latitude, Longitude points which correspond to the corner edges of each polygon in the Military Grid Reference System (MGRS) shapefile.

How can this be done in QGIS?

In this picture the red arrows point to the places I would like to know the Latitude, Longitude: enter image description here

Here is what the MGRS shapefiles look like in QGIS 2.8.16, notice the corners look good: enter image description here

When I used: y_min(bounds($geometry)) x_min(bounds($geometry)) y_max(bounds($geometry)) x_max(bounds($geometry))

And then plotted the data in Tableau Desktop, the result is some of the polygons are overlapping slightly and the corners aren't matching up exactly. enter image description here

Here are the points which make up 14SPC:

GZD,LATITUDE,LONGITUDE,MGRS,PointID 14S,32.519328,-97.93512,14SPB,1 14S,33.434729,-99,14SNC,1 14S,33.420739,-97.924236,14SPC,1 14S,33.403103,-96.848967,14SQC,1 14S,34.322005,-97.912856,14SPD,1 14S,33.434729,-97.93512,14SPB,2 14S,34.341303,-99,14SNC,2 14S,34.336476,-97.924236,14SPC,2 14S,34.322005,-96.848967,14SQC,2 14S,35.238088,-97.912856,14SPD,2 14S,33.434729,-96.848967,14SPB,3 14S,34.341303,-97.912856,14SNC,3 14S,34.336476,-96.826229,14SPC,3 14S,34.322005,-96,14SQC,3 14S,35.238088,-96.802458,14SPD,3 14S,32.519328,-96.848967,14SPB,4 14S,33.434729,-97.912856,14SNC,4 14S,33.420739,-96.826229,14SPC,4 14S,33.403103,-96,14SQC,4 14S,34.322005,-96.802458,14SPD,4

2
  • 1
    Welcome to gis.stackexchange! Please note that a good question on this site is expected to show some degree of research on your part, i.e. what you have tried and - if applicable - code so far. For more info, you can check our faq.
    – underdark
    Jul 17, 2018 at 18:04
  • After days of Googling and trying to find a way in both QGIS and ArcDesktop, I wasn't finding anything that was helpful. If I had something that was sort of working or worth posting I would have posted it.
    – qgistester
    Jul 17, 2018 at 18:47

3 Answers 3

2

You can use the field calculator to add this values to the attribute table of the layer (may be a virtual field is the best, because this values are recalculated when opening the attribute table).

Open the attribute table of your layer and select field calculator (the abacus icon):

expression for x_max

Similar way you can create x_min, y_min and y_max. You can find the bound and x_max, y_max, x_min, y_min functions in the geometry group.

2

In QGIS, use the tool Extract Vertices to convert the vertices of your polygon layer to points. Make sure to save this layer in a geographic coordinate system.

You can view the coordinates of each point by clicking on it with the Identify tool.

To extract all the coordinates as a table, use the Field Calculator to add X and Y fields. Then save the vertices layer in CSV format. Now you have a CSV file that you can open with Excel.

2
  • In QGIS 2.8.16, do I need to install a plugin to use the Extract Vertices tool? I don't see it when I look in my menu drop downs.
    – qgistester
    Jul 18, 2018 at 17:24
  • I have no idea. You didn't specify a version of QGIS, so I assumed you were using a recent one.
    – csk
    Jul 18, 2018 at 17:30
1

In QGIS 3.x you can make use of side effects to extract edge points from polygons, when you copy&paste features from your polygon layer to a memory point layer:

layer = QgsVectorLayer("Point?crs=epsg:4326&field=name:string(255)", "nodes", "memory")
layer.addExpressionField( '$x', QgsField( 'x', QVariant.Double) )
layer.addExpressionField( '$y', QgsField( 'y', QVariant.Double) )
layer.addExpressionField( '$id - minimum( $id,group_by:="name") + 1', QgsField( 'id', QVariant.Int) )
QgsProject.instance().addMapLayers([layer])

The edge point Ids are autoicremented and start at 1 for every polygon. The big benefit is: you can always change the CRS of the memory layer before you copy the polygons.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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