Tag Info

Hot answers tagged

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


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.


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

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

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

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


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


3

The (optional) is added to the interface automatically when you specify that the parameter is optional so it really can't be avoided. You can set all fields as required but default the values to something: Then in the tool if the value is default or nonsensical (not found in file system for example): import arcpy, os, sys Oparam = sys.argv[1] if ...


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

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

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

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

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

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


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


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


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

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

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

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

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


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

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



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