Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
9

Python is treating \t as tab so you are really doing C{TAB}est you need to escape with \\ or use a raw string using r e.g r'C:\test_script'


8

Try explicitly defining the workspace: import arcpy arcpy.env.workspace = r'C:\path\to\your\ws' rasl = arcpy.ListRasters() The documentation shows that you cannot include the path of your workspace in the ListRaster function: The workspace environment must be set first before using several of the List functions, including ListDatasets, ...


8

You just need to include the root path with the shapefile "file" name. os.walk returns the root and then either the directory or file for every element in each folder - meaning that for each file variable in the loop, the name is only "somefile.shp" without any path information, which arcpy needs to process. So an additional line will get this to work as ...


7

This is because the Layer to KML tool takes either LAYERS (feature layers in a map for example), or LAYER FILES (.lyr files on disk pointing at featureclasses). If you want to run this as a script outside of ArcMap you'll have to run MakeFeatureLayer on every shapefile, turning them into a layer first and pass that onto Layer to KML. This is starter code......


7

So currently you're using the input of your shape file name but not indicating a directory. The full path is needed for the merge to work. Or you can set your environment's workspace each time you find a file. You're also not actually merging anything, since you have only a single input. I'd populate a list of all the matches found, so that you can use it ...


6

From the ArcGIS help: The Raster Calculator tool is intended for use in the ArcGIS Desktop application only as a GP tool dialog box or in ModelBuilder. It is not intended for use in scripting and is not available in the ArcPy Spatial Analyst module. You need to use the Spatial Analyst module map algebra syntax instead.


6

My initial thought is that you must have assigned the variable pente_Rclass to a string representation of a raster instead of a raster object. This would cause your first error. See below: pente_Rclass = "myRasterName" represents a string... if you are using this in arcpy methods, it will automatically assume that this string is the name of a dataset in ...


6

Might as well makes this an answer. The Project method/tool works with vector data only. To reproject a raster, you need to use the Project Raster tool. That is, the ProjectRaster_management method. The help topic for ArcGIS for Desktop 10.2 is here. Here's the arcpy sample from the help: import arcpy from arcpy import env arcpy.ProjectRaster_management("c:...


6

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


5

Setting the output of a geoprocessing tool to an emtpy arcpy.geometry object is not the standard method for using in-memory workspaces. Instead, you want to set the output of the Union to a string variable that references the "file name" of the in-memory feature dataset, almost exactly as if you were using a shapefile. The only difference is that instead of ...


5

You cant create a feature layer on disk, it is stored in memory only. Change: sortedftr = 'C:/Users/srcha/Desktop/Cluster_Analysis/output/Ld_Play_extra_sort_ftr.shp' To: sortedftr = 'sortedftr_lyr' After the selection if you can use Copy features to convert the layer to a shapefile on disk. You dont actually need Select by attributes, this can be done ...


4

It appears the error is encountered on the line for CreateFeatureclass, that the location is bad: C:\Documents and Settings\benoyn\Desktop\DaS GISwork\data_extraction_test\pleasepleaseplease And this should have been a string made of: out_folder_path_gdb + "\" + out_name_gdb Note that the end component of that string should have been a gdb and it appears ...


4

Assuming that your text files are some sort of tables (e.g. CSV having X and Y coordinates in rows with delimited columns), try using 'Iterate Tables' instead of 'Iterate Files'. You will be offered an option of choosing DBF or INFO as the type. Ignore this field. It is optional. You should now be able to connect the output file to the 'Make XY Event ...


4

I haven't had too much trouble using arcpy on linux so far. I installed arcgis into the arc users home (this was the default location, and it was recommended one install as the arc user). As mentioned above in .../arcgis/server/tools you will find a 'python' executable. If you look at that file, you'll see how to run arc's concept of python on linux. To ...


4

There's no "easy" way to do it that I can see unfortunately. I think you've got the right idea with stacking rasters with the correct focal distance and picking the answer. However Spatial Analyst seems a bit slow... I wrote a quick script to test the times taken if I did the processing in scipy.ndimage (version 0.7 to be compatible with arcpy) to compare ...


4

The paths with a single backslash are no valid paths. Use: one forward slash: "c:/test/test.shp" Two backslash: "c:\\test\\test.shp" letter r before a string containing a backslash: r"c:\test\test.shp"


4

An alternative solution may be to use a cursor: arcpy.UpdateCursor - (http://resources.arcgis.com/en/help/main/10.1/index.html#//018v00000064000000) Calculate Field is nice for in-application use (i.e. changing field values in ArcMap/Catalog or model builder, but cursors are much more powerful (and easier to use) when accessing attribute data in code. Try ...


4

It works in the python window because JHJ is likely a layer in the map and therefore can be reference in your script as "JHJ". When run outside of Arcmap, you need to tell arcpy where to look. Here are just a few ways you can do this (untested, but it should give you a few ideas): 1) jhj = arcpy.CreateFeatureclass_management(r"C:\temp\TestArcGis\FraFil","...


4

Try entering your path as a rawstring, such as in this snippet: arcpy.CreateFeatureclass_management(r"C:\test_script\Fish.gdb", ... Basically, just prepend an r.


4

As @MichaelMiles-Stimson has mentioned, you can get around this by removing the space in the group layer name. However as you have mentioned that you have several MXDs and layers already set up, it is a relatively small change to your code (which doesn't seem to touch the space) that will get it working. The fc from inFeatures is passing a string like "'...


4

To expand on @GetSpatial's comment, if your Contacts is a Table and not a Feature Class, you will get the 000732 error Con‌​tacts does not exist or is not supported Failed to execute (MakeFeatureLayer). Try changing the arcpy.MakeFeatureLayer() for a arcpy.MakeTableView() gdb = r"\\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb" arcpy....


4

Your model has a lot of what looks to be LAYER input parameters. Meaning the input to the tools have come from the ToC inside Pro. When you run the model outside of Pro (ie. using python at command line), those layers don't exist. Thats what your error screen shot is saying. I cant find the input data While you aren't really exporting your model to a script,...


3

ArcPy adds single quotes around parameters that contain spaces. You can use filename.strip("'") to get rid of them. This is safe to use even if there are no single quotes in the string: >>> filename1=r"'Z:\DATA FOR 2009\Base.gdb\CREEKS_UTM'" >>> filename2=r"Z:\DATA_FOR_2009\Base.gdb\CREEKS_UTM" >>> print filename1.strip("'") Z:\...


3

The following might help you some: stat = "STATIC_forestland" vict = "mapvictoria20121210" con = 'OutRas = Con("{0}" == 0, -255, Con("{1}" >= 115, -255, Con(("{1}" > 100) & ("{1}" < 115), 100, Con("{1}" <= -15, -255, Con(("{1}" < 0) & ("{1}" > -15), 0, "{1}")))))'.format(stat, vict) arcpy.gp....


3

The following should work - just run each tool interactively to work out the parameter values, then Copy As Python Snippet each result from the Geoprocessing | Results window into a Python script and your done: Buffer Clip Summary Statistics I've modified your code quite a lot below. It is untested but should work as long as your sites.shp has a field ...


3

I would recommend that you copy the geodatabase first arcpy.Copy_management(r"\Servername\Datafolder\Test.gdb", "C:/Test/TestGDB2.gdb") and then upgrade the geodatabase arcpy.UpgradeGDB_management("C:/Test/TestGDB2.gdb", "PREREQUISITE_CHECK", "UPGRADE")


3

Try using ' '.join(parameters[2].values). It will give you space delimited string instead. Alternately, map them to raster objects with value_list = [arcpy.Raster(val) for val in parameters[2].values]


3

I've not used JoinField_management. Every time I want to join I've used AddJoin_management. They appear to do very similar things, so it is possible that the Add Join would work for you. I am thinking that the problem with your script is that the Join data is of type feature class, not that Python has strong types, but both tools specifically call for layer ...


3

The help state, regarding Make Feature Layer, that: the layer that is created by the tool is temporary and will not persist after the session ends Simply change the following variables... Pts_Lyr = scratchWorkspace + "/Pts_Lyr.lyr" Map_Layer = scratchWorkspace + "/Map_Layer.lyr" Prism_Lyr = scratchWorkspace + "/Prism_Lyr.lyr" to... Pts_Lyr = "...


3

The attached (untested) script takes the name of a feature class, splits it by "_" and uses that as a basename for the join operations. The general idea is to use: basename = fc.split("_")[0] which converts, for example, abc_clip_diss to abc Then, you can use that basename to create new variables with os.path.join(): inFeatures = os.path.join(ws, ...


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