Tag Info

New answers tagged

1

I would use Tabulate Area (Spatial Analyst) rather than Zonal Statistics if you are after proportions. import arcpy from arcpy import env from arcpy.sa import * env.workspace = "C:/sapyexamples/data" TabulateArea("zonedata.shp", "IDStr", "valueraster", "VALUE", "C:/sapyexamples/output/areatable.dbf", 2)


5

I was able to replicate your problem, but found a solution. You have to remove the datasets that are used by Terrain dataset first before you can delete it. A bit weird but that seems the way it must work... So the following code completely removed the FeatureDataset containing the Terrain datasets and the FeatureClass used to construct it. The order that ...


1

Your best bet for this approach would definitely be a cursor. You can create a python tool that takes 2 inputs: Feature class/table in question multi-value parameter for all the fields you are interested in The code to grab all this information is pretty straightforward: import math, itertools, arcpy FC = arcpy.GetParameterAsText(0) fields = ...


3

(I don't have enough rep to comment so I'm answering instead.) @Michalis Avraam This isn't enirely true, a FGDB has 3 types of locks. SR - schema lock RD - read lock ED - edit lock The proposed solution by StacyR will work in all situations except for exclusive edit locks (ED) according to arcgis help documentation. ...


1

for MIN, MAX and MEAN, you can use the summary statistics and compute the global values accross the fields using the field calculator (min is min of min, max is max of max and mean is mean of mean in this case). For the standard deviation, it is a bit more complicated but still possible based on the partitioning of the sum of squares. Var_tot = ...


2

If there is, I do not know it, but if you are using an RDBMS then maybe a view or trigger can be used to maintain a field like that. For a file geodatabase there are some ArcGIS Ideas that, if implemented, would make this easy for you: Add the ability to add dynamic calculated field with formula based on other fields Dynamic Fields for Shape Features and ...


4

It would be better to remove the layer using arcpy.mapping.RemoveLayer. The parameters are the data frame to remove the layer from (possibly a group layer if you are trying to remove from a group) and the layer itself, this alleviates any chance of confusion: def onClick(self): mxd = arcpy.mapping.MapDocument("CURRENT") df = ...


5

The help for this tool does not explicitly state there is a limit but in a project about a year ago I was feeding it folders with many thousands of rasters and the performance was very poor. What I eventually did was SUM the rasters in batches of 100 then SUMMED the batched values. This ran much quicker and was easily implemented with a bit of looping in ...


2

Well, the answer to that really is "It depends". Both options are very viable solutions for your problem and would likely fully be able to meet your needs. However, some things you should consider when making this decision: Model Builder uses the graphic user interface of the geoprocessing tools you are likely already used to using and the parameters in ...


0

My suggestion would be to use the Raster to Polygon (Conversion) tool on each of the two rasters, using non-simplified output. You could then use each of the resulting feature classes to erase the overlap from the original line features calculate the length of the remaining end portions.


2

Use the Copy Rows Tool to save the table view.


1

Presuming that you mean a feature selection (select by location) and not a geoprocessing intersect then I think you want ISpatialFilter. This allows the same actions as SelectLayerByLocation including overlap type options and attribute queries.


6

If memory use is your prime concern, then lots of little (low vertex count) features is probably going to be more to your liking than a few very large (high vertex count) features. But you may find that "too many features" may eventually overwhelm even "too many vertices" for processing speed. If you think about how the algorithms must be structured to ...


6

A Dissolve operation will usually reduce the number of features, arcs and nodes within a layer, particularly for layers with significant lengths of shared boundaries. Since the time spent during a Buffering operation is highly dependent on the number of nodes, pre-processing with Dissolve may significantly reduce the running time (and memory requirements). ...


1

The .loc files generated by an address locator are plain text files. Therefore, you can modify any settings that are specified in the .loc file without the need for an arcpy function. For example, to change the minimum match score from the default to 70%: locator_fn = 'my_address_locator.loc' locator_file = open(locator_fn,'a') # open for appending ...


6

Use arcpy.env.overwriteOutput. arcpy.env.overwriteOutput = True # Execute ZonalStatisticsAsTable outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster, outTable, "NODATA", "MEAN")


5

You can place all the feature classes within a single dataset then use model builder to clip all at once and output to a new dataset:


2

You could try popping from your csvdict list after using a row to rename a raster: for layer in arcpy.mapping.ListLayers(mxd): for i in range(len(csvdict)): if layer.name == csvdict[i][0]: layer.name = csvdict[i][1] csvdict.pop(i) break


0

If your example is typical of what you are trying to select then if you convert your input dataset into a file geodatabase featureclass you could use the sql expression: SUBSTRING( B, 1 , 3) = A This will select rows where the first 3 characters of field B match the entire contents of field A.


5

In you case (only one tool), you can simply right click on the clip tool in your toolbox, and launch it as a "batch". See the ArcGIS help for more details


1

The simplest solution I have found thanks to GISGe's hint is modifying only the updateParameter() method in validationtool class, adding this code. if self.params[0].value: self.params[4].value = "output" This will generate a string with the default workspace with basename, "output". I dont have to modify the python script at all. Thanks to all!!!


6

You can use a simple block of code either directly from Python window in ArcGIS or as a Python script or as a custom script tool. Below is a sample code for a script tool. Just add your vector layers into a map document (.mxd) and specify the clip layer and the output geodatabase. import arcpy arcpy.env.overwriteOutput = True clip_layer = ...


0

If you are trying to match an existing raster in ArcPy you set the extent to that raster and it's also a good idea to set the snapRaster as well: import arcpy InRaster = "c:\\some\\path\\to\\raster.tif" DescObj = arcpy.Describe(InRaster) arcpy.env.extent = DescObj.extent # match the extent of the input raster arcpy.env.snapRaster = InRaster # match the ...


1

I got good debugging ideas which helped me ultimately come up with my solution which ended up being simpler than what I was trying to do. Basically, I let the arcpy UpdateLayer do more of the work of fixing my Display Expression problem. I'm not sure what was the source of my original problem but the following solution did what I wanted: * EDIT Here's my ...


2

You'll need to pass in the value of your group field to the autoIncrement function now, but this would work: import collections recs = collections.defaultdict(int) def autoIncrement(field_value): recs[field_value] += 1 return recs[field_value] So something like this: FeatureClass = "newFC" expCalc = "import collections\n\nrecs = ...


5

Try adjusting your code, your /n should be \n: arcpy.CalculateField_management("path/to/my/layer","field","RemoveBad( !field!)","PYTHON_9.3","def RemoveBad(x):\n x = x.replace(\"<=\", \" Less Than or Equal To \" )\n x = x.replace(\">=\", \" Greater Than or Equal To \")\n x = x.replace(\"<\", \" Less Than \")\n x = x.replace(\">\", \" ...


1

if a feature class has a geographic coordinate system AND the buffer is performed with a linear unit (e.g arcpy.Buffer_analysis(input, output, "100 Feet"), ArcGIS will automatically use geodesic distance, which is great. Just make sure that you specify the unit


1

You can define the origin as the Xmin, Ymin (or Left & Bottom) of the extent environment setting. Click the Environment button at the bottom of the tool's interface, click Processing Extent and fill in the extent properties. You have to indicate Xmax & Ymax (Right, Top) as well:


1

The error you are receiving looks it can be avoided by adding the Build Raster Attribute Table (Data Management) tool to your script prior to using the CostPath tool because it: Adds a raster attribute table to a raster dataset or updates an existing one. As an aside your code looks like it has been created by exporting a model to a Python script. ...


1

It had to do with ArcFM, which I had a feeling was the problem. The script needs to checkout a license. They have a sample script available: How-To - Work with ArcFM features in Python Solution As when working with ArcFM features in VBA, ArcGIS for Desktop, or anywhere else, an ArcFM license is required to edit the features...


0

I think I've run into the same problem and discovered the reason why your field "Shape" was not being removed. When using this loop: if field.name in (['OBJECTID', 'Shape', 'Shape_Length']): fields.remove(field) I have discovered it is actually only removing every other field. So it will first loop through, remove 'OBJECTID', and then the 'Shape' ...


3

per comments - it seems the raster band properties contain a read-only no data property. import arcpy desc=arcpy.Describe('rasterName') print desc.noDataValue resulted in a value of -3.40282346639e+38 on a single bad ESRI binary grid that i had lying around. thanks!


5

Your code fails because the variable name (pocidCnt) is inside a string and is therefore being taken literally: the final query being used is "pocid" = pocidCnt, where pocidCnt is clearly not a number that can be matched. You can substitute the value represented by the pocidCnt variable into the query string in the following ways: cursor = ...


4

I found the solution on an ESRI blog. The idea is to convert the raster to a raster object and then access the specific NoData value with .noDataValue. import arcpy arcpy.env.workspace = r'C:\temp' rasterList = arcpy.ListRasters() for raster in rasterList: rasterObj = arcpy.Raster(raster) noData = rasterObj.noDataValue print "NoData Value: ...


2

Here is my part of the code : #I have a dictionary field name and domain name self.domainName = {'Inspection_Type' : 'VM_SourceType', 'Clearance_From_Conductor' : 'VM_Clearance' , 'Clearance_Category' : 'VM_ClearanceClass' , 'Outside_Clearance' : 'VM_OutClearance' , ...


4

To do this I would use the Summary Statistics (Analysis) tool and this statistic type on ObjectID: MAX—Finds the largest value for all records of the specified field. Then if you want to read the MAX (highest) value you can use a search cursor on its output table to open and read the one record therein.


1

To debug this I recommend that you change: for df in dflist: if df.scale <= 126720: for lyr in (arcpy.mapping.ListLayers(mxd, "", df)): if lyr.supports("DEFINITIONQUERY"): to: for df in dflist: if df.scale <= 126720: for lyr in (arcpy.mapping.ListLayers(mxd, "", df)): print df.name + ": " + lyr.name if ...


0

For this to work, the variables p and etp must have the complete path, since the rasters they reference are located in separate directories. So changing this: outRaster = Raster(p) - Raster(etp) To this: outRaster = Raster(path +"\\"+ folders[0] + "\\" + p) - Raster(path +"\\"+ folders[1] + "\\" + petp) ...would seem to be a quick band aid. You might ...


1

I would generate a list from the rt_long_nm field with a list comprehension and use that for the logic check. The list comprehension searches for all values except for None and adds those to a list. If the length of the list equals 0, perform some action, else perform another action. import arcpy OutShapesFCname = r'C:\path\to\fc' vals = [row[0] for row ...


3

I would use a search cursor to find out if there are any rows in a table with empty string (i.e., ""). fc = r"C:\ArcGIS\Default.gdb\Parcels" with arcpy.da.SearchCursor(fc,"RouteName") as scur: for field in scur: if field[0] == "": #dissolve on one field else: #dissolve on another field


0

You can also use arcpy.env.scratchWorkspace as it returns: "e:\arcgisserver\directories\arcgisjobs\analysis\your_program\j83b20a86cc2d471cb684b4ce0aa9b81b\scratch" To isolate the job id from the string: job_id = arcpy.env.scratchWorkspace.rsplit("\\", 2)[1] >>>"j83b20a86cc2d471cb684b4ce0aa9b81b"


2

To copy shapefiles from multiple folders into a single geodatabase, you could do this: import arcpy import os ws = #path to input folder dst = #path to output geodatabase for dirpath, dirnames, filenames in arcpy.da.Walk(ws,datatype="FeatureClass"): for file in filenames: print file filepath = os.path.join(dirpath,file) outpath = ...


1

You should use arcpy.Describe() and/or the os.path Python module. For example: import arcpy, os input = arcpy.GetParameterAsText(0) output_workspace = arcpy.Describe(input).path # the file path, or geodatabase for geodatabase datasets suffix = 1 output_name = arcpy.Describe(input).baseName + "_" + suffix # the file base name + a suffix ...


1

Not sure what you mean. The only options are to "derive" a parameter, ie. when you select a featureclass as a first parameter, one of the derived parameters could be a list of fields for the second input parameter. Alternately, you can provide defaults for any parameter so that when a tool is opened, it will appear as the default option.


2

Sounds like you're looking for the valueField property in the UniqueValuesSymbology class: http://resources.arcgis.com/en/help/main/10.1/index.html#/UniqueValuesSymbology/00s30000005s000000/


0

I have used Rename Master a lot for similar sounding tasks with much success.


0

The other way to get FME to use a different interpreter is under Tools > Options > Runtime in the Workbench menu:


1

If you want to use the ArcGIS Data Reviewer with ArcPy then the GIS & Python blog seems to be a fan and offers some starting code: Data Reviewer for ArcGIS Desktop is a pretty neat tool, especially when errors need to go through a system of correction and validation. A common workflow is to create standalone or batch checks and write the ...


0

If I understand your question correctly, the following workflow could be an alternative. Create sets of non-overlapping polygon either by code (see this discussion) or manually (run 'zonal statistics as table', identify the zones that have not been calculated and separate them into a new layer. Repeat with the separated layer to find more potential ...


1

Are these polygons features (it appears they are)? Is there a unique field of type "Text" (something other than FID)? If so, you could also just use the Split_Analysis tool, and use the featureclass as both the input features and split features, the "Text" field as the split field, and then define your target workspace.



Top 50 recent answers are included