Microsoft SQL Geometryはそんなに優秀なのか? – 2 –


前回
引き続き、今回は日本全土の図形(ある程度島含みのマルチパートジオメトリ)
にランダム点2万点の包含判定速度

環境は前回記事参照

結果、Microsftの圧勝
やはりレコード取得に使いそうなのは速いのか?

ISpatialIndexを付加したらESRIの方が早い

コードの使い回しで朝仕込んだ結果程度だが、結果が面白いので良しとしよう
>何かミスが無いかはやはり気になる

次回は、実際SQL Server上にある物をIFeatureCursor vs DataTableで比較して完予定

リザルト
msTime: 26,483.5147ms
esriTime: 119,679.8453ms
msTime: 26,102.493ms
esriTime: 120,234.877ms
msTime: 26,497.5156ms
esriTime: 118,870.799ms
msTime: 27,147.5528ms
esriTime: 118,912.8014ms
msTime: 26,416.5109ms
esriTime: 118,840.7973ms

コード

public static void TEST(string gdbPath,string areaName , string ptName)
{
    using (ComReleaser lifetime = new ComReleaser())
    {
        Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
        IWorkspaceFactory2 wsf = (IWorkspaceFactory2)Activator.CreateInstance(t);
        lifetime.ManageLifetime(wsf);

        IFeatureWorkspace fw = (IFeatureWorkspace)wsf.OpenFromFile(gdbPath, 0);
        lifetime.ManageLifetime(fw);

        Type geomType = Type.GetTypeFromProgID("esriGeometry.GeometryEnvironment");
        IGeometryFactory3 geomfact = (IGeometryFactory3)Activator.CreateInstance(geomType);
        lifetime.ManageLifetime(geomfact);

        IRelationalOperator areaComGeom = null;
        SqlGeometry areaGeom = null;
        IFeatureClass fcArea = fw.OpenFeatureClass(areaName);
        IFeatureCursor areaCursor = fcArea.Search(null, true);
        lifetime.ManageLifetime(areaCursor);

        IFeature areaFeature = null;
        while ((areaFeature = areaCursor.NextFeature()) != null)
        {
            areaComGeom = (IRelationalOperator)areaFeature.ShapeCopy;
            lifetime.ManageLifetime(areaGeom);

            byte[] shape = (byte[])geomfact.CreateWkbVariantFromGeometry(areaFeature.Shape);

            System.Data.SqlTypes.SqlBytes bytes = new SqlBytes(shape);
            Microsoft.SqlServer.Types.SqlGeometry geom = SqlGeometry.STGeomFromWKB(bytes, 0);
            areaGeom = geom;

            ComReleaser.ReleaseCOMObject(areaFeature);
            break;
        }

        IFeatureClass ptFc = fw.OpenFeatureClass(ptName);
        lifetime.ManageLifetime(ptFc);

        IFeature ptFeature = null;
        IFeatureCursor cursor = ptFc.Search(null, false);
        lifetime.ManageLifetime(cursor);

        List<IGeometry> topoList = new List<IGeometry>(); ;
        List<SqlGeometry> sqlGeomList = new List<SqlGeometry>();

        while ((ptFeature = cursor.NextFeature()) != null)
        {
            byte[] shape = (byte[])geomfact.CreateWkbVariantFromGeometry(ptFeature.Shape);

            System.Data.SqlTypes.SqlBytes bytes = new SqlBytes(shape);
            Microsoft.SqlServer.Types.SqlGeometry geom = SqlGeometry.STGeomFromWKB(bytes, 0);

            sqlGeomList.Add(geom);
            topoList.Add((IGeometry)ptFeature.ShapeCopy);
        }
        for (int i = 0; i < 5; i++)
        {
            DateTime dt = DateTime.Now;

            foreach (var item in topoList)
            {
                //Console.Write(
                areaComGeom.Contains(item);
                //);
            }

            TimeSpan esriTime = DateTime.Now - dt;

            dt = DateTime.Now;

            foreach (var item in sqlGeomList)
            {
                //Console.Write(
                areaGeom.STContains(item);
                //);
            }

            TimeSpan msTime = DateTime.Now - dt;

            string msg = string.Format("msTime:{0}ms\nesriTime:{1}ms", msTime.TotalMilliseconds, esriTime.TotalMilliseconds);
            Console.WriteLine(msg);
        }

        foreach (var item in topoList)
        {
            ComReleaser.ReleaseCOMObject(item);
        }
        topoList.Clear();
        topoList = null;

    }//end com
}//end method
カテゴリー: 開発, 設計 タグ: パーマリンク