POST
|
Hi, I am very new to Python (this is in fact my first attempt at scripting) so I am hoping someone could please give me some guidance. Any help would be greatly appreciated!:confused: Thanks very much I would like to be able to autopopulate the unique ID of a sample locations featureclass. The unique ID is based on the grid square that each sample location intesects (grid squares are saved in a separate grid featureclass) and a sequential number. eg sample locations in grid square 'A1' will be assigned a unique ID of A1_1, A1_2, A1_3 and so on. The script will be run whenever new features are added and require the next unique sequential ID's to be calculated. I have had an attempt but I am not sure I have the logic correct (and definitely not all of the coding) and may need to start from scratch. Bits of this script are from a previous forum which i have adapted. The script is not updating the [Location_Code] which is the unique ID field at the moment. If I unindent the last 'for statement' at the bottom it does update the [Location_Code] field but only with the same value for each sample location so it seems like the indenting was incorrect. I have also not incorporated a spatial join yet and am selecting based on a pre calculated [Grid_Code] field but ideally it would be nice to have this in the same script. The print statements are merely for me to work out what is going on. Thanks again, Karyn import arcpy, sys, re, os
from arcpy import env
import string
# Assign environment workspace
env.workspace = r'C:\Users\karyn\Documents\My Documents\Business\GIS\ArcGIS\Learnings\Python\ivgn_loc_new_ID\127613066.gdb'
#Create filter for selecting only features where there is a location code
filter = "\"Location_Code\" <> ' '"
#Define sample locations feature layer which require their IDs to be populated
selected_feat = r'C:\Users\karyn\Documents\My Documents\Business\GIS\ArcGIS\Learnings\Python\ivgn_loc_new_ID\ivgn_locn_pt selection.lyr'
#Define sample location featureclass
fc = r'C:\Users\karyn\Documents\My Documents\Business\GIS\ArcGIS\Learnings\Python\ivgn_loc_new_ID\127613066.gdb\ivgn_locn_pt'
#Define cursors
selrows = arcpy.SearchCursor(selected_feat)
orirows = arcpy.UpdateCursor(fc, filter)
selrows2 = arcpy.UpdateCursor(selected_feat)
print "variables assigned"
#Get the gridcode for the sample locations that need updated - this needs updating to access this through a spatial join
for selrow in selrows:
fcgridcode = selrow.Grid_Code
print "grid code assigned" + fcgridcode
# iterate through fc to find where the grid code of the new sample locations equals the grid code of the existing sample locations. Then
# work out location code with the highest sequential number and asign the new location code to be the highest ID + 1
for orirow in orirows:
origlocation_code = orirow.Location_Code
#assign first 2 letters of location code to the varible (which is the grid code)
origgridcode = origlocation_code[:2]
print "orig" + origgridcode
print "fc" + fcgridcode
if origgridcode == fcgridcode:
# Iterate through rows and get highest ID values
print "gridcode match " + origgridcode + fcgridcode
for row1 in orirows:
high_id = 0
high_idfull = row1.Location_Code
high_id1 = int(high_idfull[:3])
if high_id < high_id1:
high_id = high_id1
print high_id
# Iterate through rows and update values
for selrow2 in selrows2:
i = high_id1
i += 1
selrow2.Location_Code = fcgridcode + "_" + str(high_id1)
selrows2.updateRow(selrow2)
print high_id
del selrow, selrows, orirow, orirows, selrows2
print "script complete"
... View more
09-16-2012
01:46 AM
|
0
|
1
|
1881
|
POST
|
Hi, Sorry for the delayed response. Thanks very much for your replies. We don't have the Production Mapping extension but I am downloading the free trial and will have a play with it. Is there any way of doing this without the production mapping extension? Thanks again, Karyn
... View more
05-31-2011
07:33 PM
|
0
|
0
|
2233
|
POST
|
Hi, I am creating a map series and would like to insert an excel table for each page. (in ArcMap10) It would be great to have the excel spreadsheet to dynamically update for each map page but I haven't been able to work out how to do this. The way I am going about it (and probably not the most efficient) is by creating a table in excel for each map page. I then copy and paste the excel table into word and save. In ArcMap, I am then going Insert>Object and inserting the word document into the map (as a link). The table comes in correctly. (I have tried to link directly to excel but it never works properly as it won't recognise the data range I am interested in). When I insert the tables I insert them into data View rather than layout view in a logical location for each page. This means that when I print the series, the tables will be different for each page. I am however now having issues with my workspace and I am guessing that having lots of linked excel tables in an MXD is causing problems. I could go back and copy and paste the tables as an image rather than a link but perhaps that will cause the similar problems. There are approximately 150 maps in each series (and we are doing about 17 series). Not every map page has an attribute table, only about half. Has anyone done something similar successfully or have a better solution? Thanks very much for your help!
... View more
05-18-2011
05:08 PM
|
0
|
15
|
8902
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|