官术网_书友最值得收藏!

Referencing map documents on a disk

In addition to being able to reference the currently active map document file in ArcMap, you can also access map document files stored on a local or remote drive using the MapDocument() method. In this recipe, you'll learn how to access these map documents.

Getting ready

As I mentioned earlier, you can also reference a map document file that resides somewhere on your computer or a shared server. This is done simply by providing a path to the file. This is a more versatile way of obtaining a reference to a map document because it can be run outside the ArcGIS Python window or a custom script tool.

How to do it…

Follow these steps to learn how to access a map document stored on a local or remote drive:

  1. Open the IDLE development environment from Start | Programs | ArcGIS | Python 2.7 | IDLE.
  2. Create a new IDLE script window by selecting New | New Window from the IDLE shell window.
  3. Import arcpy.mapping:
    import arcpy.mapping as mapping
  4. Reference the copy of the crime map document that you created in the last recipe:
    mxd = mapping.MapDocument("c:/ArcpyBook/Ch3/crime_copy.mxd")
  5. Print the title of the map document:
    print mxd.title
  6. Run the script to see the following output:
    Copy of Crime Project
    

How it works…

The only difference between this recipe and the last is that we've provided a reference to a map document file on a local or remote drive rather than using the CURRENT keyword. This is the recommended way of referencing a map document file unless you know for sure that your geoprocessing script will be run inside ArcGIS, either in the Python window or as a custom script tool.

主站蜘蛛池模板: 湘潭市| 平谷区| 文登市| 马鞍山市| 太谷县| 灵台县| 聂拉木县| 永春县| 白朗县| 永嘉县| 察哈| 新巴尔虎右旗| 页游| 郸城县| 纳雍县| 阿巴嘎旗| 莆田市| 龙门县| 周至县| 吉木乃县| 桐城市| 拜泉县| 鄂州市| 堆龙德庆县| 屏山县| 桃园县| 双辽市| 津南区| 班戈县| 黄陵县| 上林县| 吴川市| 临武县| 滁州市| 泾阳县| 漳州市| 蓝田县| 伊春市| 黄平县| 新龙县| 商水县|