Select to view content in your preferred language

Spatial Reference grab not working...

3094
11
02-27-2013 11:42 AM
by Anonymous User
Not applicable
Original User: SStrand

I have a large metadata generating script that is working great, except for some reason the spatial reference of the data being grabbed and wrote to a Word file is not working.

First, the portion to write text to word (this works fine for all other instances in the script):

def search_replace_all(newword, find_str, replace_str):
    wdFindContinue = 1
    wdReplaceAll = 2
    app = win32com.client.Dispatch("Word.Application")
    app.Visible = 0
    app.DisplayAlerts = 0

    app.Documents.Open(newword)
    app.Selection.Find.Execute(find_str, False, False, False, False, False, \
        True, wdFindContinue, False, replace_str, wdReplaceAll)
    app.ActiveDocument.Close(SaveChanges=True)

    app.Quit()

search_replace_all(newword, olddate, newdate)


Here is the code that isn't working:

spatialdesc = arcpy.Describe(newlayer)
sr = spatialdesc.SpatialReference
newspatial = sr.Name

search_replace_all(newword, oldspatial, newspatial)


I've also seen this as/tried unsuccesfully in my code:


sr = arcpy.Describe(newlayer).spatialReference
newspatial = sr.name

search_replace_all(newword, oldspatial, newspatial)


All I get is a generic script error failure response when it gets to this point. Any ideas as to why it won't complete this part correctly?

I am using ArcGIS 10.0 SP3, Windows 7, Python 2.7
0 Kudos
11 Replies
by Anonymous User
Not applicable
Original User: SStrand

So the other computer I have access to here is running 10.1 so I'm not sure if that is a major issue. It shouldn't be in regards to what I am doing.

Running the script on 10.1, it still fails in the same spot but I get a real error!

Traceback (most recent call last)
  File KSDE_SystemlayersAGS10_Layers_LayerCreation.py, line 139, in module
    spatialdesc = arcpy.Describe(newlayer)
  File cprogram filesarcgisdesktop10.1arcpyarcpy__init__.py, line 1200, in Describe
    return gp.describe(value)
  File cprogram filesarcgisdesktop10.1arcpyarcpygeoprocessing_base.py, line 374, in describe
    self._gp.Describe(gp_fixargs(args, True)))
IOError AnnexationAreas_SOI does not exist

Failed to execute (LayerCreation).

AnnexationAreas_SOI is the file I am testing the script with.
0 Kudos
curtvprice
MVP Alum
Check to see exactly what is getting passed. Repr() is very handy for this.

arcpy.AddMessage("newlayer: " + repr(newlayer))


it sounds from your error message that "AnnexationAreas_SOI" is what got passed. If your script is running within the ArcMap context (ie as a script tool in Arcmap) the Describe should be able to identify that string as a layer and successfully find it and retrieve it's spatialReference.

If not, it's just a string and what you should have passed a dataset instead.
0 Kudos