AnsweredAssumed Answered

ArcXML/ArcIMS equivalents in python/arcpy - creating points and lines

Question asked by Noodles484 on Nov 25, 2015
Latest reply on Nov 30, 2015 by dkwiens

I need to update an old script that uses ArcIMS and ArcXML into modern day python and arcpy.  This script runs in perl, but the part I need to recreate has to do with creating graphics layers on the fly.  Given some lat/longs, how do I create them as points, then draw lines between them, and then symbolize them how I want?


In perl, I create the xml I want, then send it to the server pretty easily as seen below:

In this code I create the points and lines based on an array of lat/longs


Then I send the request to the arcims server which is hosting a basemap that these are drawn on and export a jpeg:



This seems much harder than it should be in python.  The script I've come up with so far is below.  It creates a points layer and adds it to an existing map (which works fine), but I cant change the symbols.  Basically I just want to use a text letter for each point.  The other tricky part will be creating the lines from it.  I will use the script and tool in arctoolbox, but this is really a ton more work and I still don't know how to change the symbols.  The only idea I came up with is to add a dummy layer that is symbolized how I want but turned off, then apply that symbology to the newly created letters.  But that won't give me the dynamic creation I need.  (These scripts do a bunch more, I just tried to simplify it here.)  At the end it exports a jpeg of the map.


import arcpy

import os

import uuid


arcpy.env.overwriteOutput = True

templateMxd = r"C:\location\to\my\mxd.mxd"

mxd = arcpy.mapping.MapDocument(templateMxd)



# list of lat/longs

ptList = [[-82.1, 29.51], [-80.07, 31.13], [-82.97, 31.96], [-86.12, 27.71], [-82.9, 25.25]]

pt = arcpy.Point()

ptGeoms = []

for p in ptList:

    pt.X = p[0]

    pt.Y = p[1]



tempPoints = os.path.join(arcpy.env.scratchGDB, 'tempPoints')

arcpy.env.workspace = arcpy.env.scratchFolder


arcpy.CopyFeatures_management(ptGeoms, tempPoints)

arcpy.MakeFeatureLayer_management(tempPoints, "Start_Points")

arcpy.SaveToLayerFile_management("Start_Points", "Start_Points.lyr")


tempPointsLayer = os.path.join(arcpy.env.scratchFolder, 'Start_Points.lyr')

addLayer = arcpy.mapping.Layer(tempPointsLayer)


df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0]

arcpy.mapping.AddLayer(df, addLayer, "TOP")

lyrExtent = addLayer.getSelectedExtent()

df.extent = lyrExtent


output = 'WebMap_{}.jpg'.format(str(uuid.uuid1()))

Output_File = os.path.join(arcpy.env.scratchFolder, output)


# Export the WebMap

arcpy.mapping.ExportToJPEG(mxd, Output_File, df, df_export_width=500, df_export_height=500, resolution=150)


# Set the output parameter to be the output file of the server job

arcpy.SetParameterAsText(1, Output_File)

del mxd, addLayer, lyr