Filter Vector Data to Remove Unwanted Points

Often a set of data contains unwanted data mixed in with the desired values. For example, your data might include vectors covering the entire United States, but you only want to work with those falling in Alabama. Sometimes a data set contains noise—perhaps three or four points out of several thousand are obvious errors (for example, one of your city points is in the middle of the ocean). In such cases, locating outliers and errors in the data arrays can be quite tedious.

The filterm command uses a data grid to filter a vector data set. Its calling sequence is as follows:

[flats,flons] = filterm(lats,lons,grid,refvector,allowed)

Each location defined by lats and lons is mapped to a cell in grid, and the value of that grid cell is obtained. If that value is found in allowed, that point is output to flats and flons. Otherwise, the point is filtered out.

The grid might encode political units, and the allowed values might be the code or codes indexing certain states or countries (e.g., Alabama). The grid might also be real-valued (e.g., terrain elevations), although it could be awkward to specify all the values allowed. More often, logical or relational operators give better results for such grids, enabling the allowed value to be 1 (for true). For example, you could use this transformation of the topo grid:

[flats,flons] = filterm(lats,lons,double(topo>0),topolegend,1)

The output would be those points in lats and lons that occupy dry land (mostly because some water bodies are above sea level).

For further information, see the filterm reference page. Also see Data Grids as Logical Variables and Trim Vectors to Preserve Polygonal Patches.