InMmeoryFeatureClassのサブクエリ


結論から言うと副問い合わせはできない。
DB格納は勿論、ファイルジオデータベースも副問い合わせはいけるが残念。

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

  mapDoc.Open(@"C:\Data.mxd", null);

  var flayer = (IFeatureLayer)mapDoc.get_Layer(0, 0);
  com.ManageLifetime(mapDoc);

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

  var tab = (ITable)((IStandaloneTableCollection)mapDoc.get_Map(0)).get_StandaloneTable(0);
  com.ManageLifetime(tab);

  mapDoc.Close();

  string fcName = ((IDataset)fc).Name;
  string tabName = ((IDataset)tab).Name;

  var fcRset = (IRecordSet2)this.getRecordSet((ITable)fc, null);
  com.ManageLifetime(fcRset);

  var tabRset = (IRecordSet2)this.getRecordSet(tab, null);
  com.ManageLifetime(tabRset);

  var t = Type.GetTypeFromProgID("esriDataSourcesGDB.InMemoryWorkspaceFactory");

  var workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(t);
  com.ManageLifetime(workspaceFactory);

  var workspaceName = workspaceFactory.Create(null, "MyWorkspace", null, 0);
  com.ManageLifetime(workspaceName);
  var name = (IName)workspaceName;

  var workspace = (IWorkspace)name.Open();
  com.ManageLifetime(workspace);

  var memFc = (IFeatureClass)fcRset.SaveAsTable(workspace, fcName);
  com.ManageLifetime(memFc);

  var memTab = tabRset.SaveAsTable(workspace, tabName);
  com.ManageLifetime(memTab);

  string where = string.Format("JCODE IN (SELECT {0}.JCODE FROM {0} WHERE KEN = '東京都')", tabName);
  IQueryFilter qfilter = new QueryFilterClass();
  com.ManageLifetime(qfilter);
  qfilter.WhereClause = where;

  //dont-work
  IFeatureCursor cursor = memFc.Search(qfilter, true);
  com.ManageLifetime(cursor);

  IFeature feature = null;
  int finx = memFc.FindField("SIKUCHOSON");

  while ((feature = cursor.NextFeature()) != null)
  {
    Console.WriteLine(feature.get_Value(finx).ToString());
  }
}//end com
private IRecordSet2 getRecordSet(ITable tab, IQueryFilter qFilter)
{
  IRecordSetInit rInit = new RecordSetClass();
  rInit.SetSourceTable(tab, qFilter);
  return (IRecordSet2)rInit;
}
カテゴリー: 開発 タグ: パーマリンク