Tag Info

Hot answers tagged

5

Here's the ListLayers documentation ListLayers(map_document_or_layer, {wildcard}, {data_frame}) You can use a wildcard if you know the name of the layer. mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] road_layer = arcpy.mapping.ListLayers(mxd, "Road", df)[0] river_layer = arcpy.mapping.ListLayers(mxd, "River", ...


5

I use the following settings to "Start a program" in the task scheduler. I find it best to use the full path to the Python executable to be safe. Program/script: Full path to Python.exe, C:\Python27\ArcGIS10.2\python.exe Arguments: Name of script, script.py Start in: Location of script.py, something like C:\path\to\script Also, if you pass in arguments ...


5

The problem is that your string inputFeature_json has special characters that are not in the ascii encoding. If you have characters that are not in the english alphabet they can cause encoding errors. Try to convert the string as unicode. for example: # Script arguments inputFeatures_json = arcpy.GetParameterAsText(0) #wtite to file jsonFileName = ...


4

that's nearly it, but the referencing of the field should be done on the field list, not the field name fieldList = arcpy.ListFields(r"C:\your.shp") for field in fieldList[19:]: print field.name


3

I think that you will have to keep the polygons as separate features. Polygon multiparts are an evil construct that has no logical topology for analysis and even display in your case. What is wrong with a separate featureclass? If you want to aggregate the properties, then a Dissolve will do this. You could relate the multiple features to the single ...


3

Based on the comment by @KHibma I put together the code snippet below to demonstrate how to "use arcpy.GetMessageCount and arcpy.GetMessage and get [messages] 1 by 1 by index" import arcpy try: arcpy.CreateFolder_management(r"C:\temp1","test") except: pass for idx in range(0,arcpy.GetMessageCount()): print "Message {}: ...


2

You should save the output raster to a raster format, not to a geodatabase, e.g.: outReclass1.save(r"C:\output\reclass.tif") EDIT: And there is a missing bracket in the Reclassify line (RemapRange is enclosed but not Reclassify). I've updated my code as well. You can also simplify the remap parameter a little bit by using the missing_values parameter for ...


2

I have always set up simple batch files like this: start C:\Python27\ArcGIS10.3\python.exe \\some_server\some_script.py You'll just want to make sure the full path to the executable and script match exactly. If the path has any spaces in in it, you'll need to wrap it in double quotes. (" ")


2

First of all you have some errors in your code: inputlayer = fcs have to be changed inputlayer = fc At my mind the syntax is wrong here: os.path.join(*(fcs) + '.lyr') Here is a working example of your code, it takes mxd file and add every feature class from GDB to mxd file and saves it: import arcpy, os arcpy.env.workspace = r"C:\New File ...


2

Yes, you can run multiprocessing child processes from a toolbox script. Below is some code to demonstrate in a Python Toolbox (*.pyt). There are a number of "gotchas". Some (but not all) will be applicable to Python script tools in a binary toolbox (*.tbx), but I only use Python Toolboxes these days so have not tested. Some "gotchas"/tips: Make sure ...


2

As an alternative to pymssql, you might consider using the arcpy.ArcSDESQLExecute class to execute your SQL statements. Something along the lines of (simplest form and untested): import arcpy sde = r"Database Connections\Connection-to-SDE.sde" sde_conn = arcpy.ArcSDESQLExecute(sde) sql = """CREATE TABLE tempIntersect_withNATA (ZIP varchar(max), ...


2

Using field calculator (or, arcpy.management.CalculateField() if you want): In the code block: def fix_matrix(field_value): if field_value.endswith("A") or field_value.endswith("B"): return field_value[:-1]+"AB" else: return field_value In the expression: fix_matrix(!MATRIX!) + !PLANT! + !PCT! + !SITE!


2

>>> outPoly = "C:\output\newpoly.shp" >>> print "'{0}'".format(outPoly) 'C:\output ewpoly.shp' >>> >>> outPoly = r"C:\output\newpoly.shp" >>> print "'{0}'".format(outPoly) 'C:\output\newpoly.shp' >>> This probably explains it best: https://docs.python.org/2.0/ref/strings.html


2

Your example code does not do what your post title asks. You are not attempting to update multiple columns (which are called fields) with a cursor. You are attempting to process through the cursor records (which are called features or rows) more than once with a single cursor. That is not allowed and is never really necessary, since there are better ...


2

names = ['','_A', '_B', '_C'] mxdPath = wrFolder + "/M_" + WorkrequestRaw +"_01" for name in names: mxdOutput = mxdPath + name + '.mxd' if not arcpy.Exists(mxdOutput): pdfversion = name break


1

You need to make sure the pageNum is an integer, and you need to split the input values. For this example, you'll need to enter the pages like 1, 2, 3 with spaces. Give this a try: import arcpy mxd = arcpy.mapping.MapDocument("E:\\User Folders\\Recreation.mxd") ddp = mxd.dataDrivenPages pageNumbers = raw_input("Enter Page/s: ") for pageNum in ...


1

You need to make a list of the jpeg's and the n loop trough them. You can use the glob module for that: import arcpy,os,sys, glob import arcpy.mapping from arcpy import env env.workspace = r"C:\Project\out" listOfJPG = glob.glob( r"C:\Project\out\*.jpg") for jpg in listOfJPG : name = os.path.basename(jpg) + ".tif" ...


1

It is hard to be certain what you are trying to do, and it should be fine to do all of this is a single pass of the update cursor. However, I think you may be wanting to change data on the second pass based on changes made in the first pass so I have structured the code below to do that. Perhaps give it a run and see how it goes. with ...


1

So ESRI has arcpy versions of some common operations from the os module, especially when it comes to listing directories. I have not used arcpy.ListWorkspaces() before, but it seems like it should work for you, and you could add arcpy.ListWorkspaces("*","FileGDB") because you are specifically looking for File Geodatabases. Generally it's good practice to ...


1

The code you posted should not give an indentation error. I recommend that you open a new Python script and copy/paste the code you posted and run that. I will be very surprised if you receive an indentation error by doing that. I suspect that you may have moved the start of the last line left or right in the process of writing your question. W.r.t. ...


1

CopyRows can't output to Excel, it can only output to dBASE, ArcSDE geodatabase, file geodatabase, personal geodatabase or INFO tables. You need to use the TableToExcel_conversion tool. Then you need to use os.path.dirname to get the gdb parent directory. Something like (untested...): import os, arcpy folder = arcpy.GetParameterAsText(0) for dirpath, ...


1

Below your 'CopyRows' command, where you're outputting tables inside the gdb, you need to output essentially to a level 'up', as indicated in your diagram...do this with a simple os.path.dirname(dirpath). (Make sure you've imported the os module.) FYI, to be consistent you should use os.path.join similarly (instead of '+ os.sep +'): os.path.join(dirpath, ...


1

Inside a geodatabase you can only store GeoDatabase types, from Esri Help: A key geodatabase concept is the dataset. It is the primary mechanism used to organize and use geographic information in ArcGIS. The geodatabase contains three primary dataset types: Feature classes Raster datasets Tables So, in a GeoDatabase you can only store Tables, ...


1

Get the list of columns for a table in Oracle using ALL_TAB_COLUMNS from this query using ArcSDESQLExecute... select column_name from all_tab_columns where table_name = 'TABLE_NAME'. The returned list may need to be processed to eliminate unwanted columns.



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