geographicGrid
Description
[
,
where lat
,lon
] = geographicGrid(R
,gridOption
)gridOption
is 'gridvectors'
, returns
lat
and lon
as vectors. The coordinates of
raster element (i,j)
are (lat(i),lon(j))
. The default
for gridOption
is 'fullgrid'
, which returns
lat
and lon
as 2-D arrays.
Examples
Find Coordinates of Raster Elements
Import elevation data [1] for an area around South Boulder Peak in Colorado as an array and a geographic postings reference object. Find the coordinates of each element in the array.
[Z,R] = readgeoraster('n39_w106_3arc_v2.dt1');
[lat,lon] = geographicGrid(R);
Create a map with latitude and longitude limits that match the limits of the data. Display the data using an appropriate colormap.
usamap(R.LatitudeLimits,R.LongitudeLimits) surfm(lat,lon,Z) demcmap(Z)
[1] The elevation data used in this example is courtesy of the U.S. Geological Survey.
Get Vectors Instead of Arrays
Create a geographic cells reference object for a 3-by-4 raster with latitude values in the range [0, 30] degrees and longitude values in the range [-20, 20] degrees. Get the coordinates of the raster elements and return them as row vectors.
R = georefcells([0 30],[-20 20],[3 4]);
[lat,lon] = geographicGrid(R,'gridvectors')
lat = 1×3
5 15 25
lon = 1×4
-15 -5 5 15
If you do not specify the second argument as 'gridvectors'
, then the geographicGrid
function returns 2-D arrays by default.
[latFull,lonFull] = geographicGrid(R)
latFull = 3×4
5 5 5 5
15 15 15 15
25 25 25 25
lonFull = 3×4
-15 -5 5 15
-15 -5 5 15
-15 -5 5 15
Input Arguments
R
— Spatial reference
GeographicCellsReference
object | GeographicPostingsReference
object
Spatial reference, specified as a GeographicCellsReference
or GeographicPostingsReference
object.
If R
is a GeographicCellsReference
object,
then lat
and lon
are cell centers. If
R
is a GeographicPostingsReference
object, then
lat
and lon
are posting points.
gridOption
— Grid option
'fullgrid'
(default) | 'gridvectors'
Grid option, specified as one of these values:
'fullgrid'
— Returnlat
andlon
as 2-D arrays, where each column oflat
is identical and each row oflon
is identical. This is the default behavior.'gridvectors'
— Returnlat
andlon
as row vectors. Use this option when you want to reduce memory usage and when 2-D arrays are unnecessary, such as when plotting large data sets with thesurfm
function.
This table shows the difference between 'fullgrid'
and
'gridvectors'
.
'fullgrid' | 'gridvectors' |
---|---|
R = georefcells([0 30],[-20 20],[3 4]); [lat,lon] = geographicGrid(R) lat = 5 5 5 5 15 15 15 15 25 25 25 25 lon = -15 -5 5 15 -15 -5 5 15 -15 -5 5 15 |
R = georefcells([0 30],[-20 20],[3 4]);
[lat,lon] = geographicGrid(R,'gridvectors') lat = 5 15 25 lon = -15 -5 5 15 |
Data Types: char
| string
Output Arguments
lat
— Latitudes
2-D array (default) | row vector
Latitudes, returned as a 2-D array or a row vector. By default,
lat
is a 2-D array. To return lat
as a row
vector, specify gridOption
as
'gridvectors'
.
By default, and when gridOption
is
'fullgrid'
, the sizes of lat
and
lon
each equal the RasterSize
property of
R
. When gridOption
is
'gridvectors'
, the lengths of lat
and
lon
equal the first and second elements of the
RasterSize
property of R
,
respectively.
lon
— Longitudes
2-D array (default) | row vector
Longitudes, returned as a 2-D array or a row vector. By default,
lon
is a 2-D array. To return lon
as a row
vector, specify gridOption
as
'gridvectors'
.
By default, and when gridOption
is
'fullgrid'
, the sizes of lat
and
lon
each equal the RasterSize
property of
R
. When gridOption
is
'gridvectors'
, the lengths of lat
and
lon
equal the first and second elements of the
RasterSize
property of R
,
respectively.
Version History
Introduced in R2021a
See Also
Functions
Objects
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)