Mapping Toolbox | ![]() ![]() |
Interactively perform data queries
Activation
Command Line |
qrydata(cellarray) qrydata( qrydata(h,cellarray) qrydata(h,
|
Description
A data query is used to obtain the data corresponding to a particular (x,y) or (lat,lon) point on a standard or map axes.
qrydata(cellarray)
activates a data query dialog box for interactive queries of the data set specified by cellarray
(described below). qrydata
can be used on a standard axes or a map axes. (x,y)
or (lat,lon)
coordinates are entered in the dialog box, and the data corresponding to these coordinates is then displayed.
qrydata(titlestr,cellarray)
uses the string titlestr
as the title of the query dialog box.
qrydata(h,cellarray)
and qrydata(h,
titlestr
,cellarray)
associate the data queries with the axes specified by the handle h
, which in turn allows the input coordinates to be specified by clicking on the axes.
The input cellarray
is used to define the data set and the query. The first cell must contain the string used to label the data display line. The second cell must contain the type of query operation, either a pre-defined operation or a valid user-defined function name. This input must be a string. The pre-defined query operations are 'matrix'
, 'vector'
, 'mapmatrix'
, and 'mapvector'
.
The 'matrix'
query uses the MATLAB interp2
function to find the value of the matrix Z
at the input (x,y)
point. The format of the cellarray
input for this query is: {'label','matrix',X,Y,Z,
method
}. X
and Y
are matrices specifying the points at which the data Z
is given. The rows and columns of X
and Y
must be monotonic. method
is an optional argument that specifies the interpolation method. Possible method
strings are 'nearest'
, 'linear'
, or 'cubic'
. The default is 'nearest'
.
The 'vector'
query uses the MATLAB interp2
function to find the value of the matrix Z
at the input (x,y)
point, then uses that value as an index to a data vector. The value of the data vector at that index is returned by the query. The format of cellarray
for this type of query is: {'label','vector',X,Y,Z, vector}
. X
and Y
are matrices specifying the points at which the data Z
is given. The rows and columns of X
and Y
must be monotonic. vector
is the data vector.
The 'mapmatrix'
query interpolates to find the value of the map at the input (lat,lon)
point. The format of cellarray
for this query is: {'label','mapmatrix',map,maplegend,
method
}
. map
and maplegend
are the matrix map and the corresponding matrix map legend. method
is an optional argument that specifies the interpolation method. Possible method
strings are 'nearest'
, 'linear'
, or 'cubic'
. The default is 'nearest'
.
The 'mapvector'
query interpolates to find the value of the map at the input (lat,lon)
point, then uses that value as an index to a data vector. The value of the vector at that index is returned by the query. The format of cellarray
for this type of query is {'label','mapvector',map,maplegend, vector}
. map
and maplegend
are the matrix map and the corresponding matrix map legend. vector
is the data vector.
User-defined query operations allow for functional operations using the input (x,y)
or (lat,lon)
coordinates. The format of cellarray
for this type of query is {'label',
function
,other arguments...}
where the other arguments are the remaining elements of cellarray
as in the four pre-defined operations above. function
is a user-created function and must refer to an M-file of the form z = fcn(x,y,other_arguments...)
.
qrydata(...,cellarray1,cellarray2,...)
is used to input multiple cell arrays. This allows more than one data query to be performed on a given point.
Controls
If an axes handle h
is not provided, or if the axes specified by h
is not a map axes, the currently selected point is labeled as Xloc and Yloc at the top of the query dialog box. If h
is a map axes, the current point is labeled as Lat and Lon. Displayed below the current point are the results from the queries, each labeled as specified by the 'label'
input arguments.
The Get button appears if an axes handle h
is provided. Pressing this button activates a mouse cursor, which is used to select the desired point by clicking on the axes. Once a point is selected, the queries are performed and the results are displayed.
The Process button appears if the handle h
is not provided. In this case, the (x,y)
coordinates of the desired point are entered into the edit boxes. Pressing the Process button performs the data queries and displays the results.
Pressing the Close button closes the query dialog box.
Examples
The following example can be found in the wrlddemo
query demo provided with the Mapping Toolbox. The call to qrydata
creates a query dialog box that enables the user to click on the map display and retrieve the name of the country corresponding to that point.
load worldmtx axesm robinson colormap(clrmap) meshm(map,maplegend) qrydata(gca,'Data Query',{'Country:','mapvector',... map,maplegend,strvcat(nations(:).name)})
The next example makes use of a user-defined query to display city names for map points specified by a mouse click.
axesm miller load worldlo lat = [PPtext.lat]'; lon = [PPtext.long]'; mat = strvcat(PPtext.string); displaym(POline) displaym(PPpoint) qrydata(gca,'City Data',{'City','qrytest',lat,lon,mat})
The following code would be contained in the M-file qrytest
, created by the user.
% function QRYTEST returns city name for mouse click % QRYTEST will find the closest city (min radius) from % the mouse click, within an angle of 5 degrees. % latdiff=lt-lat;londiff=lg-lon; rad = sqrt(latdiff.^2+londiff.^2); [minrad,index]=min(rad); if minrad > 5; index = []; end; switch length(index) case 0, cityname='No city located near click'; case 1, cityname=mat(index,:); end
Clicking the mouse over a city marker displays the name of the selected city. Clicking the mouse in an area away from any city markers displays the string 'No city located near click'
.
See Also
interp2
qrydemo
wrlddemo
![]() | property editors | quiver3m | ![]() |