Tag Info

New answers tagged

1

import arcpy fcA = "fcA.shp" fcB = "fcB.shp" arcpy.MakeFeatureLayer_management(fcB, "layerfcB") desc = arcpy.Describe(fcA) shapefieldname = desc.ShapeFieldName i=0 with arcpy.SearchCursor(fcA) as cursor: for row in cursor: arcpy.SelectByLocation_management("layerfcB", "within", row.getValue(shapefieldname)) ...


3

Environments aren't propagated from process to process, so changing extent in one won't affect the other at all.


2

Based on your variable, you just need to make sure variables and strings are not confused field_1="!field_name1!" field_2="!field_name2!" arcpy.CalculateField_management("Layer", field_0, field_1 + " / " + field_2, "PYTHON_9.3") note that if you have the strings as variables without the "!", it is nicer to use format() field_1="field_name1" ...


1

Have a search in help for the subject "Performance tips for joining data" it offers advice on improving join performance. Your code does not indicate you have added an attribute index which can often improve performance.


1

You are missing the wrapping exclamation marks, try this: arcpy.CalculateField_management("Layer", field_0, '!' + field_1 + '!/!' + field_2 + '!', "PYTHON_9.3")


1

You have embedded the string variable within a string so python sees it as a string. I would suggest you make you code something like: field_0="field_name0" calcString = "!field_name1! / !field_name2!" arcpy.CalculateField_management("Layer", field_0, calcString', "PYTHON_9.3")


0

I've not done much with labelling with ArcObjects so this may not be relevant or you have tried it already? Have you tried setting IAnnotateLayerProperties.DisplayAnnotation Property?


-1

Can you use Spatial Join to stamp the IDs into the polygons?


1

there is a flipline tool, though it doesn't seem to allow queries on a feature. it may be that you can provide the tool with a feature layer based on the selected attributes. EDIT: As @JasonT mentioned, the flip tool should honor selections, so perhaps use make feature layer with a SQL clause on the features that should be flipped and pass that layer to ...


4

I am not sure if the following will not do the same thing as dissolve, but if I'm correct, it should not. You can use a SearchCursor() to loop through the polygons, get each polygon's geometry, add these as parts on a new polygon geometry object, and use an InsertCursor() to insert this new record. sc = arcpy.SearchCursor("c:/temp/fishnet2.shp") ic = ...


0

The workaround that I used is to sort an old-fashioned UpdateCursor, since a da.UpdateCursor cannot be sorted. sql = """"StartTime" IS NOT NULL""" rows = arcpy.UpdateCursor(fcStops, sql, "", "", "StartTime") for row in rows: if row.getValue("AssignedTech") == Technician: row.setValue("VisitOrder", counter) rows.updateRow(row) ...


1

The only types of layers you can add to an mxd with arcpy.mapping are map layers (layers in an mxd), and layer files (.lyr). A feature layer (in-memory layer) you create using the Make Feature Layer tool is not valid. In addition, Make Feature Layer doesn't accept topologies as input (a topology is a dataset, not a feature class). You can export a ...


1

Got it figured out! Thanks to @Aaron's comments I was able to find a conversion: dMeanRatio2 = numpy.asscalar(dMeanRatio)


2

No it is not possible to add "Folder Connections" using Arcpy. Folder Connections are stored in the ArcCatalog.gx file, which is typically located at c:\Users\*username*\AppData\Roaming\ESRI\*Desktopverion*\ArcCatalog\ArcCatalog.gx This is a binary file, so forget about editing it. The only thing you could possibly do is to create the Folder ...


1

I'm not sure why, it must be some memory issue, but you need to use the full file path to the feature class you are creating the feature layer on. So for fcStops, put the full file path, not just the layer name from ArcMap. I tested it on my machine, and it failed with the same error when I used the layer in the TOC, but worked fine when I used the full ...


2

I went with simply installing the manager pip-Win. It will install pip and virtualenv for you. Then it can identify your python installations (or you can browse to a specific python.exe to add more) and take care of all of your pip execution and package maintenance. https://sites.google.com/site/pydatalog/python/pip-for-windows Very important warning: ...


2

You might notice that when you manually change between Data View and Layout view, the scale changes. I would suggest changing to Layout view before you set the scale i.e. something like: mxd.activeView='PAGE_LAYOUT' df.zoomToSelectedFeatures(); df.scale = 2400.0


1

There is no guarantee that a model exported to Python will run without debugging and, depending on your model's complexity, that debugging effort could be considerable. I would wrap your model into a very short Python script that consists of little more than arcpy.ImportToolbox(). For example, if you have a TestModel (without an alias) in ...


2

ListRasters will list the rasters in your workspace. ListLayers will list the rasters in a map document. rasters = arcpy.mapping.ListLayers(MXD, "", DF) for raster in rasters: #do work Use the wildcard argument to limit your results.


2

EDIT : I assume that you have a correct list of rasters, you can check this using print(raster) you need to save your raster at each iteration in order to persist it. Note that it is not necessary to use the mxd. outMeasurement = "PERCENT_RISE" zFactor = 1 arcpy.env.workspace = in_workspace #note that it is recommended to avoid spaces in your ...


1

An else on a for loop doesn't work like that. for row in theseRows: # do interesting work else: print "No rows found" will always print "No rows found" as long as no break was encountered in the for loop. A For on an empty list is still a non-breaking For. Something like this would work: flag = False for row in theseRows: flag = True # ...


4

You can't get this information as the Python script will block until the tool has finished running.


2

Well I figured it out. I ran a repair geometry on the input polygon feature class. Problem solved. I should have tried that first!


1

As stated in the comments, the Con tool uses the '&' operator, not 'and'. Edit: to clarify, 'and' also worked up until ArcGIS 9.3 (map algebra operators).


0

The script will return an array of point objects for each part (returned by the GetPart method) for each record in the feature class. The number of points returned is not defined by any tolerance; the array will contain all the vertices that make up that polygon part. The only way to get more points would be to place them on the existing lines, which (if ...


0

Whenever I have seen this option grayed out it is because the shapefile (or feature class) does not have a spatial index. To address this from a script I would use the Add Spatial Index (Data Management) tool. To do it on every shapefile (feature class) I would use arcpy.da.Walk to visit every workspace and run the tool on any shapefiles (feature classes) ...


2

Situations requiring edit sessions: Feature classes participating in a topology Feature classes participating in a geometric network Versioned datasets in ArcSDE geodatabases Some object and feature classes with class extensions I'd say you need to start an edit session, and save the edits before you do the append. The Editor class allows use of ...


2

It looks like you need to set a temporary alias on your toolbox (or a permanent one via its Properties) as described in the Help for ImportToolbox (arcpy): If the toolbox does not have an alias, the module_name is required. When a tool is accessed through the ArcPy site package, the toolbox alias where the tool is contained is a required suffix ...


0

You have not included the version of ArcGIS for Desktop that you are using but the error message you are seeing is consistent with it being ArcGIS Desktop 10.0 because the listLegendItemLayers method was only added to the LegendElement Class at ArcGIS 10.1 for Desktop. I am not aware of any workaround to doing this at 10.0 so I recommend upgrading to 10.1 ...


0

Maybe replace : legend = arcpy.mapping.ListLayoutElements(mxd,"LEGEND_ELEMENT")[0] for lyr in legend.listLegendItemLayers(): With the following: legend = arcpy.mapping.ListLayoutElements(mxd,"LEGEND_ELEMENT")[0] legendObject = legend[0] for lyr in legendObject.listLegendItemLayers(): I believe, possibly, that the legend object you've created by ...


0

I have a similar problem but because my process is iterative, I can have it easier by reusing the path and updating the feature every iteration. I also coded the program to be a standalone python rather than trying to run it inside arcGIS. I've basically coded everything into its own function, so for example, the part where I solve and export the OD table ...


2

You can use the else block on a for loop: theseRows = arcpy.SearchCursor(table, query) for row in theseRows: # do interesting work else: print "No rows found"


2

Try using ... set rows = arcpy.UpdateCursor("qcPoints") instead of setting rows to qcPoints_lyr. You should be able to do away with the Append that way. I thought that might work and it sounds like you confirmed it. MakeFeatureLayer is needed for doing selections but you don't need to set your updateCursor to the output.


0

I do not know how this will be done by script, but if you have a vector data and want it in a text file or in excel format then: Add layer in ArcMap Open attribute table Select all the features and from right click you select copy features and paste them in excel or word file.


2

If you don't already have this set, I would setup the Geoprocessing Options like so: Also, you could always programmatically close the ArcMap document and open it up again. You could do this from python or even a .bat script. Edit: From this thread, it appears that you can disable logging via arcpy.gp.logHistory = False but it doesn't appear to have any ...


1

You may use ListWorkspaces method (once you make the connection) to list the existing databases within SDE: Lists all of the workspaces within the set workspace. Search conditions can be specified for the workspace name and workspace type to limit the list that is returned. workspaces = arcpy.ListWorkspaces("*", "SDE") for workspace in ...


3

Sort of, but the final JSON have to be small enough fit in memory (though your sample script has that same restriction). The RecordSet object has a .JSON property so you can roll your own that way too: r = RecordSet(tablePath) with open('out.json', 'w') as out_file: out_file.write(r.JSON)


1

Thank you everyone for your help on this! I knew that this had something to do with how ArcMap performs its internal tool validation and I noticed the hasBeenValidated property for Parameters. I now have my update functions set up as follows and the tool works the way I've wanted it to: def updateParameters(self, parameters): if parameters[2].value == ...


0

I think your only option here is to create a custom global function in which you pass in the toolID as a parameter and then assign a default value to that tool in order to reset it. I haven't tested this and am just writing it off the top of my head, but it should nudge you in the right direction: def resetTool(toolID, defaultValue): toolID.value = ...


0

I don't think you can name your feature classes as those {DC034A5A-77FD-4B9E-BD36-ECDE5ABD576B} for defining variable names in Python code. You should perhaps replace them with a string ("temp_layername"). I would recommend opening manually a GP tool in Network Analyst toolbox > define the parameters > run it > make sure it worked fine > go to Results window ...


2

Update: You can just use filters for this and not bother with tool validation code: See Defining parameters in a Python toolbox use a filter (Applying filters to parameters section). There is a filter type for Feature Classes, against which you can specify Point and Multipoint geometry types. Update 2: If you'd like to customize the filter behavior to ...


-1

i think is ... class ExampleTool(object): """Implementation for Example_addin.tool1 (Tool)""" def __init__(self): self.enabled = True self.shape = "NONE" def onMouseDownMap(self, x, y, button, shift): # My code here, then.. self.enabled = False def deactivate(self): # Do I need to add something ...


0

I have experienced exactly the same problem earlier and was looking for the solution on the Internet. It seems as using pypyodbc library works much better. I was able to publish a GP service and call stored procedures & perform multiple SQL statements obtaining as a result object record sets without any problem. Pypyodbc is a pure Python ODBC interface ...


0

If I understand you correctly, you could use os.walk and remove the folder from dirnames. Python docs show an example of this, similar to what fluidmotion has but within the traversing itself. import os from os.path import join, getsize for root, dirs, files in os.walk('python/Lib/email'): print root, "consumes", print sum(getsize(join(root, name)) ...


1

You can largely avoid opening the reference mxd by using layers. This is generally how arcpy.mapping operates anyways, is through layer files. For example, I have used a workflow which looks something like this: arcpy.MakeFeatureLayer_management - here is where you can subset the data arcpy.SaveToLayerFile_management arcpy.mapping.UpdateLayer - allows you ...


0

maybe a bit clunky, but it seems you could try something like if os.path.split(os.path.dirname(f1))[-1]!='resultfolder': os.remove(f1) so that after glob returns a full path, this would strip off the last directory of the path and compare it with 'resultfolder' - if the directory is different, it would remove the file


1

I think I understand what you are trying to do, but correct me if I am wrong. If I have understood the use case I would not involve Data Driven Pages to do this. I think you are saying that you want to: Export to PDF your layout which has Group 1 elements on it - let's call it Group1.pdf You get hold of Group 1 and move it off the page You get hold of ...


2

You can list text and other graphic elements with arcpy.ListLayoutElements(). This will even give you the option of returning only text elements, graphic elements, mapsurround elements (like north arrow, scale bar). For each of these elements you can set its location by setting the X and Y properties e.g. element.elementPositionX = 12.5. This allows you as ...


3

In his comment, @ian is correct about AddWarning() being useless outside of a tool's execute() method. I think the method you do want is setWarningMessage(). Try this: describe = arcpy.Describe(parameters[0].value) if describe.shapeType in ('Point', 'Multipoint'): # catch point & multipoint parameters[0].setWarningMessage('This is a point feature ...


5

I think it may be as simple as changing this line: describe = arcpy.Describe(parameters[0].value) or maybe describe = arcpy.Describe(parameters[0].valueAsText)



Top 50 recent answers are included