Tag Info

Hot answers tagged

5

Your Try: statement is capitalised, it should be lower case - try:


4

Figured it out. Boy that was easy! >>> import arcpy ... ... fc = "C:\Users\PythonTesting.gdb\My_File" ... f1, f2, f3 = "EDITOR", "COUNTY", "OBJECTID" ... clause = arcpy.AddFieldDelimiters(fc, f3) + "= 1" ... for row in sorted (arcpy.da.SearchCursor (fc, [f1, f2], clause)): ... print ("{0}_{1}".format(row[0], row[1])) ... name ...


4

I think your question is pure Python rather than GIS but I put together a simple Python script called test.py below to prove that it can be easily done. import arcpy arcpy.CreateFeatureclass_management("C:/temp","test.shp") I placed test.py in C:\temp and used Windows Explorer to double-click it. A DOS window appeared for about 10-15 seconds, and then ...


3

Don't manually concatenate paths. It leads to errors and makes your code non-portable to other OS's. Use os.path.join instead. For example, replace any instance of projectGDB = path + projectName + ".gdb" with : projectGDB = os.path.join(path, projectName + ".gdb") I believe this will solve your problem, since "F:\GIS\TEST" doesn't end in a path ...


3

The problem may be in how you concatenate the variables to create projectGDB. What you're endiing up with for projectGDB is "F:\GIS\TESTTEST.gdb" Notice there's no slash between the path and the gdb name. I'd suggest using os.path.join(path, projectName + '.gdb') to set projectGDB. Alternately, you could add a slash in front of projectName manually. Also, ...


3

float("Inf") is not a true float. You can't do normal math with it. Feature class fields can only store actual numeric values, within specific ranges. From the help: Data type | Storable range --------------------------------------------------- Short integer | -32,768 to 32,767 Long integer | -2,147,483,648 to 2,147,483,647 Float | ...


3

there is no such thing as the "sum" operator for difference (which is not permutable), so you should test the validity of each item to decide how you run the substraction. def stack(item1,item2): if item1 != None and item2 != None: return item1-item2 elif item1 != None: return item1 elif item2 != None: return -item2 ...


2

As Michael suggested, first creating a layer file of populated rows should do the trick. Before your code, create a variable with the proper SQL query, and then create your layer file. Execute your time conversion on your layer file. code: sql = '"START_DATE" IS NOT NULL' arcpy.MakeFeatureLayer_management (SA_TEN_GOV_els, "lyr", sql) ...


2

You can do this by looping through the shapefile first with a SearchCursor, creating a dictionary item for each "Key" field, where the value is a list of the "Accuracy" field values. Then loop through again with a UpdateCursor, compare with the maximum accuracy value from the dictionary, and delete the row as appropriate. import arcpy # Create dictionary d ...


2

If you don't have .lyr files or an existing mxd referencing the data, I think what you're trying to do should be impossible with Python. A better approach would be to create (manually) a template mxd with a geotiff and an ascii file in it, then (with Python): copy the template mxd (with saveACopy) and replace the data sources of both layers with e.g. ...


2

Your basic code is very good. As per my comments: arcpy.da.UpdateCursor(inFeatures, ('x','y',"shape@")) should be arcpy.da.UpdateCursor(inFeatures,['x','y','shape@']) The square brackets make it a list which is what the tool is expecting. Schema locks occur when you have the same data open in multiple sources or have left a cursor unclosed - using ...


2

Years and Months behave differently in several ways that make your expression work for years, but break for months. Any set of year ranges that are positive will work with the original years expression. No set of ranges across multiple years alone can select just dates from a given month. For months you have to set an overall range of all dates regardless ...


2

You've forgotten to add cur.updateRow(row) in the end of the loop, to save changes.


2

Have you looked at the arcpy.mapping LegendElement? Not sure that will do what you want, but is one way of manipulating legend elements.


2

Following on Phloem's comment about using arguments in the printPages() method, and echoing Emil's answer as well: My gut reaction says we need to select the desired active page by setting the currentPageID property in the mxd.dataDrivenPages object, and then run the mxd.dataDrivenPages.printPages() method to send the active page to the printer. I'm ...


2

Here's a snippet of code that might work for you. the variable 'pageName' is the name of the page to be printed. pageName = "page1" mxd = arcpy.mapping.MapDocument (r"M:\CCAO_GIS_Projects\Library_Districts\MXD\Lib_Test_new.mxd") pageIndex = mxd.DataDrivenPages.getPageIDFromName (pageName) mxd.DataDrivenPages.printPages ("HP Color LaserJet 2600n (Copy 1)", ...


1

The reason is probably in ArcMap unable to recognize a NoData value set by the IDW tool as either 3.40282e+038 or -3.40282e+038. I'd recommend using SetNull tool for these two values on the result and see if that gets rid of any senseless values (should set them correctly to NoData). If not, a flaw in the input data might be present (I'm unsure if IDW ...


1

This code will do the trick I think. It looks for any line with $PHOTO_NUM, and when it finds one it checks three lines below with the use of the linecache module. If $TERRAIN_HEIGHT : is found three lines down, the script performs a cursor to find the replacement value, and calculates the index of the line to do the replacement in. Once this index is ...


1

I can think of a few ways to accomplish this, if you want to automate the process you would use a similar approach to this example in the ArcGIS help LegendElement example 4: The following script updates all layers in the legend to use a custom legend item style item called MyNewStyle. import arcpy mxd = ...


1

Try this: for month in range (01,12): arcpy.MakeFeatureLayer_management("Sightings1995-2014", "test%s" %month,"DATE >= date'01.%s.1995' AND DATE < date'01.%s.2014'" % (month, month+1) When you did it for year you ended your for statement with a colon (:), but when you did it for month that was omitted.


1

I would confirm as @Vince suggests if your input datasets have spatial indices. If your inputs are Shapefiles then these by default do not have spatial indices and need building. Another suggestion that will speed up your code is to replace the cursor you are using with a cursor from the da module as described here.


1

The long execution time is relatively normal. I had a script which I ran from the Python window inside ArcMap and that took more than two hours. I realized that when I converted the script to a script tool, the execution time went down to 12 minutes. A script tool is like a toolbox. You connect your script to the tool. You will need to add a few lines in ...


1

Similar to what the other posters have said. Use arcpy.da.searchcursor and use the where clause. You can then set the where clause to be "where accuarcy > 80" or whatever you want. check out this resource http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001r000000


1

You have this problem because the field names to be used when you have a join are not the original field names. If you don't need the join anymore, you can use the "remove join" tool. If you do need the values from the joined table, you must include the table name in the field name, like this : !table_name.field_name! If you want to make sure of the ...


1

The grid I was using was stored as a feature class within a geodatabase; printing cursor iterations over the table revealed that it was only reading about 1,000 records at a time at which point it would pause for quite a while before reading another 1,000 records. AFter 45 minutes, the table still had not been traversed. By exporting to a shapefile I was ...



Only top voted, non community-wiki answers of a minimum length are eligible