POST
|
If I can't get the density data to show up as elements on a PNG, would this Search Cursor at least get me the tract number and density information in the Python window after the program runs?
... View more
12-12-2013
12:59 PM
|
0
|
0
|
606
|
POST
|
The traceback is saying Traceback (most recent call last): File "C:\Python27\ArcGIS10.1\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript exec codeObject in __main__.__dict__ File "C:\Users\dallascowboy83\Desktop\final project 2\final project\finalscript2.py", line 37, in <module> cursor=arcpy.da.SearchCursor(lyr) TypeError: Required argument 'field_names' (pos 2) not found I am guessing the density field is either not defined within the Search Cursor or its not locating the density field. And the reason I keep saying new layer is because I actually did create a new layer within the same script. I am wanting the user to select census tracts by attributes (tract number), which copies the features of the tract and then creates a new feature class of just that specific tract. I then want the script to work by adding a title and density data of that specified tract to the map layout of the new layer (plano_tract_select) and then export to a PNG. I just don't know if this can be achieved with the Search Cursor or in arcpy at all.
... View more
12-12-2013
12:32 PM
|
0
|
0
|
606
|
POST
|
I am getting a syntax error on the titleElem.text line and not sure where the mistake is.
#Edit text:
titleElem.text="Census tract: "+str(tract)+" - "Density: "+str(density)
mxd.save()
del titleElem, mxd
Thank you so much for your help, btw Josh. I am learning at a much quicker pace now. And I was wondering, how do I manually set the title element for a new layer? Can't I only do that with an existing layer?
... View more
12-12-2013
11:38 AM
|
0
|
0
|
606
|
POST
|
I think this works for a layer that is already current but what I was trying to do was automate this from a new layer I created in the same Python process. I had a user input that selected census tract attributes and calculated population density. I then wanted tthe specific tract number and density data from the attribute table from the new layer in the map layout and then exported in a PNG. After the zoom, I wanted to create the layout and export it. Someone mentioned that I could do this using a Search Cursor, but I wasn't sure how. Here is my code:
#user selects tract, Select by Attribute tool runs
arcpy.MakeFeatureLayer_management("plano_tract", "plano_tract_lyr")
arcpy.SelectLayerByAttribute_management("plano_tract_lyr", "NEW_SELECTION", "\"Tract_Number\" = "+ tract)
arcpy.CopyFeatures_management("plano_tract_lyr", "plano_tract_select")
#add field
arcpy.AddField_management("plano_tract_select", "density", "DOUBLE")
#calculate field
arcpy.CalculateField_management("plano_tract_select", "density", "[DP0010001] / [sq_mile_1]", "VB", "")
print "executed successfully"
#zoom to selected features
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "plano_tract_select", df) [0]
df.extent = lyr.getExtent(True)
arcpy.RefreshActiveView()
print "zoomed to layer"
... View more
12-12-2013
10:40 AM
|
0
|
0
|
606
|
POST
|
I was wondering if there was a way to put a title and integer data from an attribute table in a new layer created in Python. I was able to create a new layer using copy features, zoom to the selected features, and export the zoomed features in a map as a PNG all using arcpy, but I also wanted a title at the top and data from the attribute table of that specific layer in the map layout before it was exported. Is it possible to get all this automated using Python?
... View more
12-12-2013
09:37 AM
|
0
|
9
|
3454
|
POST
|
So this is what I was able to get for my code for the user input. import arcpy import os from arcpy import env env.workspace = r"C:\Users\dallascowboy83\Desktop\final project 2\final project\final project.gdb" env.overwriteOutput = True #set local variables tracts = "plano_tract" #ask user for tract to search tract = raw_input("Please type Tract Number: ") #user selects tract, Select by Attribute tool runs arcpy.MakeFeatureLayer_management("plano_tract", "plano_tract_lyr") arcpy.SelectLayerByAttribute_management("plano_tract_lyr", "NEW_SELECTION", "Tract_Number = " + tract) arcpy.CopyFeatures_management("plano_tract", "plano_tract_feat") #add field arcpy.AddField_management("plano_tract_feat", "density", "DOUBLE") #calculate field arcpy.CalculateField_management("plano_tract_select", "density", "[DP0010001] / [sq_mile_1]", "PYTHON", "") print "executed successfully" 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? Victor
... View more
12-11-2013
07:23 AM
|
0
|
0
|
364
|
POST
|
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. I then wanted to provide a map layout in ArcMap of the specific tract with the population, area, and population density being shown. 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? Thanks
... View more
12-03-2013
12:37 PM
|
0
|
2
|
1093
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|