Tag Info

New answers tagged

1

My advice is that you specify the output location. Something like this: output = "C:\yourfolder\yourgdb.gdb\DEM_park" Because it is not clear to me where is your DEM going, check your environment settings. EDIT: Oh, I see it now. You created a tif. GDB's cannot store tif format rasters, so of course it is not there at the default gdb. Then your output ...


0

As a couple others have pointed out, you're missing a return value. You're also confusing the assignment operator = for an equality operator == (in the 2nd if). The if structure is also incorrect (if/if/else), and will calculate the wrong value for anything less than 60 (should be if/elif/else). If you still want to use CalculateField (the other answer with ...


3

It is much more intuitive, in my opinion, to work with Cursors (rather than trying to emulate the field calculator in a script) for this type of problem. This is how you would port the problem over to an Update Cursor: import arcpy # The input FC fc = "C:/W/Sik.gdb/yourFC" with arcpy.da.UpdateCursor(fc, ["aspect", "aspect_m60"]) as cursor: for row in ...


3

Your function is not returning anything. I've modified your code to return the value of aspect_m60. # Calculate Field import arcpy # Set environment settings arcpy.env.workspace = "c:/W/Sik" # Set local variables inTable = "Point" fieldName = "aspect_m60" expression = "getCalc(!aspect!)" codeblock = """def getCalc(aspect): if (aspect < 60): ...


2

You are trying to set the field within the code block, when actually you need the code block to return the value you're looking for. If you just just add return aspect_m60 after the else block, it should work fine. Think of the code block as a place to write functions whose results can be used in your field calculator expression.


2

Having looked at your code where is row[] being created, I guess we are not seeing the full picture? I've seen this "GPL0" error before. It's indicating that the first parameter is invalid. If you look at the syntax section of the help for this tool it states the input features are of Data Type FeatureLayer. As we are not seeing the full code we have no ...


2

Assuming that you always want to match like files from Original and Processed folders (i.e. Paris(O).shp always matched with Paris(P).shp or New York City(O).shp always matched with New York City(P).shp), You need to add a conditional after your second for loop to filter out everything you are grabbing from the processed folder. for f in glob.glob(root_dir ...


1

Why not just use the Delete Field tool within the Fields toolbox? ArcToolbox --> Data Management Tools --> Fields --> Delete Field Choose your input table/feature class, and select the fields you want to remove. If you want to script it out to delete certain fields every time, it'd be pretty easy. arcpy.DeleteField_management(in_table, ...


1

I've tested the following script on GNU/Linux, QGIS v.2.8.1, Processing v.2.6 and Processing v.2.9.1. import sys,os,glob from qgis.core import * from PyQt4.QtGui import * app = QApplication([]) QgsApplication.setPrefixPath("/usr", True) # Adjust it to your path QgsApplication.initQgis() path_dir = "/docs/borrar/test/" path_res = path_dir + "results/" ...


2

For the first question: You need to create a QgsVectorLayer object from your Shapefile path. Only then you can access the getFeatures() function. That is: for fname in glob.glob(path_dir + "*.shp"): for feature in QgsVectorLayer(fname,"any name","ogr").getFeatures(): My recommended way of doing it You don't actually need to access getFeatures() nor ...


3

This works for me. Are you trying to drag it from the Project Pane (either Folder or toolbox node) into Modelbuilder? Either make a connection to the folder the TBX lives in, or from the Toolbox node, right click and add toolbox pointing to your existing tool. If you're trying to drag from ArcMap to Pro, this wont work.


3

Try this: import os, glob, shutil root_dir = "C:\Users\xxxx\Desktop\Test\\" country_dir = "Country_" grid_path = "C:\Users\xxxx\Desktop\Test\Grid\Grid.shp" # Get all files that constitute the Grid Shapefile gridShpFiles = glob.glob(grid_path[:-3]+"*") for path,dirname,files in os.walk(root_dir): if country_dir in path: for f in gridShpFiles: ...


1

os.walk returns a tuple of three values: for path, dirs, files in os.walk() Also consider http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python


1

Following the idea from Cannot rename output file using standalone script for QGIS, I would do something like this: for file in files: if file.endswith('.shp'): pieces = list(os.path.splitext(file)) pieces[0]=pieces[0][:-3]+"(B)" newFile = "".join(pieces) outputs_2=general.runalg("qgis:clip", outputs_1['SAVENAME'], ...


2

I am not an ArcGIS user, but the following links may contain information and tips on how to add layers to your TOC: Add layer in ArcGIS Use python to add layers to TOC How to add several layers to the table of contents in ArcMap using Python in one shot?


2

Try changing this line: outputs_2=general.runalg("qgis:clip", outputs_1['SAVENAME'], file, os.path.sep.join(path.split(os.path.sep)[:-1]) + os.path.sep + processed_dir + os.path.sep + file) to: outputs_2=general.runalg("qgis:clip", outputs_1['SAVENAME'], file, os.path.join(os.path.dirname(path), processed_dir, file))


3

Yes, you can run multiprocessing child processes from a toolbox script. Below is some code to demonstrate in a Python Toolbox (*.pyt). There are a number of "gotchas". Some (but not all) will be applicable to Python script tools in a binary toolbox (*.tbx), but I only use Python Toolboxes these days so have not tested. Some "gotchas"/tips: Make sure ...



Top 50 recent answers are included