Tag Info

New answers tagged

0

I can't speak to the intricacies of memory management but I can show you a couple examples that suggest it is more efficient. First lets compare the spatial analyst (SA) method to the 3d method that more resembles model builder (for this example I created a small constant integer raster "raster 1" and used a constant constant2 = 10, there is a lot of ...


2

The arcpy.gp.Plus_sa() is probably an older method of doing the same thing. I would go with the ESRI help version because it is Actually Documented and probably won't be dropped from support as quickly.


0

The TypeError: GPToolDialog() takes at most 1 argument (2 given) error was caused by an error in the toolName value, this is not the name as it appears in the tool box, it must be set in the Model Properties.


2

You need to filter away those map documents which contain "land use" in their names. It is better to test and if the evaluation gave us "false", proceed with the processing. env.workspace = r"C:\Project" Layer1 = arcpy.mapping.Layer("abc.lyr") for mxd in arcpy.ListFiles("*.mxd"): if 'land use' not in mxd: print mxd mapdoc = ...


1

Having looked at your code where is row[] being created, I guess we are not seeing the full picture? I've seen this "GPL0" error before. It's indicating that the first parameter is invalid. If you look at the syntax section of the help for this tool it states the input features are of Data Type FeatureLayer. As we are not seeing the full code we have no ...


1

Here is one approach that performs the following actions: Create a new .mdb with old FGDB name, but in new workspace Find all FC's in FGDB--take into account empty FDS's Copy all FC's to .mdb import arcpy, os arcpy.env.workspace = r'C:\temp\inws' inws = arcpy.env.workspace outws = r'C:\temp\outws' fgdb = arcpy.ListWorkspaces(workspace_type = ...


0

Another user asked a similar question on github, which might be of interest to you. Here's the gist of what one user recommended to import arcpy autocompletion data for anaconda: DamnWidget commented on Feb 26 https://github.com/DamnWidget/anaconda/issues/284 Open a PowerShell or CMD.exe and go to your anaconda installation under the Packages folder ...


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


4

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


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


0

The easiest way to do this without demystifying feature layers was to create another feature class and use the where clause there then proceed with the magic of search cursors etc. SCDE5556= "feature1" SOSC = "feature2" Clause1= "PlannedDate = CONVERT(DATE, GETDATE()) AND RESOLUTION_CODE IN ( '55', '56')" Clause2= "NUMBERCYLA > 'SR07885524' AND ...


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

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

Ok, the first error is easy to avoid. It's failing because you are trying to find the datasource of a group layer, and group layers don't have data sources. Filter the group layers out by doing this: for lyr in arcpy.mapping.ListLayers(mxd, "" ,df): if not lyr.supports("DATASOURCE"): continue #further code here for non-group layers ...


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


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)


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


0

If you don't have available license and you want to import related library (e.g if you don't have editor license but you want to import arceditor), you will get this error. I think it is a bug, so what we did is use try-catch to catch this error.


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

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


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


0

Looking at your python version, it appears you are not setting the length of the text fields when you add them, you must do this, it is not optional for a text field. This would explain why the assign default would fail.


1

The function below is based on Ryan's idea, but is a little more direct. ArcGIS map documents are actually OLE documents, which can be parsed with the oletools module (available on pypi: https://pypi.python.org/pypi/oletools). The function opens the file and reads the version string. Tested with 9.0, 9.3, 10.1 and 10.3, but should work with anything (not ...


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


0

It looks like you have a string with three variables that you are trying to send to the progress dialog of the Geoprocessing framework. I've made what I think are the variables show up bold below. 4 datasets have been reprojected to: WGS Web Mercator (auxiliary sphere) and saved in S:\GisData I suggest that you use a Python variable to count how many ...


0

The arcpy.AddMessage is bread and butter for adding your own messages in ArcToolbox Scripts tools. Also you can get the geoprocessing messages with arcpy.GetMessage/s. These are very powerful when used in: if else and try statements. Adding A Script Tool import arcpy import os arcpy.AddMessage(" ") ...


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


0

In your code where you have used a read-only search cursor: with arcpy.da.SearcCursor(fc, fields) as cursor: you need to use a read-write update cursor: with arcpy.da.UpdateCursor(fc, fields) as cursor: You will also need to use arcpy.ListFields() to produce Python lists of the fields in your feature class and table.


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


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


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


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


0

using; arcpy.AddMessage("\n") At start of my script got the line space I needed.


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


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


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


0

Ok, so after many trials and tribulations, I have wrangled arcpy into submitting to multiprocessing for running the Solar Analyst tool. Behold: import multiprocessing import time import arcpy import os import shutil def final(x): # Check out any necessary licenses arcpy.CheckOutExtension("Spatial") arcpy.env.overwriteOutput = True ...


0

What you want to do is make use of Iterate Feature Classes. That way you'll only need to have the entire model up there once. Just have the user put the Feature Classes they want to work on in the same folder or GDB, then feed that into the model. At the end of it you have two options: Use Collect Values, then feed that into the Merge. Create an empty ...


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)


0

In fact there are two (may be more) ways to do this- Using arcpy completely using arcpy and builtin library These are illustrated below Suppose I have three folder input, output and template Method One import arcpy arcpy.env.workspace = r"C:\Users\Winrock\Desktop\gstack\Project\input" fcs = arcpy.ListFeatureClasses() outputFolder = ...


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)


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


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

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



Top 50 recent answers are included