IWkbとIGeometryFactoryの速度差


IWkb使う方が優位かも。

レイヤ:World Cities -esriGeometryPoint- 2539
IGeometryFactory:69
IWkb:48
レイヤ:Continents -esriGeometryPolygon- 8
IGeometryFactory:341
IWkb:337
レイヤ:World -esriGeometryPolygon- 72
IGeometryFactory:10
IWkb:9
var mxd = @"C:\Program Files (x86)\ArcGIS\DeveloperKit10.3\Samples\data\World\World.mxd";
using (ComReleaser com = new ComReleaser())
{
  var mapDoc = new MapDocumentClass();
  com.ManageLifetime(mapDoc);

  mapDoc.Open(mxd);
  var map = mapDoc.get_Map(0);
  com.ManageLifetime(map);


  UID uid = new UIDClass();
  com.ManageLifetime(uid);

  uid.Value = "{" + typeof(IFeatureLayer).GUID.ToString() + "}";

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

  IFeatureLayer layer = null;
  while ((layer = (IFeatureLayer)enumLayer.Next()) != null)
  {
    //var layer = map.get_Layer(0) as IFeatureLayer;
    com.ManageLifetime(layer);

    var fc = layer.FeatureClass;
    com.ManageLifetime(fc);

    Console.WriteLine("レイヤ:{0} -{1}- {2}", layer.Name, fc.ShapeType.ToString("G"), fc.FeatureCount(null));


    var spWatch = new System.Diagnostics.Stopwatch();
    spWatch.Start();

    var cursor = fc.Search(null, true);
    com.ManageLifetime(cursor);


    var geomFactory = (IGeometryFactory3)new GeometryEnvironmentClass();
    com.ManageLifetime(geomFactory);


    IFeature f = null;
    while ((f = cursor.NextFeature()) != null)
    {
      var data = (byte[])geomFactory.CreateWkbVariantFromGeometry(f.Shape);

      var sqlBytes = new System.Data.SqlTypes.SqlBytes(data);
      var sqlGeometry = Microsoft.SqlServer.Types.SqlGeometry.STGeomFromWKB(sqlBytes, 0);
    }//end feature loop

    var msg = string.Format("IGeometryFactory:{0}", spWatch.ElapsedMilliseconds);
    Console.WriteLine(msg);


    spWatch.Restart();
    cursor = fc.Search(null, true);
    com.ManageLifetime(cursor);
    f = null;

    while ((f = cursor.NextFeature()) != null)
    {
      IWkb wkb = (IWkb)f.Shape;
      int wkbSize = wkb.WkbSize;
      byte[] data = new byte[wkbSize];
      int byte_count = wkbSize;
      wkb.ExportToWkb(ref byte_count, out data[0]);


      if (byte_count != wkbSize)
        data = data.Take(byte_count).ToArray();

      var sqlBytes = new System.Data.SqlTypes.SqlBytes(data);
      var sqlGeometry = Microsoft.SqlServer.Types.SqlGeometry.STGeomFromWKB(sqlBytes, 0);
    }//end feature loop

    msg = string.Format("IWkb:{0}", spWatch.ElapsedMilliseconds);
    Console.WriteLine(msg);

  }//end layer loop
}//end com
カテゴリー: 開発 タグ: パーマリンク