Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

Thank-you,
Will

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

-----EDIT 6/18/2014 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

share|improve this question
    
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 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 at 17:42
add comment

1 Answer

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.

share|improve this answer
    
@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 at 21:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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