2

I'm trying to automate the setup of some flood depth/hazard maps. The user specifies a folder containing depth grids generated by a hydraulic model (.asc format) and some background mapping (geotiff format). I've got the mapping to import correctly using code similar to that below. But the code does not work for the ASCII datasets.

depthgrid = "<userspecifiedfolder>\\maximumdepthgrid.asc"
arcpy.mapping.AddLayer(df, depthgrid)

Upon running the code I get the error: "AssertionError"

Conversion from ASCII to another filetype is not really an option as I need the files in this ASCII format for various other tasks too and would prefer not to double up on data.

Example ASCII data:

ncols 2068

nrows 1522

xllcorner 516810.000

yllcorner 466168.000

cellsize 1.000

NODATA_value -999.

-999.0000 -999.0000 -999.0000 -999.0000 -999.0000 -999.0000 ...

more data ...

  • 1
    Can you view the ASCII files in Catalog? Frequently files called ASCII are not the format that Esri anticipates hence the error. resources.esri.com/help/9.3/arcgisengine/java/GP_ToolRef/… – Michael Stimson Dec 15 '14 at 23:18
  • Is it possible to shorten asc file name – FelixIP Dec 15 '14 at 23:49
  • 1
    I'd really like to see the first dozen lines. ASCII files are supported by Esri as an image format however software like CAD packages have been known to export gridded X,Y,Z with the .asc extension; other text-based image formats exist as an interchange that could be considered ASCII as that's simply the character set the text is presented in en.wikipedia.org/wiki/ASCII , so all it's saying is the file is 'text'. Only the Esri ASCII (on previous comments' link) is the correct format to load as an image. – Michael Stimson Dec 16 '14 at 0:23
  • I am able to see the data in ArcCatalog. I'm also able to add the data to ArcMap manually using the black/yellow Add Data button. I've added some example data to the original question above. Ta. – davehughes87 Dec 16 '14 at 9:45
  • AddLayer is only supposed to work with .lyr files or with layers already in the TOC of an mxd. How do you even manage to import the Geotiffs using this function? – GISGe Dec 16 '14 at 10:48
2

If you don't have .lyr files or an existing mxd referencing the data, I think what you're trying to do should be impossible with Python.

A better approach would be to create (manually) a template mxd with a geotiff and an ascii file in it, then (with Python): copy the template mxd (with saveACopy) and replace the data sources of both layers with e.g. replaceDataSource.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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