Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    I need help on this error message


    I was trying to write a custom python script for Definition query for a particular layer and this error message was what i got
    NameError: name 'field' is not defined

    after entering the following codes -
    #Variables to form defintion query
    field = '"Name_Allottee"'
    value = "'Fadare A Adetoye'"
    #concatenate query syntax
    queryStr = "Name_Allottee" + "=" + "Fadare A Adetoye"
    #Specify the MXD project (CURRENT), dataframe (Layers)
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")
    #Apply defintion query to specified layer group (KWAGIS_Parcels)
    for lyr in arcpy.mapping.ListLayers(mxd, "KWAGIS_Parcel", df):
    if lyr.supports("DEFINITIONQUERY"):
    lyr.definitionQuery = queryStr
    arcpy.RefreshActiveView()
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    Run following program, study output, determine if the resulting knowledge you've gained can resolve your trouble:
    Code:
    field = '"Name_Allottee"'
    value = "'Fadare A Adetoye'"
    print "Name_Allottee" + "=" + "Fadare A Adetoye"
    print field + '=' + value
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Syntax Error


    Thank you very much for your response,i really appreciate it. Thanks

    This line of code - print "Name_Allottee" + "=" + "Fadare A Adetoye"

    is giving me this error - syntax error - invalid syntax
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    Sorry, I usually code for valid python 2 and 3. I had participated in an overnight sailing race (we placed third after handicap in the spinnaker fleet) and wasn't clear headed. Still recovering??? Maybe.

    Code:
    field = '"Name_Allottee"'
    value = "'Fadare A Adetoye'"
    print("Name_Allottee" + "=" + "Fadare A Adetoye")
    print(field + '=' + value)
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Thanks, but see this


    After using this

    #Variables to form defintion query
    field = '"Name_Allottee"'
    value = "'Fadare A Adetoye'"
    print ("Name_Allottee" + "=" + "Fadare A Adetoye")
    print (field + '=' + value)
    #concatenate query syntax
    queryStr = "Name_Allottee" + "=" + "Fadare A Adetoye"
    #Specify the MXD project (CURRENT), dataframe (Layers)
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")
    #Apply defintion query to specified layer group (KWAGIS_Parcels)
    for lyr in arcpy.mapping.ListLayers(mxd, "KWAGIS_Parcel", df):
    if lyr.supports("DEFINITIONQUERY"):
    lyr.definitionQuery = queryStr
    arcpy.RefreshActiveView()

    I got this error message


    Name_Allottee=Fadare A Adetoye

    Traceback (most recent call last):
    File "C:\Users\Administrator\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{95D0FD7B-F31F-5373-3A2B-C58D26139764}\DefinitionQuery_addin.py", line 15, in <module>
    print (field + '=' + value)
    NameError: name 'field' is not defined
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    I had suggested that you run 4 lines of code, hoping you'd understand them and notice that in one case the strings are quoted and in the other case they are not. I'll do it for you:
    Code:
    >>> field = '"Name_Allottee"'
    >>> value = "'Fadare A Adetoye'"
    >>> print("Name_Allottee" + "=" + "Fadare A Adetoye")
    Name_Allottee=Fadare A Adetoye
    >>> print(field + '=' + value)
    "Name_Allottee"='Fadare A Adetoye'
    >>>
    No syntax errors, no name errors, no errors of any sort occur. I don't know any specific details about your arcpy module.

    Try this queryStr assignment. If you can't tell why there could be important quote marks then I suspect you'll need to read some manuals.
    Code:
    queryStr = '''Name_Allottee="Fadare A Adetoye"'''
    Please read the information about posting python code with correct indentation found at the link in my signature. Follow the advice.

    Your line 15 might be the call to RefreshActiveView. I have difficulty believing that the code that executes causing the error is the same code that you report in this forum. On the other hand, you've altered code and managed to change your error message.
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Thanks


    Yeah the code for the concatenation is working, but it just for the definitionquery to work i.e.

    #Apply defintion query to specified layer group (KWAGIS_Parcels)
    for lyr in arcpy.mapping.ListLayers("C:/Users/Administrator/Desktop/Kwara Bureau of Lands/GIS/TDP-Template.mxd", "KWAGIS_Parcel", df):
    if lyr.supports("DEFINITIONQUERY"):
    lyr.definitionQuery = queryStr
    arcpy.RefreshActiveView()

    Error Message

    Runtime error
    Traceback (most recent call last):
    File "<string>", line 2, in <module>
    File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
    File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\mapping.py", line 1499, in ListLayers
    result = mixins.MapDocumentMixin(map_document_or_layer).listLayers(wildcard, data_frame)
    File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 819, in listLayers
    raise TypeError(str(type(dataframe)))
    TypeError: <type 'str'>

    I am using Pythonscripter to compile then iwould install the addin in ArcGIS 10.1, if you run the previous code under the python module within the ArcGIS environment it is smooth and without errors, but not give me the end product which is to use a definitionquery (Page Definition Queries allow you to specify which features of a layer draw based on an SQL query). Please do you have any ideas? Thanks
  14. #8
  15. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    You might get better support at
    http://forums.arcgis.com/
    I'm clueless.
    [code]Code tags[/code] are essential for python code and Makefiles!
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Thanks


    How was the overnight sailing jaunt?
  18. #10
  19. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    2012 Full moon regatta, race report.

    The Full moon regatta is long enough to share some aspects of ROGAINE. {edit: rugged outdoor group activity involving navigation and endurance}
    Long range strategy (based on weather forecast) is important, mentally tiring (less physically exhausting) for lack of sleep, not all the crew remembers after 6 hours that we're racing, not merely sailing. {edit: we raced for 13 hours 15 minutes}

    We experienced many wind shifts and sail changes, including sailing at our top speed of eight and a half knots dropping to zero knots in dead calm within about 10 minutes at dawn.

    Overnight sailing is cool---no sunburn nor squinting.

    We all came with differing wind forecasts. Nori produced detailed hourly wind vector maps of lake Erie. Based on these he predicted that we'd finish between 11AM and 4PM Saturday. We finished by around 8AM.

    Dave.


    I'll include my inspired report from the event last year, when we placed second on corrected time. This describes the sloop somewhat.


    My 2011 log:

    6 of us sailed the Full Moon regatta on Lake Erie aboard a Tartan 41, Sparkman & Stephens designed sloop, built of fiberglass in 1974. The triangular race of about 12 hours started at 6PM by the Buffalo harbor outer breakwater. We rounded the first mark shortly before sunset, then tacked for Dunkirk. Their well lit coal fired power plant was easy to see from a long distance. Wind blew 10 to 15 knots. Boat speed ranged from 5 to 9 knots, averaging a bit over 8 knots. Clear sky, bright moon allowed us to see the tell-tales without flashlight during much of the night. Tacked around the red flashing buoy near Dunkirk, set the spinnaker and returned on a reach, spinnaker pole at the forestay.

    The other 4 crew members had previous experience on this boat. I initially watched them to understand operations and which lines controlled what. We started the race with reefed main and smaller jib, pitching with a slow large motion in the short wavelength swells at the west end of shallow lake Erie. The motion surprised me since the Blue Heron is a 10 ton (yes, 20,000 pounds) boat. The moment of inertia perhaps is small with most of the weight in the keel? The deck was vast. I initially found hanging on difficult because I couldn't reach from the mast to the shrouds when moving about. I learned to stay by the boom or with the rail. The two people who handled the spinnaker pole complained to boat owner Nori that he should invest in the carbon fiber version. Though I didn't lift it, watching them I estimate its weight between 60 and 100 pounds of aluminum. That was later because we beat almost all the way to Dunkirk. Two modern 40' boats sailed away from us. We shook out the reef in the main before dark, by which time I participated more actively since I had determined that the other four were less experienced. They didn't know to set the sails or how to set the them, though could follow instructions. They cleated the working sheets with half hitches. They tailed behind my hand with sheet wrapped about it. They back-winded the jib on tacking. It was torment, so I took over these tasks. They were, however, pleasant, fun, thoughtful, nice.

    Sometime after nautical twilight with diminished wind, we changed the headsail to the #1 genny. I took over the helm when Nori went on deck to help with that process. I managed though it was a wheel, not a tiller. These were roller furling jibs. They didn't furl before dropping. OK, it was darkish, I was 38' away, and I don't yet understand the rig. A boat caught up to us while we were underpowered during sail change. The dark triangle stayed with us for an hour until the wind increased again and we advanced. The wind swung slowly to the south---on the GPS I saw that our beat to lake Erie's southern shore formed an arc. At this point Nori and I were awake, the rest of the crew asleep on the windward side of the deck and in the cabin. The wind finished its shift, heading us for about a minute. I suggested the obvious, tack. We awoke the crew, tacked, and headed directly for the bright Dunkirk light which had appeared on the horizon. The shadow behind us likewise tacked. Nori went off to sleep. I was nice and shared steering with Dave. Maybe it was Bill, they looked like maternal twins but weren't. He eventually went off for a slice of pizza and I again took the wheel. The bright white light of the Dunkirk power plant expanded into yellow lights and blinking lights and street lights as we approached. We saw one boat pass with spinnaker set heading for the finish line. We did not see the other one returning. Nori woke from our discussion of which blinking red light we should round. We tacked about it, set the spinnaker with a little difficulty. My fault? I steered on the desired course, a reach, before filling the chute downwind. My photo of the spinnaker didn't turn out well. The conditions were too dark possibly because my finger was over the camera lens? Wind kept swinging around and increasing, guy out full extent, spinnaker sheet tight. A gust might have broached us. The wind wasn't gusty. 10 tons versus 50' mast and huge spinnaker. Unfurled the jib, dropped the spinnaker, reached. The other 5 snoozed. If I'd learned to use the autopilot I could have played with the sail trim. I let them sleep.

    We didn't have to jibe spinnaker. The pole is too heavy for an "end-to-end" jibe. We'd have to disconnect the guy, swing the pole across, and re-connect. Except that it would hit the forestay, so the pole has to be first hoisted up the mast on one end, dropped by the topping lift to tilt at a steep angle. The "dip" jibe.

    Finishing at dawn, the race committee chose against greeting us. We reported our time by email. Results not yet available. We have some chance to win on corrected time but we're thinking that the overall winner didn't spend quite as long sailing in during the span of reduced wind.
    Last edited by b49P23TIvg; August 7th, 2012 at 09:28 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Cool


    Its fun! i'm looking forward to when i can go for such jaunts. I live in Abuja, Nigeria.

    Can you create custom forms with python, i mean like visual studio, i'm asking cos i use pyscripter and i have not seen any of such module.

    What do you use your python for GIS Development? or application development?

    Thanks
  22. #12
  23. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    I've used python with numpy as a programmable well documented front end of a program that predicts penalties in an optical communication system, and for stand-alone physics simulations.

    The first simulation was essential to the optical index profile design of Corning Incorporated's Large Effective Area fiber (successful LEAF product). Basically the system needs to carry as many different channels (optical frequencies) as possible, at as high a data rate as possible (modulation frequency). The channels interfere with themselves and with each other as they propagate along the fiber, and the amplifiers and other components add noise and other kinds of interference. For instance an optical amplifier will have non-uniform gain across the channels. After the many spans in a transoceanic cable one channel could preferentially grab all the power.
    [code]Code tags[/code] are essential for python code and Makefiles!
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    I want to use an if else statement to return a condition


    I want to use an if else statement to return a condition and it is not returning any of the stated values please can you help me check my code to see whats wrong with it? Thanks

    Code:
    fc = "Parcels"
    field = "GeneratedN"
    cursor = arcpy.SearchCursor(fc)
    for row in cursor:
        row.getValue(field)
    Val = row.getValue(field)
    if Val == 1:
        print "Done"
    else:
        print "Not Done"
  26. #14
  27. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    Code:
    fc = "Parcels"
    field = "GeneratedN"
    cursor = arcpy.SearchCursor(fc)
    print(('Not ','')[1 in (row.getValue(field) for row in cursor)+'Done'])
    [code]Code tags[/code] are essential for python code and Makefiles!
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    I want to drop my pdf output in a nested folder


    Thanks man, i got it
    I've been able to create my folders by combining two variables at a time since the create folder function can only take 2 arguments at a time this is my code;

    Code:
    >>> outName6 = str(val) + "_LGA" + "(" + str(val1) + " _Area" + ")"
    >>> outName1 = "Plot_" + str(val3) + "(" "Block_" + str(val3) + ")"
    >>> arcpy.CreateFolder_management("C:\\ARA_STATE\\", outName6)
    <Result 'C:\\ARA_STATE\\rin_South_LGA(GRA_Buo_Oho _Area)'>
    >>> arcpy.CreateFolder_management("C:\\ARA_STATE\\"+ outName6,outName1)
    <Result 'C:\\ARA_STATE\\rin_South_LGA(GRA_Buo_Oho _Area)\\Plot_9(Block_9)'>
    My next problem is how to drop my pdf in the last folder, i used this code and got this errror message;

    Code:
    >>> outName2 = "TDP_FOR_" + "Block_" + str(val2) + "_Plot_" + str(val3) + "_" + str(val1) + "_Area_of_" + str(val) + "_LGA" + ".pdf"
    >>> arcpy.mapping.ExportToPDF(mxd,"C:\\ARA_STATE\\" + outName6,outName1,outName2)
    Runtime error 
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
        return fn(*args, **kw)
      File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\mapping.py", line 1133, in ExportToPDF
        assert isinstance(data_frame, DataFrame) or (isinstance(data_frame, basestring) and data_frame.lower() == 'page_layout')
    AssertionError
    >>> arcpy.mapping.ExportToPDF(mxd,"C:\\ARA_STATE\\" + outName6,outName1)
    Runtime error 
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
        return fn(*args, **kw)
      File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\mapping.py", line 1133, in ExportToPDF
        assert isinstance(data_frame, DataFrame) or (isinstance(data_frame, basestring) and data_frame.lower() == 'page_layout')
    AssertionError
    What do you think please. Thanks
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo