New answers tagged

0

The problem is detailed in the error, you do not have a adequate spatial analysis license. please see a previous question in gis.stackechange


1

I have found that the error you receieved AttributeError: 'module' object has no attribute 'EnableDataReviewer_Reviewer' occurs in (at least) three situations. You don't have Data Reviewer installed - Data Reviewer is a separate install of ArcGIS Desktop; it is not installed by default. You don't have a Data Reviewer license - it appears that the ...


0

Try using the the VECTORIZE_BITMAP parameter of ExportToSVG arcpy.mapping.ExportToSVG(mxd, 'd:\\maps\\etages.svg', df, 256*30, 256*30, "", "", "", "VECTORIZE_BITMAP")


1

Your error is unrelated to your looping/iteration. To see this try running this code snippet instead: import arcpy lake = "your_lake_layer_or_feature_class" In_Cities = "your_In_Cities_layer_or_feature_class" Near_analysis(lake, In_Cities) and I would expect you to get the same error message. You are receiving that error because there is not a function ...


2

This line desc = arcpy.Describe(fcs) should be desc = arcpy.Describe(fc) - you have fcs which is a list of all files from your CSV, and instead it should be fc for each file one at a time (since you're looping through fcs one at a time in the for fc in fcs: loop). import csv import arcpy from os import path csvpath = r"D:\QAQC\Chk_Rep_File_list.csv" with ...


0

Since you already know what will be your new path, you could simply define it yourself... import os ... result = arcpy.CreateFeatureclass_management(env, fc, arcpy.GetParameterAsText(3),"","","",arcpy.GetParameterAsText(4)) if result.status == 4: newpath = os.path.join(env,fc) arcpy.AddField_management(newpath, "Company", "TEXT") ...


0

Solution: # local variables root_dir = r"path\to\dir" #inside dir a gdb with a FC gdb = os.path.join(root_dir, "gdb2shp.gdb") feature_class = os.path.join(gdb, "FC") # Get list of distinct UTM values utm_field = "UTM_grid" #FC attribute sql_prefix = "DISTINCT {}".format(utm_field) sql_suffix = None distinct_utm = [ i[0] for i in ...


1

I got it working! It wanted the following environment variable set: arcpy.env.maintainSpatialIndex = True Below is a full list of all environment settings that were used. arcpy.env.overwriteOutput = True arcpy.env.outputMFlag = "Same As Input" arcpy.env.outputZFlag = "Same As Input" # Setting XYDomain to "" is the equivalent as "Same As Input" ...


2

I see a couple things going on here. In your first code example you tried to set fc to a list of two feature classes. The listFields function expects a single feature class, not a list. If you wanted to do that, you'd have to iterate through your feature class list. The next big thing I see is that those funny characters that you're trying to get rid of are ...


5

You need to use the str.replace() to replace the characters in your field values. Also needed to put a for fc in fcs: to loop through your shapefiles, and remove the square brackets from around fieldList in your cursor (this is what is giving you the error 'field_names' must be string or non empty sequence of strings) And note the u in front of u"Ü" so ...


1

Yes it's possible to do this in python. Check out the documentation on the Make Query Layer tool http://pro.arcgis.com/en/pro-app/tool-reference/data-management/make-query-layer.htm You can also use the make query table tool (http://pro.arcgis.com/en/pro-app/tool-reference/data-management/make-query-table.htm); if you specify a shape field the query table ...


1

I believe I figured out the issue. Because I had the SearchCursor embedded in the UpdateCursor, and used "row" as the variable in for loops for both cursors there was an issue when I used row.setValue(). Once I changed the UpdateCursor variables to "uRow" from "row", the fields successfully updated.


1

You can get the result of a GP Service in JSON by simply asking for the response format to be returned as JSON. You just need f=json in the request. For example (emphasis added, but removes it from the clickable link), the following will output JSON. JSON Features actually, similiar output to what you'd get when doing your buffer-merge workflow. ...


1

You should be able to just paste the code below into your ArcMap Python console window for it to work, unless you are using a geodatabase in which case you'll need to change the "uniqueIdFieldName" to match your input table's unique id field (like OBJECTID). Like @dslamb said, you will need a field name for a "unique id" in your table. If one "group" has ...


1

One way to do this would be to add an attribute to your polygon layer, say "VALUE", and assign it numeric value of 1000 or more. Then convert the polygon layer to a raster. In arcpy using the spatial analyst module these rasters can be multiplied easily. elevRast = arcpy.Raster("path/elevrast") polyRast = arcpy.Raster("path/polygonraster") resultRast = ...


4

Looks like you're trying to add data to the insert cursor one column at a time. Cursors think about the world one row at time. I recommend the following code. A few other notes... Python code runs in order, so make sure you declare your outpath variable before you set your env.workspace to outpath. Also, this code is going to create a shapefile with the ...


1

You'll need a unique id for each row to distinguish between GEBID's and their area. You could use FID, but this is subject to change when a featureclass is edited (assuming this is a featureclass and not a table of some sort). Assuming you have this unique row ID. You could do something like this. import arcpy gebids = {} #using searchcursor from the da ...


2

I think that this is possible as long as the gp service that you have dumps it as a json and then you can make the call to that output from your JS. See this thread for more info. RESTful Geoprocessing Service Request returns empty Result object without errors


1

Based on your description are you looking for Get Count? Returns the total number of rows for a table. If the input is a layer or table view containing a selected set of records, only the selected records will be counted.


1

If lyr.longName is what you want to use to name your Feature Dataset, then you can just create an empty list fdList = [] and append it with the lyr.longName to pass as FD name later. import arcpy, os mxd = arcpy.mapping.MapDocument("CURRENT") fdList = [] for lyr in arcpy.mapping.ListLayers(mxd): if lyr.isGroupLayer == True: if ...


1

Look at creating a set of valid animal/year values . feed that into the loop. Using arcpy, run frequency analysis on the data, using the two fields as the frequency fields. The resulting rows will be the valid combinations. With a cursor on the table, read the animal/year into your query. freqFields = ['ANIMAL', 'YEAR'] freq = arcpy.Frequency_analysis(data, ...


4

You'll want to use a cursor to figure out the rows that have values that have already occurred four times. Then you can create an SQL and a feature layer or table view with the SQL applied. Finally you can delete rows from the feature layer or table view. Sample code: #Table/shapefile table = r"C:\Users\e1b8\Desktop\E1B8\Workspace\Workspace.gdb\abc123" ...


1

A couple things might be happening here. You have a transparency on the layer (unlikely). You have a stretch type defined in the symbology for the raster. This might be standard deviation: Set it to None and see if that makes any difference.


2

That's because a geodatabase is an Esri object and not a filesystem object. You can't get a creation date of a feature class (even in ArcObjects) but you can get the date of the database that it resides in. The first thing you need to look at is lyr.isBroken, unreferenced layers are broken and trying to get the path from them will cause issues, then check ...


1

First, use a da cursor to make your code 10 times faster. Replace the list with a dictionary where the keys are the streetnames and the value is the sum of all lengths. Then you can write it all back in a single pass of an update cursor. At the same time you can get the OID list and do a single SelectLayerbyAttribute to Copy all the features at once to ...


0

The problem is that you aren't iterating over RoadList: you're essentially doing this each time: >>> "OID = " + str([1,2,3,4]) 'OID = [1, 2, 3, 4]' To change this, you could use a for loop instead: for road in RoadList: query = "STREETNAME = '{}'".format(road) As an alternative approach, there is a GP tool that does this for you very simply: ...


0

So the answer to my original question "Is it possible to have two input feature layers and a derived output feature layer in an ArcGIS Python Toolbox tool?" is of course yes. Finally got the Python Toolbox to work. Was a combination of parts of my code not being indented correctly and working out the correct input and output tools in model builder to ...


1

The output parameter, when I've used it, seems to really only work to add the output as a layer to the map document the tool has been called in. I noticed something that may be giving you errors in your code: if parameters[0].altered: parameters[1].value = arcpy.ValidateFieldName(parameters[1].value, parameters[0].value) parameter[1] is equivalent ...


3

You have some repeating processes that could probably be rearranged. It may help with speed. Clearing all the layers' selections could be done at the beginning of the loop instead of within each if/else statement Edit (this may slow down the process since the clear selection happens every iteration): if count == 1: with arcpy.da.SearchCursor(table, ...


0

I've modified the code I provided originally, hopefully with what you need. I'm using the da module, and switched the list to a dictionary where the keys are the street name and value is a list of the ids. I think you were primarily missing the first id whenever it switched over to a new street. streetlist = {} with ...


1

Based off your code, it sounds like you're trying to disable a button rather than an entire toolbar. Instead of WTF_toolbar.enabled = False do fish_button.enabled = False to disable the button. Same goes for WTF_toolbar.enabled = True. More info here


-1

I find the answer : Need to do MakeFeatureLayer_management dataFrame = arcpy.mapping.ListDataFrames(Mxd)[0] Layers=arcpy.mapping.ListLayers(Mxd, "", dataFrame)[0] for layer in dataFrame: Layers=arcpy.mapping.ListLayers(Mxd, "", dataFrame)[0] if Layers.name=="Signs": arcpy.MakeFeatureLayer_management(layer,"Signs_Shape_layer") ...


1

Your layer needs to refer to the layer in your MXD, not the path to the feature class. layer = "Layer In MXD" desc = arcpy.Describe(layer) selected = desc.FIDSet print (selected) desc.Fidset will return the ObjectIDs of the selected features mxd = arcpy.mapping.MapDocument("CURRENT") dataFrame = arcpy.mapping.ListDataFrames(mxd)[0] layers = ...


7

The reason it works inside your module is that you are passing each feature class (fc) into your function. If you look carefully you can see that the line: fcname = fc is redundant. Here you are essentially reassigning the feature class to the variable fcname and then not using it i.e. checkfields = FieldExists(fc, fieldname) # you are still passing fc ...


7

In your main script you have switched a couple of parameters around. In the first line of your for loop you have fc = fcname and it should read fcname = fc import arcpy from arcpy import env arcpy.env.workspace = "C:/EsriPress/Python/Data/Final/Scratch.gdb" import final_functions fclist = arcpy.ListFeatureClasses('Fire*') for fc in fclist: fcname = fc ...


1

The following would do it with your directories: import arcpy InWork = ["D:\\GIS_Temp\Folder A", "D:\\GIS_Temp\\Folder"] for ws in InWork: arcpy.env.workspace = ws datasets = arcpy.ListFeatureClasses() for fc in datasets: newName = fc.replace(' ','_') arcpy.Rename_management(fc, newName[:-4]) Note the [:-4], which I do to ...


2

The line os.path.join is throwing the error. This can be fixed by changing that line to fullPath = os.path.join(workSpace, lyr.name) although personally I'd remove it and use the following: mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, '')[0] workSpace = r"J:\foo\bar\test.gdb" for lyr in ...


2

I would use Rename_management to make sure you get all the parts to the shape file: import os, sys, arcpy InWork = sys.argv[1] # this script designed to be used as a tool, replace with a path if you wish arcpy.env.workspace = InWork for thisFC in arcpy.ListFeatureClasses(): newName = thisFC.replace(" ","_") arcpy.Rename_management(thisFC,newName) ...


2

It would be helpful if you gave more details about the contents of your CSV file (is there more than one line?) and about what error you are seeing. The main issue I see with your code is that you are making the variable fcs a list, and the arcpy tool you call is looking for a single input object. Passing a list might cause an error (I am not sure as you do ...


0

I have a workaround I've been using in production for 2 years. Not pretty, but works reliably. In your py script you call a batch file which gets a string of user input and writes it to a temp text file. Then python reads that file. The batch file (getInput.bat): @ echo off REM Takes a single line of user input and writes it to an ascii file. More ...


4

You can try to use a python script and use one of the two following modules. But think of it carefully as running a program out of a script can do many unpleasent things. import subprocess subprocess.call(['C:\\folder\\gams.exe']) import os os.system('"C:\\folder\\gams.exe"') Update as it is about a file of the type .gms: Check out the answers on this ...


0

I figured it out- I used a da.updateCursor with an SQL query- import arcpy from arcpy import env env.overwriteOutput = True arcpy.env.workspace = "F:/EMILY/TEST/GET_TYPE_TEST/" infc = "SpJoinscript.shp" with arcpy.da.UpdateCursor(infc, "TYPE_1", "TYPE_1=''") as cursor: for row in cursor: row[0] = "OFF_ROAD" cursor.updateRow(row) ...


0

If the field is empty (or NULL), the thing to test is whether the field is None. Try changing the if row.TYPE_1 == "": to if row.TYPE_1 is None:


2

You can try something like this (see also @radouxju's comment): import arcpy pt = r"C:\AIS\Density_Grid_test.gdb\PivotTable" flist = arcpy.ListFields(pt, "*ShipTypeGroup*") for f in flist: arcpy.AddField_management(pt, f.name.replace("ShipTypeGroup","Ave_STG"),"DOUBLE") newflist = arcpy.ListFields(pt, "*Ave_STG*") for nf in newflist: ...


0

You can simplify your code somewhat by using: df = self.mxd.activeDataFrame layer = r'G:\Gis\DATEN\wvdat\Querbauwerke\Fischaufstieg.lyr' if arcpy.Exists(layer): layerToAdd = arcpy.mapping.Layer(layer) arcpy.mapping.AddLayer(df, layerToAdd, 'TOP') else: warningButton = pythonaddins.MessageBox("warning") You might also want to set the mxd ...


2

Why not just do the following instead of doing it under a nested loop: import arcpy pt = r"C:\AIS\Density_Grid_test.gdb\PivotTable" arcpy.AddField_management(pt, "Ave_STG", "DOUBLE") arcpy.CalculateField_management(pt, "Ave_STG", "!ShipTypeGroup! / 12", "PYTHON_9.3") or you could try doing it with an UpdateCursor import arcpy pt = ...


0

You could try something like this: import os import arcpy arcpy.env.overwriteOutput = 1 output_folder = r"full_path_to_folder" fc = r"full_path_to_feature_class" fields = ["OID@","SHAPE@","UTM_GRID"] #modify as required template_fc = r"full_path_to_template_schema" #with fields you want to keep - they should also be in the field list above fc_data = ...


2

You've swapped usage of quotes in your Python snippet. Instead of passing in a quoted field name, you've supplied a string literal, ie "KOD5" <> 'KOD5_1'. You need to change the quoting so that the second field name is quoted with double quotes instead: # select areals without no change if change == "Exclude": where_clause = '"' + field_initial + ...


2

There is a Help page entitled Understanding script tool parameters that explains how to do this. You configure the Parameters on the tool dialog and then get them within your script using either arcpy.GetParameter() or arcpy.GetParameterAsText().


0

Here is a script that would achieve it: import arcpy import os arcpy.env.workspace = r"D:\Test\Data_Points" Buffers = arcpy.ListFeatureClasses() out = r'D:\Test\data.gdb' for buff in Buffers: arcpy.Buffer_analysis(buff, os.path.join(out,buff[:-4] + '_buffer'), '20 kilometers') print 'done' This script takes all shapefiles from directory, buffers ...



Top 50 recent answers are included