Tag Info

Hot answers tagged

6

Well, there are a few ways to go about this. Here is one approach: import arcpy from os.path import splitext #Use splitext, as slicing is hardcoded for extension length photos = arcpy.GetParameterAsText(0) #photos folder fc = arcpy.GetParameterAsText(1) #feature class arcpy.env.workspace = photos #Create list of image names without extension nameList = ...


5

My understanding is that Background Geoprocessing runs as a separate process and, unlike Foreground Geoprocessing, is unaware of your current ArcMap environment. Consequently, I don't think you'll have success with your current approach. AutoSaving maps is not the same as AutoSaving edits but you could look at Incremental "auto save" in ArcMap ...


4

No - in_memory workspaces are only similar to and not identical to geodatabase workspaces. They support feature classes but not feature datasets. This is documented on the Using in-memory workspace help page: Feature datasets or folders cannot be created in the in-memory workspace.


4

This can be accomplished by adding a value list filter to the tool parameter. Right click the tool in the catalog window and select properties, then navigate to the 'Parameters' tab. Highlight the parameter you would like to add the value list to, navigate to the 'Parameter Properties' box and select 'Value List' from the drop-down menu in the 'filter' ...


4

I'm not able to test this but I tweaked a couple things: Leave off the trailing backslashes in rootdir Use os.path.join to join rootdir and subdir import arcpy import os rootdir = r'\\server\test\ARCHIVE' for subdir in os.listdir(rootdir): path = os.path.join(rootdir, subdir) arcpy.env.workspace = path databases = arcpy.ListWorkspaces("*", ...


4

I thought at first the arcpy.Polyline.getLength() method would work, as you can specify a measurement type and units but it did not because it is GCS. As you can see here, we are still in Decimal Degrees: >>> with arcpy.da.SearchCursor("line_wgs", 'SHAPE@') as rows: ... for row in rows: ... print row[0].getLength('PLANAR', 'METERS') ... ...


4

You can access the feature extent of a feature class by using the Describe function import arcpy, os fc = r'C:\path\to\your.gdb\fc' desc = arcpy.Describe(fc) xmin = desc.extent.XMin xmax = desc.extent.XMax ymin = desc.extent.YMin ymax = desc.extent.YMax print "xmin: %s \nxmax: %s \nymin: %s \nymax: %s" % (xmin, xmax, ymin, ymax) You can change the ...


3

Since the field datatypes are static, you can pre-cast pylist to whatever you need it to be. For example: pylist= [(1.0, u'10',''), (2.0, 1.0, 2.0), (u'9', '', 2.0)] cast = [(float(x), str(y), str(z)) for x,y,z in pylist] #[(1.0, '10', ''), (2.0, '1.0', '2.0'), (9.0, '', '2.0')] fields =["A", "B", "C"] #fields of arcgis table #using with means closure in ...


3

Are you sure it is arcpy.ListFeatureClasses() that takes such a long time? Could it be some other piece of code? Verify with the profiler with just a dummy os.time as shown here. On the SSD disk (2 years old, was heavily used daily), the arcpy.ListFeatureClasses() returns the list of ~800 shapefiles found in the folder specified in less than 5 secs (just ...


2

This can be easily achieved with QGIS (I'm doing this in 2.10) and the Atlas generator. Open up your shapefile in QGIS. Symbolise it as desired. Project>New Print Composer Add a map to the layout that covers the whole page. After the map is added, we need to set it as controlled by atlas (select the map and go into Item properties): Next we set up the ...


2

I recommend becoming familiar with ArcGIS's Data Driven Pages toolbar. Set up a map file to appear as you desire, and then add the DDP toolbar. Click Set Up Data Driven Pages. Update the layer drop-down menu with the layer you wish to iterate through. On the extent tab, you can set a margin (that 'zoom out a tad more' part of what you're after). Once you ...


2

I have tried to understand what you are asking without success. What I can say is that I think your code snippet should start from code like below: l = [[u'OBJECTID', 1.0 , 2.0 , 3.0 , 4.0 ], [u'LENGTH', 56.29, 61.8 , 11.01 ,164.03]] print l[0] From this you can see that a list gets printed: [u'OBJECTID', 1.0, 2.0, 3.0, 4.0] However, I am unable ...


2

You are referring to the tool parameter validation. This can be achieved with tool validator class either when you use the script tools or pure Python tools (for those you work directly with the parameters in the script).


2

To simplify matters, I'll assume your excel spreadsheet is really a csv file with no headers and is formed like: field_name,alias: import arcpy, csv csvfile = "<path to file>" FC = "<path to feature class>" #List of tuples name_alias = [rows for rows in csv.reader(open(csvfile))] errors = [] for name,alias in name_alias: try: ...


2

Riffing on @mkennedy's comment above, here's a small script to parse and create a spatial reference if the datum is NAD83. import arcpy inputString = r'PROJCS["GCS North American 1983 UTM Zone 10S (Calculated)",GEOGCS[ETCETCETC]' editString = inputString.replace(" ", "_").upper() if "NORTH_AMERICAN_1983" in editString and "UTM_ZONE" in editString: ...


2

Copy Features handles the conversion of file formats (shp into sde-fc like in your example) simply by what workspace has been defined in the output path.


2

Just change the path of fc to your feature class, and change YourField to the field name. import arcpy fc = "C:\\Temp\\Data.gdb\\FeatureClass" with arcpy.da.UpdateCursor(fc, ("YourField")) as cursor: for row in cursor: row[0] = None cursor.updateRow(row) To do multiple fields, just add another field to the tuple and set the row equal ...


2

If your scripts are failing at lines where you're using the arcpy package, you can use try & except statements. In the try statement you should put your arcpy methods, and in the except you can write out arcpy.GetMessages() to a log file. arcpy.getMessages() writes out the messages from the last geoprocessing event attempted. It may help you identify ...


2

When you are running a script in the background, a python process is spawned that is separate from ArcMap. So essentially, arcpy.mapping.MapDocument("CURRENT") is attempting to open a map document that it cannot see. This makes sense as imagine the issues if you had multiple .mxd open: Python would not know which one you mean by "CURRENT". You can see this ...


1

You could try using XTools Pro, which has an autosave MXD function built in


1

To do this you'll need to update the Description within the metadata. Unfortunately, there doesn't seem to be a real simple way to do this with arcpy. However, @Ashatz11 over on Stackoverflow documented a pretty straightforward workflow: Updating metadata for feature classes programatically using arcpy Also, here's a similar post on GIS SE, that's worth ...


1

There are few very basic steps to follow: Get value from shape field Get it's part Iterate through elements (points) in this part, where you can access all of the point's properties, i.e. X, Y, Z and M. See if field calculator solution helps Also note that behaviour of Python in calculator and script is slightly different


1

I've come up with a solution that's maybe not the prettiest but it works. Below is code that will parse out the needed information from a feature class field after the Calculate UTM Zone tool is run, and then use it to create the spatial reference object. >>> cursor = arcpy.da.SearchCursor ("test", "utm_zone") >>> for utmStr, in cursor: ...


1

I have run into a similar problem in the past. ArcGIS was importing columns as interger and truncating leading zeros. ArcGIS uses its own method of determining column types. I had to specifically tell ArcGIS that the attribute column was to be text by using a schema.ini file. This is the article I used to get started.


1

Yes, you can. Use the Copy_Features GP tool for that. pnt_fc = r"C:\Users\us\Documents\ArcGIS\Default.gdb\_PointDistanceFc" mem1 = r"in_memory\bufferOne" mem2 = r"in_memory\bufferTwo" arcpy.Buffer_analysis(in_features=pnt_fc, out_feature_class=mem1, buffer_distance_or_field='10 Meters') ...


1

It is not possible to save the output of the Copy tool to in_memory, whatever the input's workspace. It is explained in the last answer of the post you mentioned, I add here an updated reference. FYI, there are some other tools that don't accept in_memory as output workspace, e.g. Project.


1

It looks like you are configuring a Python script tool in a standard toolbox so I replaced your python-toolbox tag (which is for Python toolboxes) with one for python-script-tool. To set irrdist you are reading the 4th parameter (indexed as 3) but you have not shown us how that parameter has been configured on the tool dialog. I suspect that you are not ...



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