Main Content

worldfilewrite

Write world file from raster reference object

    Description

    worldfilewrite(R,filename) writes a world file from the specified raster reference object.

    example

    Examples

    collapse all

    Read an image as an array by using the imread function.

    A = imread("boston_common.jpg");

    Spatially reference the image by creating a map cells reference object. For more information about how to spatially reference an image, see Spatially Reference Imported Rasters.

    xlimits = [235150 236150];
    ylimits = [900100 901100];
    R = maprefcells(xlimits,ylimits,size(A),ColumnsStartFrom="north");

    Write the reference object to a world file. Get the filename for the world file by using the getworldfilename function.

    filename = getworldfilename("boston_common.jpg");
    worldfilewrite(R,filename)

    Verify the result. Read the world file into the workspace as a new reference object. Then, display the georeferenced image on a map.

    newR = worldfileread(filename,"planar",size(A));
    mapshow(A,newR)

    Figure contains an axes object. The axes object contains an object of type image.

    The data used in this example is derived from data provided by MassGIS (Bureau of Geographic Information). See the file boston_common.txt for more details.

    Input Arguments

    collapse all

    Filename, specified as a string scalar or a character vector. You can get the name of a world file from the name of an image file by using the getworldfilename function. Common world file extensions include .tfw, .jgw, and .pgw.

    The way you specify filename depends on the location you are writing to.

    • To write to the current folder, specify the name of the file, such as "myWorldfile.tfw".

    • To write to a folder different from the current folder, specify the full or relative path name, such as "C:\myfolder\myWorldfile.jgw" or "dataDir\myWorldfile.pgw".

    If filename is the name of an existing file, then worldfilewrite overwrites the file. If filename does not already exist, then worldfilewrite creates the file.

    Data Types: char | string

    Version History

    Introduced before R2006a

    expand all