0

I am a Python (v2.6.5) noob trying to plot a series of 3D polylines into graphs. So far I've come up with:

    # Import system modules
    import arcpy, os, sys, string
    from arcpy import env

    print "Modules imported."

    # Set environment settings
    arcpy.env.overwriteOutput = True
    arcpy.env.workspace = r"X:\HaulRoad\SpatialData"
    arcpy.env.scratchWorkspace = r"X:\HaulRoad\SpatialData"

    print "Workspaces set."

    # Set local variables
    infc = "\HaulRd.gdb\Treatment\XS_2009BEBRklnTerr_interpZ_Rte_isect"
    graph_template = r"\XS\XS_Seg02.55.grf"  # template graph originally created with 3d Analyst profile tool, customized in Advanced Properties, then exported to grf format

    print "Local variables set."


    #create list of fields of interest from FC or table of interest
    fields = ['SegID','STA_calc','shape.Z','shape.M']


    #create empty list for cursor to populate
    list = []

    print "Table and empty list created."

    # use search cursor to get field value for a given record 
    rows = arcpy.SearchCursor(infc, "", "", "SegID; STA_calc")
    for row in rows:
        list.append(row.SegID)
        list.append(row.STA_calc)

    del row, rows

    print "Rows appended to temporary table.  List deleted."

    #remove duplicates from list
    list = dict.fromkeys(list)
    list = list.keys()

    print "Duplicates removed."

    #create a temporary memory variable
    memoryFC = "in_memory" + "\\" + "virtualFC"
    print "Memory Feature created."

    for n in list:
        arcpy.TableSelect_analysis(infc, memoryFC, "STA_calc = " + str(n))
        out_Seg = fields[0]
        out_STA = fields[1]
        out_graph_name = n
        out_graph_pdf = r"\XS\Script\XS_chart_Seg" + str(out_Seg) + str(out_STA) + ".pdf"
        graph_data = memoryFC

        # Create temporary feature layer 
        arcpy.MakeFeatureLayer_management(infc, "XS_lyr")

        # Create the graph from temporary feature layer
        graph = arcpy.Graph()

        # Specify the title of the Graph
        graph.graphPropsGeneral.title = "Segment " + out_Seg

        # Specify the subtitle of the Graph
        graph.graphPropsGeneral.subtitle = "Station " + out_STA

        # Specify the title of the left axis
        graph.graphAxis[0].title = "Elevation (ft)"

        # Specify the title of the bottom axis
        graph.graphAxis[2].title = "Station (ft)"

        # Add a vertical bar series to the graph
        graph.addSeriesLineVertical("XS_lyr", shape.Z, shape.M)

        # Output a graph, which is created in-memory
        arcpy.MakeGraph_management(graph_template, graph, out_graph_name)

        # Save the graph as an PDF
        arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 800, 600)

    #clean in-memory
    arcpy.Delete_management("in_memory")

    print "PDFs created and memory cleaned."

I get an error in line 82 where I am adding the vertical line series. I assume the problem is that I am trying to plot values based on feature geometry as opposed to values in the attribute table.

Is this possible without some intermediate conversion (e.g. converting vertices to points)?

The source data is a polyline feature class with Z and M values in an Arc 10.0 SP4 file geodatabase.


My overall intent is communciated in an earlier post: Creating dynamic chart titles in ArcMap? I was unsuccessful in my attempts to perform from within Arc.


error message I receive in IDLE follows:

Traceback (most recent call last): File "C:\temp\MakeGraphTest_v100_20140616.py", line 82, in graph.addSeriesLineVertical("XS_lyr", shape.Z, shape.M) NameError: name 'shape' is not defined

2
  • The 'out_graph_pdf' variable seems to have an incomplete path, could you check this? What is the error message you get?
    – GISGe
    Jun 18, 2014 at 12:18
  • thanks for reply. code line with pdf conversion has worked for me in a different script. I'm assuming it's OK, but can't confirm as script bails before it gets to it. I've posted error message at end of my original post.
    – willfish
    Jun 18, 2014 at 17:42

1 Answer 1

1

shape.Z and shape.M aren't fields, they are properties of the shape field. If you want to plot Z and M, you should export these to new fields and use the new fields in arcpy.graph.addSeriesLineVertical.

1
  • @GISGe....thanks, I've been working on that part. have amended my process to converting vertices to points early in script (before FOR loop). Then seems, I can go one of two ways:<br> 1) add z and m fields to point table or 2) create a temporary table/array in memory. My impediment at this point is finding the syntax to extract z and m values from feature geometry. Ironic that it's as easy as right-clicking a field name in ArcMap and so hard to figure out for code. Thanks for any suggestions on syntax.
    – willfish
    Jun 19, 2014 at 21:36

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.