Tag Info

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


5

You can do this using 2 os.path functions (splitext and basename): import os os.path.splitext(os.path.basename(r'C:\user\shapefiles\polygon.shp'))[0] # returns 'polygon'


4

You can use the python threading library to run a function periodically: I have used the following statements to remove a set of graphics after 3 seconds: from threading import Timer Timer( 3, self._clearGraphicLayer, ()).start() def _clearGraphicLayer(self): for graphic in self.graphicsLayer: self.iface.mapCanvas().scene().removeItem(graphic) ...


4

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


4

Here is the code that should work for you: import arcpy mylist = ['A4126','A4190'] print str(tuple(mylist)) tempFeat_1 = r"C:\ArcGIS\Default.gdb\AR_postalcodes" tempFeat_2 = r"C:\ArcGIS\Default.gdb\AR_postalcodes_sel" qry = """POSTCODE IN {0}""".format(str(tuple(mylist))) arcpy.Select_analysis(tempFeat_1, tempFeat_2, qry) A couple of comments: ...


4

You need to open it as a QgsVectorLayer layer = QgsVectorLayer('/path/to/shapefile_folder/test.shp', 'test', 'ogr') QgsVectorLayer objects have a method called geometryType. If you call that method for your newly created layer : >>> print layer.geometryType() 2 Where 0 is points, 1 is lines and 2 is polygons


4

Finally found the proper way of running processing algorithms in PyQGIS standalone scripts. This answer is based on answers to Problem with import qgis.core when writing a stand-alone Python script that uses QGIS and to Error: Algorithm not found, which is in turn based on a Qgis-dev mailing-list discussion. I suggest you to follow the work flow given in ...


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

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

I guess the "proper" way is to use QGIS' API which I'd hope would expose that. But I don't know how to do that. An alternative is to look without the shapefile itself. The basics of the specification are on Wikipedia: https://en.wikipedia.org/wiki/Shapefile#Shapefile_shape_format_.28.shp.29 What you want is: bytes 32–35 of the main header which dictates ...


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


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

This answer is based on answers to Problem with import qgis.core when writing a stand-alone Python script that uses QGIS and to How to use QGIS explode lines with Python. I suggest you to follow the work flow given in Problem with import qgis.core when writing a stand-alone Python script that uses QGIS to enable your QGIS libraries in your OSGeo4W Shell. ...


3

I have written a short snippet code with simple syntax, so it will be easy to understand for a beginner. The flow is that you need to get the unique values in the Strings field and then find out whether there are more than one value in the Integers field for this String. If yes - then keep, if no (i.e., the only value was -1) - then delete the row. ...


3

There is an Esri blog post that describes the technique for doing this in detail called If you are stuck at "if" – Part 1: Part 1 – Gives examples of quick and dirty ways of using the Calculate Value tool to create branches using if statements in a model. In your case you want to check for the existence of a feature class rather than a product ...


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

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


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

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


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

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

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


2

Try the following: #!/bin/bash read -p 'Enter country code: ' EXP echo "exporting data from $EXP" echo ogr2ogr -f GeoJSON export.geojson PG:'dbname=alamedaok user=postgres host=localhost' -sql "SELECT id_alameda, pais, geom FROM poblaciones_def WHERE pais = '$EXP'" Notes: read uses the -p parameter to set the prompt You used backquotes (``) in your SQL ...


2

Bash is particular about the quote characters `, ' and ". Use double quotes to substitute the variable in a string like "wonderful $VAR". Also with Bash, the convention is that variables are upper-case, and I'd avoid using export as a variable name since it is a command for environment variables. Consider these changes: #!/bin/bash read -p "enter country ...


2

As the script works for some files and not for others, I suspect the problem is originated somewhere in the data (or handling of special cases in the data). TypeError suggest that you may have a mix of data types. I'm not sure how numpy would handle a mix like that. Have you tried to e.g. float the elevation to make sure they are all float numbers? ...


2

Instead of using PIPE in the subprocess.Popen, you can use a file path to save the output. You can create the path by using the arcpy.CreateScratchName() (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/CreateScratchName/000v0000001z000000/). After the subprocess runs and you have the output in the file, you might set the output parameter ...


2

Yes - to do this I would: Use the extent of the polygon just digitized to Create [a] Fishnet of the same size Use SelectLayerByLocation on the fishnet just created to select those that overlap the polygon geometry that you digitized Use GetCount to count how many of the fishnet cells overlap with the polygon geometry Use an update cursor or CalculateField ...


2

As of ArcGIS 10.2.1 for Desktop, you can use Alter Fields (Data Management) with an Advanced level license to: to rename fields or rename field aliases for any geodatabase table or feature class The same tool became available to Basic and Standard level licenses at ArcGIS 10.2.2 for Desktop.


2

The problem is in your code block. Instead of: def Reclass( !CODE! , !COMPLEX! ): if ( !CODE! == 1.1.7 and !COMPLEX! == 4): return 1.3 elif ( !CODE! == 3.2.0 and !COMPLEX! == 4): return 1.3 else: return 0 try: def Reclass( CODE , COMPLEX ): if ( CODE == "1.1.7" and COMPLEX == 4): return 1.3 elif ( ...



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