0

I have created a map series on ArcGIS Pro 2.5.1 displaying distribution data for different bird species over a UK county. Each page displays a different species. The index feature is a point feature class which is just a list of the different species, each with the same coordinates to centre the map. I want to export each page as a GIF file.

This Python code snippet from this help page seemed to be for the same general task:

https://pro.arcgis.com/en/pro-app/arcpy/mapping/mapseries-class.htm

relpath = os.path.dirname(sys.argv[0])

p = arcpy.mp.ArcGISProject(relpath + "\\MapSeries\\US_States.aprx")
l = p.listLayouts()[0]
if not l.mapSeries is None:
  ms = l.mapSeries
  if ms.enabled:
    for pageNum in range(1, ms.pageCount + 1):
      ms.currentPageNumber = pageNum
      print("Exporting {0}".format(ms.pageRow.STATE_NAME))
      pageName = ms.pageRow.STATE_NAME
      l.exportToPNG(os.path.join(relpath, "Output", f"Ex2_{ms.pageRow.STATE_NAME}.png"))

I have tried to modify this to fit my own workflow:

relpath = os.path.dirname("C:\Yusef\Pembrokeshire Avifauna\Breeding 2000s gif")
p = arcpy.mp.ArcGISProject("C:\Yusef\Pembrokeshire Avifauna\Pembrokeshire Avifauna_working.aprx")
l = p.listLayouts()[0]
if not l.mapSeries is None:
  ms = l.mapSeries
  if ms.enabled:
    for pageNum in range(1, ms.pageCount + 1):
      ms.currentPageNumber = pageNum
      print("Exporting {0}".format(ms.pageRow.Species))
      pageName = ms.pageRow.Species
      l.exportToGIF(os.path.join(relpath, "Output", f"Ex2_{ms.pageRow.Species}.gif"))

For which I get the following error message, which I'm not sure how to interpet:

Traceback (most recent call last):
  File "<string>", line 12, in <module>
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 1029, in exportToGIF
    return convertArcObjectToPythonObject(self._arc_object.exportToGIF(*gp_fixargs((out_gif, resolution, gif_color_mode, clip_to_elements), True)))
OSError: C:\Yusef\Pembrokeshire Avifauna\Output\Ex2_Barn Owl.gif

Can anyone tell me what I'm doing wrong?

1 Answer 1

2

It looks like the source of the error is the spaces in the file path names. I suggest using the string literal 'r' before the strings, as described here: https://docs.python.org/2/reference/lexical_analysis.html#string-literals

relpath = os.path.dirname(r"C:\Yusef\Pembrokeshire Avifauna\Breeding 2000s gif")
p = arcpy.mp.ArcGISProject(r"C:\Yusef\Pembrokeshire Avifauna\Pembrokeshire Avifauna_working.aprx")
l = p.listLayouts()[0]
if not l.mapSeries is None:
  ms = l.mapSeries
  if ms.enabled:
    for pageNum in range(1, ms.pageCount + 1):
      ms.currentPageNumber = pageNum
      print("Exporting {0}".format(ms.pageRow.Species))
      pageName = ms.pageRow.Species
      l.exportToGIF(os.path.join(relpath, "\\Output\\", r"Ex2_{ms.pageRow.Species}.gif"))
1
  • Thanks @Drbeene, I tried inserting the 'r's as you suggested but got the same error message as before: Traceback (most recent call last): File "<string>", line 11, in <module> File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 1029, in exportToGIF return convertArcObjectToPythonObject(self._arc_object.exportToGIF(*gp_fixargs((out_gif, resolution, gif_color_mode, clip_to_elements), True))) OSError: C:\Output\Ex2_{ms.pageRow.Species}.gif
    – Yusef_S
    Jul 15, 2020 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.