GPSFileDepot Forums

General Category => Map Making Support => Topic started by: Boyd on April 21, 2013, 01:14:13 PM

Title: Tutorial: Make your own forest shading/landcover
Post by: Boyd on April 21, 2013, 01:14:13 PM
NOTE 6/5/23: Sorry, the illustrations for this post no longer exist and I no longer recommend this approach anyway. I believe you can download landcover from openstreetmap now.

Some of you know this has been a pet topic of mine.  :) After lots of trial and error, I have a procedure that I'm pretty happy with so I would like to share it. You will need Globalmapper and either Photoshop or Photoshop Elements (could also be done with GIMP I'm sure). The procedure is pretty straightforward but involves a number of steps that I will summarize below.

This tutorial assumes you have some basic knowledge of the NLCD and its color coding scheme, although I will show the exact process that I used.

First you need to download the 2006 NLCD imagery, which is one big file covering the entire US. I suggest you crop this down to a very small area for the purpose of experimenting because processing time can be significant with a large file. For example, one USGS 24k quad is about 500x500 pixels and will process pretty quickly.


This is what you should initially see in Globalmapper.


Right-click the image layer in the Control Center and create area features. This function creates polygons from raster images based on the criteria you specify.


I have decided to only extract two things from the image: forest cover and populated areas. I'll leave it up to you to work out similar techniques for extracting other data. Create a layer called forest using the option for selected colors, then choose the colors shown - Palette ID numbers 1, 3, 4, 5 and 8. These are different kinds of vegetation recognized by the NLCD.

After completing this, use the following options to extract the populated areas (which I will call "residential") - palette ID numbers 11, 12 and 13. I am also creating a new layer called residential for these.

This is what you should now see.

Change the Globalmapper background color to black - this will help isolate the colors in Photoshop.


Select all objects on the residential layer, specify a custom style with a null border and solid fill of primary red (RGB value of 255,0,0).

Repeat this for the forest layer using primary green as the fill (RGB 0,255,0). You should now see something like this

We will now export the results as a TIFF raster image using the following options. I am up-sampling the image in order to create a smoother final result (anti-aliasing). I find that 50 feet/pixel is a reasonable setting for a 24k map but feel free to try other values. Processing time and file size will increase with higher settings, lower settings may look too "jaggy". Also be sure to save a TFW and PRJ file or you will have a problem opening it in Globalmapper after modifying in Photoshop.

(continued in next post)
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Boyd on April 21, 2013, 01:46:03 PM
NOTE 6/5/23: Sorry, the illustrations for this post no longer exist and I no longer recommend this approach anyway. I believe you can download landcover from openstreetmap now.

Part Two

Now we'll process the image in Photoshop (I am using Photoshop Elements which was included for free with a scanner I bought). Open the TIFF file and convert to RGB color.

Now apply a Gaussian blur. I've found that 2 pixels is a good number, but feel free to experiment with this.

Now switch back to indexed color, and this is where the "magic" happens. :)

Choose Local (Perceptual) for the palette with 3 colors. This will force photoshop to decide on whether each pixel is closest to red, green or black. Since we blurred everything, the result is creating rounded features to replace the stair-stepped image of the original.

Save the Photoshop file over the original TIFF (keeping the same filename) and be sure not to use any form of image compression. Now we return to Globalmapper and open the modified TIFF file. You must repeat the same procedure as before to "vectorize" the new image but it will be much faster this time because we only have 3 colors to deal with.

Again create a forest layer using selected colors and choose the green color from the palette. After the vectorization process completes, repeat the same steps to create a residential layer by choosing the red color from the palette.

The final steps are selecting the forest and residential objects and changing them to a Globalmapper type. If your goal is making a Garmin map, assign an appropriate MP_TYPE attribute to the results. I am using 0x01 for residential and 0x50 for forest. You can also choose USGS style mint green and pink colors to display in Globalmapper. You may want to merge the forest and residential layers into a single one, or maybe add them to an existing layer in a topo map. The rest is really up to you....

That's about all there is to it.  :)  Here are the final results viewed at 1:48000 when combined with other topo features.

And a closer view at 1:24000

Here you can see the landcover elements by themselves at 1:24000. There are some "jaggies" visible and you could smooth these by up-sampling the image more (such as 30 feet/pixel) but that will require more processing time for diminishing results. You may also get into issues where the edges of the residential and forest areas don't register very well when you increase the resolution.

Anyway, this is what I have learned and I felt it was worth sharing. Hope this helps you add a little color to your maps!  :)



Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Boyd on April 21, 2013, 03:03:30 PM
NOTE 6/5/23: Sorry, the illustrations for this post no longer exist and I no longer recommend this approach anyway. I believe you can download landcover from openstreetmap now.

Here's a little more information that may help you do other things with the NLCD data. First, this is the color code (note this is a .jpg and not color accurate, but it makes a good reference).

And here are the actual palette colors.

Finally, here are the colors in text format. Paste this into a notepad file, save it and change the extension to .pal. This will give you a palette file that Globalmapper should be able to open.

Enjoy!  :)


71,107,161
186,217,235
112,163,186
28,99,48
105,171,99
181,201,143
219,217,61
227,227,194
204,186,125
179,173,163
171,112,41
217,148,130
237,0,0
171,0,0
222,201,201
0,0,0
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: -Oz- on April 21, 2013, 07:24:01 PM
This is great.  How do you "mix" it with having actual National Parks/forests and the like?  I am thinking of doing this with my update to the AZ topo I'm working on.

Also, should we post this as a full up tutorial (since I can make that happen :)).
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Seldom on April 21, 2013, 10:28:54 PM
Quote from: -Oz- on April 21, 2013, 07:24:01 PM
This is great.  How do you "mix" it with having actual National Parks/forests and the like?  I am thinking of doing this with my update to the AZ topo I'm working on.

I've been doing wooded area using a similar GM script on Desert Southwest.  Wooded areas are a semi-transparent TYP.  Land ownership (Parks, BLM, etc.) are all mutually exclusive solid color polygons.  Adding paved areas or other types of landcover like paved areas would be a problem though, because patterns would get pretty complicated.
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Boyd on April 22, 2013, 05:13:14 AM
I have not yet found a technique I like for combining forest shading and parks. I wanted to stick with a style like USGS, and they just use boundary lines, so that's what I currently have. But it leaves a lot to be desired, since you can't easily tell whether you're inside or outside of a park while zoomed in. The transparent pattern is probably the way to go, but I just haven't liked the tests I've done.

Oz, glad you like it - feel free to turn this into a "real" tutorial.  :)
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Seldom on April 22, 2013, 08:14:16 AM
Nice idea to use gaussian blur in Photoshop.  :)  Whenever I used Photoshop to saveas TIFF, I needed to re-rectify, when I re-imported, because, although GM exported a geoTIFF, Photoshop stripped it of the reference data.  That was a long time ago.  Does it still do that?
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Boyd on April 22, 2013, 08:21:54 AM
Yes, it's a problem but I addressed it in the tutorial. When exporting the TIFF in Globalmapper, choose the option to include a PRJ and TFW file. I guess that Photoshop strips the geo information that Globalmapper embeds in the TIFF, but if you have a separate PRJ and TFW with the same name, Globalmapper will automatically use them.

Quote from: Boyd on April 21, 2013, 01:14:13 PMAlso be sure to save a TFW and PRJ file or you will have a problem opening it in Globalmapper after modifying in Photoshop.

(http://boydsmaps.com/nlcd_tutorial/09.jpg)
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: popej on April 22, 2013, 01:56:54 PM
Why don't you use vector functions instead of photoshop? Like for example "smooth" option form Global Mapper.

Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Boyd on April 22, 2013, 02:27:53 PM
I tried that before, and did not like the results. It created gaps and overlaps of adjacent objects. But that can be somewhat of an issue no matter how you approach the problem (converting stair-steps to a smooth line). I felt the blur combined with a limited palette produced the most visually pleasing results.

Really, the tutorial is just offered as one approach and also a way to get people thinking about different methods. I would encourage everyone to try their own ideas and post examples.
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: popej on April 22, 2013, 03:56:24 PM
Well, there are land cover data for Europe too, unfortunately already in shp format ;)
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Boyd on April 22, 2013, 04:20:40 PM
Here in New Jersey we have high quality LULC data available as shapefiles also (at a scale of 1:12,000). But the whole reason I got interested in this project is the fact that I haven't been able to find any decent vector landcover data for other states (have looked for PA, NY, DE, MD, ME and others). There are some old DLG USGS files but they are only 1:250,000 resolution so not very good for a 24k map.  :)
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: nm_map_user on April 23, 2013, 09:32:49 AM
Quote from: Seldom on April 22, 2013, 08:14:16 AM
Nice idea to use gaussian blur in Photoshop.  :)  Whenever I used Photoshop to saveas TIFF, I needed to re-rectify, when I re-imported, because, although GM exported a geoTIFF, Photoshop stripped it of the reference data.  That was a long time ago.  Does it still do that?

As Boyd already noted, yes, Photoshop strips off the GeoTiff tags. In fact, almost every image editor will strip them off because they are viewed as non-standard tags so they are neither read nor re-written. Boyd has already explained how to address this in GM. For other tools that don't have this capability, you can use two programs from the GDAL package to save the header information and restore it. listgeo will read the tags and write them in ASCII to a file. geotifcp will read the tag file and insert the tags into a tiff file, making it a geotiff.
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: nm_map_user on April 23, 2013, 05:07:01 PM
It's possible to remap the colors of the entire NLCD in one shot using gdal_translate. The basic idea is to first convert the geotiff to a .vrt (virtual raster). This step takes essentially no time, as it just creates an XML file describing the key properties of the file. You then edit the .vrt file to change the palette to the one you want on output and add a look-up table to provide the mapping between input colors and output colors. With this done, you run gdal_translate again to generate a new geotiff with the new color palette. (It's actually easier than it looks written like that). gdal tools tend to work on very large rasters, so I suspect it is fully capable of processing the entire NLCD image in one shot. After that, you can skip right to the blurring step (presumably on an extracted tile), though I suppose it's possible that Photoshop might be able to handle the entire map as well.

If anyone is interested, I can provide more details on editing the .vrt file
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Seldom on May 23, 2013, 11:25:48 AM
Should anyone be interested in a GM script to vectorize raster maps, GM 14 has a feature, EQUAL_COLORS, to restrict vector processing to just colors you are interested in rather than the entire map.  Using EQUAL_COLORS cut my processing time to 1/6th of what it was without it.

GENERATE_EQUAL_VAL_AREAS FILENAME="%FNAME%" COLOR_DIST=0.0 ATTR_NAME="COLOR" EQUAL_COLORS=RGB(105,171,099);RGB(028,099,048);RGB(181,201,143)

The code fragment is from a do-loop that processes all the TIFFs in a directory.

GENERATE_EQUAL_VAL_AREAS calls the processes that Boyd calls in the "Create area features" dialog above.  EQUAL_COLORS limits the processing to the 3 RGB colors that follow it.  Note that the colors listed are for the NLCD2006_landcover_4-20-11_se5.zip that covers the entire US.   They match the colors in Boyd's example, but they don't match the colors that I downloaded a year or two ago from the National Map Seamless server.    Figuring out why my old scripts weren't working took a while.  :-[
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Boyd on May 23, 2013, 12:03:55 PM
Pretty cool - thanks.  :) But I'm on GM 12 and have decided to sit out a few upgrades since it really does everything I need at this point.

BTW, if anyone is playing around with this, I made a couple small tweaks that I think produce better results. First, when I select all the features in the "Residential" layer, I am use primary BLUE as a color instead of RED like the tutorial. This seems to create a more accurate boundary between the forest and populated areas. Since red and green are complimentary colors, I *think* this was creating a gray zone between areas after blending in Photoshop and gray is closer to the black pallete color, therfore creating a gap.

The other difference is that I am up-sampling the raster export at 30 feet per pixel instead of 50 feet per pixel in the tutotial. This makes for less noticeable stair-steps as you zoom in on the finished map. At 50 feet/pixel the landcover starts to look pretty "jaggy" zooming in closer than .3 miles in Mapsource. At 30 feet/pixel the jaggies become noticeable when you hit the 500 foot zoom in Mapsource.

Further experimentation would be a good idea if you plan to use this technique, to see what you personally find acceptable. It also depends on other map features. In an area with lots of roads and/or contour lines the jaggies aren't so noticeable.

Also, in areas that are predominately forest you can end up with some huge and very complex green polygons. These are fine until you try to slice and dice them (such as as gridded export). If the polygons are too big and complex, GM messes them up when cropping sometimes. The only fix I have found for this is to work with smaller images to prevent the polygons from getting too large.
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Seldom on May 23, 2013, 01:19:13 PM
Quote from: Boyd on May 23, 2013, 12:03:55 PM
Pretty cool - thanks.  :) But I'm on GM 12 and have decided to sit out a few upgrades since it really does everything I need at this point....

Also, in areas that are predominately forest you can end up with some huge and very complex green polygons. These are fine until you try to slice and dice them (such as as gridded export). If the polygons are too big and complex, GM messes them up when cropping sometimes. The only fix I have found for this is to work with smaller images to prevent the polygons from getting too large.

You can still script GENERATE_EQUAL_VAL_AREAS with GM12, just not EQUAL_COLORS.

I'm pretty sure the problem you describe with large wooded areas  processed in PhotoShop is malformed polygons. (Photoshop creates a bowtie where it should have a rectangle.)  If you only process the areas in GM and leave the 30 meter jaggies the polygons will remain well formed.  I slice my wooded areas in GPSmapEdit all the time with no trouble.  When I tried to slice them after PhotoShop the shapes got pretty bizarre.
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Boyd on May 23, 2013, 02:20:03 PM
Basically I think you're saying that it's easier to turn a simple image into a polygon than a complex image. Definitely true. But I like the curves that photoshop creates with the up-sampled raster image. I had the same problems big time when I turned shaded LIDAR terrain into polygons.

My standard map tile is a USGS 24k quad. I find that if I cut the NLCD tiff's into about 9 quads (3x3) it works pretty well. I like to think in terms of USGS quads, they have names and there's just something intangible that I like about them. It is also a convenient size to hand-edit. But it can get tedious because they are pretty small. Wouldn't be practical to use my workflow if I were mapping a large state.  ;)
Title: Re: Tutorial: Make your own forest shading/landcover
Post by: Seldom on May 23, 2013, 03:48:56 PM
Quote from: Boyd on May 23, 2013, 02:20:03 PM
I like to think in terms of USGS quads, they have names and there's just something intangible that I like about them.

When I came across the Carcass Canyon and Scorpion Gulch quads, I knew Utah was the right place for me.