Tag Info

New answers tagged

0

I had some problems getting ArcGIS to handle NoData values correctly with the examples shown here. I extended the example from reomtesensing.io blog (which is more or less similar to the solutions shown here) to better handle NoData. Apparently ArcGIS (10.1) likes the value -3.40282347e+38 as NoData. So I convert back and forth between numpy NaN and ...


0

Thanks for your answer. I figured out what the issue was. If I use the script within my pre-code block, I need to define the variable %name%. This is what I wrote in my pre-code block script: def my_funcrtion(): import arcpy my_name = "%name%" fc = "C:/" + my_name + "/Dropbox/featureclass"


1

I suggest you to write a proxy class in managed C++ if this is an option for your. Realistically, you might need to perform the kind of operation that takes longer in .NET or Arcpy(large iterations of small operations).You have the choice to write a proxy class in Managed C++ where you can place ArcObjects code that heavily uses the interop layer. Once ...


0

Last week, I achieved, what cost me some of my productive time. As I assumed, the problem wassn't related to wrong formatting in the code itself. It was tricky as simple. There is a conflict related to the international language settings created by SplineWithBarriers() which actuelly Java code. If your systems decimal delimiter is ",", which is usual in ...


1

With arcpy you can only modify the following types of symbology for vectors: Graduated symbols Graduated colors Unique values. You cannot actually change the type of symbology (e.g. from single symbol to graduated colors) but you can change some properties of the symbology type chosen. Using arcpy this is anyway not possible with piecharts, as far as I ...


0

Bill from Esri Inc gave me a hand with this one. You can call the LOD via json: import urllib, json parameters = urllib.urlencode({'f':'json'}) request = "http://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer?" + parameters response = json.loads(urllib.urlopen(request).read()) try: tileinfo = ...


1

As it turns out this is caused by an "issue" in the env.settings. I used arcpy.ResetEnvironments() and arcpy.ClearEnvironment("workspace") before using the arcpy.arcpy.MakeRasterLayer_management and everything worked as expected. arcpy.ClearEnvironment("workspace") arcpy.ResetEnvironments() AddRasterMxd = ...


0

Like in the comment of PolyGeo, Compacting database recalculates feature class extent, so here is an arcpy script to automate this task and also to make rebuild index and analyze: import arcpy , sys , os , subprocess arcpy.env.overwriteOutput = True def main(): db_path = os.path.join(os.path.dirname(__file__), "Connection_db_name.sde") ...


1

I've used filled elevation model (with streams removed) to replicate your coefficients: Keeping in mind that water usually runs downhill :), it is reasonable to expect that all the values in output should be less or equal to the value at start point. I've checked results using difference [Filled]-[ScriptOutput] and found that script (see below) failed ...


0

you can use your inline variable directly in the calculateField tool. with a Python expression entered in the CalculateField tool, it would look like this: "C:\\Users\\{}\\Dropbox".format(%name%) The variable should be present in your model (right clic > create variable > Type = String). Here I renamed it "Name" and required it as a precondition, but ...


3

Those coordinate differences are measured in Angstroms. File geodatabase uses a technique similar to the integer storage representation conversion in enterprise geodatabases (ArcSDE) to snap 64-bit floating-point coordinate values to a feature class coordinate resolution grid. This coordinate resolution is established at feature class creation (and it's ...


1

Start by checking if the value is None. If it is, replace the value with this if rowData[idx] is None: rowData[idx] = datetime.datetime(1970, 1, 1, 0, 0)


3

Building on @artwork21's excellent answer, the following is how you would accomplish the task with Python using an UpdateCursor. import arcpy # The input feature class fc = r'C:\temp\myfgdb.gdb\yourFC' # Add three new fields arcpy.AddField_management(fc, "TOWN", "TEXT") arcpy.AddField_management(fc, "ERF", "TEXT") arcpy.AddField_management(fc, "PORTION", ...


13

If the length of the ID field values is always constant I would recommend using either Field Calculator or Calculate Fields tool with python slices. TOWN calculation: !ID![:8] ERF calculation !ID![8:16] PORTION calculation !ID![-5:]


1

Here is your answer: As you are trying to add a Cached Image Folder, you must use MakeImageServerLayer_management instead of MakeRasterLayer_management. Here is the simple snippet to do what you need. You can simply paste it into the python window and see the response. just change the path to your compact cache folder (Raster): import arcpy mxd = ...


0

There is a bug called NIM082145 - In-memory raster layer is missing source information and tabs are not all correct. A .afr file is created instead of a .lyr file. This issue has been found in 10.1 and in fixed in 10.1 SP1. So, easy fix: upgrade to 10.2/3 or just install 10.1 SP1 from here.


2

ArcPad Checkout from python command line works in arcgis 10.1, but you need to add arcpad toolbox with arcpy.AddToolbox(). this is a working sample script, in this script i pass the path of the axf as first argument in commande line: import arcpy , sys arcpy.env.overwriteOutput = True arcpy.AddToolbox(r"C:\Program Files ...


0

There is a bug for this - NIM102547 - ArcPad tools fail to work in Python outside of ArcMap. It's been found in 10.2.1 but there's no reason why the behaviour should be different in previous versions. As an alternative, you can run your script as a script tool or from the Python window. Also, as @om_henners says, it's not a good idea to use combinations ...


2

I figured it out! My question was misguided and sent everyone in the wrong direction, sorry for the confusion folks. The error was that the tool parameters and the command line parameters were not, after all, precisely the same. The "magic" is that when using a Toolbox all paths are converted to fully qualified paths, ..\source\data.gdb\some_layer --> ...


1

This way it worked fine for me: Try to get symbology in a separate line?


1

I always find it's easiest to first check if your value is not NULL before adding it to a table. For example, say you have a value to be added to your table in variable Value. A simple if statement will do the trick. if will return True if the variable contains a value and is not NULL Code: *processing* = Value if Value: *update table etc*


2

When running your tools from the console it is suggested you use the more general sys.argv instead of the arcpy-specific arcpy.GetParameterAsText(). This page from Esri shows you how to use sys.argv. Change all of your inputs to this, and you should be able to run it from the console. mxd = sys.argv[1] clip_layer = sys.argv[2] out_gdb = sys.argv[3] Also ...


1

I have tried calling the list as weighted_overlay(variables, other parameters), and using just variables = [] in the function code, which did not work. If you are defining the list outside of the function, you do not want to then redefine it within the function. def weighted_overlay(variables, other parameters): variables = [] print ...


0

This question is a pure python question. Despite artwork21 suggestion, you can make your list a global variable and then manipulate that variable in any function. Please check this SE Question which is related to yours: Using global variables in a function other than the one that created them


1

Try this: # Import arcpy module import arcpy # Check out any necessary licenses arcpy.CheckOutExtension("spatial") # Local variables: c1 = "F:\\img1.tif" c2 = "F:\\img2.tif" c3 = "F:\\img3.tif" output = "F:\\output.tif" # Process: Raster Calculator arcpy.gp.RasterCalculator_sa("(\"%c1%\"+\"%c2%\"+\"%c3%\")/3", output)


2

Do you have a selection currently applied to testlayer? Do you have a definition query on testlayer? Both of these can limit the number of records in the cursor when executed directly in ArcMap.


1

Is 'rows' defined? Looks like you should be calling for row in testcursor: Try this: # create empty list LayerList = [] # create search cursor testCursor = arcpy.SearchCursor(r'D:\workspace\testlayer') for row in testCursor: if row.getValue("SURVEY_NAME"): survey = str(row.getValue("SURVEY_NAME")) print survey if survey not ...


3

@dvdhns suggestions, are what you should do. However you don't need to write a xslt for html conversion because Esri has done this for your before. see this code snippet: import arcpy from arcpy import env env.workspace = "C:/data" #set local variables dir = arcpy.GetInstallInfo("desktop")["InstallDir"] xslt = dir + "Metadata/Stylesheets/ArcGIS.xsl" ...


2

You are almost there. You just need to test in the list comprehension you get that the v.name is not equal to certain strings. def getParameterInfo(self): """Define parameter definitions""" param0 = arcpy.Parameter( displayName="Input Features", name="in_features", datatype="GPString", ...


3

No. You cannot directly export ESRI Feature Class metadata into PDF files. This is how I would attempt to do it using python, rather than ArcObjects: Use arcpy to export the metadata to xml files. Use python and xslt (xml style sheets) to format the xml files into something human readable, my recommendation is a simply formated txt or html file. Use a ...


7

A good starting point to understanding this is a help page entitled Understanding the progress dialog box in script tools: There are four functions you use to control the progress dialog box and its progressor. This certainly works for foreground Geoprocessing and I assume that it will have a similar effect on the Background Geoprocessing dialog.


5

Ok, based on what I think you are asking for, I think all you should need is: import arcpy toolboxes = arcpy.ListToolboxes() for toolbox in toolboxes: print toolbox tools = arcpy.ListTools('*_'+toolbox[toolbox.index('(')+1:toolbox.index(')')]) for tool in tools: print tool print '\n' Fair warning, this script will print every tool ...


2

Here's a script I just happened to have lying around, it merges all lines, points and polygons from a database into a new database feature class; there's no field mapping, at this time we just wanted to see all the geometries together without having to load over 1k layers... A feature class (shapefile or database) can only store one geometry type so it's ...


2

You can use an asterisks to specify all of the fields in the feature class. Try the following example: import arcpy fc = r"C:\Users\Scratch\oc.shp" with arcpy.da.SearchCursor(fc, "*") as cursor: for row in cursor: """ row[0] = OID or FID row[1] = Centroid coordinates row[2] = Your 1st field row[3] = Your 2nd ...


2

Out of range means that you are trying to access a field that is not included in your result. Before you use your cursor you have to define which fields you want it to return. Those fields should be entered in a list. In your case you would change this line: catchments = arcpy.da.SearchCursor(oc,"FEATUREID") to something like this: catchments = ...


2

The search cursor second parameter is the field name list. You are only providing one field name that is why it is not going beyond index 0. A list (or tuple) of field names. For a single field, you can use a string instead of a list of strings. Try: catchmentFields = ["FEATUREID", "field2", "field3"] catchments = arcpy.da.SearchCursor(oc, ...


1

It is about transferring points coordinates to table. You might use this process: Add X and Y fields to points' table Join above to TABLE using common field. Calculate similar field e.g. [XN]=Points!X Export joined table to new one. Create XY event table from output at step 4. Based on your Q you'll end up with duplicate points in some cases.


2

I have tested it like this: def updateParameters(self): ValuesStr = self.params[0].value Values = ValuesStr.split(';') self.params[1].value = Values[0] self.params[2].value = Values[1] self.params[3].value = Values[2] self.params[4].value = Values[3] isExportFeatureClassStr = Values[4] if isExportFeatureClassStr == ...


1

Try this: import os, arcpy, shutil from arcpy import env if os.path.exists(r'E://tmp//ProcData'): shutil.rmtree(r'E://tmp//ProcData') if not os.path.exists(r'E://tmp//ProcData'): os.makedirs(r'E://tmp//ProcData') importFiles = r'E://tmp//RawData' outputFolder = r'E://tmp//ProcData' spatialRef = arcpy.SpatialReference(26917) env.workspace = ...


2

I assume you are trying to convert your scripts so that they can be used in open source software or with open source libraries, otherwise the question's title would not make too much sense to me. First of all you have to be aware that arcpy.AddMessage solely makes sense in one specific context: when used in a script tool that is used within ArcGIS. It does ...


2

Have you tested ReconcileVersions_management in data management toolbox? This tool reconciles a version or multiple versions against a target version. It can be used standalone or with python window of ArcMap. However that tool won't pop up the interactive conflict window. To pop up that window I suggest you to create a python addin (a bottom) and set the ...


0

Build your model and make sure it works. Use Feature Layer instead of feature class as the input of your model. to do so, simply drag the layers to your model. after you successfully run the model, close it and right click the model in the Catalog Window > Properties Go go parameters tab and click the plus button to add a new parameter select the ...


1

After working through Michael's suggestions in the comments above, I got to thinking about not just what privileges the user saved in the SDE connection had to the data, but what permissions it had with the database itself. As I mentioned in my original question, we have a few other SDE connections to different geodatabases; a production SDE and a testing ...


1

You show the smoothing factor as a string in the first example, and an integer in the second. Did you check to make sure the input parameters are formatted correctly? Also, Z_value_field = "id" seems like a suspect field name for an elevation value.


0

You stated in a comment in PolyGeo's answer that you have the geometry working. Updating the attribute is very similar. You want to update the row object before inserting it. Remove the last for loop and update the code prior to this: # Use the insert cursor to put the point object # and attributes in the feature class newPoint = rowInserter.newRow() ...


0

Using the da.Updatecursor, I tried modifying the z values of individual vertices, creating a new geometry object, and replacing the existing geometry with the z-modified geometry. cursor = arcpy.da.UpdateCursor(out_features, ["SHAPE@", height_field]) for row in cursor: newGeom = arcpy.Array() for part in row[0].getPart(): newPart = ...


2

I've had to do something very similar using some cobbled together python script: >>> field_name = "name" >>> mxd = arcpy.mapping.MapDocument("CURRENT") ... for i in range(1, mxd.dataDrivenPages.pageCount + 1): ... mxd.dataDrivenPages.currentPageID = i ... row = mxd.dataDrivenPages.pageRow ... print row.getValue(field_name) ... ...


0

thanks for the responses guys. I am still not 100% why the original code didn't work but I ended up going with a modified version of the trace back code shown here. In the end my coded ended up looking like this (see below), which produced the results that I was after: import sys errorLog = r'd:\log.txt' filePath = errorLog try: '''Code not included in ...


2

This is one option. The k:v mapping found here. statusDictionary = { 0: "New", 1: "Submitted", 2: "Waiting", 3: "Executing", 4: "Succeeded", 5: "Failed", 6: "Timed out", 7: "Cancelling", 8: "Cancelled", 9: "Deleting", 10: "Deleted" } print statusDictionary[arcpy.FeatureClassToFeatureClass_conversion(inputTable, ...


3

It lools like the problem is that pnt has no spatial reference and arc is having a spit, It's that or your field isn't being retrieved correctly, it's best to use row.getValue(field_name) rather than row.field_name as getValue is more flexible. Please ensure the fields X_Coord and Y_Coord exist in your layer (and aren't turned off) in the layer dialog. Try ...



Top 50 recent answers are included