New answers tagged

0

I didn't really manage to work out field mappings entirely, but someoene did post an insert cursor solution that I experimented with and managed to get it to work. Thank you to that mysterious person who looks like they have disappeared. So far this seems to be working (I think) the external mapping sheet looks something like this: and the code that loops ...


4

Try this: import arcpy infc = r"E:/gis payannameh/Pychram_tabu/extractVP/net1.shp" arcpy.AddField_management(in_table=infc, field_name="Qi", field_type="DOUBLE") arcpy.CalculateField_management(in_table=infc, field="Qi", expression='!RASTERVALUE!', expression_type="PYTHON") I almost never use Calculate ...


1

Better later than never. If your desired color scheme is not available, you can create one manually, save it, and then call it in your script. For example, here's what I did to get a Red to Yellow scheme (which didn't exist) in a graduated colors ramp using ArcGIS Pro 2.8.0: 1.) Symbology pane --> Color Scheme drop down --> Format color scheme... 2.) ...


2

You have an error in your code where you are supplying your coordinates in the sequence of Latitude (Y) then Longitude (X). Look at the tool's help page and you we see that the tool requires Longitude (X) then Latitude (Y). My test data was a folder of just one csv so you'll need to adjust your code accordingly, but this worked for me: import arcpy arcpy.env....


0

There is no need for arcpy: import os import pandas as pd mainfolder = r'C:\GIS\data\testdata' drop_column = 'CRY' for root, folder, files in os.walk(mainfolder): #Will include all subfolders. If you dont want this use os.listdir for file in files: fullname = os.path.join(root, file) if os.path.isfile(fullname) and file.endswith('.xlsx')...


1

BERA's answer can also be used directly in the field calculator : len([val for val in [!MAN_1!,!MAN_2!,!MAN_3!] if val is not None]) Note that this works that your "null" are No Data value and not the text "null". Alternatively, as you have a small list of workers and no risk of typographic errors because of the use of a drop down list, ...


2

Using cursors seems to work: import arcpy fc = r'C:\folder\data.gdb\featureclass' fields = ['MAN_1','MAN_2','MAN_3','TOTAL_MANPOWER'] with arcpy.da.UpdateCursor(fc, fields) as cursor: for row in cursor: row[3] = len([val for val in row[:3] if val is not None]) cursor.updateRow(row)


0

The refreshing of a linked Word document does not automatically happen as you have discovered and stated in the KB document. Amazingly this was reported in 2016 and ESRI have still (and I guess highly unlikely) not fixed it. But all it not lost! I experimented with some code, running it in the Python console in Arcmap and I managed to get the layout linked ...


1

If you read the help file for graduated symbols the first paragraph under the discussion section states there is no mechanism for changing a symbol in ArcMap, you need to apply an existing symbology to the entire layer, you cannot drill down to a single symbol and tweak it. As suggested by @MichaelStimson use the apply symbology tool.


4

This is the case when scripting is massive overkill, because: arcpy.Intersect_analysis("buffer #;fish_net #","in_memory/isect", "ONLY_FID") arcpy.Dissolve_management("isect", "in_memory/dissolve", dissolve_field="FID_fish_net") Does the job in no time:


0

As commented by @Hornbydd: You cannot remove that button. Just accept it is there and provide decent parameter help through it's item description to guide the user.


4

This should work - it finds the polygon that intersects with the buffer centroid, and finds the intersection only of the polygon that contains the buffer centroid. Not tested. Please note that this will modify your data in place, so make a copy. import arcpy polygon_geom_list = [] buffers = r'C:\path_to_your_buffer_layer' polys = r'C:\...


4

I have had problems loosing the objectid field (which I needed for joins) when copying data from a server. What solved my problem was using featuresets and recordsets: import arcpy, os connection_file = r"D:\folder\connectiontoserver.sde" local_fgdb = r'D:\download\data.gdb' list_of_tables = ['table1','table2'] for t in list_of_tables: ...


0

As commented by @Aaron: It looks like you need to define a valid output featureclass in the merge tool. It appears as if you are defining an output directory rather than an output featureclass.


1

Use Split by attributes: Splits an input dataset by unique attributes.


1

arcpy requires ArcGIS Pro and cannot be used without a full ArcGIS Pro install. However, you can install and use the the ArcGIS API for Python as per the documentation you linked to, but note that this is not arcpy. The API will have some additional functionality if arcpy is installed, but it is not required. You're trying to create a virtualenv, but you ...


0

I tested 3 lines: 2D, 3D with values and 3D with z values set to NULL. Espression !Shape!.firstPoint.Z returned NULL for 2D line only: So, it's Ok to use z value from first point.


0

I don't know if my answer will help you at all, but I'll offer you my "solution" to field mapping... I routinely download address points (and many other layers) from multiple different counties, and combine/merge them together to make a set of "Regional Address Points". Of course, each county has a different field schema and so if you do ...


0

** I used this simple script and it worked for me>>>** the most important thing is to create {{{{{Graph.grf or .tee}}}} from the same files(and fields) on which you want to run the script. import arcpy # Graph Variables out_graph_name = "VerticalBarGraph" out_graph_bmp = "VerticalBarGraph13.bmp" input_template = &...


1

Maybe the updatecursor is blocking the insertcursor from inserting new rows? You dont seem to use it for updating records so you might aswell replace da.UpdateCursor with da.SearchCursor: ... cur2 = arcpy.da.InsertCursor('JustEstimates', ['FID','PRICEEST']) with arcpy.da.SearchCursor(feature1, ['IN_FID','ESTPRICE']) as cur: for row in cur: if ...


2

I think you are mixing SQL, VB and python syntax. Use python parser and: Pre-Logic: def reclass(siteclass): if 'ST' in siteclass: val = "Optimal" elif 'WT' in siteclass: val = "SubSuitable" else: val = "Unsuitable" return val Call with MACSITE_CL= reclass(!SITE_CLASS!)


1

execute is called when you click the run button, not when the tool loads. Set params 1-6 enabled = False in getParameterInfo initially. getParameterInfo is called automatically, don't call it yourself updateParameters and updateMessages are passed a positional parameters argument by ArcGIS, your method def needs to accept this. You don't return the params, ...


2

You create a list of layers that are of type point and you feed that into the the select by location tool with an additive selection. If you review the help file for the Select by Location tool the parameter setting "SHARE_A_LINE_SEGMENT_WITH" works only with lines (read the relationship section) so frankly I'm surprised you get any selection. If ...


0

You'll need to have the admin provide a key that you can add to the end of the URL, something that looks like this: https://gis.somewebsite.com/geoserver/wfs?authkey=ABCDEFGHIJKLMNOP1234567890...


4

I tried on a Mosaic Dataset stored on an external hard-drive (40k rasters). This seems fastest: Followed by: aSet = set(row[0] for row in arcpy.da.TableToNumPyArray(r"NORTHLAND_MosaicLayer\Footprint","OID@")) Note my AOI layer made up from 2945 polygons made of 1779853 (1.8M!) points.


0

The problem was that I had projected my shapefile to the projection of my raster files (NetCDF). But the raster files did not have any projected coordinate system (only contained Geographic Coordinate!). So, I solved it the other way. Now before doing the zonal statistics, I project each raster into my shapefile projection that contains both GCS and PCS, ...


2

You can use cursors like this: import arcpy fc = r'C:\folder\data.gdb\featureclass' #Change to your data source fields = ['AREA','SUM','Ratio'] totsum = sum([row[0] for row in arcpy.da.SearchCursor(fc, fields[0])]) #List all values in area field and sum them #Update/calculate sum and ratio fields with arcpy.da.UpdateCursor(fc, fields) as cursor: for ...


2

List all object ids, then iterate over these and select: import arcpy fc = r'C:\data.gdb\featureclass' arcpy.MakeFeatureLayer_management(in_features=fc, out_layer='lyr') oids = [oid[0] for oid in arcpy.da.SearchCursor(fc,'OID@')] oidfield = arcpy.Describe(fc).OIDFieldName() def chunker(seq, size): return (seq[pos:pos + size] for pos in range(0, len(...


3

The python range function lets you choose a step size: >>> list(range(1,10001,1000)) [1, 1001, 2001, 3001, 4001, 5001, 6001, 7001, 8001, 9001] So loop over that and select attributes from N to N+1000: for N in range(1, NMAX, 1000): clear_selection() for I in range(1000): select_attribute(N+I) # now we've got 1000 selected features ...


0

I think you should do it in batches, so output of these: for shapefile in folder: if shapefile.endswith(".shp"): shape_location = os.path.join(folder, shapefile) shapelist.append(shape_location) Merge(shapelist,in_memory/MERGED_BUFFERS") FeatureToPolygon("MERGED_BUFFERS", "INDIV_POLYGONS") FeatureToPoint(...


0

The below will take either shapefile or feature class (or a mixture of), and convert to feature class in defined gdb, adding the additional naming to the end as per user input. Code commented. import arcpy ## input features fcList = arcpy.GetParameterAsText(0) ## output geodatabase outFC_Dir = arcpy.GetParameterAsText(1) ## text to append onto input layer ...


1

Use ListFields with sets: import arcpy fc = r'C:\folder\file.shp' all_fields = {f.name for f in arcpy.ListFields(fc)} #Create a set of all fieldnames if {'Northing','Easting'}.issubset(all_fields): print 'All fields are here' else: print 'Field(s) are missing' Or simply: all_fields = [f.name for f in arcpy.ListFields(fc)] for fieldname in ['...


2

The basic scripting logic would be: Use your point in a select by location tool, this would select 1 or more polygons. Use a search cursor to step over that selection and extract the information you require If you actually scroll to the bottom of the help pages for these tools you can see examples of how to use them in a python script.


1

The error is telling you that you cant assign (=) your string (the output path) to the the save method of a raster object. The correct syntax for saving a raster object is: my_kriging.save(r'C:\path\to\database.gdb\rastername')


0

Check out the post by JeffreyBurka at the bottom of the thread here: https://community.esri.com/t5/modelbuilder-questions/calculate-and-use-extent-of-feature-class-in-model/m-p/1087260#M3476


2

Since we need to compile a list of IDs for an SQL IN operator anyway, let's use that string as the comparison basis to generate the unique lists... import random import arcpy numSets = 100 setSize = 20 sourceFC = r'D:\gis_se\pick49.shp' outputGDB = r'D:\gis_se\picked.gdb' # Extract all IDs rawIDs = sorted([row[0] for row in arcpy.da.SearchCursor(...


1

Here is an alternative approach in ModelBuilder requiring almost no code that creates the random subsets: The Data: The Model: The results (from just 5 iterations as way of an example): The key to this model is using the point data itself as a constraint and seeding the random number generator on each iteration. Note that the output of the calculate ...


2

This might not be what you are asking, if so let me know. This will select 20 random points 20 times with no repeats: import arcpy, random arcpy.env.overwriteOutput=True fc = r'C:\GIS\ArcMap_default_folder\Default.gdb\jl_riks_Intersect' oidfield = arcpy.Describe(fc).OIDFieldName alloids = [row[0] for row in arcpy.da.SearchCursor(fc,'OID@')] #List all ...


-1

This approach helped. for item in street_names: in_data = arcpy.management.SelectLayerByAttribute(self.street, "ADD_TO_SELECTION", "ST_NAME1 ='{}'".format(item) or "Remark1 ='{}'".format(item) or "ST_NAME2 ='{}'".format(item) or "Remark2 ='{}'".format(item) or "ST_NAME3 ='{}'".format(item) or "...


1

I usually use AddFieldDelimiters and format: import arcpy arcpy.env.workspace = r'C:\GIS\ArcMap_default_folder\Default.gdb' feature_class = 'ak_riks' field_to_select_by = 'OBJECTID' sql = "{0} IN (132, 254)".format(arcpy.AddFieldDelimiters(datasource=feature_class, field=field_to_select_by)) arcpy.MakeFeatureLayer_management(in_features=...


0

You need to access the result of the GetCount tool - https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/get-count.htm count = arcpy.GetCount_management("pipe").getOutput(0))


1

I have achieved similar in the past with the below code. I have commented but let me know if anything needs clarification. Basically it uses a combination of the AGOL Python API and ArcPy to access the feature services and export layers to feature classes in a gdb. from arcgis import GIS import arcpy ## set to True if you want any attachments to also be ...


1

Yes, da.SearchCursor SearchCursor establishes read-only access to the records returned from a feature class or table. It returns an iterator of tuples. The order of values in the tuple matches the order of fields specified by the field_names argument. And da.UpdateCursor if you want to update/change values.


Top 50 recent answers are included