New answers tagged

0

I have created a toolbar with tools that do the split of the road and ranges, both using the traditional split (one road at a time) and a Planarize split (many intersecting roads selected at one time split where they intersect each other). I just warn the user if they did not select a feature. I won't build a tool that pauses for a user to select a line ...


0

Your output needs to be either a shapefile or a geodatabase feature class. Currently you aren't outputting either: C:\Code\Module6\Bufferroads does not exist If this were a shapefile the output would be C:\Code\Module6\Bufferroads.shp, and if it were a geodatabase feature class the output would be something like C:\Code\Module6\output.gdb\Bufferroads ...


0

If you're looking for the length of a field, you can use arcpy.ListFields which returns a list of field objects that contain information about the field (List Fields: http://pro.arcgis.com/en/pro-app/arcpy/functions/listfields.htm , Field Objects: http://pro.arcgis.com/en/pro-app/arcpy/classes/field.htm ). field_info = arcpy.ListFields(data) for field in ...


0

The function you're using to auto increment IDs is meant for use in the field calculator; in the field calculator you have to define the global variable to be used by other rows in the table, otherwise all your values would be 1. For your purposes, you necessarily need to define rec as a global variable, and you don't need to create a function to add 1 (...


0

As pointed out by @Ali here, while self.Destory() does not work, the issue can be solved by making sure that a new instance of self.Dialog is created each time the tool is run. The following if/then statement causes the creation of the dialog to be bypassed if it already exists: if self.dlg is None: self.dlg = TestDialog() else: self.dlg.Show(...


0

I think you are correct regarding the script only changing the UI. This is because the dlg attribute of your ToolClass2 is always pointing to the same instance of the TestDialog UI class. When you first run the tool, the TestDialog instance is created and your Add-in works as intended. Next time, since self.dlg is not None, your else clause just shows the ...


0

Dear dof1985 thanks for your comment I did it by the following code : import arcpy from arcpy import env from arcpy.sa import * import arcpy, os import arcpy.da env.workspace = "E:/spring/cases/main/9_jan_2016/New Folder/output" output1=r"E:\main\9_jan_2016\New Folder" output=r"E:\main\9_jan_2016\New Folder\output\test" output2=r"E:\main\9_jan_2016\...


0

Using it as-is (other than a different path to GDB) I had no issues running your code. import arcpy as arc #arc.env.workspace = r"I:\\folder\\FGDB.gdb\\" arc.env.workspace = r"D:\\temp\\SE\\Time.gdb\\" for fc in arc.ListFeatureClasses(): #outfc = "I:\\folder\\FGDB.gdb\\" outfc = "D:\\temp\\SE\\Time.gdb\\" arc.ConvertTimeField_management(fc,"...


0

First I would suggest looking at Arcpy.GetMessages() to see if there are some more helpful error messages that arcpy is giving that you aren't seeing. One big problem that I've run into with MosaictoNewRaster_management is it failing when I am trying to merge too many rasters together which ends in failure when the resulting raster would be too large for ...


0

Try adding a few print statements to verify your values while testing. Something like for row in cursor: print "dmready = '{}'".format(row[0]) print "total_records = '{}'".format(row[1]) print "dm_stat = '{}'".format(row[2]) if row[0] == row[1] and row[2] == "Ready for DM": row[3] = "Y" cursor.updateRow(row) else: ...


0

This is what I want to do that the residential values is the user input , so I can not write '"Fieldname" in ("value1","value2","value3")'


0

First of all: write a line before select_analysis: print where Just to view what "where clause" returns. Than try to convert it in specific expressions: For example: If your feature class "inputLandUseParcels_FeatureClass" is shapefile, than "where" should be: '"Fieldname" in ("value1","value2","value3")' if the input feature is inside ".gdb" or ".mdb" ...


0

Taking your code you need to wrap it up in a loop. The code below assumes you have an ID starting from 1 going to 100. mxd = arcpy.mapping.MapDocument("CURRENT") for x in range(1,101): arcpy.SelectLayerByAttribute_management("sites","NEW_SELECTION",' "Id = ' + str(x)) df = arcpy.mapping.ListDataFrames(mxd)[0] df.zoomToSelectedFeatures() df.scale=...


1

In the result the expression it has returned two single quotes, it should be or with one single quote or with double quote. I suggest to try it: where = "{} in ({})"....... Also do not forget if the source is .gdb Expression should be: **Fieldname = 'value'** if the source is .mdb: Expression is: **[Fieldname] = value** And if it is shapefile: ...


2

I didn't find a pre-built tool to do this, but ended up using the following code which was easy enough to then query the dictionary to pass to arcpy.ChangePrivileges_management() import arcpy def retrieve_permissions(db, fc): sdeDBConn = arcpy.ArcSDESQLExecute(db) permissionsQuery = """SELECT permission_name, state, pr.name FROM sys....


1

As per my comment, why not just use a combobox for the layer list within the AddIn itself? Here is an example of how I have done this before in a Python AddIn: class LayerList(object): """Implementation for ClipAndShip_addin.combobox (ComboBox)""" def __init__(self): self.items = [] self.editable = True self.enabled = True ...


2

This field calculator expression took 0.65 seconds to populate new field by 1 - first occurrence or 2 - twin in 10000 large table. aDict={} def FirstOrNot(a,b): key=tuple(set([a,b])) if key in aDict: return 2 aDict[key]=0 return 1 --------------------------- FirstOrNot(!FID!, !NEAR_FID! ) This is a very big zoom: Points symbolised by this ...


5

You can set the spatial reference of the data frame object in Python. mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] df.spatialReference = 31982 # SIRGAS_2000_UTM_Zone_22S However, I think it will be much more efficient to leave the data frame as is and just project the point geometry on the fly. sr = arcpy....


1

The Add Geometry Attributes tool will allow you to perform many of the functions found in the Calculate Geometry tool from within a model or Python script.


2

Use the field calculator. If you have a field (like start_x), use the field calculator with the expression !SHAPE!.firstPoint.X, and for a field like end_x you would use !SHAPE!.lastPoint.X. for your Y coordinates, you would use !SHAPE!.firstPoint.Y and !SHAPE!.lastPoint.Y Check out the arcpy geometry documentation(http://desktop.arcgis.com/en/arcmap/10.3/...


1

I do this all the time. In my particular case I maintain a one-off database that needs to be synchronized with the actively maintained data, but it cannot be overwritten by the original database, since I maintain additional fields in my copy that are not in the original. The fastest approach for this scenario requires the use of dictionaries and cursors. ...


0

The following possible solution is merely a reflex-reaction to the situation described in your question. I am concerned that this solution combined with the amount of records involved will present an issue in terms of the amount of computation necessary to complete the task. The following would essentially pass through your large table (500K records), and ...


2

I think the most inefficient part of your code is Select by Attribute part which requires relatively high overhead to add marked item to your current selection. First create a new SHORT field in your table to mark the desired pairs. And then I suggest you to first create a Python set with row[0] and row[1] as converted to string and with a delimiter first, ...


-2

Have you tried: try: from osgeo import ogr except ImportError: import ogr


2

If the first run works but the second run fails, the first thing to check would be to make sure you're not trying to create a new dataset where one already exists. Also, you've defined output_location at the top of the script but aren't using it anywhere. Perhaps you need to change the output_features assignment in your loop? output_features = os.path....


1

Locate your shapefile. The error message says it's in: "D:\CLASSES\Debugging_andErrorHandlingLab\Data\TravisCountyAustinTxx.mxd\parks.shp" The .MXD can't be a folder, so it's definitely not there. Perhaps it's in the same folder as the MXD: dataset = r"D:\CLASSES\Debugging_andErrorHandlingLab\Data\parks.shp"


0

For cleaning up building footprints from lidar, please check out the ArcGIS Regularize Building Footprint Tool. Another new tool in ArcGIS Pro 1.3 is the Classify LAS Building.


1

LOTS OF ERRORS were fixed --.spatialRefernce (no good) .extent(no good), lyrlist, had too many arguments--FIXED import arcpy mxd = r"D:\CLASSES\Debugging_andErrorHandlingLab\Data\TravisCountyAustinTxx.mxd" mapdoc = arcpy.mapping.MapDocument(mxd) dataset = r"D:\CLASSES\Debugging_andErrorHandlingLab\Data\TravisCountyAustinTxx.mxd" spatialref = arcpy....


0

If you installed Arc before Anaconda, your default IDLE, Python Window (in Arc), and Python console will always pull from your Arc-installed modules, i.e. C:\Python27\ArcGIS <version>\Lib (and/or) Lib\site-packages. If you have packages installed with Anaconda that you want to use with Arc's install of Python you'll need to write .pth files in order to ...


-1

This tutorial shows you how to set up conda environment to work with ArcGIS 10.4 and ArcGIS Pro 1.3. Workflow to set up Anaconda with ArcGIS 10.4 Install Anaconda without fouling the Windows environment (paths, registry) to break Esri's python stack Configure Anaconda with the particular add-ons you want, and Configure ArcGIS's Python so that ...


2

To dissolve down to Single-Part features your input features need to intersect (touching edges or overlapping), even when dissolving on an attribute. If the features don't intersect at all then the output will be the same as the input. If your features do not intersect you will need to set your dissolve to output Multi-Part features. This will dissolve ...


0

As commented by @Vince: Even though it is not mentioned in the body, and no version of ArcGIS is specified, the question is tagged ArcPy. Since multiple distances are needed, a command like Near would be more appropriate.


0

I figured it out. The first mistake I made was appending the newList to a self.items in the setVersion object. That just adds the entire list in as one item. Instead do this: self.items = button2.nameList The other mistake I made was trying to get items to update in the onSelChange function. The list needs to be updated in a different function. I don't ...


3

I'm thinking this code is almost there, and the only problem might be the one you have have already identified as the source of the does not support item assignment error. While the item-wise assignment strategy is fancy and rather cool, if I were in a similar situation I would sort of simplify or dumb-down the code surrounding the error. Hopefully the ...


3

To update the labels, you'll need to update them all at once by providing a list to lyr.symbology.classLabels. if lyr.symbologyType == "UNIQUE_VALUES": vals = lyr.symbology.classLabels newLabels = [] for v in vals: if v == "a": v = 'landUse' newLabels.append(v) # push each label into the list lyr.symbology....


0

If you're able to execute import arcpy in under 4 seconds, the DLL files are already cached in memory, and that's as fast as you can hope to achieve. It's a very large library, and it takes Python a while to read and register. The best way to reduce repeat import cost is to not exit().


4

Found it - I was using incorrect terminology in my searches. There is a tool called Test Schema Lock which will return True or False based on whether a lock can be applied or not. So my code would be: if not arcpy.TestSchemaLock(myFC): print "Can't proceed - feature class is locked" else: arcpy.Delete_management(myFC) Because it returns True if ...


0

Open ArcGIS (author says it requires Arc 10.1). On the Standard Toolbar, select/click on the ArcToolbox button (ArcToolbox icon has little red toolbox on it). When the ArcToolbox Dialog window opens, right-click in it and select "Add Toolbox". Browse to where you extracted the Sinuosity.pyt file, click "Open". This adds the toolbox to your ArcGIS ...


1

I have never used the tool you downlaoded, but you can use the following calculation to calculate sinuosity. Open the Attribute Table of the Road feature class, right click the column heading of the Double field you want to hold the Sinuosity value and choose Field Calculator... from the context menu: Select the Python option at the top of the Field ...


3

All search cursors must be loaded to dictinaries. This will dramatically improve your performance. I never ever embed cursors now and never will again. The look up of a dictionary is immediate without looping and all you have to do is check for the common key value. All fields outside the key can be loaded into a list (or list of lists) in the ...


0

This is what I ended up using and it worked out: inFeature = outFeature my_list = ['a', 'b', 'c', 'Shape_Area'] divfield = len(my_list) - 1 with arcpy.da.UpdateCursor(inFeature, my_list) as cursor: for row in cursor: for n in range(len(my_list)): row[n] = row[n] / row[divfield] cursor.updateRow(row)


1

List indices must be integers, not strings. Where you use row[divfield] you are trying to use "Shape_Area" (the value of divfield), which is a string, as a list index. You have opened your cursor with three fields 'a', 'b' and 'c' which you can refer to the values of using row[0], row[1] and row[2] respectively.


3

You can do it like this: # I'm assuming cat is the full path to a raster # or a raster object TempDir = os.environ.get("TEMP") # Your temp folder ColFile = os.path.join(TempDir,"TEMP_CLR_FILE.clr") with open(ColFile,'w') as ColWrite: ColWrite.write("1 255 0 0\n") # 1 = red ColWrite.write("2 0 0 255\n") # 2 = blue arcpy.AddColormap_management(cat,...


3

I'd say that it's exporting but to the same directory and then overwriting or tripping up on the first iteration of listdir.. best to do all of it in one pass of listdir: import arcpy, os arcpy.CheckOutExtension('Spatial') arcpy.env.overwriteOutput = True arcpy.env.qualifiedFieldNames = False folders=r'E:\Sheyenne\Landsat_8\spatial' out=r'E:\Sheyenne\...


0

The Where Clause in the cursor will be case sensitive (see Building a query expression) so you'll need to allow for that. Try this: countyname = "ADAMS" where_clause = """UPPER(COUNTY) = '{}'""".format(countyname) print where_clause with arcpy.da.UpdateCursor(COpath, fieldlist, where_clause) as countycursor: for row in countycursor: print row[...


0

I don't know of any other way to do this unless you could access the image's EXIF data. Test "datetime" or "datetimeoriginal" and check the month the image was taken. The Python image library (PIL) module can do this like below. import arcpy, os, glob, re from arcpy import env from arcpy.sa import * from PIL import Image arcpy.env.overwriteOutput = True ...


0

So it looks like the lock on the mxd was causing the problem. If anyone else runs into the same issue, just reassign the mxd above the DDP refresh command and everything is happy. arcpy.SpatialJoin_analysis(target_features=selected_URD, join_features=selected_ugcable, out_feature_class=URD_CABLE, join_operation="JOIN_ONE_TO_ONE", join_type="KEEP_ALL", ...


1

Now I have a solution to my own question. I have used arcpy.ListRaters() function to identify correct GRID raster. I would like to share my solution as follows: import os import arcpy path = r"F:\Geodaten" for root, dirs, files in os.walk(path): #accessing files........................... for fileName in files: basename, extension = os.path....


1

While I believe the error is correct and you shouldn't be able to enable archiving on an individual Feature Class (FC) within a Feature Dataset (FD), you can get around this in three ways (that I've tested so far). I'll outline what should be happening, and also what I found in my testing. Everything in a FD is done as a group (the entire dataset) - ...


1

You can use enumerate with for loop to count the number of rasters inside a workspace and in the same time get the raster bands as objects. enumerate by default starts with 0, but you need to start with 1, so you have to write enumerate(rasterlist, start=1). Then you can use Spatial Analysts -> Times function to multiply each band with 2. The variable ...



Top 50 recent answers are included