Hot answers tagged

6

The format of your 2 fields is probably double. Turn them to integer first (with or without the string.format() method, but the latter is more elegant): vakkrt_name = str(int(row[0])) + "_" + str(int(row[1])) or vakkrt_name = "{}_{}".format(int(row[0]), int(row[1]))


6

The wonderful thing about open source is that it's possible to answer an interesting question like this when it arises ;) A large part of QGIS is in C++, but surprisingly large amounts are also written in Python, including Processing. Processing is technically a Python plugin, although it's been 'brought into core' - made into a standard feature. You can ...


4

You could build a topology in a geodatabase, and then when you validate that topology, it will add vertices in the manner you describe. http://resources.arcgis.com/en/help/main/10.2/index.html#/Designing_a_geodatabase_topology/006200000004000000/ If you are not familiar with this, basically what you would do is create a feature dataset in a geodatabase, ...


4

Use the "Any Value" data type instead of the "String" data type. I have no idea why multivalue strings don't work, but it's very counterintuitive...


4

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


4

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


4

Can you use GDAL? The first step would to be create an output merge.shp file, so file1 you would do: ogr2ogr -f ‘ESRI Shapefile’ merge.shp filename1.shp Then update that merge.shp file with the other files: ogr2ogr -f ‘ESRI Shapefile’ -update -append merge.shp filename2.shp -nln merge You would loop that last command for each of the files that are ...


4

Short answer: No, this is not possible. You need to have ArcView 3.x to run these files. I seem to remember there used to be an ArcView project importer made by Esri that allowed for ArcView 3.x projects to be imported into ArcGIS Desktop. However I'm not sure (Actually, I'm quite certain) that Avenue code is not converted by the importer. If you want to ...


4

## Iterate through each of the buildings That should be a single comment sign (#), not a double one, otherwise, it tries to parse it as if it was a parameter, and it fails BTW, you do not need to add the script from file. Just save it to the scripts folder, and it will be automatically added to the toolbox Hope this helps!


4

Saving this in a Python file and using it in the --code arg should do what you need: from PyQt4.QtCore import * from PyQt4.QtGui import * import os from qgis.core import * from qgis.gui import * from qgis.utils import iface for comp in iface.activeComposers(): print comp folder = r"C:\temp" title = "testing" printer = QPrinter() ...


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


3

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


3

When working with large tables and performing joins I would recommend creating an attribute index for both tables, Add Attribute Index, this should help the overall process speed wise.


3

I just tested (albeit at ArcGIS 10.3 for Desktop) to confirm that you can do this using the Integrate (Data Management) tool. This is available at all license levels and is a single quick step. The output is as below where the vertices are shown for the northern polygon but an extra vertex was inserted on the southern polygon too.


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


3

Use this function to return all of the feature classes in the GDB: def listFcsInGDB(): for fds in arcpy.ListDatasets('','feature') + ['']: for fc in arcpy.ListFeatureClasses('','',fds): yield os.path.join(arcpy.env.workspace, fds, fc) Now loop over that function to work with each individual feature class: arcpy.env.workspace = ...


3

No you can't. mapLayersByName returns a list of layers matching a single name (you can have many layers with the same name) setActiveLayer takes a single active layer because there is only one active layer at a time in QGIS.


3

self refer to the instance of the class you have to load to make any QGIS plugin work e.g this example file. In the console, you don't need the self stuff as you don't use the same loading mechanism as in a QGIS plugin. self isn't specific to QGIS, it's a convention when doing object oriented programming with Python. You can look at some Python course to ...


2

@GeoJohn: I don't know if you've solved this, but the result of the pointGeometry.projectAs("WGS 1984") needs to be assigned to a result variable (e.g., projectedPointGeometry = pointGeometry.projectAs("WGS 1984")). The original pointGeometry is unchanged by the projectAs method. The result variable should have the location in decimal degrees. I need to do a ...


2

for transforming form Swiss-LV95 to WGS84 I currently use arcpy.PointGeometry(arcpy.Point(swissX,swissY),arcpy.SpatialReference(2056)).projectAs(arcpy.SpatialReference(4326)) with ArcGIS 10.1


2

I think i found it. If i use >>>execfile instead of >>>import (name of script) it works as many times as i want without closing QGIS


2

This would be enough: iface.mapCanvas().layers()


2

The Origin-Destination Cost Matrix is the best workflow in Network Analyst for processing thousands of routes at once. It could easily generate a table with 250,000 rows describing the travel time between each unique pair of nodes. However, OD Cost matrix does not export the actual route geometry between each origin and destination, as stated in the Esri ...


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


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


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

Found a solution from this post where I only had to add the following code to the script: from osgeo import gdal gdal.PushErrorHandler('CPLQuietErrorHandler') After adding the above and removing the try statement, the working script ignores the ERROR 1 messages: from osgeo import gdal gdal.PushErrorHandler('CPLQuietErrorHandler') def run(): ...



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