#include #include #include #include #include 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"); }