New answers tagged

2

I created three sample random point datasets - 10 features, 100k features, 1m features - and tested the following options Copy (arcpy.Copy_management()) Insert Cursor (arcpy.da.InsertCursor()) Feature Class to Feature Class (arcpy.FeatureClassToFeatureClass_conversion()) Copy Features (arcpy.CopyFeatures_management()) Here are the results: Copying 10 ...


1

as @radouxju has said, you can link the different tags together: lblClass.expression = '"{}" + [OBJECTID] + "{}"'.format("<FNT size = '10'><CLR red='255' green='255' blue='255'>","</CLR></FNT>") which should output something like <FNT size = '10'><CLR red='255' green='255' blue='255'>[OBJECTID]</CLR></FNT>


1

you just need to open and close your color tags in the expression lblClass.expression = '"{}" + [OBJECTID] + "{}"'.format("<CLR red = '255' green = '255' blue = '255'><FNT size = '10'>","</FNT></CLR>")


2

As it's not working, take it back a step and print yourlayer2QRY to see what is being passed to your arcpy.MakeFeatureLayer_management() - you'll see it's currently trying to query literally on "ID IN " + ZoneTuple + " AND " + "Labelr="+"'ZoneB'" whereas you want it to query on ID IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) AND Labelr = 'ZoneB' Once you get ...


2

You've got some weird quoting going on. I find it helpful to print out the query being used in cases like this. In your case, the value of layer2QRY is literally: ' "ID IN " + ZoneTuple + " AND " + "Labelr="+"\'ZoneB\'" ' You've used triple quotes, which means everything between them is a string literal. Your first attempt may have been closer to ...


0

I have found the solution. It is a low level problem that I do not understand in full, however just changing the scratch workspace fixes the bug. Perhaps the default scratch workspace has a certain limit that is reached, then it needs to change. Here is a read for more information: https://geonet.esri.com/thread/86027 The code I used is the standard for ...


1

Interface: Script to divide polygon into 2 single part polygons, using field fraction (0..1): ## split polygons import arcpy, traceback, os, sys gr=(math.sqrt(5)-1)/2 try: def showPyMessage(): arcpy.AddMessage(str(time.ctime()) + " - " + message) #golden section to find minimum def gss(a,b,tol): c=b-gr*(b-a) ...


0

Without a more concise code snippet to try and debug I think any answer to your question, as it stands, may be need to be part guesswork. However, I had the same error message today from the same tool and like you I was also using the buildWhereClauseFromList and selectRelatedRecords functions that I found at Efficiently selecting related records using ...


2

As FelixIP pointed out, first I had to add some part of the code, which was missing. Second, there was a mistake with input parameters, but Midavalo sorted it out. At first, I had 3 parameters: Input file as feature class. Input field with original data (field as input, no multivalue, derived from feature class Input field for derived data (field as input, ...


0

I would do an intersection resulting in a new feature class with the overlaps. Then run Select by Location (select with polygon in Qgis) with a search radius of a few meters and select features from your polygons that overlap with the intersections. Then export your selection to a new feature class.


1

All three properties you are working with are Read/Write properties, so to test what is happening and whether things are changing I would focus on just one MXD (and once it's working set it to loop through all your MXDs), and print the fontSize, elementPositionX, elementPositionY before and after each change, to see what it is doing and whether it is ...


3

Your output suggests that your script found a layout element of type text element in each of three maps, and that it moved each of them. When working with layout elements I think you would be wise to give each of them a unique name on their Size & Position tab so that you can use their name property (e.g. elm.name) to access them. I'm not clear from ...


1

You can use Exists (arcpy) to check for duplicates in your geodatabase. For example: import arcpy, os, fnmatch from arcpy import env env.overwriteOutput=True rootDir = "whatever directory" search = "whatever criteria" outGDB = "whatever GDB" shpLst = [] for root, dirs., files in os.walk(rootDir, topdown=True): for filename in fnmatch.filter(files, ...


2

By using os.path.basename(shpLst[0]), you are specifying the first list item in the shpLst list. This will be the same every time. Instead, you need to perform string manipulation with the fc variable. Slicing a basename can be problematic if the number of characters is different for any of the basenames. The os module's split method is what is needed in ...


0

There is a good post on this site with working code on how to do this. Shout out to Emil. The errors you may be dealing with involve whether or not the data is versioned and if you have edit permissions per This Post: If the tables are versioned with the option to move the edits to the base, THEN you do not use startOperation() and stopOperation(). ...


5

You are 99% there. The issue you are having is that the arcpy.getParameterAsText is returning a semi-colon separated string.(e.g. "FCpath1;FCpath2" ) This is not a list (e.g. ['FCpath1','FCpath2'] ) like you had before. Your script is now iterating over the string, passing the first letter instead of the whole path. Based on the error we can see that your ...


3

More logical solution in your case Con(isnull(raw) or (raw<20), 0, formulae) Use symbol from raster calculator for OR, I cannot find one on my phone Formulae is .004*raw-0.08 which is negative at raw < 20


0

Found the answer. The problem is that somehow the dtFrame and layer variables loose their ability to pass any property back to the map if changed once. So after the first time the definition query is changed, any additional tries to change the definition query again will fail to pass the property back to the map. The solution is simply to recall both the ...


1

Remove the line that converts defq to unicode. I do not think it is needed. Also you are changing the definition query on a layer that at the same time is using a cursor based on a different definition query. That will screw up the cursor. Embedded loops almost always cause problems when the same layer is being changed in both loops. Load the ...


0

I think arcpy.da.Editor requires an arcpy environment workspace (arcpy.env.workspace) to be set. This is what I've got in one of my Editing python scripts arcpy.env.workspace = os.path.join(outFolderPath, outName) edit = arcpy.da.Editor(arcpy.env.workspace) edit.startEditing(True, True) edit.startOperation()


1

Looks like you are not referencing the full path to your newly created SDE connection. Try this: edit = arcpy.da.Editor(os.path.join(outFolderPath, outName))


2

Is using direct connect an option? This is preferred as SDE services (Three Tier connections) are depreciated. If must use a three tier connection your SDE administrator will be able to tell you the service name, 5150 and 5151 are the most common ones I have come across (they correspond to the port number).


3

You've got a little tied up constructing your string def label(wah, field): for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == wah: if lyr.supports("LABELCLASSES"): for lblClass in lyr.labelClasses: lblClass.expression = "<FNT size='8'>[{}]</FNT>".format(field) ...


1

The tile layers are image tiles (unless you are pulling from the new Vector Tiles services), so all the data in them is flattened into an image. There would be no way to 'vectorize' them. I think ESRI vector tiles are still in Beta development, and I have no idea whether they are planning to allow you to export them as a map other vector formats (eps or ...


2

I'm not sure where your single quotes came from in the expression. They aren't there in the hard-coded version, and they aren't needed. Change: lblClass.expression = "'["+field+"]'" to: lblClass.expression = "["+field+"]" Or, better yet: lblClass.expression = '[{0}]'.format(field) The string formatting is prettier (especially with longer string ...


2

If it's simply a matter of whether or not your license server is running, you could ping it, parse the response, and then act accordingly. Something like: import subprocess p = subprocess.Popen(["ping", "<lic server>"], stdout=subprocess.PIPE) print p.communicate() ('\r\nPinging <lic server> [184.154.235.5] with 32 bytes of data:\r\nRepl y from ...


5

As mentioned in the documentation, you can refer to other 'types' by using the appropriate ID. This is what you set in the wizard when creating the combo-box, button, etc. and you can change it by editing the config.xml file in the root directory of your addin source. A really simple example that clears a combo-box list when the user presses a button: ...


1

The row object can't be used in the manner that you're attempting: arcpy.FeatureClassToFeatureClass_conversion(row1[1],outSup... Because it's a row and not a feature class, to split your feature class to a single feature per output: desc = arcpy.Describe(catch10) OID_Field = desc.OIDFieldName # the name of the OID field, could be OID, OBJECTID, FID or ...


2

Since your working in arcpy and doing a simple data transfer, use a search cursor to load your Spatial Join count results as the value in a dictionary associated with the FID key and then use and update cursor to read the FID from the current feature being updated and lookup the count from the dictionary to post it. It takes a few more lines of code to set ...


1

Yes you can. You should be able to do this with an update cursor. Something like this would work: # make sure you're in an edit session fields = [blob_field, file_name] #blob field is your blob field and file_name is the file name field with arcpy.da.UpdateCursor(attachments, fields) as rows: for r in rows: # save to jpg on disk for temp ...


0

Found a solution for my problem: When debugging the import of arcpy with stepping in the import process, I found that the import of the Toolboxes of some extensions hanged. In my case, these were the extensions AGD data reviewer and AGD workflow manager. After deinstalling these extensions, arcpy could be imported (e.g. in Idle for Python 2.7.5). These are ...


1

I found that using "isMultipart" returned any features that had more than 1 feature part AND any features that had donut holes. I created this script that will instead loop over the features, check the the number of actual objects, then select all features that have 2 or more geometry objects via SelectLayerByAttribute_management. import arcview, arcpy ...


2

Assuming that you are using the "CURRENT" map I think what you may be missing is: arcpy.RefreshActiveView() at the end of each iteration.


0

The excel parameter's datatype would be 'File', with a filter of "xls;xlsx" as per @crmackey comment. The sheet parameter's datatype would be 'String'. There is no automatic behavior for populating the 'sheets' into a combobox/choice list from the 'File'. This is something you'll need to do yourself. Fortunately this has been done, you could just copy the ...


0

Got it, #Setting map layout mxd = arcpy.mapping.MapDocument(r"CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "")[0] addLayer = arcpy.mapping.Layer(output) arcpy.mapping.AddLayer(df, addLayer, "TOP") #Set symbology lyr = arcpy.mapping.ListLayers(mxd)[0] arcpy.ApplySymbologyFromLayer_management(lyr, dataset) mxd.saveACopy(finalmap) ...


1

Fonts are part of the Windows OS, not specifically ArcMap. In order to add a font to your system, typically you would have a .ttf (TrueType Font, seems to be the most common) or.otf file. To install it, you simply double-click the file and follow the prompts. I think Myriad Pro is bundled with Adobe Reader and the files are located in the Reader install ...


1

Refer to this help page. You are going to need the true type font file for Myriad Pro, a .ttf file. Following those steps will add the font to ArcMap and allow you to use it in your .mxd


3

If I am understanding you right you started out with an NLCD raster and a polygon feature class of your grids. You then converted the raster to polygon within each of your grids cells to yield polygons with the corresponding NLCD land cover class. Spatial Analyst Approach: I would redesign your workflow as follows: Before converting to polygons I recommend ...


0

This from the ESRI Help The second technique is to use the CURRENT keyword as an input parameter to the MapDocument function. This technique only works from within an ArcMap application because the MapDocument object references the map document that is currently loaded into the ArcMap application. Using CURRENT is very helpful when quickly testing and ...


2

Point Distance - arcpy.PointDistance_analysis (in_features, near_features, out_table, {search_radius})


2

First, File Geodatabases (limited) and enterprise geodatabases (full) are the only types of geodatabases that support subqueries like you are doing. See here for examples: http://pro.arcgis.com/en/pro-app/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm You might begin with a more simple query and build up from there. Or try ...


0

To avoid reapeating the ET_GPErase tool you can group all of your inputs and outputs in a list, and then use a loop. Here's how that could be achieved: import arcpy #Set workspace arcpy.env.workspace = "USER_TEMP\\RAY\\test\\" #Erase and Current buffer workspace eraseAndCurrent = [ ["/ADE01_ALL_BUFFERS_05_09_16.shp","/ADE01_ALL_BUFFERS_TEST.shp"], ...


1

I am not sure if you set the arcpy paths correctly, but this is how I did to import arcpy into Spyder. To set the path of arcpy, go to Tools -> PYTHONPATH Manager and add the following paths: C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcToolbox\Scripts C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy C:\Program Files (x86)\ArcGIS\Desktop10.3\bin It ...


4

You're tripping over your own feet here.. All cursors need to be removed or they will lock the data; until you free the cursor you could still go back to it at any stage. In your code you're using a mixture of old and new style cursors, I wouldn't, try to stick to one or the other. They both work but I would use arcpy.da cursors exclusively. Older style ...


1

As alexGIS already said, it would be easiest to create a replica between your SDE database and your local backup fileGDB Make sure that your SDE database is versioned and all feature classes have a GlobalID. If you want to work with a fileGDB check-in/ check-out replicas is the right choise: ...


2

For the old style cursor that you are using I would use this code: import arcpy tabla="C:/Users/jaguero/Desktop/validacion tabla/Valid.gdb/Predios" rows=arcpy.SearchCursor(tabla) for row in rows: if len(row.PRM_IDENTIFICA) != 14: #new code print len(row.PRM_IDENTIFICA) del row,rows However, I strongly recommend using Data Access cursors if ...


0

I have a layer (shapefile) with 37 features in it sitting on the top of my Table of Content. It has text field "NAME". Every odd record populated by 3 characters long string, other records populated by 2 characters long string. I tested if CHAR_LENGTH function is valid one for query definition using this script: mxd = arcpy.mapping.MapDocument("CURRENT") ...


0

I would use a simple if statement to skip values that equal 14. import arcpy tabla="C:/Users/jaguero/Desktop/validacion tabla/Valid.gdb/Predios" rows=arcpy.SearchCursor(tabla) row=rows.next() while row: if len(row.PRM_IDENTIFICA) != 14: #new code print len(row.PRM_IDENTIFICA) row=rows.next()


1

Try putting your number "01" into a second set of quotes "'01'" (double-quote then single-quote or the other way around) arcpy.CalculateField_management("Table1","Field1","'01'","PYTHON","#")


2

Okay, I see two things here. The Make Raster Layer tool makes a temporary layer, not a tangible file, so if you're looking for something that will persist after your ArcMap session is over, you need to take the layer you made and export it out to a raster file with something like the Copy Raster tool. Also, you're iterating through a list, but each time ...



Top 50 recent answers are included