Tag Info

Hot answers tagged

6

I would use format instead, since % is probably your wildcard character. def searchHospitals(work,strZip): fc= "Hospital.shp" whereClause= '"ZIPCODE" LIKE'+"'{0}%'".format(strZip) But you can also use double percent signs (%%) in your method: def searchHospitals(work,strZip): fc= "Hospital.shp" whereClause= '"ZIPCODE" LIKE'+"'%s%%'"% ...


4

As stated in the tool documentation for Calculate Field: Python expressions can use the geometry area and length properties with an areal or linear unit to convert the value to a different unit of measure (for example, !shape.length@kilometers!) These expressions are not usable with points or individual coordinates. Fortunately, you can use other ...


2

As requested, comment is appended below as an answer: "Also, is Feature To Polygon designed to work on a layer selection? Perhaps export the layer as a standalone feature class with Copy Features (in memory perhaps) and try running the tool that way. If that doesn't solve it, there are some threads here and here that use arcpy.Geometry.cut() for those who ...


2

I figured it out. Rather than setting up a new variable "params" and holding the multiple parameters to be returned through that, I just simplified it to return the parameters directly as shown below. return [param0, param1] Now it loads the tool up when clicked on with both of the parameters correctly displayed. I guess it's best to keep it simple ...


2

This is calling on the built in map function, which takes a function as the first argument (arcpy.AddError) and telling it to call AddError for every piece of the message split by a new line character. So for example, if the traceback message was this: Error Reading File: File is of the wrong type Needs to be CSV file the raw string would be: ...


2

I think you are seeing that particular error message from this line of your code: arcpy.KMLToLayer_conversion( r"C:\Project\gis\layers" ,r'C:\Project\gis') arcpy.KMLToLayer_conversion expects a file as its first parameter (KML or KMZ) but you are giving it a folder name. You could try concatenating the contents of your filename variable, with the ...


2

I just wanted to point out that just using if not row.Stand may yield undesired results (remember, explicit is better than implicit from the Zen of Python). Take the following example: >>> for i, sample in enumerate(['a',1,None, '', ' ', 0]): if not sample: print 'value "{}" at index {} is empty'.format(sample, i) value "None" at ...


1

The code you require is below: import arcpy # Set workspace arcpy.env.workspace = r"C:\Scratch\fGDB_Scratch.gdb" # This returns a list of FeatureClasses in the top level of the geodatabase fcl = arcpy.ListFeatureClasses("*") # Main loop for fc in fcl: print "Adding fields to " + fc # The "#" inputs mean just use defaults ...


1

Below is the code you require: import arcpy xls = r"C:\Scratch\Book1.xls" table =r"C:\Scratch\tempxls.dbf" arcpy.ExcelToTable_conversion(xls,table) with arcpy.da.SearchCursor(table,["Feature"]) as cursor: for row in cursor: fd = row[0] print "Creating FeatureDataset: " + fd ...


1

As long as your query is structured correctly this should work. I used the da.SearchCursor instead because I noticed you were on 10.2. I also removed work from the function parameters because it wasn't being used anywhere. import arcpy arcpy.env.overwriteOutput = True workspace = "C:\\Users\\Cara\\Documents\\MPSGIS\\Programming and Scripting\\Lab6\\Lab 6 ...


1

There is a problem with your code. if your code goes into this if statement: if lyr.name == "Parcels": then the layerStation will be None (it will not be assigned). Therefore, MakeFeatureLayer will throw an error. the proper code would be: for lyr in myLayers: if lyr.name == "Parcels": print "Parcels have been found." finalLayer = lyr ...


1

The documentation for Near Analysis indicates "NEAR_DISTANCE: The distance between the input and near feature. The value is in the linear unit of the input features coordinate system, or Meters when the Method parameter is set to GEODESIC and the input is in a geographic coordinate system." So my understanding of that statement is: A Geographic Coordinate ...


1

I would suggest using a where clause to lessen the impact of pulling out geometry info that way you are not iterating through the entire table: import arcpy fc = 'c:/base/data.gdb/roads' class_field = 'Road Class' name_field = 'Name' # Create an expression with proper delimiters expression = arcpy.AddFieldDelimiters(fc, name_field) + ' = 2' # Create a ...


1

If your license level allows it, use the Erase Tool. If you license level will not allow it, you can use a reverse mask and then Clip.


1

I do not think that this can be done, and have never come across a requirement for it. My only thought was to try a backspace (\b) so I tried the code below behind a Python script tool: import arcpy arcpy.AddMessage("Doing something ...") arcpy.AddMessage ("\bDone") When I ran it this is what appeared in the tool results dialog:


1

This is an old and long document from the 9.3 Help solved my problem. On right clicking the model and opening the properties, there was the option to use relative paths.


1

If raster fields are not supported for use in an update cursor (see parameter 2 'field_names') you could consider using the Calculate Field (Data Management) tool on your mosaic dataset via arcpy? I just tested on a custom field and it worked as expected.


1

If you really need your layer physically (e.g., saved on your disk), you should follow @Tangnar's advice, but if you want to play with the layer (basically what they are for), there is no such need (since you are testing layer behaviour by a script). Professionally I do not use (never, ever) MakeFeatureLayer_management to create layer in Python scripts but ...


1

So with the help of Branco and FelixIP I repaired my code. Actually I did not need the update layer to be a list at all and I also needed to add the buffer with an arcpy.mapping.AddLayer to be later seen on the layout: if "something.mxd" in path or "otherthing.mxd" in path: if len(arcpy.Describe("myLayer").FIDSet.split('; ')) == 1: mxd ...


1

Expression type needs to be PYTHON_9.3 This code worked for me: from arcpy import * fc = r"C:\test\test.gdb\test" fld = "testfld" shapeFldName = Describe (fc).shapeFieldName CalculateField_management (fc, fld, "!{}!.firstPoint.Z".format (shapeFldName), "PYTHON_9.3") Happy ...


1

I think it is important to make this Q&A cover not just ArcGIS Desktop 10.0, Python 2.7 and Python 3.1, but also to incorporate the latest versions of desktop products from the ArcGIS platform and the Python programming language. For Python support in the (currently) latest desktop products from the ArcGIS platform I think you should consider: ArcGIS ...



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