Hot answers tagged

7

Try placing the wellCntList list outside of the for loop. Otherwise, each iteration is writing over the results of the previous one--ultimately leaving only the last iteration's results. wellCntList = [] for cname in countyList: whereclause = "{} = '{}'".format("COUNTY", cname) wellCnt = 0 with arcpy.da.SearchCursor(Wells_Intersect_Layer, ...


7

The output you are receiving is correct. Assuming you have two polygons, one without a hole, and one with a hole, then each of these shapes is single-part. Polygon geometry has two levels of construction - parts and rings. Each part must have one exterior ring, but may contain additional interior rings (aka "holes"). The partCount property returns the ...


7

I think the speed problem you are having is looping around each feature and using geoprocessing tools inside the loop. They are not designed for that. They expect to process the whole dataset at once. So restructure your script to avoid the loop and it should complete "within the time to drink a cup of coffee". The data is in my opinion so small that it ...


6

You can circumvent the error of the deep deep folders / file path longer than 255 characters in two ways in Python. One way is to use the win32api and get a short representation of the long filepath. From what I understand this is also what WinExplorer does internally. from win32api import GetShortPathName long_path = ...


6

One of the basic laws of binary computers is to never trust the conversion of any floating-point value except zero. This is because computers don't store "2817018.499512", but break it into sign, exponent, and mantissa, then encode those values in a bytestream (float = 0x4a2befea). If the value you want is other than that bit pattern, the test will fail. ...


5

There is property isBroken - Returns True if a layer's data source is broken. for layer in arcpy.mapping.ListLayers(mxd, "*", df): if layer.isBroken: arcpy.mapping.RemoveLayer(df, layer) Link to Esri help


4

Try this: import arcpy from arcpy import env env.workspace = r"D:\desktop\Project" for mxdname in arcpy.ListFiles("*.mxd"): print mxdname mxd = arcpy.mapping.MapDocument(r"D:\desktop\Project\\" + mxdname) for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"): #fixed indent and replaced equality test. ...


4

It sounds like what you are after is Background Geoprocessing, which was introduced at ArcGIS Desktop 10.0. However, I think ArcPy only became "Background Geoprocessing aware" with the introduction of Python Toolboxes at 10.1 - see Setting "Always run in foreground" within ArcPy code?


4

Ah! Firstly consult rules for python string literals when there is a mix of both single and double quotes. Here expression is a string that may need to be mixed of single and double quotes. You can not enclose double quotes with double quotes or single quotes with single quotes without special sanitization. There are couple of ways you can assign your ...


3

I have found the solution to my problem. Instead of referencing the dataset within the geodatabase, simply reference the geodatabase. For example: # workspace = output + "\\PlanningSession.gdb\\DIDs" ## Referencing the Feature Dataset workspace = output + "\\PlanningSession.gdb" ## Referencing the GDB lyr = ...


3

I think this should work. Note that I use the r specifier for both the internal and external strings. You can skip the outer one, but then you need to double all backslashes. arcpy.management.CalculateField("test", "Link", r'r"\\ftp\raw" + time.strftime("%Y%m%d") + r"\files\boundary" + !NAME! + ".shp"', "PYTHON") Or, slightly longer, but with a more ...


3

The problem may be with the way you are referencing the CSV file and how python interprets a slash symbol. You have: HRU06 = "F:\Users\User\River\HRU06.csv" It should be: HRU06 = r"F:\Users\User\River\HRU06.csv" Python should then interpret the text as raw text and it should work, assuming the comments above are valid. As a side note you should ...


3

I do not see a way to define or change the label engine from Arcpy or the system registry. However, an mxd seems to preserve the Label Engine choice on the Labeling toolbar.


3

just a quick answer, but I see that you combine your aspect conditions using minus, which mean that you will end up with 3 values (-1, 0 and 1). You should instead multiply those results if you want to find layers that satisfy both conditions. Note that you can also use "and" operator in this case. sAspectFinal = n * s slopeFinal = idealslope * ...


3

To answer your specific question "How to iterate through layers of an MXD?" mxd = arcpy.mapping.MapDocument("CURRENT") # Uses your currently open MXD df = arcpy.mapping.ListDataFrames(mxd, '')[0] # Chooses the first dataframe for lyr in arcpy.mapping.ListLayers(mxd, '', df): # Loop through layers # Any tools you want to run on each layer go here ...


2

a global variable gives me an error, but i didn't looked further, because i thought of another approach. Given a Script-Tool with three checkboxes (boolean parameter 0,1,2) i added a fouth parameter (long) which stores the users choice. This one you can also evaluate in the Tools Python script. One problem remains: a checkbox can be unchecked, so i decided ...


2

I hope I understood your problem sufficiently. As far as I got it, I would try the following: # predefine the constant parts of your expression using a variable: constant = "\ftp\raw\YYYYMMDD\Files\Charles" nameVar = "yourobject.Name" # use the built in function .format for setting up the expression for your arcpy.CaculateField_management function: ...


2

I think the only way to do this is through ArcObjects. The IMap.AnnotationEngine property can be used to get or set the label engine. As Arcpy is a subset of ArcObjects, this particular property has not been implemented at the moment. I can't see Esri adding it any time soon, as Arcpy is supposed to be a reduced set of features and they are very reluctant ...


2

You seem to have misinterpreted a suggestion offered in a comment. Instead of: inputOne = "C:\Users\DELL\AppData\Local\Temp\tmpA378\tmpA379.gdb\PerpendicularLine" inPointElevations = inputOne print os.path.dirname(inputOne) pathAfterJoin = os.path.join(inputOne) arcpy.TopoToRaster_3d(inPointElevations,"D:\\Temp\\topo1234") try using: inputOne = ...


2

I believe your second solution is way slower that the first one, since Clip has an inner Selection By Location plus other geometrical operations. So I suggest some improvements to your first algorithm: As per @artwork21 comment, merge the shapefiles if possible. e.g. they share the same schema. This procedure removes an extra loop over the shapefiles, ...


2

My understanding is that ArcPy does not have access to the order in which layout elements draw/display in ArcMap. Consequently, I think that this is something that you would need to pre-author into the map using ArcMap, so that the order is already what you need in ArcPy. You could submit an ArcGIS Idea to have this enhanced but, if you do, I suggest ...


2

row.getPart(0) is necessarily returning the first geometry in the row, so it won't be an iterable. Thus your code becomes: import arcpy # Set up the Environment arcpy.env.overwriteOutput = True arcpy.env.workspace = r"C:\temp" fc = r"C:\Utemp\cities.shp" fields = ['SHAPE@XY'] output = open(r"C:\temp\cities.txt", 'w') COFilePath = r"C:\temp\cities.csv" ...


2

Found out why always only the current join_count was added. This is due to the dummyField that was added, meaning this was the only field that was preserved, all others were deleted, also the previou join_counts.


1

I found out how it works: shpList = container.split(";") for singleShp in shpList: arcpy.Buffer_analysis(singleShp, "F:\test\" + singleShp, "100 Meters")


1

I see 3 things that need to be changed: For and if bodies both have to be indented. Here is a link: https://docs.python.org/2/tutorial/controlflow.html Wildcards don't work with equals =. You will need to manipulate strings in python. Here is a link: https://docs.python.org/2/library/stdtypes.html#string-methods When you print a variable, it should not be ...


1

I found that replacing geometries by their string "signatures" is very efficient technique when comparing geometries. E.g. Assign point IDs to respective start and end attributes of a polyline or finding points that overlap. This approach combined with dictionaries is a game changer. By some reason, that I don't fully understand, truncate produce more ...


1

A few small modifications to your code, but replaces each layer with a new layer and keeps the same layer order. Combined everything as elif into the one for, and added the remove into each if. Before: After: import arcpy #Add constants mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd,'*')[0] Mylayer = r"D:\Temp\GISSE" ...


1

There are two answers depending on your definition of distance: bird's flight or along the road. they wil be identical on a straight line but differ on curves or broken lines. bird's flight you could create a buffer around your point, then intersect the buffer geometry with the line. You can do this for all your points at once using the geoprocessing tool ...


1

I use the Gridded Soil Survey Geographic (gSSURGO) by State data provided by Geospatial data gateway. Two Geodatabases are provided with the download (gSSURGO_PA.gdb, valu_fy2016.gdb) along with a User Guide on how to use the data. Inside the gSSURGO_PA.gdb you will find a raster called "MapunitRaster_PA_10m" and a featurclass called "Map Unit Polydons - ...


1

Here is the best solution I have found thus far using dbfpy and arcpy. import arcpy from dbfpy import dbf from arcpy import env def DBFtoCSV(): '''Convert every DBF table into CSV table. ''' env.workspace = pathlist[1] # Set new workplace where tables are located tablelist = arcpy.ListTables() # list tables in file for table in ...



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