Clip, Zip and Ship your image service, using Python

Here is a Python sample that can be used to clip items from your image service, package them into a mosaic dataset with all the metadata field values, and then ship them to a client or colleague. As with all other code samples that we add to our gallery, it is meant to help show you how something can be done in code; the actual implementation may need some altering in order for it to work for your particular example.

Description:
This python sample application accepts a input image service layer or URL as input. You can draw a polygon feature to define an area on the image service that you want to clip.

The program will start creating a local mosaic dataset with all metadata field recovered from the image service. And then it will download the image service item one by one according to the geometry of the polygon, and clip the image using the polygon.

You also have the option to clip the image using the default raster function if there is any. And you can also define the output image’s cell size.

The downloaded image will be added back to the local mosaic dataset along with all the metadata field values from the image service.

Note:
This python scripting tool uses the 10.1 Image Server REST API. Some of the functionality, such as define output image spatial reference in the ExportImage REST request is not available in 10.0. This is only a sample, and you may need to alter it, order for it to work for your particular case.

Submitted by: Jie Zhang

This entry was posted in Imagery and tagged , , , , . Bookmark the permalink.

Leave a Reply

4 Comments

  1. ceslop says:

    Hello there,

    Didn’t work for me.

    Here’s the log details:

    ClipAndShip Mosaic_Web c:temp C:tempUso_agua2.gdb teste reservatorio 10 true 0 true

    C:Usersc050883Documentos PessoaisProgramasArcGISArcScriptsClipAndShipToolbox.tbxClipAndShip

    Wed Sep 05 14:45:16 2012

    Mosaic_Web

    c:temp

    C:tempUso_agua2.gdb

    teste

    reservatorio

    10

    true

    0

    true

    C:Usersc050883AppDataLocalTemparc791Mosaic_WebBand_1

    Z:__projetosuhe_colider.gdbreservatorio

    SINGLE

    1000

    C:Usersc050883DocumentsArcGISDefault.gdb

    false

    LZ77

    MEAN

    0 ACM599

    STATISTICS 1 1

    false

    NEAREST

    NONE

    Same As Input

    true

    128 128

    PYRAMIDS -1 NEAREST DEFAULT 75 NO_SKIP

    CURRENT

    NONE

    0

    MAXOF

    Same As Input

    0

    0

    false

    C:Usersc050883DocumentsArcGISDefault.gdb

    HIGHEST

    ERROR: Failure in getting the general service info

    Clip and ship application failed

    Failed to execute (ClipAndShip).

    Wed Sep 05 14:45:16 2012

    0,00 seconds

  2. Simon Woo says:

    This is only a sample application, and is not meant for production per se. All our samples are meant to help you develop your own custom code. The samples are there to help provide a basis of how to start such a custom application.

    That said, the 2 main things I would look for is:
    - check is make sure the server is 10.1 version server
    - check to make sure the image service is published through mosaic dataset

    I hope this helps to make your code work for you.

  3. hlzhang525 says:

    Good idea! For unknown reasons, it is not working for us.

    We feel that effective and efficient ‘clip/export’ functionality is very important for any ‘real’ system because of ‘interoperation’, especially, as a batch.

    So, I am wondering if the following approach can be done in 10.1 in the near future.
    1: With a pre-defined SHP (feature class) containing many tiles with corresponding fields (at least, a field), which will be used to ‘naming’, during directly exporting /clipping image service (or directly from Mosaic Dataset);
    2: the tool functionality will support Mosaic Dataset, TIFF, and IMG, at least, when ‘export/clip’