Main Content

setpostn

(Removed) Convert latitude-longitude to data grid rows and columns

The setpostn function has been removed. Use the geographicToDiscrete function instead. For more information, see Version History.

Syntax

[row, col] = setpostn(Z, R, lat, lon)
indx = setpostn(...)
[row, col, indxPointOutsideGrid] = setpostn(...)

Description

[row, col] = setpostn(Z, R, lat, lon) returns the row and column indices of the regular data grid Z for the points specified by the vectors lat and lon. R can be a geographic raster reference object, a referencing vector, or a referencing matrix.

If R is a geographic raster reference object, its RasterSize property must be consistent with size(Z).

If R is a referencing vector, it must be 1-by-3 with elements:

[cells/degree northern_latitude_limit western_longitude_limit]
If R is a referencing matrix, it must be 3-by-2 and transform raster row and column indices to/from geographic coordinates according to:
[lon lat] = [row col 1] * R
If R is a referencing matrix, it must define a (non-rotational, non-skewed) relationship in which each column of the data grid falls along a meridian and each row falls along a parallel. Points falling outside the grid are ignored in row and col. All input angles are in degrees.

indx = setpostn(...) returns the indices of Z corresponding to the points in lat and lon. Points falling outside the grid are ignored in indx.

[row, col, indxPointOutsideGrid] = setpostn(...) returns the indices of lat and lon corresponding to points outside the grid. These points are ignored in row and col.

Examples

Load elevation raster data and a geographic cells reference object. Then, find the matrix coordinates of Denver, Colorado.

load topo60c
[row,col] = setpostn(topo60c,topo60cR,39.7,105)
row =

   130


col =

   105

Version History

Introduced before R2006a

expand all

R2024a: Errors

Some functions that accept referencing vectors or referencing matrices as input have been removed, including the setpostn function. Use a geographic raster reference object and the geographicToDiscrete function instead. Reference objects have several advantages over referencing vectors and matrices.

  • Unlike referencing vectors and matrices, reference objects have properties that document the size of the associated raster, its geographic limits, and the direction of its rows and columns. For more information about reference object properties, see the GeographicCellsReference and GeographicPostingsReference objects.

  • You can manipulate the limits of rasters associated with reference objects using the geocrop function.

  • You can manipulate the size and resolution of rasters associated with reference objects using the georesize function.

  • Most functions that accept referencing vectors or matrices as inputs also accept reference objects.

To update your code, first create a reference object for either a raster of cells using the georefcells function or a raster of regularly posted samples using the georefpostings function. Alternatively, convert from a referencing vector or a referencing matrix to a reference object using the refvecToGeoRasterReference or refmatToGeoRasterReference function, respectively.

Then, replace uses of the setpostn function with the geographicToDiscrete function according to these patterns. Note that the geographicToDiscrete function includes NaN values in row and col for points outside the raster limits instead of discarding them. Additionally, the geographicToDiscrete function does not issue a warning for points outside the raster limits.

RemovedRecommended
[row,col] = setpostn(A,R,lat,lon);
[row,col] = geographicToDiscrete(R,lat,lon);
n = isnan(row);
row(n) = [];
col(n) = [];
indx = setpostn(A,R,lat,lon);
[row,col] = geographicToDiscrete(R,lat,lon);
indx = sub2ind(R.RasterSize,row,col);
[row,col,indexPointOutsideGrid] = setpostn(A,R,lat,lon);
[row,col] = geographicToDiscrete(R,lat,lon);
n = isnan(row);
row(n) = [];
col(n) = [];
indexPointOutsideGrid = find(n);