1

I am currently working with ArcGIS 10.2.2 and need a script to create a tool (if possible). I have USGS 7.5' Quad Maps as my base and a series of UTM coordinates representing sites. I would like the tool to accept an Easting and Northing. Then zoom the map to the area and put a cross-hair in the location. Is this possible by using arcpy scripting?

If so, I am open to suggestions on where to start or even how to complete this task.

4
  • Is this just a list of coordinates you want to create points for, or are you expecting dynamic input? If the former, you just need to take a look at one of the several add/create xy event layer tools/questions here. For example this help file: resources.arcgis.com/en/help/main/10.2/index.html#//… which also references this tool: resources.arcgis.com/en/help/main/10.2/index.html#//…
    – Chris W
    Commented Apr 21, 2015 at 22:49
  • I am actually not using the proposed tool for mapping the UTM points that I have but using it in a searching manner. Thank you for your interest and links Chris.
    – How_To
    Commented Apr 22, 2015 at 15:44
  • 1
    So is there a reason the Go to XY tool mentioned by @mr.adam won't work? It can take UTM, zoom to location, flash location, and draw a point or labeled point at the location. Symbology for said point can be changed on the Draw toolbar with Default symbol properties, indicating it's a graphic and not a feature (though it could be saved as such). It also stores a recent history of entered coordinates.
    – Chris W
    Commented Apr 22, 2015 at 18:41
  • Well, I mentioned it but I was so fixated on using arcpy that I didn't even think to mention that tool as the solution, which it certainly seems like it should be... :)
    – mr.adam
    Commented Apr 23, 2015 at 0:29

1 Answer 1

1

Ok, I thought this was going to be easier than it seems to be, but it's a good exercise either way. I was hoping to create a marker graphic on the map (in data view) that is not a feature (just like using the Go To XY tool), but as far as I could tell, that is not possible. So there's a little bit of prepwork to get this to work.

Prepwork:

  1. Add a point layer to the TOC and name it something novel: "ZOOM TO HERE"
  2. Choose a cross-hair symbol for the layer

Now create the tool:

  1. Create a toolbox using the ArcCatalog window, and then add a new script tool to it.
  2. Add two parameters, one for Northing and one for Easting.
  3. If these coordinates are going to be in variable UTM zones, add a parameter for that too (more about that later)

The script for the script tool should look something like this:

import arcpy

north = arcpy.GetParameterAsText(0)
east = arcpy.GetParameterAsText(1)
# zone = arcpy.GetParameterAsText(2) # see below for more info

## make map document objects
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

## make spatial reference (see rest of answer for more info)
sr = arcpy.SpatialReference(26912)

## make point
simple_point = arcpy.Point(east, north)
point_geom = arcpy.PointGeometry(simple_point,sr)

## get and zoom to extent of new point
new_extent = point_geom.extent
df.extent = new_extent

## get the dummy layer and insert this point so you can see it
lyr = arcpy.mapping.ListLayers(mxd,"ZOOM TO HERE")[0]
with arcpy.da.InsertCursor(lyr,["SHAPE@"]) as cursor:
    cursor.insertRow([point_geom])

arcpy.RefreshActiveView()   

Ok, about the spatial reference, it's very nice that now ESRI will accept an EPSG code as argument for new spatial reference objects. So just use this website to find the EPSG code for your desired UTM zone (the one above is Zone 15N). If you want, you could pass that number to the script with an extra tool parameter, or, if all these points are in the same zone, just hard-code it in.

6
  • This is great! Thank you for your help and knowledge. I will be trying this out later today.
    – How_To
    Commented Apr 22, 2015 at 15:45
  • So, I have tried to run the script and receive an AttributeError: 'module' has no attribute 'GetParameterAsText' (stops at line 3 "north = arcpy.GetParameterAsText"(0)). I am assuming this is because I set something up wrong in the prep work steps (wrong parameters, wrong set up of layer, etc.). I hate to ask this, but do you think you could give me a few more details? I am new to arcgis and python so I am confused and overwhelmed.
    – How_To
    Commented Apr 30, 2015 at 19:20
  • You may have done nothing wrong at all, for one, I see I wrote GetFeatureAsText which is totally wrong, it should be Parameter like you have said. I'll edit mine to what it should be, so double check that yours matches and try again.
    – mr.adam
    Commented Apr 30, 2015 at 19:29
  • However, did you check out the Go To XY Tool? as Chris W mentioned, it does what you're hoping for, as far as I can tell. The icon is a dot and "XY" next to the binoculars in the standard toolbar.
    – mr.adam
    Commented Apr 30, 2015 at 19:33
  • Ha, very funny. I didn't even see that. I have played with the tool a little bit. I didn't even know that there was the ability to change from long/lat till then. But I also wanted to try the script as it will give me a better idea of what is going on in the language end of the function.
    – How_To
    Commented Apr 30, 2015 at 19:41

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.