Tag Info

Hot answers tagged

4

I just created a simple Python script tool with no parameters using ArcGIS 10.3 for Desktop by adding the script below to a toolbox. import arcpy fc = r"C:\temp\abc.shp" arcpy.AddMessage(fc + "\n") arcpy.AddMessage(fc) arcpy.AddMessage(fc + "\n") When I ran the tool it produced the expected output below: Start Time: Tue Apr 14 18:20:45 2015 Running ...


4

The Extent object supports a 'disjoint' (i.e. does not intersect) method. Try something like: for mxdname in arcpy.ListFiles('*.mxd'): print mxdname mxd = arcpy.mapping.MapDocument(os.path.join(env.workspace, mxdname)) df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] for lyr in arcpy.mapping.ListLayers(mxd, "" ,df): if ...


4

Use the cursor.updateRow(field) instead of cursor.updateRow([field]). You should supply an object, not the list.


4

There are 3 issues in your code: indentation under the for fc block as @recurvata says useless line after the else output not valid for the CopyFeatures tool. Here is the corrected code: #Loop through shapfiles in folder and reproject for fc in fcList: fcspatialRef = arcpy.Describe(fc).spatialReference.name if fcspatialRef != spatialRef: ...


3

It looks like you're kind of "over-checking" for matching spatial references, and you're if/else is a little off. Try this: # Get the spatial reference spatialRef = arcpy.Describe(template).spatialReference.name #Loop through shapfiles in folder and reproject for fc in fcList: fcspatialRef = arcpy.Describe(fc).spatialReference.name # the ...


3

Yes this behaviour could seem strange but it's perfectly normal. Object Ids are managed by the geodatabase system, which maybe jump from 2 to 400 in case of the first process is still running. If you want ids from 1 to 6 for your features, you have to populate your own field ID than the system field OBJECTID. At the start of your script, get the max value ...


3

Your indentation is incorrect. Your first code sample loops through all fcs, sets the fcspatialRef each time and does nothing else. It then exits the loop, compares the last fcspatialRef to spatialRef and projects or copies the last fc only, then calls arcpy.AddMessage(fc) only if the last fc is copied, not projected. Correct indentation: #Loop through ...


3

i may be way off, but i don't see where the issue is that the script does not actually copy the correct features - it simply doesn't print them to the dialogue as you would expect (?). As others have mentioned - this is difficult to assist as we can't tell if the issue is simply indentation problems. Here's what we could assume the indentation should be: ...


3

If you want to print the number of datasets that have been projected (not those that have just been copied), you should then create a 'count' variable and increment it each time you project a dataset. Be careful with the indentation of your code, the message must be added outside the loop (once, after all datasets have been reviewed). count = 0 #Loop ...


3

You should create a new parameter of the SQL Expression data type and then set the Obtained from option to point to the feature class parameter. This will let user see all the attributes of the feature class he/she has chosen (much like Select By Attribute dialog window). If you don't want to expose the feature classes's attributes, then just create a ...


2

for future seekers: Here's a modified version of the USGS raster split tool script that doesn't require anything above the ArcGIS Basic (ArcView) license level: """ Raster Split Tool 6/16/2011 ArcGIS 10 Script Tool Python 2.6.5 Contact: Douglas A. Olsen Geographer Upper Midwest Environmental Sciences Center U.S. Geological Survey 2630 Fanta Reed Road La ...


2

One way to do this is to create a polygon feature layer of the dataframe extent, then you may select features in your dataframe to see if they intersect the extent polygon. http://anothergisblog.blogspot.com/2011/06/dataframe-object.html mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] layers = ...


2

Since it looks like you are running this in a separate arcpy script (as opposed to inside the Field Calculator), there may not be a need to use Code Blocks. Maybe better to use an UpdateCursor... From what I can tell from the code, you are testing to see if the field you need to fill is either Null or 0, and if it is, fill the field with the value from the ...


2

It looks like you already have the shapefile names being held in your fc variable so I suggest that the simplest thing will be to just use that. arcpy.AddMessage(fc)


2

There's a few problems in your script, but that's ok, you have to start somewhere. Firstly, your teacher is right, desc.extent is an object, from the Dataset properties and you can read more about the Extent Object. You don't just convert it to a string. Secondly, variables are used as such and don't get quoted "inRaster" is a string inRaster but inRaster ...


2

If you do not want the space seperator between the processed fc names than just do not include the '\n' in the add message statement: e.g. if fcspatialRef != spatialRef: arcpy.Project_management(fc, outFolder + "\\" + fc, template) arcpy.AddMessage('Reprojected...{}'.format(fc)) Result looks like: Reprojected...abc.shp Reprojected...xyz.shp ...


2

You haven't queried the raster(s) to get the spatial reference, the spatial_ref variable is still set to the spatial reference of the last feature class. Instead of this: for raster in rasters: arcpy.AddMessage("{0} : {1}".format(raster, spatial_ref.name)) Do this: for raster in rasters: spatial_ref = arcpy.Describe(raster).spatialReference ...


2

This usually works: from arcpy import env env.overwriteOutput = True env.workspace = outFolder raster_obj=FocalStatistics(raster, neighborhood, 'MAXIMUM', "DATA") raster_obj.save("outZ") del raster_obj ExtractValuesToPoints(in_point_features, outFolder+os.sep+"outZ", out_point_features)


2

Since you're using a python addin, you could use the pythonaddins.OpenDialog method. Slightly modified example based on the documentation: This add-in button uses OpenDialog() to select a set of layer files and adds each layer to the selected data frame. import arcpy import pythonaddins class AddLayers(object): def __init__(self): ...


2

You need to remove all of the quotes from your strings. Here is one approach: # 1) Split strings by "&" and 2) remove leading/tailing white space cleaned = [x.strip().replace("\"","") for x in row[1].split("&")] # "Name_From" field cleaned2 = [x.strip().replace("\"","") for x in row[2].split("&")] # "Name_To" field # Continue with script


1

Just try in python in filed calculator as below- "WP_" + str(!OBJECTID!) N.B. The field going to be populated also needs to be string/text


1

If you have a Spatial Analyst license and using rasters an option, you could use the Focal Statistics tool with the Wedge neighborhood. It's probably more appropriate than vectors in your case anyway (overlap of several layers for a suitability analysis).


1

Attached below is a modification of your code that works. Shortly, the problem was the use of outputs names, as follows: # Local variables: Output_Feature_Class = Input_Table Output_Feature_Class__2_ = Output_Feature_Class Output_Feature_Class__3_ = Output_Feature_Class__2_ Output_Feature_Class__4_ = Output_Feature_Class__3_ Output_Feature_Class__5_ = ...


1

I would put all your messages within the condition where the export is taking place. Otherwise, you will get messages of fc names that are not re-projected or error on the projCount value if the condition is false and the variable has not been created yet. for fc in fcList: fcspatialRef = arcpy.Describe(fc).spatialReference.name if fcspatialRef ...


1

I solved it; arcpy.AddMessage(fc) arcpy.Project_management(fc, outFolder + "\\" + fc, template) not arcpy.Project_management(fc, outFolder + "\\" + fc, template) arcpy.AddMessage(fc)


1

Without testing, I think you should change: Ascii_raster=arcpy.ASCIIToRaster_conversion(file,outputraster,dataType) outname=os.path.join(outWorkspace,outputraster) Ascii_raster.save(outname) to: outname=os.path.join(outWorkspace,outputraster) arcpy.ASCIIToRaster_conversion(file,outname,dataType) You are seeing your error in the original code because ...


1

You can create a Python add-in tool that first allows a user to select features (including with a mouse), and then executes a piece of logic on the selection. See the tutorial for an add-in Tool. Any time you create an ArcPy search cursor on a layer, only the selected rows are returned. In combination, you will be able to select features with your mouse, ...


1

Why not just use the Delete Field tool within the Fields toolbox? ArcToolbox --> Data Management Tools --> Fields --> Delete Field Choose your input table/feature class, and select the fields you want to remove. If you want to script it out to delete certain fields every time, it'd be pretty easy. arcpy.DeleteField_management(in_table, ...


1

You can use the name property of the Describe object: arcpy.AddMessage(arcpy.Describe(projectResult).name) >>> abc.shp Or you could aslo use the baseName property, to print the name without the .shp extension: arcpy.AddMessage(arcpy.Describe(projectResult).baseName) >>> abc


1

I'm going to assume that you are using ArcPy from ArcGIS for Desktop to write a Python script tool. To send any messages to the geoprocessing progress dialog you can use arcpy.AddMessage() For example: arcpy.AddMessage("abc.shp") or: fc = "abc.shp" arcpy.AddMessage(fc)



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