QueryLayer初期化


FeatureClass取得は通常のが早いかな。。。
GetQueryDescriptionが遅すぎる?

OpenQueryClass:73
QUERY:6231
SDE:4827

OpenQueryClass:34
QUERY:856
SDE:503

OpenFromString:225
GetQueryDescription:311
OpenQueryClass:37
QUERY:853
OpenFeatureClass:113
SDE:496

Stopwatch spWatch = new Stopwatch();
spWatch.Start();

// Build a connection string.
String[] connectionProps = 
{
    "dbclient=SQLServer", 
    "serverinstance=ほすとめい", 
    "database=でーたべーす", 
    "authentication_mode=DBMS",
    "user=ゆーざ",
    "password=ぱすわーど"
};

String connString = String.Join(";", connectionProps);


String[] connectionPropsSDE = 
{
    "dbclient=SQLServer", 
    "SERVER=ほすとめい", 
    "DATABASE=でーたべーす", 
    "INSTANCE=sde:sqlserver:ほすとめい",
    "user=ゆーざ",
    "password=ぱすわーど",
    "VERSION=dbo.DEFAULT"
};

string sde_connString = String.Join(";", connectionPropsSDE);

using (var com = new ComReleaser())
{
    var openWatch = new Stopwatch();
    openWatch.Start();

    int srid = 4612;

    Type t = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
    ISpatialReferenceFactory spRefFactory = (ISpatialReferenceFactory)Activator.CreateInstance(t);
    com.ManageLifetime(spRefFactory);

    ISpatialReference spref = spRefFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCS3Type.esriSRGeoCS_JapanGeodeticDatum2000);

    Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SqlWorkspaceFactory");
    IWorkspaceFactory2 workspaceFactory2 = (IWorkspaceFactory2)Activator.CreateInstance(factoryType);

    // Open the workspace.
    IWorkspace workspace = workspaceFactory2.OpenFromString(connString, 0);
    com.ManageLifetime(workspace);

    openWatch.Stop();
    Debug.Print("OpenFromString:{0}", spWatch.ElapsedMilliseconds);
    openWatch.Restart();


    ISqlWorkspace sqlWorkspace = (ISqlWorkspace)workspace;

    IQueryDescription queryDescription = sqlWorkspace.GetQueryDescription(
        "SELECT * FROM RND");
    com.ManageLifetime(queryDescription);
    

    //queryDescription.OIDFields = "OID";
    queryDescription.GeometryType = esriGeometryType.esriGeometryPolygon;
    queryDescription.Srid = srid.ToString();
    queryDescription.SpatialReference = spref;


    openWatch.Stop();
    Debug.Print("GetQueryDescription:{0}", spWatch.ElapsedMilliseconds);
    openWatch.Restart();


    IFeatureClass queryClass = (IFeatureClass)sqlWorkspace.OpenQueryClass("%RND", queryDescription);
    com.ManageLifetime(queryClass);

    openWatch.Stop();
    Debug.Print("OpenQueryClass:{0}", openWatch.ElapsedMilliseconds);

    //IGeoDataset geodataset = (IGeoDataset)queryClass;
    //Debug.Print("{0}", geodataset.Extent.XMax);
}
spWatch.Stop();
Debug.Print("QUERY:{0}", spWatch.ElapsedMilliseconds);
spWatch.Restart();

using (var com = new ComReleaser())
{
    Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
    IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2)Activator.CreateInstance(t);
    var fw = (IFeatureWorkspace)workspaceFactory.OpenFromString(sde_connString, 0);

    var openWatch = new Stopwatch();
    openWatch.Start();

    var featureClass = fw.OpenFeatureClass("RND");

    openWatch.Stop();
    Debug.Print("OpenFeatureClass:{0}", openWatch.ElapsedMilliseconds);


}
spWatch.Stop();
Debug.Print("SDE:{0}", spWatch.ElapsedMilliseconds);
カテゴリー: 開発 タグ: パーマリンク