ocmath_find_xy_in_rect

 

Description

Select given XY array to find all points inside the rectangle defined by XY min max values.

Syntax

int ocmath_find_xy_in_rect( uint nPts, const double * pX, const double * pY, uint * pIndices, double dxMin, double dyMin, double dxMax, double dyMax )

Parameters

nPts
[input] The number of input data points in pX, pY, pZ;
pX
[input] The array of X coordinates, must no be NULL;
pY
[input] The array of Y coordinates, must no be NULL;
pIndices
[output], must be SetSize to nPts on input and will receive the
indices of the XY points inside rect.
dxMin
[input] The minimum value of output X array;
dyMin
[input] The minimum value of output Y array;
dxMax
[input] The maximum value of output X array, must not be less than dXMin;
dyMax
[input] The maximum value of output Y array, must not be less than dYMin.

Return

0 if none found to be inside rect, otherwise the number of points found,

and will always be less than nPts.

-1 if given XY range does not define a valid Rect, like if xmin>=xmax or

ymin>=ymax.

Examples

EX1

//Before running, make sure a worksheet is active in current project
//the worksheet should has at least 2 columns and without any missing value in the first two columns
#include <wks2mat.h>
void ocmath_find_xy_in_rect_ex1(double dXMin = -1, double dYMin = -1, double dXMax =  1, double dYMax =  1)
{
    Worksheet wks = Project.ActiveLayer();
    Dataset dsX(wks, 0), dsY(wks, 1);

    vector vX(dsX), vY(dsY);
    
    vector<uint> vIndices(dsX.GetSize());
    
    int nPts = ocmath_find_xy_in_rect(dsX.GetSize(), vX, vY, vIndices, dXMin, dYMin, dXMax, dYMax);
    
    ocmath_d_copy(nPts, vIndices, vX, vX, vX.GetSize());
    ocmath_d_copy(nPts, vIndices, vY, vY, vY.GetSize());
    
    printf("%d data points are found within rect.\n", nPts);
    
    vX.SetSize(nPts);
    vY.SetSize(nPts);

    dsX = vX;
    dsY = vY;
}

Remark

Should trim Missing Value before using this function

See Also

ocmath_find_xy_in_circle

header to Include

wks2mat.h

Reference