Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By : Eric Pimpler
Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By: Eric Pimpler

Overview of this book

The book kicks off with the fundamentals of starting to use Python with ArcGIS, followed by recipes on managing map documents and layers, including how to find and fix broken data links in these files. In the second part of the book, you will learn to create custom geoprocessing tools and how to use the Attribute and Location tools to select specific features. The third part of the book covers topics for advanced users including the REST API, and also teaches you how to use Python with ArcGIS Pro. The book finishes with appendices covering how to automate Python scripts, and the five things that should be at the back of every GIS programmer's mind.
Table of Contents (17 chapters)
16
Index

Exporting a map with the ArcGIS REST API and Python


The ArcGIS REST API has a large set of operations that you can use when requesting information from an ArcGIS Server instance. For example, you can export maps, query layers, geocode addresses, and much more. In this recipe, you will learn how to export a map image from a map service.

Getting ready

The export operation can be used to create a map image from a map service. The response to this request includes the URL of the image, width, height, extent, and scale. In this recipe, you'll use the export operation to export a map as an image file.

How to do it…

  1. In your Python development environment, create a new script, save it as C:\ArcpyBook\Ch12\ExportMapToImage.py.

  2. Import the requests and json modules:

    import requests
    import json
  3. Create a new variable called agisurl, assign the URL, and export the operation, as seen here:

    import requests
    import json
    agisurl = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA...