On 25 Jan 2006 12:42:20 -0800, "IamIan" <[EMAIL PROTECTED]> wrote:

>Thank you for the replies, I'm new to Python and appreciate your
>patience. I'm using Python 2.1.
>
>To reiterate, the ASCII files in the workspace are being read correctly
>and their latitude values (coming from the filenames) are successfully
>being converted to string. Even doing LatInt = int(LatString) works,
>however the second I try to print LatInt's value or use it in
>mathematical operations, the code chokes in ArcGIS.
>
>My full code:
>
># Import system modules
>import sys, os, win32com.client
>
># Create the geoprocessor object
>gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
>print gp.usage("Hillshade_sa")
>print gp.usage("RasterToOtherFormat_conversion")
>print gp.usage("DefineProjection_management")
>
># Check license availability
>gp.AddMessage ("ArcInfo license is " + str(gp.CheckProduct("ArcInfo")))
>gp.SetProduct("ArcInfo")
>gp.CheckOutExtension("Spatial")
>
># Set workspace
>workspace = "E:\\GISTest"
>gp.workspace = workspace
>gp.AddMessage("Workspace = " + gp.workspace)
>
>filenames = os.listdir(gp.workspace)
>filenames = [filename.lower()
>for filename in filenames
>if (filename[-4:].lower() == ".asc" and filename[0] != "-" )]
>for filename in filenames:
>
>   # For each ASCII file, create Hillshade.
>   # account for latitude by computing Z units using radians
>   Latitude = filename[1:3]
>   LatString = str(Latitude)
>   LatInt = int(LatString)
    ^^^^^^--here you set LatInt to an integer

>   gp.AddMessage("LatInt is " + LatInt)
>   radians = LatInt * 0.0174532925
>   zFactor = 1/(113200 * (cos(radians)))
>
>The complete traceback:
>
>Traceback (most recent call last):
>  File "e:\python21\pythonwin\pywin\framework\scriptutils.py", line
>310, in RunScript
>    exec codeObject in __main__.__dict__
>  File "E:\Documents and
>Settings\Administrator\Desktop\Ian\GIS\Python\zOnly.py", line 32, in ?
>    gp.AddMessage("LatInt is " + LatInt)
           string--^^^^^^^^^^^^   ^^^^^^--integer
(LatString in place of LatInt might work, since it's a string (so is Latitude))
>TypeError: cannot add type "int" to string
            ^^^^^^^^^^       ^^^     ^^^^^^
            This is not lying ;-)
>
>
>I tried print repr(filename) and it returned the actual filename:
>'n16w099.asc' , 'n17w062.asc' , etc.
So you can see Latitude would be '16' '17' etc. right?

On to the next traceback ;-)

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to