Tag Info

Hot answers tagged

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)


4

Yep, this is a pretty straightforward script. import arcpy, os folder = "" arcpy.env.workspace = folder num = 50 for shp in arcpy.ListFeatureClasses(): count = int(arpcy.GetCount_management(shp)[0]) if count >= num base, ext = os.path.splitext(shp) #Append _ and the number of features in the shapefile to filename ...


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

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

It appears that you have a few typos: The most pythonic way to add the name of the shapefile without the extension is to split the extension from the base name, via the os module. You don't need to cast shp to a string since it already is a string. appendExpression = os.path.splitext(shp)[0] arcpy.CalculateField_management(AT, "ProjName",appendExpression, ...


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 ...


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() ...


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

Use Get Raster Properties, specifically the MINIMUM and MAXIMUM values. In theory, this code should make a temporary raster layer using the display extent -- although I have not tested it, and am not sure whether it will work -- and then the raster properties tool will apply to only the raster currently shown in the display. import arcpy arcpy.env.extent ...


2

This look like there is a null geometry somewhere. To solve this, you should first run the "repair" tool. To avoid you code to crash (as you said that it works for the first polygons), you can add some testing if point: print ("{0}, {1}".format(point.X,point.Y)) else: print "No point"


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

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

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


2

Using IDLE, I ran your test using ArcGIS 10.2.2 for Desktop, immediately after a reboot (by coincidence) so there should be nothing laying around from previous tests. The code is identical to the third example at Writing Geometries, and I agree with you that the point does not get written. I believe that part of the documentation is in error and that ...


2

PyScripter is somewhat lax with object lifetimes and will keep stuff around after it's run. Use the with statement to ensure you close the edit session. import arcpy fc = r"C:\Users\djh\Desktop\topo_map\test.gdb\well_location" xy = (206901.75, 5997594.47) with arcpy.da.InsertCursor(fc, ["SHAPE@XY"]) as cursor: cursor.insertRow([xy])


2

You need to pass in the full file path name to the arcpy.Describe method. It looks like you are only passing in the layer name and without knowing where to go to look for the layer, it can't find it and is telling you that it doesn't exist. When using the python window, it knows the workspace in which to look. When using a script you either need to set the ...


2

I believe there is no out of the box solution, try this (not for use in ArcCatalog): create raster with extent and cell size of interest set environment spatial extent to this raster set raster storage cell size to this raster cell size use this raster as 1st parameter in script inputs (see below) import arcpy, numpy from arcpy import env ...


1

I am confident that an uninstall/reinstall of ArcGIS for Desktop with Python will at least get IDLE working again. Although there may be ways to avoid doing this, employing them successfully will depend on your skillset and experience, and for me, I would find an uninstall/reinstall to be the expedient.


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

Buffer the points by 10 metres and then ERASE


1

I do it this way by creating an Array of Point objects that form a line that closes back on itself, and then creating a Polygon object from that Array: # feature_info eventually takes the following form: [[734855.5142000001, 4744379.424500001], [740607.6685000001, 4744379.424500001], [740607.6685000001, 4736862.1753], [734855.5142000001, 4736862.1753]] ...


1

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


1

I suspect the issue is the GDAL 1.11 bindings you're fetching from gohlke do not match the internal GDAL inside of Arc*. Your bindings need to be compiled against ESRI's GDAL to work reliably. It's possible they can be made to work, but it is going to be a lot of headache. In short, ESRI needs to provide the gdal_i.lib stub file that GDAL generates as part ...


1

Try using this, http://resources.arcgis.com/en/help/main/10.1/index.html#//0017000000m3000000 Turn the current data frame extent to a polygon via this extent = inFeature.extent extentPoly = drive + "\\NCT_GIS\\Projects\\Temp\\extentPoly.shp" # Array to hold points array = arcpy.Array() # Create the bounding box ...


1

`tableList05' - assuming it isn't empty - contains a list of the filenames only. No path names You need to set the workspace so Python knows where these tables are located: Option 1: arcpy.env.workspace = "<folder>" Option 2: #The variable now contains absolute paths to the tables. from os.path import join tableList05 = [join("<folder>", ...


1

Sometines it helps to work with a layer instead of directly on the data.You should try to creatre such a layer before you run the tools (with arcpy.MakeFeatureLayer_management), then you delete this layer (with arcpy.Delete_management, deleting the layer, not the feature class, of course) It can also help to avoid multipart features using the ...


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" ...



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