IlvMapsError status; // Open the index file. IlvShapeFileIndex* index = new IlvShapeFileIndex(shxFileName); status = index->getInitStatus(); if(status != IlvMaps::NoError()) return status; // Open the corresponding Shapefile. IlvShapeSHPReader* shape = new IlvShapeSHPReader(shpFileName); status = shape->getInitStatus(); if(status != IlvMaps::NoError()) return status; // Construct a reader from the Shapefile reader and the Shapefile index. IlvShapeFileReader* reader = new IlvShapeFileReader(shape, 0, index); status = reader->getInitStatus(); if(status != IlvMaps::NoError()) return status; // Retrieve the feature for each index. IlInt count = index->getRecordCount(); for(IlInt i = 0; i < count; i++) { const IlvMapFeature* feature = reader->getFeatureAt(i, status); if(status != IlvMaps::NoError()) return status; } |
// Create a reader with the Shapefile name and the index file name. IlvShapeFileReader* reader = new IlvShapeFileReader(shpFilename, 0, shxFilename); // Open the spatial index. IlvShapeSpatialIndex* spindex = new IlvShapeSpatialIndex(idxFileName); status = spindex->getInitStatus(); if(status != IlvMaps::NoError()) return status; // Loop on all columns and rows. for(int c = 0; c < spindex->getColumnCount(); c++) { for(int r = 0; r < spindex->getRowCount(); r++) { IlInt *ret; IlUInt size; // Retrieve the IDs of objects belonging to the tile // at column 'c' and row 'w'. status = spindex->getIdArray(c, r, ret, size); if(status != IlvMaps::NoError()) return status; // Loop on these IDs and retrieve the corresponding map feature. for(int i = 0; i < size; i++) { const IlvMapFeature* feature = reader->getFeatureAt(ret[i], status); if(status != IlvMaps::NoError()) return status; } // Free allocated array. if(ret) delete[] ret; } } |
IlvShapeSpatialIndex* tilerIndex = new IlvShapeSpatialIndex(getColumnCount(), getRowCount(), getOrigin(), getTileWidth(), getTileHeight()); status = tilerIndex->getInitStatus(); if(status != IlvMaps::NoError()) return status; IlvMapFeature* feature = (IlvMapFeature*)reader->getNextFeature(status); if(status != IlvMaps::NoError()) return status; int id = 0; while(feature) { // Determine to which tile(s) the object must belong. int row = getRow(feature); int col = getColumn(feature); // Add it to the spatial index. tilerIndex->add(row, col, id); feature = (IlvMapFeature*)reader->getNextFeature(status); if(status != IlvMaps::NoError()) return status; id++; } // Write the spatial index. tilerIndex->save("spatialIndex.idx"); |
IlvShapeFileTiler::CreateShapeSpatialIndex("example.shp", "example.idx", (IlDouble)5, (IlDouble)10); |
IlvShapeFileTiler::CreateShapeSpatialIndex("example.shp", "example.idx", (IlInt)20, (IlInt)30); |
IlvMapAdapter a(0.001); IlvShapeFileTileLoader* tileLoader = new IlvShapeFileTileLoader(shpFileName, dbfFileName, // or null if attribute // loading is not wanted. shxFileName, idxFileName, &a); IlvTiledLayer* tiledLayer = new IlvTiledLayer(getTileOrigin()); tiledLayer->setTileLoader(tileLoader); |
IlvMapAdapter a(0.001); IlvShapeFileTileLoader* tileLoader = new IlvShapeFileTileLoader(shpFileName, dbfFileName, // or null if attribute // loading is not wanted. shxFileName, idxFileName, &a); IlvShapeFileLayer* shapeLayer = new IlvShapeFileLayer(tileLoader); IlvManager* manager = new IlvManager(0); manager->addLayer(shapeLayer); manager->save(ofstream("out.ilv")); |