Tag Info

New answers tagged

1

You'll want to use a search cursor that iterates through your feature layer and reads values in the PageNumber field. Something like this: with arcpy.da.SearchCursor (IndexPoly, "PageNumber") as cursor: for pageNumber, in cursor: Expression = "PageNumber = {}".format (pageNumber) arcpy.SelectLayerByAttribute_management(IndexPoly, ...


0

I think list comprehension as well as applying sql statements to your search cursor will help you out. Here's a few tips: If you want all the unique values in a field (field ID, in this case). ##Find all unique values in a field #Return python set of unique values in field "ID" values = set([r[0] for r in arcpy.da.SearchCursor (table, "ID")]) Max value ...


0

I think you want a for loop to iterate through your polygon features. So if you have the list of features in your Expression variable: Expression = ... if stuff: ... for i in Expression: arcpy.Select arcpy.Buffer1 arcpy.Buffer2 ... arcpy.Append That will run all your processes on each element in Expression (i). Use 'print i' if you want to ...


3

I was curious as to this as well so I asked around a little and did some research. what I found was SHAPE@XY —A tuple of the feature's centroid x,y coordinates. SHAPE@TRUECENTROID —A tuple of the feature's true centroid x,y coordinates. This article describes how they are identical around 95% of the time but will result in a slight difference the ...


0

It sounds like you need the python equivalent to Model Builder's Iterate Feature Selection. See if this question/answer will help you What is Python equivalent of ModelBuilder's Iterate Feature Selection? Otherwise, if you are trying to iterate through a series of feature classes, you can use the walk function.


2

The problem is that you were adding all fields as "TEXT". The first one should have been a date. Here is an example where you can map the field types with the headers: import arcpy import os import csv import time import locale from arcpy import env start_time = time.time() ##incsv = arcpy.GetParameterAsText(0) ##outfc = arcpy.GetParameterAsText(1) ...


1

An option would be to export your models to python scripts and run them from the command line, completely avoiding the need for ArcCatalog/ArcMap to be open.


2

At one time I was running particularly large models 500+ elements with lots of iteration that frequently bailed, and like you I found that starting ArcCatalog immediately prior to running them gave them a much better chance of succeeding. I also tried to re-start my PC before starting ArcCatalog and to not do any other lower priority jobs while running ...


0

To answer part two of this question, i didnt know if it was appropriate to edit my first answer or start another so mods if i am wrong please move to correct spot, anyways so once you have network analyst toolbar loaded you will create a closest facility problem. (refer to that tutorial i posted earlier for how to do that if you need) now your incident ...


4

As Vince mentioned in the comments, 'The "with" syntax is a Data Access cursor construct'. You have a couple options: Using the old version of update cursor: cursor = arcpy.UpdateCursor(i) for row in cursor: if row.getValue("Type") == "Intermediate" and row.getValue("Depression") == "Yes": row.setValue("Contour_Type", "Intermediate_Depression") ...


0

If you use the arcpy.AddMessage(message), it should show up in your published GP, but it shows up on the job messages page (not the server logs as you indicated in your question). You also need to enable this in the service properties (or when you publish the service):


1

The AddMessage will add a message to the geoprocessing job message queue: jobs/ja861064b634648f1be2371e2307c6112?f=json For general logging, I use python logging: import logging and make sure the formatter has a process id: formatter = logging.Formatter('%(asctime)s p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s |-| %(message)s') # Set up logging ...


0

Hi i was able to acheive m goal with selecting nearby points, putting all field value in array and counting the array ocurance and pasting values into another field fc = r"C:\Akhil_Office_1\Python\test\PATest1.shp" fields = ["FEATURE_ID", "ADDRESS"] with arcpy.da.SearchCursor(fc, fields) as cursor: for row in cursor: value=row[0] #get value ...


1

Esri support got in touch with me and said to simply save a copy rather than save the .MXD itself. Further: "...when Bing layers are added to a MXD a global property is created and referenced. Even when those layers are removed the MXD maintains the reference. When saving the MXD as a copy (when Bing layers are not present) the reference is not copied. Which ...


0

Try replacing the raster layer data source after you apply symbology: obj_lyr.replaceDataSource(os.path.dirname(sPath_fc_grid), "FILEGDB_WORKSPACE", os.path.basename(sPath_fc_grid))


-1

You didn't say what version of Arc, but here's some additional properties of MapDocuments. It looks like you can control many more options (try searching that page for 'print' to pick out the important ones). I'm guessing you may have the wrong size or data frame selected and setting it in the script would rectify it.


0

Problem was not in script text, but in script object in ArcMap. When I checked Run Python script in process and publish this script, it began to work at server too.


0

It looks like you are trying to specify all the fields in the join table to be pulled through. However, if you simply leave out that parameter, then they will all be pulled through by default. Why you get the error, I am not sure but I suspect it will be related to you trying to pull through OBJECTID (by specifically naming it) when there is already an ...


1

For the sake of explanation let's call your original geotiff source.tif and the manipulated version target.tif. If you use the tool arcpy.management.ExportRasterWorldFile in conjunction with source.tif it will create a world file called source.tfw that contains the tiff's georeferencing information. Assuming that target.tif has the same pixel size, extent ...


1

I searched for "arcpy publish map service" and found Publishing a map service with Python: You can automate map service publishing in a Python script. To do this, you need to call the following sequence of functions from the arcpy.mapping module and tools from the Server toolbox.


1

You're using gridcode as text in a string, instead of a variable. Try: arcpy.SelectLayerByAttribute_management("LC_test","NEW_SELECTION", '"' gridcode + '" < 17 or "' + gridcode + '" = 21') The exact syntax you're after depends on data sources and field types. See the ArcGIS SQL reference for query expressions used in ArcGIS help.


1

In ArcGIS... Let's say you have polygons and lines such as in the example below: Perform a feature to line, with the polygons and the lines as your input. This slices the polygons by the lines. Select all the features on one side of the line. Export selected features. Turn off all layers except the new layer. Select the 'slivers'. Perform ...


0

One solution would be to create a model in ModelBuilder. You can drag and drop your two tools into the model and then connect them how you like depending on your workflow i.e. output from Tool 1 becomes input for Tool 2. If, as it sounds in your case, the user is specifying a parameter for Tool 1 which you want to also use in Tool 2, then in your model you ...


0

I tend to put major bits of py in try statements. The "AddMessage()" and "AddError()" and "except Exception as e:" are all rather handy at reporting different things. desc = arcpy.Describe(raster) SR = desc.spatialReference try: arcpy.AddMessage(" - Band Count: %d" % desc.bandCount) ...


0

For large scripts I use Eclipse. Eclipse is a very powerful, respected and free IDE that can be used for a number of languages. Eclipse can also play nicely with source control such as Subversion etc, which is handy for larger projects where a few developers are working together. For Python development you need the PyDev plugin. Setting up Eclipse for ...


0

paste your python script into the python window in arcmap and execute it from there. the error massage will tell you what line the error occurs on.


1

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


0

create a script tool from which both Tool1 and Tool2 are executed.


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


3

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

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


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


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


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

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


4

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


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


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


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


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


0

Have you tried cutting out ArcPy by converting it to an array and then using numpy's minimum function?


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


0

Probably a little late, but my solution to this problem was saving the result in a different folder than the inputs. A temporary file is created in the work folder with a default name, which is erased after the process is finished, but it generates problems when the output is created.


0

I faced similar situation recently and in my case opening ArcMap didn't solve the error. Later I found out that it has to got to do with Business Analyst Licensing. One more thing is you need to checkout the license for BA extension in Script something like this.. arcpy.CheckOutExtension("Business") In my case it was supposed to be some BA premium license ...


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.


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


-1

To answer this question nowadays (since ArcGIS 10.1 SP1) I would recommend the answer from @djq in conjunction with using arcpy.da.Walk to walk the folder structure: 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 names, and ...


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.



Top 50 recent answers are included