Project呼び出しの速度差


都度、Projectとset_OutputSpatialReferenceの差。
まあ誤差。

Project:79309
set_OutputSpatialReference:78258

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

	mapDoc.Open(@"c:\jpn.mxd");
	int loopcount = 100;

	var map = mapDoc.get_Map(0);
	var featureLayer = (IFeatureLayer)map.get_Layer(0);
	var fc = featureLayer.FeatureClass;

	IQueryFilter qFilter = new QueryFilterClass();
	com.ManageLifetime(qFilter);
	qFilter.WhereClause = "1 = 1";


	IFeature feature = null;
	IFeatureCursor cursor = null;//fc.Search(qFilter, true);
	//com.ManageLifetime(cursor);

	Type t = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
	ISpatialReferenceFactory srFactory = (ISpatialReferenceFactory)Activator.CreateInstance(t);

	var utm54srCode = ESRI.ArcGIS.Geometry.esriSRProjCS4Type.esriSRProjCS_JGD2000_UTM_Zone_54N;
	var sr = srFactory.CreateProjectedCoordinateSystem((int)utm54srCode);

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

	for (int i = 0; i < loopcount; i++)
	{
		spWatch.Stop();
		ComReleaser.ReleaseCOMObject(cursor);
		cursor = fc.Search(qFilter, true);
		spWatch.Start();

		while ((feature = cursor.NextFeature()) != null)
		{
			var geom = feature.Shape;
			geom.Project(sr);
		
			Marshal.FinalReleaseComObject(geom);
		}
	}

	spWatch.Stop();
	Console.WriteLine("Project:{0}", spWatch.ElapsedMilliseconds);


	qFilter.set_OutputSpatialReference(fc.ShapeFieldName, sr);

	Marshal.FinalReleaseComObject(cursor);
	cursor =null; //fc.Search(qFilter, true);
	//com.ManageLifetime(cursor);

	spWatch.Restart();

	for (int i = 0; i < loopcount; i++)
	{
		spWatch.Stop();
		ComReleaser.FinalReleaseComObject(cursor);
		cursor = fc.Search(qFilter, true);
		spWatch.Start();
		while ((feature = cursor.NextFeature()) != null)
		{
			var geom = feature.Shape;
			//geom.Project(sr);
		
			Marshal.FinalReleaseComObject(geom);
		}
	}

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