Finds the first segment handle within the specified MBR.
Syntax
GsFunStat GsFindFirstSegmentByMbr(GsId gs, GsSegmentHandle
*pSegment, long lon1,long lat1,long lon2,long lat2);
Arguments
GsIdgs ID returned by GsInitWithProps() for the current instance of GeoStan. Input.
GsSegmentHandle*pSegment Pointer to a street/segment handle. Returns a valid handle if GeoStan finds a segment. Input, Output.
longlon1 Minimum longitude. One of four values that make up the MBR. Input.
longlat1 Minimum latitude. One of four values that make up the MBR. Input.
longlon2 Maximum longitude. One of four values that make up the MBR. Input.
longlat2 Maximum latitude. One of four values that make up the MBR. Input.
Return Values
GS_ERROR Error occurred. You can retrieve the error using GsErrorGet().
GS_LASTLINE_NOT_FOUNDGeoStan could not find pSegment.
GS_NOT_FOUND GeoStan did not find a match.
GS_SUCCESS GeoStan found a match. If returned, pSegment is a valid segment handle that you can use with GsHandleGet(), GsHandleGetCoords(), or GsGetMbr().
Prerequisites
GsInitWithProps() and GsClear()
Notes
GeoStan handles all spatial query functions in ten-thousandths of degrees—not millionths of degrees as with GsDataGet().
Before each find function, call GsClear() to reset the internal buffers. If you do not reset the buffers, you may receive incorrect results with information from a previous find.
MBR Representation by Lat/Lon
GeoStan defines the minimum bounding rectangle by the four arguments given as lon1, lon2, lat1 and lat2, defined from the two pairs of intersecting points given as lat1/lon1 and lat2/lon2. A line between those points creates the diagonal of the rectangle as shown in the following figure.
Example
#include <stdio.h>
#include <string.h>
#define GEOSTAN_PROPERTIES
#include "geostan.h"
const char *gsxOutPath = "c:\\temp";
/* This is a random MBR. */
const long minLon = -939460;
const long minLat = 438910;
const long maxLon = -936299;
const long maxLat = 440973;
/* This matches the spatialQueryProgress typedef in geostan.h. */
intl GS_STDCALL progress(void * param, intl mode, intl value)
{
static long totalSteps;
switch (mode)
{
case 0:
printf("%sStarting...\n", param);
totalSteps = value;
break;
case 1:
printf("%s%%%.2f complete\r", param, (double)value/
(double)totalSteps * 100);
break;
case 2:
printf("\n%sDone\n", param);
break;
}
/* In an interactive progress function, such as a dialog box, the user could choose to stop this operation.
The correct return value would then be GS_PROGRESS_CANCEL. */
return GS_PROGRESS_CONTINUE;
}
int main(int argc, char **argv)
{
GsId gs;
PropList initProps;
PropList statusProps;
GsFunStat funStat;
GsSegmentHandle hSegment;
/* Initialization */
/* create an initialization property list with geostan information */
GsPropListCreate(&initProps, GS_INIT_PROP_LIST_TYPE);
/* GeoStan version */
GsPropSetLong(&initProps, GS_INIT_GSVERSION, GS_GEOSTAN_VERSION);
/* license filename and path */
GsPropSetStr(&initProps, GS_INIT_LICFILENAME, "c:\\lic\\geostan.lic");
/* license file password */
GsPropSetLong(&initProps, GS_INIT_PASSWORD, 43218765);
/* path to the data files, geostan library, and GSX files*/
GsPropSetStr(&initProps, GS_INIT_DATAPATH, "c:\\geostan\\datasets;c:\\geostan;c:\\temp");
/* path and file name of the ZIP Code geocoding data file*/
GsPropSetStr(&initProps, GS_INIT_Z4FILE, "c:\\geostan\\datasets\\us.z9");
/* GeoStan options */
GsPropSetBool(&initProps, GS_INIT_OPTIONS_ADDR_CODE, TRUE);
GsPropSetBool(&initProps, GS_INIT_OPTIONS_SPATIAL_QUERY, TRUE);
GsPropSetLong(&initProps, GS_INIT_CACHESIZE, 2);
/* create a status property list */
GsPropListCreate(&statusProps, GS_STATUS_PROP_LIST_TYPE);
gs = GsInitWithProps(&initProps, &statusProps);
if (!gs)
{
printf("Failed to initialize GeoStan library.\n");
return 1;
}
funStat = GsPrepareIndexMbr(gs, minLon, minLat, maxLon, maxLat, gsxOutPath, "MBR index preparation: ", progress);
if ( funStat == GS_ERROR )
{
printf("GsPrepareIndexMbr returned GS_ERROR.\n");
return 1;
}
funStat = GsFindFirstSegmentByMbr(gs, &hSegment, minLon, minLat, maxLon, maxLat);
while (funStat == GS_SUCCESS )
{ /* Insert code here to operate on each segment handle retrieved. */
funStat = GsFindNextSegmentByMbr(gs, &hSegment);
}
if (funStat == GS_ERROR)
{
printf("GsFindFirstSegmentByMbr or GsFindNextSegmentByMbr returned GS_ERROR.\n");
return 1;
}
GsTerm(gs);
GsPropListDestroy(&initProps);
GsPropListDestroy(&statusProps);
return 0;