223 | | The following code illustrates how to |
| 230 | The following code illustrates how to use the Spatial Index and the spatial index iterator. |
| 231 | |
| 232 | |
| 233 | {{{ |
| 234 | FdoPtr<FdoSpatialIndex> si; |
| 235 | |
| 236 | FdoPtr<FdoFgfGeometryFactory> gf = FdoFgfGeometryFactory::GetInstance(); |
| 237 | |
| 238 | /*************************** Test Polygon *************************/ |
| 239 | FdoStringP geomText = L"POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0), (1 1, 2 2, 2 1, 1 1), (3 3, 4 4, 4 3, 3 3))"; |
| 240 | |
| 241 | FdoPtr<FdoIGeometry> geom = gf->CreateGeometry(geomText); |
| 242 | FdoPtr<FdoByteArray> ba = gf->GetFgf(geom); |
| 243 | |
| 244 | // Mode #1: FdoSpatialIndex_ByGeometriesBoundingBox |
| 245 | si = FdoSpatialIndex::Create(FdoSpatialIndex_ByGeometriesBoundingBox); |
| 246 | |
| 247 | // Insert the geometry |
| 248 | si->InsertObject(777, ba); |
| 249 | |
| 250 | // Query the SI |
| 251 | FdoSpatialIndexIterator iter1(si, 1, 1, 2, 2); |
| 252 | |
| 253 | FdoInt32 iPart, iSubpart, iSegment; |
| 254 | FdoInt64 marker = 0; |
| 255 | |
| 256 | // Get the results |
| 257 | while (marker = iter1.GetNextObject()) |
| 258 | { |
| 259 | FdoInt64 fid = marker; // not encoded |
| 260 | // ... do stuff |
| 261 | } |
| 262 | |
| 263 | // Mode #2: FdoSpatialIndex_BySegmentsMultipleFeatures |
| 264 | si = FdoSpatialIndex::Create(FdoSpatialIndex_BySegmentsMultipleFeatures); |
| 265 | si->InsertObject(777, ba); |
| 266 | |
| 267 | FdoSpatialIndexIterator iter2(si, 1, 1, 2, 2); |
| 268 | |
| 269 | while (marker = iter2.GetNextObject()) |
| 270 | { |
| 271 | FdoInt32 fid; |
| 272 | si->DecodeMarker(marker, fid, iSegment); |
| 273 | // ... do stuff |
| 274 | } |
| 275 | |
| 276 | // Mode #3: FdoSpatialIndex_BySegmentsSingleFeature |
| 277 | si = FdoSpatialIndex::Create(FdoSpatialIndex_BySegmentsSingleFeature); |
| 278 | si->InsertObject(0, ba); // FeatId = 0 |
| 279 | |
| 280 | FdoSpatialIndexIterator iter3(si, 1, 1, 2, 2); |
| 281 | |
| 282 | while (marker = iter3.GetNextObject()) |
| 283 | { |
| 284 | si->DecodeMarker(marker, iPart, iSubpart, iSegment); |
| 285 | // ... do stuff |
| 286 | } |
| 287 | }}} |