# Coloring OGR\_GMT polygon files based on attribute column

**URL:** <https://forum.generic-mapping-tools.org/t/coloring-ogr-gmt-polygon-files-based-on-attribute-column/1129>\
**Category:** Q&A\
**Created:** [December 15, 2020, 5:06am UTC](https://forum.generic-mapping-tools.org/t/coloring-ogr-gmt-polygon-files-based-on-attribute-column/1129 "2020-12-15T05:06:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![weiji14](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/weiji14/32/33_2.png) [@weiji14](https://forum.generic-mapping-tools.org/u/weiji14)\
**Post date:** [December 15, 2020, 5:06am UTC](https://forum.generic-mapping-tools.org/t/coloring-ogr-gmt-polygon-files-based-on-attribute-column/1129/1 "2020-12-15T05:06:54Z")

</div>

Given an [OGR\_GMT](https://docs.generic-mapping-tools.org/6.1/cookbook/ogrgmt-format.html) with a “placename” and “zattribute” consisting of two triangular polygon areas like so:

```auto
# @VGMT1.0 @GPOLYGON
# @Nplacename|zattribute
# @Tstring|double
# FEATURE_DATA
>
# @D"Area 1"|0.70
# @P
1 5
1 3
3 3
>
# @D"Area 2"|0.80
# @P
3 3
5 3
5 1

```

I can plot the polygons ok using `gmt plot tmp.gmt -Baf -L -png map`:

 ![map](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/20dd3d6b34eb86dc7a0112bb9cff99af9288f865.png)

But how can the triangles be colored individually based on the “zattribute” column? I tried looking at the `-a` (aspatial) column in [`plot`](https://docs.generic-mapping-tools.org/dev/plot.html) but couldn’t seem to get this to work:

```bash
gmt plot tmp.gmt -Baf -L -Cbatlow -G+z -azattribute -png map
# plot [WARNING]: Mismatch between actual (3) and expected (2) fields near line 6 in file

```

I saw the answers at [https://flint.soest.hawaii.edu/t/fill-in-polygon-color/322/4](https://flint.soest.hawaii.edu/t/fill-in-polygon-color/322/4) and [https://flint.soest.hawaii.edu/t/coloring-polygon/1026/2](https://flint.soest.hawaii.edu/t/coloring-polygon/1026/2), but here I don’t have `> -Z0.7` in the multisegment header (difficult to assign it to many polygons at once, but open to ideas of bringing the “zattribute” to the `> -Z` header if anyone has ideas).

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [December 15, 2020, 7:00am UTC](https://forum.generic-mapping-tools.org/t/coloring-ogr-gmt-polygon-files-based-on-attribute-column/1129/2 "2020-12-15T07:00:42Z")

</div>

Think you need to use **-aG=zattribute** and no -G+z

See the various tests under gmt/test/ogr

---

<div class="post-metadata">

**Author:** ![weiji14](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/weiji14/32/33_2.png) [@weiji14](https://forum.generic-mapping-tools.org/u/weiji14)\
**Post date:** [December 15, 2020, 11:10am UTC](https://forum.generic-mapping-tools.org/t/coloring-ogr-gmt-polygon-files-based-on-attribute-column/1129/3 "2020-12-15T11:10:11Z")

</div>

Close! The [gmt/test/ogr/lookup.sh](https://github.com/GenericMappingTools/gmt/blob/bb0b2d9dd69a4ab537fc1b0353b5ba5f78b777c0/test/ogr/lookup.sh#L40) example was using RGB colour (e.g. 110/186/103), so not quite right in this case as it gave black coloured triangles

`gmt plot tmp.gmt -Baf -Cbatlow -L -aG=zattribute -png map`:

 ![map](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/dbca208e71de1fe0843a4b025e2ac4a9e4e336fc.png)

I had a dig around and saw this question [https://flint.soest.hawaii.edu/t/how-to-extract-attribute-values-from-shapefile-for-cpt-file-generation/464](https://flint.soest.hawaii.edu/t/how-to-extract-attribute-values-from-shapefile-for-cpt-file-generation/464), and `-aZ=zattribute` seemed to do the trick:

`gmt plot tmp.gmt -Baf -Cbatlow -L -G+z -aZ=zattribute -png map`

 ![map](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/0a2566c418966ecf6ab1ebe577921373df9fa5d1.png)
