POST
|
Finally managed to create a tool that does what I wanted, thanks to Rebecca Strauch, GISP, David Wasserman's Blog and Luke Sturtevant for your guidance. # Import system modules
import arcpy
import os
# Check out extensions and Overwrite outputs
arcpy.env.overwriteOutput = True
# Input Parameters
infeature = arcpy.GetParameterAsText(0)
# List all the field names of infeature.
fields = arcpy.ListFields(infeature)
# Change the field alias inital letters of the word to uppercase.
print "Changing the field alias to field name by Capitalising the initial letter"
for field in fields:
if not field.required:
# change field alias to a temporary name to recognise change by stripping of last 2 charecters
arcpy.AlterField_management (infeature, field.name, field.name, field.name.rstrip(field.name[-2:]))
#Change the field alias back to original field name without underscores and turn the initial letter of the word to uppercase
arcpy.AlterField_management (infeature, field.name, field.name, field.name.replace("_"," ").title())
print "Script Completed Successfully"
... View more
03-02-2016
01:37 PM
|
3
|
1
|
489
|
POST
|
Hi David Wasserman's Blog Thanks for the tool. It was really helpful but I am trying to automate the whole process so that I don't have to spend time typing all the alias names.
... View more
02-22-2016
12:11 PM
|
0
|
1
|
489
|
POST
|
So this is how my FC is now as shown below . I want to delete Join_Count, TARGET_FID, JOIN_FID and change the "appellation to Appellation" "affected_surveys to Affected_Surveys" and similar with the other fields
... View more
02-16-2016
06:19 PM
|
0
|
3
|
1574
|
POST
|
Thanks Rebecca Strauch, GISP . I dont really want to hard code the field names as I will be using it as a script tool . Can you guide me how to use the existing field names in my code( keeping in mind that my code also deletes few fields prior to Alter field.
... View more
02-16-2016
05:38 PM
|
0
|
5
|
1574
|
POST
|
Hi Rebecca Strauch, GISP I am only trying to change the field alias. its such a task to create new fields, copy and delete the old ones.
... View more
02-16-2016
03:54 PM
|
0
|
10
|
1574
|
POST
|
Hi Xander Bakker's Blog thanks for your response. As I mentioned earlier I am trying to convert this in to a tool, regarding line 15 I have set the parameters for the tool to delete only selected fields as shown below. only thing I am struggling with is line 27 to loop over the rest of the fields and change alias. Thanks to Luke Sturtevant for mentioning issue with Alias case change.
... View more
02-16-2016
11:18 AM
|
0
|
0
|
1574
|
POST
|
# Import system modules
print "Importing modules"
import arcpy
import os
# Check out extensions and Overwrite outputs
print "Checking for extensions and Overwrite outputs"
arcpy.CheckOutExtension("Analysis")
arcpy.CheckOutExtension("Data Management")
arcpy.env.overwriteOutput = True
# Input Parameters
print "checking input Parameters"
infeature = arcpy.GetParameterAsText(0)
delete_fields = arcpy.GetParameterAsText(1)
# Delete unwanted fields
print "Deleting unwanted fields"
arcpy.DeleteField_management (infeature, [delete_fields])
# Alter field alias by capitalising the initial letter of the word.
print "Changing the field alias by turning 1st letter of the word to uppercase"
fields = arcpy.ListFields(infeature)
for field in fields:
fname = field.name
alias = fname.title()
arcpy.AlterField_management (infeature, field, alias)
print "done" Hi Sephe Fox, I have been trying to dig into this code to alter it to my specifications, but seems like I am lost. could you help me out with this please. Trying to create a script tool that allows you to delete fields and alter alias names. Branched to new question by: Xander Bakker From original thread: https://community.esri.com/thread/151288
... View more
02-15-2016
07:02 PM
|
1
|
17
|
8374
|
POST
|
Yeah i got that working. Join field dint really seem helpful because of the long processing time and the number of fields i have to deal with.
... View more
08-27-2015
03:41 AM
|
0
|
0
|
848
|
POST
|
Thanks Rebecca, this piece of code took me a while to get it but was helpful. Cheers
... View more
08-26-2015
06:40 PM
|
0
|
2
|
848
|
POST
|
just few changes in that, it was meant to be "print project" instead of "print spreadsheet" and "project" instead of "name" in last indentation
... View more
08-26-2015
04:08 PM
|
0
|
0
|
207
|
POST
|
#Import system modules
import arcpy
import os
import xlrd
#Check license for extensions
print "checking license for extensions"
arcpy.CheckOutExtension("Analysis")
#Setting workspace
print "setting up workspace"
arcpy.env.workspace = os.getcwd()
#Overwrite outputs
print "Outputs will be overwritten"
arcpy.env.overwriteOutput = True
#Input data
print "checking input data layers"
primary = "\\nz-primary-parcels\\nz-primary-parcels.gdb\\NZ_Primary_Parcels"
TitleOwners = "\\nz-property-titles-including-owners\\nz-property-titles-including-owners.gdb\\NZ_Property_Titles_Including_Owners"
Out_path = "C:\\Users\\jkrishna\\Documents\\TPG Mapping\\NZTA\\Wellington\\NZ5yearRollingPlan\\Data\\Wellington-Geodatabase.gdb"
Table = "\\Wellington.xls"
#out_join = "\\Wellington-Geodatabase.gdb\\TitleOwnerJoin"
#Adding a parcel ID Field and Project Field to primary parcels
print " Adding ParcelID field and Project field"
arcpy.AddField_management (primary, "ParcelID", "LONG", "", "", 15)
arcpy.AddField_management (primary, "Project", "TEXT", "", "", 30)
arcpy.AddField_management (primary, "SAP_Ref", "LONG", "", "", 15)
#Copying data from ID field to ParcelID
print "Copying data from id field to ParcelID"
arcpy.CalculateField_management (primary, "ParcelID", '[id]')
#Create a layer file to work with
print "Creating a primary layer file"
layerfile = "primary.lyr"
arcpy.MakeFeatureLayer_management(primary, layerfile)
#Spatial join primary parcel and titleowners
print "Spatial joining primary parcel and titleowners"
out_join = Out_path + "\\TitleOwnerJoin"
arcpy.SpatialJoin_analysis (layerfile, TitleOwners, out_join, "JOIN_ONE_TO_MANY", "KEEP_ALL", "", "WITHIN")
spreadsheet = [Table + "\\BasinReserve$", Table + "\\DowseToPetone$"]#, Table + "\\InnercityBypass$", Table + "\\M2pp$",
#Table + "\\ManaParemata$", Table + "\\MellingIc$", Table + "\\MungavinIc$", Table + "\\MuriroadPukeruabay$",
#Table + "\\MtVicTunnel$", Table + "\\NgaurangaGorge$",Table + "\\NO2LTaylorsRdtoLevin$", Table + "\\NO2LWaitarereCurves$",
#Table + "\\PP2O$", Table + "\\PaekakarikiIC$",Table + "\\ParemataCarParking$", Table + "\\PukeruaBay$",
#Table + "\\SH2BPHuttRd$", Table + "\\SH58$", Table + "\\TransmissionGully$", Table + "\\WaitangiruaCorridor$",
#Table + "\\WUMAuroraTerrace$", Table + "\\WUMMurphyToMolesworthSt$", Table + "\\WUMTinakoriRd$"]
for project in spreadsheet:
print spreadsheet
#Convert excel sheet to Dbase table
print " Converting excel sheet to Dbase table"
out_dbase = "C:\\Users\\jkrishna\\Documents\\TPG Mapping\\NZTA\\Wellington\\NZ5yearRollingPlan\\Data"
out_name = project + ".dbf"
arcpy.TableToTable_conversion (project, out_dbase, out_name)
#Create a layer file to work with
print "Creating a parceljoin layer file"
joinlayer = "parceljoin.lyr"
arcpy.MakeFeatureLayer_management(out_join, joinlayer)
#Join title owners featureclass,Project dbf and Copy data from project dbf to title owners featureclass
print" Join table using parcelid field"
arcpy.AddJoin_management (joinlayer, "ParcelID", out_name, "ParcelID", "KEEP_COMMON")
print "Starting edit session"
arcpy.da.Editor(Out_path)
print "copying SAP no"
arcpy.CalculateField_management (joinlayer, "TitleOwnerJoin.SAP_Ref", '['+project+'.SAP_Refere]')
print "Copying project info to project field"
arcpy.CalculateField_management (joinlayer, "Project", '"'+project+'"')
print "Remove join"
arcpy.RemoveJoin_management (joinlayer, name)
print "done"
... View more
08-26-2015
03:54 PM
|
1
|
0
|
207
|
POST
|
sorry tried that i couldnt find where the advanced editor is. will this be helpfull? #Import system modules import arcpy import os import xlrd #Check license for extensions print "checking license for extensions" arcpy.CheckOutExtension("Analysis") #Setting workspace print "setting up workspace" arcpy.env.workspace = os.getcwd() #Overwrite outputs print "Outputs will be overwritten" arcpy.env.overwriteOutput = True #Input data print "checking input data layers" primary = "\\nz-primary-parcels\\nz-primary-parcels.gdb\\NZ_Primary_Parcels" TitleOwners = "\\nz-property-titles-including-owners\\nz-property-titles-including-owners.gdb\\NZ_Property_Titles_Including_Owners" Out_path = "C:\\Users\\jkrishna\\Documents\\TPG Mapping\\NZTA\\Wellington\\NZ5yearRollingPlan\\Data\\Wellington-Geodatabase.gdb" Table = "\\Wellington.xls" #out_join = "\\Wellington-Geodatabase.gdb\\TitleOwnerJoin" #Adding a parcel ID Field and Project Field to primary parcels print " Adding ParcelID field and Project field" arcpy.AddField_management (primary, "ParcelID", "LONG", "", "", 15) arcpy.AddField_management (primary, "Project", "TEXT", "", "", 30) arcpy.AddField_management (primary, "SAP_Ref", "LONG", "", "", 15) #Copying data from ID field to ParcelID print "Copying data from id field to ParcelID" arcpy.CalculateField_management (primary, "ParcelID", '[id]') #Create a layer file to work with print "Creating a primary layer file" layerfile = "primary.lyr" arcpy.MakeFeatureLayer_management(primary, layerfile) #Spatial join primary parcel and titleowners print "Spatial joining primary parcel and titleowners" out_join = Out_path + "\\TitleOwnerJoin" arcpy.SpatialJoin_analysis (layerfile, TitleOwners, out_join, "JOIN_ONE_TO_MANY", "KEEP_ALL", "", "WITHIN") spreadsheet = [Table + "\\BasinReserve$", Table + "\\DowseToPetone$"]#, Table + "\\InnercityBypass$", Table + "\\M2pp$", #Table + "\\ManaParemata$", Table + "\\MellingIc$", Table + "\\MungavinIc$", Table + "\\MuriroadPukeruabay$", #Table + "\\MtVicTunnel$", Table + "\\NgaurangaGorge$",Table + "\\NO2LTaylorsRdtoLevin$", Table + "\\NO2LWaitarereCurves$", #Table + "\\PP2O$", Table + "\\PaekakarikiIC$",Table + "\\ParemataCarParking$", Table + "\\PukeruaBay$", #Table + "\\SH2BPHuttRd$", Table + "\\SH58$", Table + "\\TransmissionGully$", Table + "\\WaitangiruaCorridor$", #Table + "\\WUMAuroraTerrace$", Table + "\\WUMMurphyToMolesworthSt$", Table + "\\WUMTinakoriRd$"] for project in spreadsheet: print spreadsheet #Convert excel sheet to Dbase table print " Converting excel sheet to Dbase table" out_dbase = "C:\\Users\\jkrishna\\Documents\\TPG Mapping\\NZTA\\Wellington\\NZ5yearRollingPlan\\Data" out_name = project + ".dbf" arcpy.TableToTable_conversion (project, out_dbase, out_name) #Create a layer file to work with print "Creating a parceljoin layer file" joinlayer = "parceljoin.lyr" arcpy.MakeFeatureLayer_management(out_join, joinlayer) #Join title owners featureclass,Project dbf and Copy data from project dbf to title owners featureclass print" Join table using parcelid field" arcpy.AddJoin_management (joinlayer, "ParcelID", out_name, "ParcelID", "KEEP_COMMON") print "Starting edit session" arcpy.da.Editor(Out_path) print "copying SAP no" arcpy.CalculateField_management (joinlayer, "TitleOwnerJoin.SAP_Ref", '['+project+'.SAP_Refere]') print "Copying project info to project field" arcpy.CalculateField_management (joinlayer, "Project", '"'+project+'"') print "Remove join" arcpy.RemoveJoin_management (joinlayer, name) print "done"
... View more
08-26-2015
03:42 PM
|
0
|
2
|
207
|
POST
|
Hi Darren this is what i am trying to do, add all the information from spreadsheets to a feature class by joining tables copying information and removing join
... View more
08-26-2015
03:27 PM
|
0
|
2
|
848
|
POST
|
Thanks James that was helpful. The impact of the ‘school run’ on road traffic accidents: A spatio-temporal analysis was in Christchurch in 2004 and i am looking at Hamilton city. I am looking at all types of crash to see if school zones fall in any hot spot locations. I did find some incidents around schools during school timings within 150 m, but need to look at the attributes to find out what sort of crash are they.
... View more
10-14-2014
03:36 PM
|
0
|
0
|
74
|
Title | Kudos | Posted |
---|---|---|
1 | 08-26-2015 03:54 PM | |
3 | 03-02-2016 01:37 PM | |
1 | 02-15-2016 07:02 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|