<?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: Population Density in Census Tracts in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/population-density-in-census-tracts/m-p/758896#M58581</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So this is what I was able to get for my code for the user input.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = r"C:\Users\dallascowboy83\Desktop\final project 2\final project\final project.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#set local variables&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tracts = "plano_tract"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#ask user for tract to search&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tract = raw_input("Please type Tract Number: ")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#user selects tract, Select by Attribute tool runs&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeFeatureLayer_management("plano_tract", "plano_tract_lyr")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management("plano_tract_lyr", "NEW_SELECTION", "Tract_Number = " + tract)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CopyFeatures_management("plano_tract", "plano_tract_feat")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#add field&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddField_management("plano_tract_feat", "density", "DOUBLE")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#calculate field&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management("plano_tract_select", "density", "[DP0010001] / [sq_mile_1]", "PYTHON", "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print "executed successfully"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It does end by saying "executing successfully" but for some reason it just copies the original plano_tract shapefile instead of selecting the attribute and copying the features of the inputed tract. Do I have to use a where clause for this kind of function or is there a mistake somewhere in my code?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Victor&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Dec 2013 15:23:18 GMT</pubDate>
    <dc:creator>VikJasrotia</dc:creator>
    <dc:date>2013-12-11T15:23:18Z</dc:date>
    <item>
      <title>Population Density in Census Tracts</title>
      <link>https://community.esri.com/t5/python-questions/population-density-in-census-tracts/m-p/758894#M58579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am quite new to Python and I am attempting to practice by making a simple program with ArcGIS. I wanted to make a script that automated the calculation of population density of selected census tracts within the city I live in. I also wanted to give the ability for the user to choose the census tract.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I then wanted to provide a map layout in ArcMap of the specific tract with the population, area, and population density being shown.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I realize most of this can be done using ModelBuilder, but I needed practice with Python and thought this would be a good simple program to start with. Anyone have any pointers on the script and also how I could possibly make it better?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 20:37:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/population-density-in-census-tracts/m-p/758894#M58579</guid>
      <dc:creator>VikJasrotia</dc:creator>
      <dc:date>2013-12-03T20:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Population Density in Census Tracts</title>
      <link>https://community.esri.com/t5/python-questions/population-density-in-census-tracts/m-p/758895#M58580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;One useful thing to try is running the tools that your are interested in scripting from arccatalog. Make sure the results tab is enabled.&amp;nbsp; After running the tool you can right click the result object for the tool and select "copy as python snippet."&amp;nbsp; This copies the exact command that was passed to the arcpy interpreter. you can paste it into your python editor and inspect it further.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing you should also look into is using the traceback, and os libraries (import os, traceback, etc.)&amp;nbsp; to help you debug your script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;simple error handling helps a lot when working with arcpy. something as easy as&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ListLayers(mxd)
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "there was an exception"
&amp;nbsp;&amp;nbsp;&amp;nbsp; # from arcgis python editor or toolbox execution:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetMessages()
&amp;nbsp;&amp;nbsp;&amp;nbsp; # from idle or the like:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;can prevent you from banging your head against the wall for too long.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You should also define the input parameters (separated by commas after the method call (i.e. arcpy.CopyFeatures_management (in_features, out_feature_class, {config_keyword}, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3})) so you can attach each of your processes to one another dynamically.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000035000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000035000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ESRI also has some great examples of how to set up your python script as a tool box script using the input parameters, output parameters, and data types.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/A_quick_tour_of_creating_tools_with_Python/00150000002q000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/A_quick_tour_of_creating_tools_with_Python/00150000002q000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's fun.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:10:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/population-density-in-census-tracts/m-p/758895#M58580</guid>
      <dc:creator>MaxSquires</dc:creator>
      <dc:date>2021-12-12T08:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Population Density in Census Tracts</title>
      <link>https://community.esri.com/t5/python-questions/population-density-in-census-tracts/m-p/758896#M58581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So this is what I was able to get for my code for the user input.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = r"C:\Users\dallascowboy83\Desktop\final project 2\final project\final project.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#set local variables&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tracts = "plano_tract"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#ask user for tract to search&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tract = raw_input("Please type Tract Number: ")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#user selects tract, Select by Attribute tool runs&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeFeatureLayer_management("plano_tract", "plano_tract_lyr")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management("plano_tract_lyr", "NEW_SELECTION", "Tract_Number = " + tract)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CopyFeatures_management("plano_tract", "plano_tract_feat")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#add field&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddField_management("plano_tract_feat", "density", "DOUBLE")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#calculate field&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management("plano_tract_select", "density", "[DP0010001] / [sq_mile_1]", "PYTHON", "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print "executed successfully"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It does end by saying "executing successfully" but for some reason it just copies the original plano_tract shapefile instead of selecting the attribute and copying the features of the inputed tract. Do I have to use a where clause for this kind of function or is there a mistake somewhere in my code?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Victor&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Dec 2013 15:23:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/population-density-in-census-tracts/m-p/758896#M58581</guid>
      <dc:creator>VikJasrotia</dc:creator>
      <dc:date>2013-12-11T15:23:18Z</dc:date>
    </item>
  </channel>
</rss>

