worldfilewrite
Write world file from raster reference object
Description
Examples
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)
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
Raster reference, specified as a GeographicCellsReference
, GeographicPostingsReference
, MapCellsReference
, or MapPostingsReference
object.
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 R2006aThe worldfilewrite
function does not accept referencing matrices as
input. Use a geographic raster reference object (specified as a GeographicCellsReference
or GeographicPostingsReference
object) or a map raster reference object (specified
as a MapCellsReference
or MapPostingsReference
object) as input instead.
Reference objects have several advantages over referencing matrices.
Unlike referencing matrices, reference objects have properties that document the size of the associated raster, its limits, and the direction of its rows and columns.
You can manipulate the limits of rasters associated with reference objects using the
geocrop
ormapcrop
function.You can manipulate the size and resolution of rasters associated with reference objects using the
georesize
ormapresize
function.
Depending on whether the referencing matrix is in geographic or planar coordinates, there are different ways to update your code.
Geographic Coordinates
If the referencing matrix is in geographic coordinates, create a geographic reference object.
Create a geographic reference object for a raster of cells by using the
georefcells
function.Create a geographic reference object for a raster of regularly posted samples by using the
georefpostings
function.Convert from a referencing matrix to a geographic reference object by using the
refmatToGeoRasterReference
function.
Once you have created a geographic reference object, replace uses of the referencing matrix in your code with the geographic reference object.
Planar Map Coordinates
If the referencing matrix is in planar map coordinates, create a map reference object.
Create a map reference object for a raster of cells by using the
maprefcells
function.Create a map reference object or for a raster of regularly posted samples by using the
maprefpostings
function.Convert from a referencing matrix to a map reference object by using the
refmatToMapRasterReference
function.
Once you have created a map reference object, replace uses of the referencing matrix in your code with the map reference object.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)