Trick serving a hillshade image from GeoServer

I had the perfect hillshade raster ready to throw on top of my web map, I had previewed it in QGIS and the colour stretching and values looked fine.
Hillshade in QGIS

I then loaded it into GeoServer and it looked great in the OpenLayers Layer Preview window as well.

However, once I added it as a WMS layer in a Leaflet map, I got really confused.  Even though I had my NODATA=255 parameters seemingly working well there appeared a small strip around the outside of the image that was obnoxious.

When GeoServer skews the image it creates a region around the image that has value=0.  This image already had nodata=255, so it can be very confusing.
When GeoServer skews the image it creates a region around the image that has value=0. This image already had nodata=255, so it can be very confusing.

I figured I could change it with an SLD but hadn’t done it before so it took a while to figure out.  For a couple hours I tried various permutations of the default “raster” Style, but with no luck.  The image, otherwise, looked great so the Style obviously wasn’t a real problem in and of itself.

The trick came when I realised that I need to set my color maps for the gray band explicitly.  Up to this point no particular band had been isolated for color mapping.  I found the right place to put the elements in the SLD and all worked out well.

My takeaway: there must be a better way to develop SLD for rasters.  The options in the GeoServer docs are amazing and exciting, but trying to fit them into a specific context has always been a challenge for me.  That’s why I had to write this down, but I’m sure I’ll have to remember it all again a year from now!

Note there is no skewed "collar" around the image as value=0 is ignored.
Note there is no skewed “collar” around the image as value=0 is ignored.

 
My SLD:



  
    default_hillshade
    
      Raster Hillshade
      Grayscale hillshade SLD
      
        
          rule1
          Hillshade with transparency
          Ignore values outside valid range, nodata values transparent
          
          	
            	
                	1
               	                          
            
	        
            	
                
                     
			
          
        
      
    
  

 

 

PDF Map Hack – Remove Embedded Image

Need to remove an embedded image from a PDF file?  You can easily chop out parts of it as needed with the PDFtk command line tool and a little bit of text editing.  Here’s how…

When GIS applications started allowing us to save maps into PDF files, I was happy for about 2 minutes.  The first 48MB PDF sent to a client (by “sent” I mean burned to a CD and mailed) wasn’t even viewable on their low-powered computer.

Now, more than 12 years later I’m still dealing with a similar PDF challenge: how to remove unwanted elements from the document.  This time I had a PDF that included some vector graphics on top of an orthophoto image background.  As I was going to convert the PDF to a TIFF and georeference it in QGIS for someone else to use (see below), I wanted to drop the embedded image.

Remove Image from PDF Map

I’m a big fan of the PDFtk command line toolkit (aka PDFtk Server) as it is cross platform and has never let me down when splicing, chopping, concatenating and now modifying PDF files.  So I was thrilled to read this tip from quickpdf.org forums:

1. Uncompress the original PDF using pdftk: 
    pdftk png_example.pdf output step1.pdf uncompress 

2. Edit step1.pdf (using commandline edit.exe): 
    Find the object of interest, in this case 5 0 obj. 
    Remove all references to this object by deleting the 
    lines associated with it, including: 
      /XOBJ7BC610 5 0 R 
      /XOBJ7BC610 Do 
      Everything between the line starting with 5 0 obj 
      and endobj 
    Save the edited file to step2.pdf. 

3. The xref table in step2.pdf is now corrupt, so we need to fix it. We'll also recompress the PDF: 

    pdftk step2.pdf output step3.pdf compress 

The final file, step3.pdf, is now a valid, compressed PDF, without the unwanted image (we left the text description below the spot where the image was). We can now use QuickPDF to add a new image in its place.

That is precisely what I did and it worked well.  The only gotcha was that I had never edited an uncompress PDF file and, obviously, my PDF wasn’t the same as the tip example.

I was able to find the section where the only RGB image started – it was “4 0 obj” and the “endobj” was about 400 lines further down.  I deleted those, ran the compress step and was off to the races.

PDF to TIFF Command Line Tool on OSX

As a bonus for reading this far, I then converted the PDF to TIFF so I could use it in QGIS.  I used the built-in OSX command line tool:

sips -s format tiff step3.pdf --out out_nogcp.tif

Incidentally, using QGIS Georeferencer plugin, I was only four clicks away from thin plate spline transforming the TIFF file into a georeferenced image with transparency.  Now I could put whatever background image I wanted behind it.

Web Mapping Illustrated – 10 year celebration giveaway [ENDED!]

web-mapping-tyler-mitchell-large
My O’Reilly, 2005 book

Update: All copies are gone!  If you want Geospatial Desktop or Geospatial Power Tools – go to LocatePress.com – quantity discounts available.  For Web Mapping Illustrated go to Amazon.


 

I’m giving away a couple copies of my circa 2005 classic book.  Details below…  When O’Reilly published Web Mapping Illustrated – Using Open Source GIS Toolkits – nothing like it existed on the market.  It was a gamble but worked out well in the end.

Primarily focused on MapServer, GDAL/OGR and PostGIS, it is a how-to guide for those building web apps that included maps.  That’s right, you couldn’t just use somebody else’s maps all the time – us geographers needed jobs, after all.

To help give you the context of the times, a couple months before the final print date, Google Maps, was released.  I blithely added a reference to their site just in case it became popular.

The book is still selling today and though I haven’t reviewed it in a while, I do believe many of the concepts are still as valid as when it was written.  In fact, it’s even easier to install and configure the apps now due to packaging and distribution options that didn’t exist back then.  Note this was also a year before OSGeo.org’s collaborative efforts started to help popularise the tools further.

In celebration of 10 years of sales I have a couple autographed copies as giveaways to the first two people who don’t mind paying only for the shipping (about USD$8) and who drop me a note expressing their interest.

Additionally, I have some of Gary Sherman’s excellent Geospatial Desktop books as giveaways as well.  Same deal, pay actual shipping cost only from my remote hut in northern Canada.  Just let me know you’d like one of them and I’ll email you the PayPal details.  Sorry, not autographed by Gary, though I was editor and publisher, so could scribble on it for you if desired.

WordPress Appliance - Powered by TurnKey Linux