Tag Info

Hot answers tagged

12

The principle is simple if you have R installed and is usable in command line. You can create and/or execute a R Script from QGIS using Processing in QGIS version 2.0 or Sextante in version 1.8): see: Setting “R Folder” Path in QGIS Sextante Port your R scripts to QGIS using SEXTANTE QGIS with R: Working with the SEXTANTE plugin and others


11

Since you are using v10.2 it is looking for the path of the Spatial Analyst toolbox which has changed directory locations slightly from v9: To update, open the ruggedness.py file using Notepad or some other text editor and change line 20 path to something like this: C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Toolboxes\Spatial Analyst Tools.tbx


8

You can call the GP tools in two ways: arcpy.%toolbox%.%toolname% or arcpy.%toolname%_%toolbox% Both are calling the same function, so there is no difference. It is a matter of taste; I always call functions in the arcpy.Buffer_analysis format because I seem to read the name tool faster in this way (I see first the toolname, and often seeing the ...


7

I think the short answer is NO. In arcpy you would typically "Describe" an object to get a handle on its properties. It appears there is no way within arcpy to find out the version the toolbox was saved in. If anyone knows of a way then please shoot me down in flames so I can learn from your wisdom! But you could fudge it this way: In ArcCatalog right ...


6

Should be: stringvariable = "banana" arcpy.CalculateField_management("c:\point.shp", "SUBDIRECT", "'" + stringvariable + "'", "PYTHON") If you double quote stringvariable, Python won't interpret it as "banana". Also, You have to quote the string for the field calculator to work.


4

You are trying to use a Layer object as a name for the field and since it is not a string, you get an error message. Your option is to use a layer name (as you see it in the TOC): mxd = arcpy.mapping.MapDocument("current") list_layers = arcpy.mapping.ListLayers(mxd) for lyr in list_layers: arcpy.AddField_management(lyr,lyr.name,"DOUBLE",12,2) or to ...


4

I just realized that I can use Point geometry, for example: point = arcpy.Point(x, y) ptGeometry = arcpy.PointGeometry(point) Then I can use that in a Select by Location arcpy.SelectLayerByLocation_management("Layer", "CONTAINS", ptGeometry) I didn't know I could use the ptGeometry in a Select by Location.


4

Set it as a File type. You can use parameter validation to ensure the file extension is ".pdf" or as @blah238 notes, use the filter option to restrict file type to pdf.


4

Make your expressions as triple quoted strings - nice and clean! For File geodatabases: """CRIME_INDX <= 0.02""" """NAME = 'California'""" For personal geodatabases (.mdb): """[CRIME_INDX] <= 0.02""" """[NAME] = 'California'"""


4

In general, workflows that you would like to automate I would recommend first doing it manually. Once you have that logic understood (what tools to use when), then yoiu could create a model/python script. For this case here would be the general model workflow (assuming you are using ArcGIS): Use Make XY Event Layer tool to create the GIS layer Use Add ...


4

It works in the python window because JHJ is likely a layer in the map and therefore can be reference in your script as "JHJ". When run outside of Arcmap, you need to tell arcpy where to look. Here are just a few ways you can do this (untested, but it should give you a few ideas): 1) jhj = ...


4

Put a u in front of the string so the interpreter knows it's Unicode. myCalc(!Epulettipus!, u"Lakóépület")


3

There appears to be a solution on your duplicate post on the Esri forums: You just need to delete this part (first three lines of the script): Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> I think the author of this tool meant to ...


3

I'm not by a computer where I can try this within ArcMap, but try: wf_expression = '"AGE_18_64"' + " >= " + str(wf_value) or, using str.format(): wf_expression = '"AGE_18_64" >= {0}'.format(wf_value) Try that if wf_value is supposed to be a number in the sql query (you don't generally need to enclose numeric values in quotes). If however it ...


3

The problem with the code you have is that you are trying to convert an ArcMap Map Document into into a string and then you supply the string for the arcpy.mapping.ListDataFrames function. I usually handle this by: 1) Using the ArcMap Document data type for the input parameter. 2) Referring to the mxd file path as an Map Document object. mxd_raw = ...


3

If you are creating a script tool in a regular toolbox, when defining the tools parameters, for the parameter you want to pass as a list, set the "MultiValue" property to Yes. The multiple values will get passed to your script as a semi-colon separated string. To use as a list in your python script, split the string on the semi-colon, i.e: ...


3

This bit of code might help you programmatically carry out steps 3 and 4. It will load a composer template from file and export a map to jpeg by creating a atlas. It will require some tweaking but should get you started. def quick_export(self, ref, stype, scale): # Add all layers in map canvas to render myMapRenderer = ...


3

My solution to this problem was to use the extensions available for the Arcpy Addin Toolbar. I added an extension that listens for an edit session to begin or end. I have all of my buttons on the bar set to :self.enable = False" to start with and then these buttons are then either enable or disabled by starting or stop an edit session. class ...


3

As you suspect arcpy.analysis.Buffer and arcpy.Buffer_analysis are two equivalent ways to run the same tool.


3

The attached (untested) script takes the name of a feature class, splits it by "_" and uses that as a basename for the join operations. The general idea is to use: basename = fc.split("_")[0] which converts, for example, abc_clip_diss to abc Then, you can use that basename to create new variables with os.path.join(): inFeatures = os.path.join(ws, ...


3

This look like there is a null geometry somewhere. To solve this, you should first run the "repair" tool. To avoid you code to crash (as you said that it works for the first polygons), you can add some testing if point: print ("{0}, {1}".format(point.X,point.Y)) else: print "No point"


3

I would use the "SHAPE@" token with the search cursor, then do something like this: with arcpy.da.SearchCursor(fc, ("SHAPE@", "UNIQUE_ID")) as searchCur: for row in searchCur: myDF.extent = row[0].extent myDF.scale = 50 arcpy.RefreshActiveView() arcpy.mapping.ExportToPDF(thisMap, ...


3

You don't 'Dim' variables in python, you just declare and assign them. That said, your basic route is to set the parser to python and check Show Codeblock. In the Pre-Logic Script Code box, enter your function like this: def DoThis(fld): val = 0 if fld <> 'a certain string': val = # do your calculation here return val In your ...


2

You can now rename a field using core ArcGIS Desktop GP tool - Alter Field (Data Management). This tool provides the ability to rename fields or rename field aliases for any geodatabase table or feature class. This tool is available starting with 10.2.1.


2

The cursor is expecting a tuple, not a string. You might be able to convert the string to a tuple after the fact using ast.literal_eval() as described in this answer. However, it would be far better practice to produce the tuple without using a string as an intermediary. The better way to do this would be to change: "((({0}, {1}), 34))".format(X, Y) To: ...


2

Look at Using processing algorithms from the console import processing processing.alghelp("qgis:fieldcalculator") ALGORITHM: Field calculator INPUT_LAYER <ParameterVector> FIELD_NAME <ParameterString> FIELD_TYPE <ParameterSelection> FIELD_LENGTH <ParameterNumber> FIELD_PRECISION <ParameterNumber> NEW_FIELD ...


2

QGIS can take a --code that you can pass a Python file to in order to run. qgis --code my myfile.py Run this command from the VBA shell command.


2

If I understand your question correctly, you can accomplish this without a custom tool. After you start an editing session, on the Editor Toolbar go to Editor>Options. On the Attributes tab, check Display the attributes dialog before storing new features, and then select the feature class you want to enforce this behavior on. Whenever a new feature is ...


2

You can simplify your script without using while... and x, x+1: for simple Python list, it would be best to use for or list comprehensions: ##Test=name ##Select_folder=folder ##Result=output vector import os import glob # folder path of Result shapefile path_res = os.path.dirname(Result) # go to Select_folder os.chdir(Select_folder) # copy the shapefiles ...


2

I fixed the script, you need to call bandStatistics on the dataProvider() not the renderer().So heres the final solution that works well ##[Example scripts]=group ##Limits=selection "MinMax";"StdDev";"Cumulative" ##Stretch=selection "NoStretch";"StretchToMinMax";"StretchAndClipToMinMax";"ClipToMinMax" ##StdDev=number 1.0 ##CumulativeLower=number 0.02 ...



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