5

Forgive me if this is very basic, as I'm new to GIS work (though I've been a programmer for 10 years) and so I'm not really sure how to approach this, but here goes...

Can I take a table with xmin/xmin ymin/ymax coordinates and use it to create a bunch of polygons in ArcMap 10.0? I have a connection set up to SQL Server 2008 wherein there is a table that has several pieces of information regarding various maps that our team keeps track of.

Here's what I'm working with:

Said table contains the lat/long data in the form of xmin/xmax ymin/ymax, in addition to several other attributes - gmap_id, author, year, scale, etc. My boss asked me if I could create a connection to our SQL Server, use that information to create polygons on a map of the US, and set up a little attribute window with the other information (author, gmap_id, scale, etc) for each polygon.

I've got the first part covered, I think, thanks to this question. I set up the Data Query and pulled the columns that I initially wanted from SQLServer. That gave me a table like so:

I had a screen cap but the image won't post due to my rep < 10, so the table looks like:

gmapId, scale, usgsIdF, xmin, xmax, ymin, ymax
18015, 250000, 13139, -121.891, -123.071, 43, 45.5
18016, 125000, 13140, -117, -118.936, 34.25, 35.624
...

And I now have the data listed as a Source under the Table of Contents window.

How can I now translate that information into a bunch of squares on the map? And then can I use that to set up an attribute table?

I have a lot of python experience, so if that is the way to go I can do it. I am also good with SQL Server 2008, though I have not used it's spatial capabilities yet. So if there is a solution to be had involving TSQL I can also go that route.

I'm just scratching around trying to figure a good way to start.

1 Answer 1

3

Here is a snippet from a larger process that does just what you want, I believe, and should get you started:

def push_coords(coords):
    """Push a set of corner coords to featureclass record"""
    cursor = arcpy.InsertCursor(output_fc)
    feat = cursor.newRow()
    for corner in corners:    
        point.X = corner[0]
        point.Y = corner[1]
        array.add(point)
    array.add(array.getObject(0))
    polygon = arcpy.Polygon(array)
    feat.shape = polygon
    cursor.insertRow(feat)
    array.removeAll()
    del feat
    del cursor    

point = arcpy.Point()
array = arcpy.Array()
# Corners list format: ["lowerLeft", "lowerRight", "upperRight", "upperLeft"]   
cursor = arcpy.SearchCursor(input_xls)
for row in cursor:
    corners = [[row.getValue(xls_lower_left_x), row.getValue(xls_lower_left_y)],
               [row.getValue(xls_lower_right_x), row.getValue(xls_lower_right_y)],
               [row.getValue(xls_upper_right_x), row.getValue(xls_upper_right_y)],
               [row.getValue(xls_upper_left_x), row.getValue(xls_upper_left_y)]]
    push_coords(corners)

This process reads columns from a Excel spreadsheet (input_xls) and then inserts the new polygon into output_fc, but you can easily adapt it use your input database data. The magic happens in push_coords, which takes a nested list of x,y corner coordinates.

2
  • Thanks @Chad for helping me get started. I'm working with it atm and getting some errors so now I'm figuring out how to debug a python script in arcmap :). Commented Apr 13, 2013 at 13:38
  • It still needs work to do to make it fly but it seems to be going in the direction I want :). Commented Apr 15, 2013 at 1:42

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.