Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 16 Next »

The following scripts convert images into suitable geotiffs for fast map serving without losing clarity. Completely based upon Paul Ramsey's Geotiff for Dummies guide.

Either run in the folder containing the geotiffs or pass directory as argument. Generated files are created in an 'output' sub-folder. 

Follow up process would be to build a vrt - see Mosaic thousands of raster images

Projection set?

Check that the source file have a projection set? Check by using gdalinfo.exe <some file> in the command line window. If not then a -s_srs "EPSG:27700" can be added to the gdal_translate line in each batch file.


First up, convert GeoTiffs into more GeoTiffs. All these scripts are attached to this page.

@ECHO OFF
SET runDir=%cd%
:: if provided directory
if "%~1"=="" (
	echo no folder given
) else (
	cd /d %1
	echo processing tiff files in %cd%
)
echo processing tiff files in %cd%
:: create \output folder if not present
IF NOT EXIST %cd%\output (
	mkdir output
)
:: set compression, tiles and colour space
for %%f in (*.tif) do (
	:: echo %cd%\%%f
	gdal_translate -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR -co TILED=YES "%cd%\%%f" "%cd%\output\%%f"
)
:: add overviews
cd output
for %%f in (*.tif) do (	
	gdaladdo --config COMPRESS_OVERVIEW JPEG --config PHOTOMETRIC_OVERVIEW YCBCR --config INTERLEAVE_OVERVIEW PIXEL -r average "%cd%\%%f"  2 4 8 16
)
cd /d %runDir%

Convert ECW files into GeoTiffs

@ECHO OFF
SET runDir=%cd%
:: if provided directory
if "%~1"=="" (
    echo no folder given
) else (
    cd /d %1
    echo processing tiff files in %cd%
)
echo processing tiff files in %cd%
:: create \output folder if not present
IF NOT EXIST %cd%\output (
    mkdir output
)
:: set compression, tiles and colour space
for %%f in (*.ecw) do (
    :: echo %cd%\%%f
    gdal_translate -of GTiff -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR -co TILED=YES "%cd%\%%f" "%cd%\output\%%~nf.tif"
)
:: add overviews
cd output
for %%f in (*.tif) do (
    gdaladdo --config COMPRESS_OVERVIEW JPEG --config PHOTOMETRIC_OVERVIEW YCBCR --config INTERLEAVE_OVERVIEW PIXEL -r average "%cd%\%%f"  2 4 8 16
)
cd /d %runDir%

Convert single band GeoTiffs into GeoTiffs.

@ECHO OFF
SET runDir=%cd%
:: if provided directory
if "%~1"=="" (
    echo no folder given
) else (
    cd /d %1
    echo processing tiff files in %cd%
)
echo processing tiff files in %cd%
:: create \output folder if not present
IF NOT EXIST %cd%\output (
    mkdir output
)
:: set compression, tiles and colour space
for %%f in (*.tif) do (
    :: echo %cd%\%%f
    gdal_translate -expand rgb -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR -co TILED=YES "%cd%\%%f" "%cd%\output\%%f"
)
:: add overviews
cd output
for %%f in (*.tif) do (
    gdaladdo --config COMPRESS_OVERVIEW JPEG --config PHOTOMETRIC_OVERVIEW YCBCR --config INTERLEAVE_OVERVIEW PIXEL -r average "%cd%\%%f"  2 4 8 16
)
cd /d %runDir%

Creating a Web Mapping Service

Create a tileindex. This can be done in QGIS or command line.

cd <folder>
dir /s/b *.tif > optfile.txt
gdaltindex tileindex.shp --optfile optfile.txt

Create a .map file.

MAP
	EXTENT 0 0 700000 1300000
	INCLUDE "_common.map"
	UNITS METERS
	TEMPLATEPATTERN '.'
 	IMAGECOLOR 238 238 237
	IMAGETYPE AGG_Q
	RESOLUTION 72
	SHAPEPATH "../../"
	SIZE 512 512
	MAXSIZE 8192
	STATUS ON
	CONFIG  "MS_ERRORFILE" "D:/mapserver/tmp/logs/base_rasters_debug.log"
	NAME "Raster_WMS"
	PROJECTION
		 "init=epsg:27700"
	END
	DEBUG 0
	IMAGETYPE png
	OUTPUTFORMAT
		NAME "png"
		MIMETYPE "image/png"
		DRIVER "AGG/PNG"
		EXTENSION "png"
		IMAGEMODE "RGBA" #CHANGED
		TRANSPARENT TRUE
		FORMATOPTION "TRANSPARENT=ON"
	END

	OUTPUTFORMAT
		NAME "AGG_JPEG"
		MIMETYPE "image/jpeg"
		DRIVER "AGG/JPEG"
		EXTENSION "JPG"
		IMAGEMODE "RGB"
		FORMATOPTION "interlace=off"
	END

	LEGEND
		IMAGECOLOR 255 255 255
		KEYSIZE 20 10
		KEYSPACING 5 5
		LABEL
			SIZE small
			TYPE bitmap
			BUFFER 0
			COLOR 0 0 0
			FORCE FALSE
			MINDISTANCE -1
			MINFEATURESIZE -1
			OFFSET 0 0
			PARTIALS TRUE
			MAXLENGTH 25
			WRAP " "
		END
		POSITION LL
		STATUS OFF
	END

	QUERYMAP
		COLOR 255 255 0
		SIZE -1 -1
		STATUS OFF
		STYLE HILITE
	END
	
	SCALEBAR
		COLOR 0 0 0
		IMAGECOLOR 255 255 255
		INTERVALS 4
		LABEL
			SIZE MEDIUM
			TYPE BITMAP
			BUFFER 0
			COLOR 0 0 0
			FORCE FALSE
			MINDISTANCE -1
			MINFEATURESIZE -1
			OFFSET 0 0
			PARTIALS TRUE
		END
		POSITION LL
		SIZE 200 3
		STATUS OFF
		STYLE 0
		UNITS MILES
	END
	
	WEB
		IMAGEPATH "D:\mapserver\tmp\\"
		IMAGEURL ""
		TEMPLATE "globexml.xml"
		METADATA
			 ows_title "Rasters"
			 ows_srs "EPSG:27700"
			 ows_abstract "WMS Rasters"
			 ows_enable_request "*"
		END
	END
	
    LAYER
        NAME "Aerial"
        TYPE RASTER
        STATUS OFF
        METADATA
			"ows_title"			  "Aerial Imagery"
			"ows_abstract"		  "Aerial Imagery"
        END
        TILEINDEX "<folder>\tileindex.shp"
    END

END

Create an iShare basemap legacy mapsource

  • mapsource > map name should be the .map file above.
  • details > name should be the name of the layer in the .map file.
  • details > URL should be the mapserver end-point.

Test the WMS and then publish.

  • No labels