New answers tagged

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


0

Try creating a schema.ini file for your csv, such as the example posted here


1

Here is a script tool version. I use this all the time on both layers and MXDs. Shouldn't make a difference whether or not you are in an SDE or otherwise. import arcpy, os folderPath = arcpy.GetParameterAsText(0) findString = arcpy.GetParameterAsText(1) replaceString = arcpy.GetParameterAsText(2) for root, dirs, files in os.walk(folderPath): for f ...


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


0

After adding the layer in onClick try a refresh of Table of Contents. (edited after comment) def onClick(self): mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "*")[0] addLayer = arcpy.mapping.Layer(ComboShp.value) arcpy.mapping.AddLayer(df, addLayer) arcpy.RefreshTOC()


0

FYI - As a new coder, you will have much better luck de-bugging your code if you include error handlers. http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=849&pid=839&topicname=Error_handling_with_Python import sys import traceback try: # Your indented code goes here except arcgisscripting.ExecuteError: msgs = gp.GetMessage(0) ...


1

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

After being reasonably pointed out to the shortage of my knowledge, I have conducted some further research. Now, it works with the following solution: lines_layer_name = sublayer_names["ODLines"] lines_sublayer = arcpy.mapping.ListLayers(layer_object, lines_layer_name)[0] More reading on this can be done at ArcGIS help


1

you can replace the list raster with glob.glob in order to get the list of your raster : import glob, arcpy list_composites = [] list_images = glob.glob("path_to_your_image.SAFE\GRANULE\*\IMG_DATA\*B01.jp2") #first band in each folder for image in list_images: rasters = glob.glob(image[:-6]+"*") #all bands in one folder ...


1

The Mapping module of ArcPy (arcpy.mapping) is what you will need to use so I recommend that you become familiar with its documentation: Arcpy.mapping is a Python scripting module that is part of the ArcPy site package. It gets installed with ArcGIS for Desktop and is available to all licenses. It was designed primarily to manipulate the contents ...


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


0

You can run the process against the mxd, something like the following: # Define the mxd/path mxd = arcpy.mapping.MapDocument("whatevermxdpath") # Create a list of data frames (this specifically selects the top frame) dframe = arcpy.mapping.ListDataFrames(mxd)[0] # Define the layer to process layer = arcpy.mapping.Layer("whateverlayername") # Add your ...


1

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


1

This might not be your entire problem, but MakeFeatureLayer doesn't return the layer name - you've already provided it. I don't know that it has a defined return value, so you're trying to set the mask environment variable to an unknown (from our perspective) value. Instead, you want to set it to the layer name, so change that line to arcpy.env.mask = lyr. ...


0

This sort of fine grain control of symbology is not possible with ArcPy.mapping at this time. But until then, here's a work-around... If you separate your symbology into different layers, using definition queries, you could then reorder your layers in Python, much the same way you'd be able to in the advanced symbology window within ArcMap.


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

This problem would be clearer if we could get a sense of your spatial problem, not just code. What are you trying to get arcgis to do? With only lines and polygons, I have the sense that you're probably using the wrong tools for the job. Euclidean allocation usually takes rasters, but why do you even need rasters here with lines and polygons? With lines ...


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


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


1

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


1

Some things to think about. If your example is any indicator, you are going to have over 5 million records when you are finished. Neither shapefiles or personal geodatabases will handle that very well, so you should use either a file geodatabase or SDE. Processing 48 million records won't be quick, especially when it involves a spatial selection. Perhaps ...


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


0

I did this using a python script and numpy to help me with the matrix algebra for rotation and translation of every point. Here is the key function. You have to unpack the vertices from the feature, transform and reassemble the feature. import arcpy import math import numpy def trans(px,py,tx,ty,angle): ''' Rotate a point px,py around origin ...


0

Assuming that you are using ArcGIS 10.1 SP1 (or later) for Desktop I think you are better to look past os.walk and glob because arcpy.da.Walk is more spatial data aware and can: Generate data names in a directory/database structure by walking the tree top-down or bottom-up. Each directory/workspace yields a tuple of three: directory path, directory ...


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?


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


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


0

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


0

If you have the shoreline as a polygon feature class you should be able to use geometry objects to test to see if your points are within the polygon, if it is true that the point is within the polygon, delete the point and try again. Here is the help page on geometry for 10.3([https://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-classes/geometry.htm])


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


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.


0

This is what I would do: Change your offsets so that the lines are centered over the actual points, i.e., the point is about in the middle of the line. This will make them more accurate and less likely to hit land too. Make your lines shorter. Think about how close a fishing boat would come to land and make sure they are shorter than that.


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


0

An easy way to get the script translated to python would be to create a Model, here are the steps: Create a blank model Add the Calculate Field tool, fill out everything using the UI, run it If it runs as desired export the model to python script, Model menu>Export>To Python Script. The syntax should run in python for either the originally set parser (VB ...


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


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


0

If they're all in one folder, you can probably use a combination os.walk or os.listdir and fnmatch (wildcard) in a python script such as below. rootDir = "folder path to files" outDir = "output directory outName = "Output File Name" search = "wildcard, whatever is unique to the file name" tiffLst = [] # get a list of tiffs in the folder for root, dir, ...


0

Assuming ArcMap is relying on an installed add-in/extension to read the .wm format and you are running your script from a Python prompt/IDE (e.g IDLE or PyScripter) you can try: Don't open the MXD from within your script. Even though ArcMap is open, it is a separate process to your python process, so python will not have access to the add-in/extension Run ...


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


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


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 changed this line arcpy.FeatureclassToCoverage_conversion(in_features="'"+arcpy.env.workspace+"\\lines' ARC;'"+arcpy.env.workspace+"\\points' POINT;",out_cover=coverageOutDir) to this arcpy.FeatureclassToCoverage_conversion(in_features="'lines' ARC; 'points' POINT;",out_cover=coverageOutDir) and it worked. :)


0

The solution was to use a SearchCursor and an InsertCursor to copy the data from the event layer to the feature class. This solution was found here. It is multple times faster than the arcpy.CopyFeatures_management tool.


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


0

As commented by the asker, this was their solution: I have solved the problem. All attempts inside the geoprocessing (arcgisscripting) failed even if I constructed completely new objects from scratch setting vertices' coordinate values. So, I resorted to Osgeo.ogr library to create new shape file. The data had been imported using WKT data format ...


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

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


0

okay, since Richard answered frist, I played around with his approach first. Can't get it to work though. I set up the global parameter right at the start of the code (before class ToolValidator) and tried to get it in the function updateParameters by adding "global lastChecked" inside the updateParameters. import arcpy lastChecked = 0 # here I set up the ...



Top 50 recent answers are included