1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include <stdio.h>
- #include <cstdlib>
- #include <spatialindex/capi/sidx_api.h>
- #include <spatialindex/capi/sidx_impl.h>
- #include <spatialindex/capi/sidx_config.h>
- using namespace std;
- using namespace SpatialIndex;
- void load(IndexH idx);
- void query(IndexH idx);
- void bounds(IndexH idx);
- int main()
- {
- char* pszVersion = SIDX_Version();
- fprintf(stdout, "libspatialindex version: %s\n", pszVersion);
- fflush(stdout);
- free(pszVersion);
- IndexPropertyH props = IndexProperty_Create();
-
- // create an in-memory r*-tree index
- IndexProperty_SetIndexType(props, RT_RTree);
- IndexProperty_SetIndexStorage(props, RT_Memory);
- IndexH idx = Index_Create(props);
- IndexProperty_Destroy(props);
- if (Index_IsValid(idx))
- {
- load(idx);
- bounds(idx);
- query(idx);
- Index_Destroy(idx);
- }
- else
- {
- printf("Failed to create valid index\n");
- }
- return 0;
- }
- void load(IndexH idx)
- {
- double min[] = {0.5, 0.5};
- double max[] = {0.5, 0.5};
- Index_InsertData(idx, 1, min, max, 2, 0, 0);
- }
- void query(IndexH idx)
- {
- double min[] = {0.0, 0.0};
- double max[] = {1.0, 1.0};
- uint64_t nResults;
- Index_Intersects_count(idx, min, max, 2, &nResults);
- if (nResults == 1)
- printf("Successful Query\n");
- else
- printf("Failed to execute query\n");
- }
- void bounds(IndexH idx)
- {
- uint32_t dims;
- double* pMins;
- double* pMaxs;
- Index_GetBounds(idx, &pMins, &pMaxs, &dims);
- free(pMins);
- free(pMaxs);
- if (dims == 2)
- printf("Successful bounds query\n");
- else
- printf("Failed to execute bounds query\n");
- }
|