<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating a Custom arcgis tool in Transportation Questions</title>
    <link>https://community.esri.com/t5/transportation-questions/creating-a-custom-arcgis-tool/m-p/201603#M690</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I see a school and 'Final Project' in your workspace, so a few ideas to point you in the right direction:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-import statements at go at the top, then the function definitions (Clean style thing)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-check on arcpy.AddMessage in addition to print if you want to see messages in your script console&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-arcpy.GetParameterAsText&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Read these sections of the ArcGIS Help "Accessing parameters in a script tool", "Understanding script tool parameters", "Setting script tool parameters" (Pay attention to the 'Obtained from' property of the parameter).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 06 May 2013 17:50:21 GMT</pubDate>
    <dc:creator>TimDine</dc:creator>
    <dc:date>2013-05-06T17:50:21Z</dc:date>
    <item>
      <title>Creating a Custom arcgis tool</title>
      <link>https://community.esri.com/t5/transportation-questions/creating-a-custom-arcgis-tool/m-p/201601#M688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: luke.kaim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a script that works in IDLE,&amp;nbsp; but now I want to create a custom tool to be run inside arcgis. I am a little confused about how to modify the code to get it to work though. I have a point shapefile and 1 or 2 polygon layers. If there are two polygon layer then I use union. I know I will need gp.GetParameterAsText, but I am a little confused how to get that to work within my update cursor as it is right now. I want this tool to work on any input point shapefile and any input polygon shapefile. The two input files have to have an address field at the very least. How do I let the user select which fields they want to be used in the cursor? Also order of these fields matters in the way I currently have the script written. The goal of this script is for Quality analysis. I want to make sure a points attributes match the polygon it is in. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def SpatialJoin(infile,join,outfile):
&amp;nbsp;&amp;nbsp;&amp;nbsp; #this is to test a different workflow compared to the one above and see which one is faster. 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SpatialJoin_analysis(infile,join,outfile,"JOIN_ONE_TO_ONE","KEEP_ALL","","INTERSECT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; #add field to the spatial join that will be updated later if the addresses match.
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(outfile,"Missmatch2","LONG","","","","","NULLABLE","REQUIRED")
&amp;nbsp; 

def UpdateCursor(infile,fieldname):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # update the spatial join shapefile if addresses match.
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(infile,fieldname) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #update cursor.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #for loop to read over cursor.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0]==row[2]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[3]!= " ":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[4]=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif row[1]!=row[3]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[4]=5
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[4]=4

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif row[0]!=row[2]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #if address column does not eqaul polygon address column then row missmatch eqaul 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[4]=2
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[2] == " ":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[4]=3
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print row[2]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #update row values into the cursor


print "Start"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# Import&amp;nbsp; module
import arcpy, datetime
# Overwrite environment parameters
arcpy.env.overwriteOutput = True
# Set work space
from arcpy import env
workspace=arcpy.env.workspace =r"C:\Users\Luke Kaim\Documents\University of Maine\Spring_2013\GIS_Application\finalproject"
#declare variable names
stateSHP="USA_adm1.shp"
Country="Country.shp"
Union="Union.shp"
globeSHP("globeAtNight.shp")
PointField=["SHAPE@","PointID","PointCNTRY","PointState"]

createShape('GaN2012.txt',"globeAtNight.shp",PointField)
Join=["PointCNTRY","PointState","CountryPly", "StatePly","Missmatch2"]
if Country != " ":
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Union_analysis([Country,stateSHP],Union,"ALL")&amp;nbsp; 
start1=datetime.datetime.now()
#start new timer.
##arcpy.Union_analysis([Country,stateSHP],Union,"ALL")&amp;nbsp; 
SpatialJoin("globeAtNight.shp",Union,"Join.shp")
###function call to join all points to country polygon.
UpdateCursor("Join.shp",Join)
end1=datetime.datetime.now()
#end new timer. 
print "DONE updateJoin", end1-start1
print "END"

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help will be greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:01:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/creating-a-custom-arcgis-tool/m-p/201601#M688</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T10:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Custom arcgis tool</title>
      <link>https://community.esri.com/t5/transportation-questions/creating-a-custom-arcgis-tool/m-p/201602#M689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: scoggins&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your script is slightly confusing. You start with a spatial join and then import modules half way through? Maybe the first part is an example? And you'll want to make sure to use arcpy.GetParameterAsText, not gp.GetParameterAsText... just saying!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 May 2013 03:19:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/creating-a-custom-arcgis-tool/m-p/201602#M689</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-05-05T03:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Custom arcgis tool</title>
      <link>https://community.esri.com/t5/transportation-questions/creating-a-custom-arcgis-tool/m-p/201603#M690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I see a school and 'Final Project' in your workspace, so a few ideas to point you in the right direction:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-import statements at go at the top, then the function definitions (Clean style thing)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-check on arcpy.AddMessage in addition to print if you want to see messages in your script console&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-arcpy.GetParameterAsText&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Read these sections of the ArcGIS Help "Accessing parameters in a script tool", "Understanding script tool parameters", "Setting script tool parameters" (Pay attention to the 'Obtained from' property of the parameter).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 May 2013 17:50:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/creating-a-custom-arcgis-tool/m-p/201603#M690</guid>
      <dc:creator>TimDine</dc:creator>
      <dc:date>2013-05-06T17:50:21Z</dc:date>
    </item>
  </channel>
</rss>

