0

How would I change the following code (outJPEG section) if I'd like to have the original attribute table name (eg Adress) and the attribute field name (eg ZipCode) as file name? (Adress_ZipCode)

The code as I have it now would just name the output JPG after the field in the attribute table (ZipCode)

Maybe os.path.split is an option but I am not so familiar with python and cannot make it work..

# export as jpeg

outJPEG = os.path.join(outPath, attr + ".jpg")  #atrr and outPath are defined in another part of the code
arcpy.mapping.ExportToJPEG(mxd, outJPEG, "PAGE_LAYOUT", 200, 200, 300, False, "24-BIT_TRUE_COLOR", 90, False)
6
  • 1
    The code you have presented would fall over with an error of the variable attr being undefined. When you present code snippets for assistance they should work up to the point you are stuck, and have any error message thrown included. Commented Jun 11, 2015 at 5:08
  • 1
    What is it you're trying to do? What have you currently got? I've read that 3 times and can't figure it out. Do you already have an image called [ADDRESS].jpg (for example 1 Smith Road.jpg)? Are you trying to find the address in the Zip Code table to make the name [ADDRESS][Zip].jpg (example 1 Smith Road 11111.jpg)? Commented Jun 11, 2015 at 5:28
  • Now that we can see the code it appears to be the same as the code provided in two later duplicates, and so presumably it will error in the same way that you were mentioning in the first of those two duplicates. If this code errors, then can you please include the exact error message from your provided code so that we will need to do less guessing before being able to start helping you. Commented Jun 11, 2015 at 7:11
  • To try and work with the focussed Q&A format that we use here to resolve many questions very quickly I would ask that you review meta.gis.stackexchange.com/a/3353 If all you need to do is to "generate a file output name consisting out of the name of the feature class + name of the attribute" then it is just the code snippet that you are using to try and do that which we need to see edited into your question - and any error that occurs when you run it. Commented Jun 11, 2015 at 7:29
  • Please be aware that we do not offer a code writing/revising/debugging service but are happy to try and help with any focussed questions that you may have about using GIS site-packages for Python. Commented Jun 11, 2015 at 7:33

1 Answer 1

1

I ran your code snippet in IDLE, and as expected, it first complained about its indentation which I corrected to the following:

# export as jpeg

outJPEG = os.path.join(outPath, attr + ".jpg")  #atrr and outPath are defined in another part of the code
arcpy.mapping.ExportToJPEG(mxd, outJPEG, "PAGE_LAYOUT", 200, 200, 300, False, "24-BIT_TRUE_COLOR", 90, False)

When I ran that, as expected, I received the error below because your code snippet does not include the necessary import os before you try to use that module.

> Traceback (most recent call last):   File "C:\temp\test.py", line 3,
> in <module>
>     outJPEG = os.path.join(outPath, attr + ".jpg")  #atrr and outPath are defined in another part of the code NameError: name 'os' is not
> defined

We really need you to test your code snippets before you post them so that we can focus on where you are actually stuck and not on errors introduced by quickly copy/pasting lines of code.

2
  • We just need to see enough of your code to see the error. In your case your whole code is not much more than a snippet so I am happy for you to post that but what I have not seen is an error that tells us the line number on which you are seeing an error and the precise wording of that error so it can be lined up against your code. Commented Jun 11, 2015 at 8:02
  • I'm not aware of an English word "snippled" - it is snippet that I keep referring to: dictionary.reference.com/browse/snippet Commented Jun 11, 2015 at 8:31

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.