DEM データのラスター・リーダーの記述

新しいデジタル標高モデル (DEM 形式) を読み取るには、addMap メソッドで IlvRasterAbstractReader のサブクラスを記述する必要があります。地図の読み込みおよび保存機能を利用する場合、リーダーのシリアライゼーションを管理するメソッド、つまり、必要とされる機能を実行するメソッドを提供する必要があります。
リーダーを作成するには、以下の手順に従います。
  1. 以下の例のように、ラスター DEM ファイルの一覧を読み込みます。
    public class MyDEMReader extends IlvRasterAbstractReader {
        // list of files to be read.
        private ArrayList filenameList = new ArrayList();
        /** default constructor */
        public MyDEMReader() {
        }
    
  2. addMap メソッドを記述し、ファイル名に付加されている IlvRasterProperties および IlvRasterMappedBuffer を計算します (「ラスター・イメージの管理」を参照)。次にこの情報をリーダーが管理している一覧に追加します。この手順は形式によって異なるので、ここでは要約のみを挙げます。
    public void addMap(final String filename) throws IOException {
         IlvRasterProperties loadingRaster = read/compute raster properties ...
         IlvRasterMappedBuffer source= read/compute raster pixel values...
        loadingRaster.setBaseName(filename);
        // to retrieve the file name when serializing data.
        addRaster(loadingRaster, source);
          }
    
地図読み込みおよび保存機能を使用するには、以下の手順に従います。
  1. イメージを再構築するのに必要なすべての情報をシリアル化します (この例では、ファイル名のみ)。
        public void write(IlvOutputStream stream) throws IOException {
            super.write(stream);
            int imageCount = getImageCount();
            for (int i = 0; i < imageCount; i++) {
                IlvRasterProperties props=getRasterProperties(i);
                stream.write("filename"+i,props.getBaseName());
            }
        }
    
  2. シリアル化データからリーダーを再構築します。イメージ・データは、地図に関連付けられている IMG ファイルに保存されている場合があるので、ファイルそのものではなく、ラスター DEM のファイル名のみを読み込みます。
     public MyDEMReader(IlvInputStream stream) throws IlvReadFileException {
          super(stream);
          try {
                 for(int count=0;true;count++) {
                  String filename = stream.readString("filename"+count);
                  filenameList.add(filename);
              }
          } catch (IlvReadFileException e1) {
              // No more filenames to read
          }
        }
    
  3. 完全な地図データが保存されている場合、標準メカニズムによって未加工のイメージ・データが再接続されます。ただし、ユーザーが地図のデータではなく地図の説明のみを保存したときにファイルを再ロードするようにするには、再ロード・メソッドを記述します。
        public void reload(IlvThreadMonitoringData monitorInfo) {
            super.reload(monitorInfo);
            // clear all images
            dispose();
            // save the known filenames in a temporary array – the addMap would 
    else add them again.
            String[] filenames = (String[])filenameList.toArray(new String[0]);
            // clear the file name list
            filenameList.clear();
            for (int i = 0; i < filenames.length; i++) {
                try {
                    // load each file
                    addMap(filenames[i]);
                    if (monitorInfo != null) {
                        // update the thread monitoring information, if 
    necessary
                        int percent = Math.round(i/(float)filenames.length
                        * 100);
                        monitorInfo.updateProgress(percent);
                    }
                } catch (IOException e) {
                    new IlvExceptionMessage(e,null);
                }
            }
        }