1

How do I adjust my script to accept a raster with a filename like the example below when used as a tool in ArcGIS with MulitValue set to Yes?

"008. STUDY AREA MAP_rectified_NAD83_Z12.tif"

With files named in the same way as above the script works in python with two rasters separated with a semi-colon(;).

It also works as a tool when the input parameter (Raster Dataset) has MultiValue set to no.

If I use input file with more conventional names (just numbers and letters) the MultiValue option works correctly.

However, with MultiValue set to yes it fails at the first GetRasterProperties_management task with:

ERROR 000865: [filepath\filename] does not exist

Unfortunately it is not possible to rename the files. Script below;

ScannedMaps = r'C:\ArcGIS\GeoRefCentrepoint\Data\010. STUDY AREA MAP1_rectified_NAD83_Z12.tif;C:\ArcGIS\GeoRefCentrepoint\Data\009. STUDY AREA MAP2_rectified_NAD83_Z12.tif'

        for image in ScannedMaps.split(;):
            print 'Starting: ',image
            arcpy.AddMessage('Starting: '+image)
            #Capture extent of georeferenced scanned map
            MaxX = float(arcpy.GetRasterProperties_management(image,"RIGHT").getOutput(0))
            MinX = float(arcpy.GetRasterProperties_management(image,"LEFT").getOutput(0))
            MaxY = float(arcpy.GetRasterProperties_management(image,"TOP").getOutput(0))
            MinY = float(arcpy.GetRasterProperties_management(image,"BOTTOM").getOutput(0))
            print '- Extent captured'
            arcpy.AddMessage('- Extent captured')

            #Calculate centre point
            centreX = (MaxX + MinX)/2
            centreY = (MaxY + MinY)/2
            print '- Centre point calculated'
            arcpy.AddMessage('- Centre point calculated')

            #Add centre point to feature, change file path, populate fields
            NewFilePath = image.replace('S:','\\\UNCNAME\FOLDER\SUBFOLDER')
            FileName = os.path.basename(image).split('.')[0]
            NewRow = [(FileName, NewFilePath, KeyWords, (centreX,centreY))]
            cursor = arcpy.da.InsertCursor(Feature,['DOCUMENT_NAME','URL','KEY_WORDS','SHAPE@XY'])
            print '- Attributes created'
            arcpy.AddMessage('- Attributes created')
            for data in NewRow:
                cursor.insertRow(data)
                print '- File:',FileName,'added successfully\n'
                arcpy.AddMessage('- File '+FileName+' added successfully')
            del cursor
    print 'Complete'

Update -

Output of when the script runs successfully from in PythonWin, included print ScannedMaps statement as requested:

Starting tool:

ScannedMaps = C:\ArcGIS\GeoRefCentrepoint\Data\010. MAP_rectified_NAD83_Z12.tif;C:\ArcGIS\GeoRefCentrepoint\Data\009.  MAP_rectified_NAD83_Z12.tif
Starting:  C:\ArcGIS\GeoRefCentrepoint\Data\010. MAP_rectified_NAD83_Z12.tif
- Extent captured
- Centre point calculated
- Attributes created
- File: 010 added successfully

ScannedMaps = C:\ArcGIS\GeoRefCentrepoint\Data\010. MAP_rectified_NAD83_Z12.tif;C:\ArcGIS\GeoRefCentrepoint\Data\009. MAP_rectified_NAD83_Z12.tif
Starting:  C:\ArcGIS\GeoRefCentrepoint\Data\009. MAP_rectified_NAD83_Z12.tif
- Extent captured
- Centre point calculated
- Attributes created
- File: 009 added successfully

Complete
5
  • What is your variable ScannedMaps set to? Have you reviewed previous occurrences of this error: gis.stackexchange.com/questions/tagged/error-000865
    – PolyGeo
    Commented Nov 11, 2016 at 23:45
  • ScannedMaps = arcpy.GetParameterAsText(0) as the script is being used as a tool in ArcGIS. That parameter is the input raster dataset.
    – Cjd111
    Commented Nov 14, 2016 at 18:26
  • Can you add a print ScannedMaps line to "capture" what ScannedMaps is set to for one occasion when you see this, and include a manual setting of that in your code snippet, please?
    – PolyGeo
    Commented Nov 14, 2016 at 19:43
  • Probably a bit late but I would say starting file names with numbers is bad practise and long names with many spaces should be avoided to. By adhering to short names, no spaces, don't have unusual characters and do not start with numbers your code is less likely to malfunction.
    – Hornbydd
    Commented Nov 17, 2016 at 15:05
  • Completely agree, and have made that suggestion to the client, but unfortunately we cannot change the names of the files. Had thought about including at the start of the script a copy and rename of each file but that then doubles the size of the stored data.
    – Cjd111
    Commented Nov 17, 2016 at 19:52

1 Answer 1

4

If the name has spaces, ArcGIS will wrap it in single quotes.

Use something like

rasters = [f.strip("'") for f in rasters.split(";")]
2
  • Not sure how to incorporate that into my existing code above? Also why does it work when MultiValue is set to No?
    – Cjd111
    Commented Nov 16, 2016 at 18:43
  • @Cjd111 Because ArcGIS only wraps literal single quotes around MultiValue filepaths with spaces, not single value filepaths with spaces. ScannedMaps = [f.strip("'") for f in ScannedMaps.split(";")]
    – user2856
    Commented Nov 16, 2016 at 22:32

Your Answer

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

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