描画速度向上(劣化防止?)


ふとどこかで見たマルチレイヤシンボルを試す。
計測方法と向上時間及びデータが書いてない情報はだったので あまりレコード多くなければそこまで効果はないだろうと思っていたが意外と効果あり。

MXD速度調整
で使用したデータ (豊中DM)とMXDを使用してマルチレイヤシンボルである必要のないマルチレイヤシンボルを修正していく

ほぼすべてシンプルシンボルに代替可能の好条件とは言え MXD内に200ほどあるマルチレイヤを代替すると10%ほど速度向上した、これ不具合レベルだろ。。。

なおArcGIS 10.1 SP1

マルチレイヤシンボル シンプルシンボル
1354.195 1282.1678
1408.1821 1222.1538
1283.1954 1266.1754
1394.1772 1286.1634
1298.1681 1209.1479
1306.1833 1225.1447
1246.1645 1068.1336
1646.209 1237.1634
1303.1951 1237.1534
1359.9633 1225.933711
90.14%

コードは下記

とりあえずSavaメソッドでMXD保存して、Engineアプリである程度固定で読んでいる場合は、差し替えてもいいかも。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Output;
using System.Diagnostics;

namespace SingleSymbol
{
class Class1
{
  private static int APP_CHANGE_COUNT = 0;

  public static void Test(bool isNormalExport)
  {
    APP_CHANGE_COUNT = 0;

    using (ComReleaser com = new ComReleaser())
    {
      IMapDocument mapDoc = new MapDocumentClass();
      com.ManageLifetime(mapDoc);

      mapDoc.Open(@"C:\tmp\DM\TokyoDATA.mxd");
      //mapDoc.Open(@"C:\tmp\DM\TokyoDATA2.mxd");

      IMap map = mapDoc.get_Map(0);

      ////warm-up 
      //CreateJPEGFromActiveView((IActiveView)map, @"C:\tmp\DM\TTTTTTT.jpg");
      ////warm-up 

      DateTime dt = DateTime.Now;

      if (isNormalExport)
      {
        CreateJPEGFromActiveView((IActiveView)map, @"C:\tmp\DM\multi.jpg");

        Console.WriteLine("Multi:" + (DateTime.Now - dt).TotalMilliseconds.ToString() + "ms");

        return;
      }
      UID uid = new UIDClass();
      com.ManageLifetime(uid);
      uid.Value = "{" + typeof(IGeoFeatureLayer).GUID.ToString() + "}";

      IEnumLayer enumLayer = map.get_Layers(uid);
      com.ManageLifetime(enumLayer);
      enumLayer.Reset();

      ILayer layer = null;
      while ((layer = enumLayer.Next()) != null)
      {
        setSingleSymbol(layer);
      }

      Console.WriteLine(APP_CHANGE_COUNT + " CHANGE");

      dt = DateTime.Now;
      CreateJPEGFromActiveView((IActiveView)map, @"C:\tmp\DM\single.jpg");

      Console.WriteLine("Single:" + (DateTime.Now - dt).TotalMilliseconds.ToString() + "ms");

      //mapDoc.ReplaceContents((IMxdContents)map);
      //mapDoc.SaveAs(@"C:\tmp\DM\TokyoDATA2.mxd");

    }
  }//end method

  private static void setSingleSymbol(ILayer layer)
  {
    IGeoFeatureLayer geoLayer = layer as IGeoFeatureLayer;
    if (geoLayer == null)
      return;

    if (geoLayer.Renderer is ISimpleRenderer)
    {
      ISimpleRenderer simRender = (ISimpleRenderer)geoLayer.Renderer;
      ISymbol sym = simRender.Symbol;
      sym = setSymbol(sym);
      simRender.Symbol = sym;

    }
    else if (geoLayer.Renderer is IUniqueValueRenderer)
    {
      IUniqueValueRenderer unique = (IUniqueValueRenderer)geoLayer.Renderer;
      for (int i = 0; i < unique.ValueCount; i++)
      {
        string value = unique.get_Value(i);
        ISymbol sym = unique.get_Symbol(value);
        sym = setSymbol(sym);
        unique.set_Symbol(value, sym);

      }//end loop
    }
    else
    {
      Debug.WriteLine(geoLayer.Name);
    }//end if
    //IMultiLayerMarkerSymbol
  }//end method

  private static ISymbol setSymbol(ISymbol sym)
  {
    if (sym is IMultiLayerMarkerSymbol &&
      ((IMultiLayerMarkerSymbol)sym).LayerCount == 1 )
    {
      APP_CHANGE_COUNT++;
      return (ISymbol) ((IMultiLayerMarkerSymbol)sym).get_Layer(0);
    }
    else if (sym is IMultiLayerLineSymbol &&
      ((IMultiLayerLineSymbol)sym).LayerCount == 1)
    {
      APP_CHANGE_COUNT++;
      return (ISymbol)((IMultiLayerLineSymbol)sym).get_Layer(0);
    }
    else if (sym is IMultiLayerFillSymbol &&
      ((IMultiLayerFillSymbol)sym).LayerCount == 1)
    {
      APP_CHANGE_COUNT++;
      return (ISymbol)((IMultiLayerFillSymbol)sym).get_Layer(0);
    }

    return sym;
  }

  #region JPEG export

  public static bool CreateJPEGFromActiveView(IActiveView activeView, string pathFileName)
  {
    //parameter check
    if (activeView == null || !(pathFileName.EndsWith(".jpg")))
    {
      return false;
    }
    IExport export = new ExportJPEGClass();
    export.ExportFileName = pathFileName;

    // Microsoft Windows default DPI resolution
    export.Resolution = 96;
    tagRECT exportRECT = activeView.ExportFrame;
    IEnvelope envelope = new EnvelopeClass();
    envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
    export.PixelBounds = envelope;
    System.Int32 hDC = export.StartExporting();
    activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);

    // Finish writing the export file and cleanup any intermediate files
    export.FinishExporting();
    export.Cleanup();

    return true;
  }
  #endregion JPEG export

}//end class
}//end namespace
カテゴリー: 運用, 開発 タグ: , パーマリンク