Tag Info

Hot answers tagged

5

Using cursors is a good way to inspect how datetime fields can be accessed and written to. This is taken from a feature class, with a a date field: with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor: for row in cursor: print row[0], type(row[0]) 2014-07-18 06:03:05 <type 'datetime.datetime'> 2014-07-17 00:00:00 <type ...


4

try this: ctotal = sum([row[0] for row in arcpy.da.SearchCursor("inputtable",["columnX","PercentColumn"])])#column total with arcpy.da.UpdateCursor("inputtable",["columnX","PercentColumn"]) as cursor: for row in cursor: row[1] = (row[0]/float(ctotal))*100 cursor.updateRow(row)


3

Another solution would be to use the Copy Raster tool: arcpy.CopyRaster_management(in_raster, out_rasterdataset) Where you add the file extension to out_rasterdataset


3

You're probably getting some sort of exception being raised. Perhaps use a Queue to pass messages back to the parent process. import os, sys, time from multiprocessing import Process from multiprocessing.queues import SimpleQueue def a_subprocess(msgs, arg1, etc): try: raise Exception('Oops') msgs.put('Finished') except Exception as ...


3

You could use the multiprocessing module. The code below creates a separate process to run the ImportCAD_conversion tool in, waits for it to complete and terminates it if the timeout is exceeded. Note the use of the if __name__ == '__main__': syntax, which is required on Windows. import os, arcpy, arcgisscripting, time, sys gp = arcgisscripting.create() ...


3

If you do decide to use Make Feature Layer, note that it allows you to specify a where clause: MakeFeatureLayer_management (in_features, out_layer, {where_clause}... I haven't tested to see whether this improves performance, but you could potentially save some time by running the query while creating the layer, thus omitting the Select By Attributes. You ...


2

I have FOUND the ANSWER infc = arcpy.GetParameterAsText(0) repnum = arcpy.GetParameterAsText(1) gRows = arcpy.da.SearchCursor(infc, "Shape@") for row in gRows: origpoly = row del gRows aRows = arcpy.da.InsertCursor(infc, "Shape@") for x in xrange(0, int(repnum)): aRows.insertRow(origpoly) del aRows


2

this tool SplitLayerByAttributes already does what you need. and a similar thread on this topic is How can I iterate Selection by Attributes?.


2

Apologies guys, The answer is fairly straight forward. I had not defined the name of the data frame properly in line 30. Where I had stated "layers" I should have put "Land Drainage GIS".


2

You keep on redefining s1 as an empty list for each iteration. Try this instead: s1 = [] for row in rows: s1.append(row.getValue("Count")) print sum(s1) Or: counter = 0 for row in rows: counter += row.getValue("Count") print counter For bonus points, arcpy.da, utilizing a generator expression: print sum(row[0] for row in ...


2

I think it will be more ArcPythonic to use the Select (Analysis) tool in place of MakeFeatureLayer, SelectLayerByAttributes and CopyFeatures. def unique_values(table, field): with arcpy.da.SearchCursor(table, [field]) as cursor: dict = sorted({x[0] for x in cursor}) print type(dict) for i in range(len(dict)): whereD = ...


2

You could still use zonal statistics with the minimum option. It produces a raster would could be used for further processing Zonal Statistics


1

Add a new field (text) In field calculator, round the original Percent value to no decimals, and append a percent sign: format(round(!Percent!)) + "%" or the shorter, more elegant "{}%".format(round(!Percent!)) (Thanks to Paul for the improved syntax!)


1

Related to answer I gave to a similar question (determine min and max elevation ... within my current extent), I wonder if this would work: import arcpy # this sets extent to current display, you can instead set it to ROI polygon arcpy.env.extent = arcpy.mapping.MapDocument.activeView.Extent # for a multi-band raster, pay attention to the band index (last ...


1

The Raster to Other Format tool should do what you need. RasterToOtherFormat_conversion (Input_Rasters, Output_Workspace, {Raster_Format})


1

I've attempted to remove the errors from your code. You had "\\" but you started the string with an r so I think python was actually seeing "\\\\" instead of "\". Also you import a toolbox at the beginning of the script then add another within the loop which has the same name, that makes no sense so I have commented it out. But may be wanted to use that one ...


1

If you are adding additional pages outside of ArcGIS and will be packaging your pages together later, one possible and easy solution would be to add 2 to the PageNumber attribute in your table in ArcGIS. You could easily accomplish this in field calculator with: !YourField! + 2 And then you could add dynamic text from teh data driven pages toolbar >> ...


1

Short answer - No. ArcGIS will pass parameters as as positional arguments. Longer answer - Sort of, if you use a slightly hacky technique of accepting both positional arguments or options in your script, using the parse_known_args method. Something like: import argparse def main(arg1,arg2,arg3): print arg1,arg2,arg3 parser = ...


1

it would be easier to combine with arcpy.da.InsertCursor. Note that in your code the row[1] value is the shape field. EDIT: as you found out, the main problem came from the use of 2 cursors together (and my first suggestion to use an edit session did not solve that). polygons_shape="C:\\temp\\FinalLayers.gdb\\FinalLayers\\Polygons" ...


1

To turn your array into a polyline you need to use arcpy.polyline, but I suspect that what you're really having an issue with is inserting features into a feature class, for this I recommend an insert cursor - they come in two flavors arcpy and arcpy.da. I generally use the arcpy (old method) but am coming to like the arcpy.da method. To use an insert ...


1

here is an alternative to your solution #store field values in a new list newlist=[] with arcpy.da.SearchCursor(fc, ("valueField")) as scursor: for row in scursor: newlist.append(row[0]) #find the boundaries between classes newlist.sort() limits=[0] for j in range(newlist): if (newlist[j+1]-newlist[j])>2.5: ...


1

Cursors can read data from the DBFs and then write that data to a "master" table that holds all the information. Note: This is going to end up making an extremely large table or feature if you have 1000 fields. I'd also suggest testing it with a much smaller subset (e.g., two) of DBF files first, to make sure the script is working correctly for your data. ...


1

So the file names would then be fields in the output table? Seems like you would need to add a field to each table (let's call it "FILE_NAME"), merge all the tables together, then use the ArcGIS PivotTable tool (pivot on the FILE_NAME field). If you have 1000 tables, would you then have 1000+ fields? Not sure if this would be the best table structure... ...


1

After your newest updates to the question, this should work: def change(OldFor_Com, Area_Ha): if OldFor_Com == "OTHH": return Area_Ha / 40.0 elif OldFor_Com == "OHWH": return Area_Ha / 30.0 elif OldFor_Com == "OOFH": return Area_Ha / 375.0 elif OldFor_Com == "OSFH": return Area_Ha / 375.0 elif OldFor_Com ...



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