テーブル結合時の参照先付け替え


DBMS参照時、テーブル結合するとレンダラやラベル設定のカラム指定がフル名称となるので参照先のDBやスキーマ名が変わるとレンダラやラベルが機能しなくなる。
ArcCatalogのデータ切替/ArcPy等いずれも同じ。
面倒だが地道に覗いて直すしかなさそう。

void copyMap(IMap src, IMap dst, string srcDbName, string dstDbName)
{
  using (ComReleaser com = new ComReleaser())
  {
    UID uid = new UIDClass();
    com.ManageLifetime(uid);
    uid.Value = "{" + typeof(IGeoFeatureLayer).GUID.ToString() + "}";

    IEnumLayer srcEnumLayer = src.get_Layers(uid, true);
    com.ManageLifetime(srcEnumLayer);
    srcEnumLayer.Reset();

    IEnumLayer dstEnumLayer = dst.get_Layers(uid, true);
    com.ManageLifetime(dstEnumLayer);
    dstEnumLayer.Reset();

    ILayer srcLayer = null;
    ILayer dstLayer = null;

    while ((srcLayer = srcEnumLayer.Next()) != null &&
            (dstLayer = dstEnumLayer.Next()) != null)
    {
      if (srcLayer.Name != dstLayer.Name)
      {
        var msg = string.Format("入力:{0} 対象:{1} 順列ずれ", srcLayer.Name, dstLayer.Name);
        throw new ArgumentException(msg);
      }//end if
      var srcGeo = (IGeoFeatureLayer)srcLayer;
      var dstGeo = (IGeoFeatureLayer)dstLayer;

      if (!(dstGeo.Renderer is IUniqueValueRenderer))
        continue;

      IUniqueValueRenderer unique = (IUniqueValueRenderer)dstGeo.Renderer;
      List<string> fields = new List<string>();

      for (int i = 0; i < unique.FieldCount; i++)
      {
        var f = unique.get_Field(i);
        fields.Add(f);

        unique.set_Field(i,
            f.Replace(srcDbName, dstDbName)
        );
      }
      Debug.Print("FIELDS:{0}", string.Join(",", fields.ToArray()));
      dstGeo.Renderer = (IFeatureRenderer)unique;

    }//end loop

  }//end com

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