ArcObjects@PowerShell-2


ArcObjects@PowerShell
これはこう書けるがもうDLLにしたほうがいい気がしてくる。


$adf = [System.Reflection.Assembly]::LoadWithPartialName('ESRI.ArcGIS.ADF.Connection.Local')
$cart = [System.Reflection.Assembly]::LoadWithPartialName('ESRI.ArcGIS.Carto')
$geom = [System.Reflection.Assembly]::LoadWithPartialName('ESRI.ArcGIS.Geometry')
$sys = [System.Reflection.Assembly]::LoadWithPartialName('ESRI.ArcGIS.System')
$ver = [System.Reflection.Assembly]::LoadWithPartialName('ESRI.ArcGIS.Version')

#[System.Console]::WriteLine($adf.Location)


$assemblies = (
 'System',
 $adf.Location,
 $cart.Location,
 $geom.Location,
 $sys.Location,
 $ver.Location
)

$source = @"
using ESRI.ArcGIS;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Carto;

//ESRI.ArcGIS.ADF.Connection.Local
//ESRI.ArcGIS.Carto
//ESRI.ArcGIS.Geometry
//ESRI.ArcGIS.System
//ESRI.ArcGIS.Version

public static class Test
{
  public static void SetMxd(string mxd)
  {
    RuntimeManager.Bind(ProductCode.EngineOrDesktop);

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

      var map = mapDoc.get_Map(0);
      com.ManageLifetime(map);

      var ext = ((IActiveView)map).FullExtent;
      com.ManageLifetime(ext);

      ext.PutCoords(ext.XMin, ext.YMin, ext.XMin + (ext.Width / 2.0d), ext.YMin + (ext.Height / 2.0d));
      map.AreaOfInterest = ext;

      mapDoc.Save();

      mapDoc.Close();
    }//end com

  }//end method
}//end class

"@
Add-Type -ReferencedAssemblies $assemblies -TypeDefinition $source -Language CSharp

[Test]::SetMxd('C:\Program Files (x86)\ArcGIS\DeveloperKit10.1\Samples\data\World\World.mxd')
カテゴリー: 開発 タグ: , パーマリンク