New answers tagged

1

As mikewatt noted in comment the SearchCursor returns a tuple with an entry for each field requested. In your case you only requested a single field ("ReportQueryDate") so you get a tuple with a single item, and that item is of type datetime. So if you print it the row in the for row in cursor: loop you'd see something like: (datetime.datetime(2019, 12,...


0

Given last comment I think this '"Trip_Start_Timestamp" = datetime '2019-06-01 00:00:00'') has incorrect quotes. Try changing to "Trip_Start_Timestamp=timestamp'2019-12-11 00:00:00'" or "Trip_Start_Timestamp=date'2019-12-11 00:00:00'" I don't diff between using date v timestamp, but in Pro the Select By Attributes GP tool used timestamp in the SQL. As ...


1

A KMZ/KML can store multiple geometrie-types. A shapefile just one. I guess that is the reason for the FGDB output (multiple Feature Classes). So the FGDB can theoretically contain a point, line and polygon feature class. With arcpy.ListFeatureClasses and arcpy.FeatureClassToShapefile_conversion a conversion is possible. import arcpy import os def ...


0

We have to separately draw the resulted route back on the map using draw function. ArcGis changes the existing map interactively in order to show the map. my_map.draw(result['routes']['features']['attributes']['geometry']


1

Most probably you are using a reserved word for file geodatabase (https://support.esri.com/en/technical-article/000010906), explained as: Using a reserved word as a column name will return an error indicating that the column name is invalid. Copy/Paste from a data source where the word is not reserved will add a "_" to the end of any table or column ...


1

Get the first element of the tuple as mentioned here: https://stackoverflow.com/questions/32211300/tuple-to-datetime-object The below mentioned code works for me! import arcpy import datetime import time arcpy.env.workspace = r"D:\Data\Alisha\TemplateData\TemplateData\Test\New File Geodatabase.gdb" ptFC = r"D:\Data\Alisha\TemplateData\TemplateData\Test\New ...


1

The KML To Layer tool will always output a File Geodatabase. I don't know why that is, but the documentation for the Output Location says (emphasis mine): Output location: The destination folder for the file geodatabase and layer (.lyr) file. If you need a shapefile, you will need KML To Layer first, and then Copy Features (in the Data Management tools,...


0

What is the python syntax for adding transparent background in PNG export? I used transparent_color ='True' and I get an error as below: TypeError: exportToPNG() got an unexpected keyword argument 'transparent_color' Here the full code: import arcpy, os, sys aprx = arcpy.mp.ArcGISProject(r"D:\Working folder\ArcGIS Pro\THUMBNAILS\THUMBNAIL 800X800.aprx") ...


0

Add the line arcpy.RefreshActiveView() to the end of the script. (Or choose "Refresh" from the "View" menu in ArcMap.) ArcMap does not automatically redraw the map after each and every script command. But it does redraw the map if you move a layer using the GUI Table of Contents, as you've described moving the layers out-of/into the group. The arcpy....


1

You need date at the start of each date and single quotes for its value. You may also need to use 00:00:00 for midnight. Try selecting by attribute in ArcMap first and copying its format. "Trip_Start_Timestamp = date '2019-06-01 00:00:00'"


0

I got a hint from the default esri server printing tool box. This tool box has been in general a source of inspiration, how to handle printing issues. result = arcpy.mp.ConvertWebMapToArcGISProject(webmap) mapView = result.ArcGISProject.listMaps()[0].defaultView dpi = int(result.DPI) #a workaround for now for a bug mapView.exportToPDF("C:\\temp\\export.pdf",...


2

I think you are confusing ArcGIS Pro with where it should look for its data. At the moment you are setting a current workspace (using arcpy.env.workspace), providing full pathnames to feature classes in another workspace, and giving it "SHAPE_START" which it may try to interpret as a layer name. Try this, and I would expect that error to disappear. I am ...


0

As the standalone script is dynamically typed and anticipates the type of the variables, ArcMap is a little more sensitive to variable types. So, the following works: nitrogen_recommendation = (1.6 * float(yieldGoal)) - (organicMatterField * 20.0) - (nitrogenField) - float(pca)


4

Your print() is inside a SearchCursor. In your SearchCursor you also define the variable si for your CalculateField. So you write in CalculateField_management for all features the last si from the SearchCursor. SearchCursor can not modify rows. Try it with an arcpy.da.UpdateCursor(): # not tested fc = "streams.shp" new_field = "Sindex" arcpy....


1

You can't* do this using FeatureVerticesToPoints without writing to an intermediate feature class. You have two options: Use FeatureVerticesToPoints and write to the in_memory workspace, then append: arcpy.management.FeatureVerticesToPoints(input_lines, "in_memory\\output_points", "ALL") arcpy.management.Append("in_memory\\output_points", existing_fc, "...


2

In your tool's 'Parameters' section, you need to select the field parameter ('Nitrogen field'), and then set its 'Obtained From' setting to be the feature class parameter from which the list of fields should be derived ('Soil points').


1

Determined the problem for anyone else running into this issue. I just needed to return the new layer as output, then add that layer to the map. I discovered this by finding a setting selected in ->Project->Options->Geoprocessing "Add output datasets to open map". out_lyr = a_map.listLayers('countries')[0] new_lyr = arcpy.MakeFeatureLayer_management(...


2

I haven't seen any function that accomplish that implemented within arcpy. However, it is a rather simple function and it could look something like: import math def magic_rounding_function(res, n): """ :param res: pixel resolution :param n: arbitrary number :return: nearest multiple of the pixel resolution to n """ return math....


0

You can only do upload to server with tile package file. You need to export tile cache to tpk file. ExportTileCache_management


0

Try passing a polygon object, instead of a list of point objects. You can create a polygon object from your point objects, and then pass that to your insert cursor. See: Polygon class documentation


0

You could clone ArcGispro conda like below: conda creat --name arcgispro --clone="C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3" Then, you could activate this conda env and install spyder on it. conda activate arcgispro conda install spyder


2

Your problem is you're not iterating your cursor so row is never set, you should be using an arcpy.da cursor like: with arcpy.da.SearchCursor(nitrogenStats,"SUM_Value") as nitrogenCursor: for row in nitrogenCursor: totalNitrogen = row[0] break # to ensure we only read the first value exit the loop Or as a one-liner: totalNitrogen = [row[0] ...


0

If I run this tool while using ArcMap 10.3 instead of 10.7 I don't seem to have this issue. I can't seem to find any differences between the clip function from 10.3 to 10.7. I will likely have to contact ESRI support


2

That method cannot be used on a file geodatabase, from the tool help document, see usage statement below: Data must be from a database or an enterprise, workgroup, or desktop geodatabase. This tool does not work with file or personal geodatabases. To add an index to an existing feature class within a geodatabase you may use the Add Attribute Index or ...


0

thanks for all yours suggestions, but I did find the solution on my own. Despite the declaration of the WMS provider about the scale limit (stated at 1:6000) I have put my scale at 1:3000 and the procedure works. Of course it is much slower than expected ... but this is another problem. The second problem I had (the shift in images) was due simply to the ...


0

The arcpy search cursor has an optional SQL query that should be used to limit the rows returned instead of selecting by attribute. To my knowledge the arcpy search cursors will not honor existing selections. So if no SQL query is provided to the search cursor parameter you are searching through the entire table. The documentation can be found here. So ...


0

When creating a vtpk where the service type = True ( not "ONLINE" I guess ), the SRID of the map layer you're using has to be web mercator. Open your file, select the map you're referencing, and change the project properties of the source map to be 3857 Web Mercator Aux Sphere.


1

The tool you mention in your question is GridIndexFeatures_cartography, looking at the tool help you will see that the parameters for the width and height: polygon_width (Optional) Width of the index polygon specifed in either map or page units. If page units are being used the default value is 1 inch. If map units are being used the default is 1 ...


1

So, I believe what you want would be found in the ArcGIS API for Python. There is a "share()" method under the "Item" class. Please have a look at the documentation here and see if this helps. https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.share. If you haven't done so already, you can use Jupyter Notebooks that comes ...


0

In your code you are providing "df" to the data_frame parameter. When you provide this parameter you must also specify a data frame export width and height. Otherwise these values will default to 640 pixel width and 480 pixel height. It is possible this is why you are seeing a shift in your exported images.Compared to when you exported to PNG through the ...


0

There could be two issues here: This line: for field in arcpy.ListFields(lyr.dataSource): this is returning a Field Object which you are adding to list which you then feed into your param[3]. I'm guessing param[3] is of type string? So you need to feed into you uniqueList field.name. Also this line looks odd to me: uniqueList = list(set(field)). field is a ...


3

namE[0] is a string. RemoveLayer method expects a Layer instance. You need to get Layerinstance of layer "No_Work_Done". You should use arcpy.mapping.ListLayers method. This method gives you list of layers as a list of Layer instances, not as a list of strings. When you change the script as follows, the layer will be removed. mxd = arcpy.mapping.MapDocument(...


1

You have a number of issues with your script which will either cause issues now, or will cause issues when you reach Python 3. import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, '')[0] for layer in arcpy.mapping.ListLayers(mxd, None, df): # function variable elimination # Ignore layers without local data ...


1

Here are a few things I want to point out: To assign variables you should use the = operator instead of the == operator (which is a comparison operator). There is no need to specify int nor str. You can refactor your code as you are assigning 0 and 40 multiple times. Your code could look something like: if previousCrop == "Alfalfa: >5 plants/square ...


0

I was encountering this same error with the ArcGIS Pro 'mp' module for Arcpy. I determined that the reason the 'visible' property was not editable was because the layers I was trying to control were inside of a group layer. When I placed them outside of the group layer, I was able to control the 'visible' property successfully. Hope this helps others having ...


1

A few things to outline here: As @Hornbydd mentioned, your indentation after the for loop is messed up. Everything after that loop should be indented, as well as the lines after the if and else statements. Indentation has to be a multiple of four always (each indentation block corresponds to four spaces). For example, your current indentation from lines 10 ...


3

Taking a look at the Kriging tool's documentation I see that "ORDINARY" is not an option for the semi-variogram type in the KrigingModelOrdinary class. SPHERICAL — Spherical semivariogram model. This is the default. CIRCULAR — Circular semivariogram model. EXPONENTIAL — Exponential semivariogram model. GAUSSIAN — Gaussian (or normal distribution) ...


1

To answer yout question about how to set a spatialReference of a polygon layer: arcpy.CreateFeatureclass_management(path, fc, "POLYGON") # arcpy.AddField_management(fc, "NAME", "TEXT") sr = arcpy.SpatialReference("the_name_of_file_of_the_crs") arcpy.DefineProjection_management(fc, sr) This is, what I use to define the spatial reference. It takes a name, ...


2

Closing this question. Word of advice: check you SQL data types, as unsupported types, such as "date" can cause ERROR 999999.


0

I've got an idea what's going on here and I tested it and Bingo! I started ArcMap making sure Geoprocessing Python window was not opened. My addin running that problematic tkFileDialog.askopenfilename() code worked well, no crashes. Checked several times. Then I opened Geoprocessing Python window and tested later code in it (in Python window), it worked ...


1

That code is a good start. Before I go about making recommendations you must be made aware that getting an exact percent is very difficult, the sample to be selected from may not be a multiple of the percent, for example 50% of 3 is 1.5 but you can't have half a feature so it becomes either 1 (int/floor) or 2 (ceil). In order to use any kind of unique field ...


1

import arcpy mxd = arcpy.mapping.MapDocument(r"CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] lyrList = arcpy.mapping.ListLayers(mxd, "", df) for lyr in lyrList: if lyr.supports("dataSource"): fields = arcpy.ListFields(lyr.dataSource) print("{} {}, {}".format(lyr.name, [f.name for f in fields], [f.type for f in fields])) ...


0

I combined some help received here and elsewhere and am using the following as the solution that does exactly what I want in the validator. Thank you, appreciate the advice and tips for thinking like the machine. import arcpy class ToolValidator(object): def __init__(self): self.params = arcpy.GetParameterInfo() def initializeParameters(self): ...


3

The problem is in your code: def updateParameters(self): if self.params[0].value == "Digital Map": self.params[1].value = "No scale required" if self.params[0].value == "Paper Map": self.params[1].filter.list = ["1:10,000", "1:25,000"] return If you think like a computer your initialization sets parameter 0 as "...


0

Your problem is with not having ";" between rasters in your list. Try this: ras_list = ";".join(list_raster) arcpy.MosaicToNewRaster_management (ras_list, output_location, "merged_woody_2013.tif", "","", "", "1", "FIRST", "


0

please check QGIS MST plugin you can take look at code from githubenter link description here as you can see the resulte on GIS i


2

In the ArcGIS Pro Help for arcpy.GetParameterAsText() its Summary is that it: Gets the specified parameter as a text string by its index position from the list of parameters. The way I think of it is that it is the means used to communicate, as text rather than objects, the choices made by an end user from the tool dialog that fronts a Python Script ...


4

The summary on the Esri GetParameterAsText documentation states: Gets the specified parameter as a text string by its index position from the list of parameters. Functionally this allows you to pass arguments to a Python script tool. Script tools allow you to provide custom functionality in a GUI to those who do not want to use Python. The ...


0

I believe that you are using ArcGIS server scripting when in the error it is telling you that the .sd file that was created is meant to be published through portal. See below: 002760: This service definition file was created for a hosted layer and must be uploaded directly to a portal using the portal website or ArcMap . Description The service definition ...


0

I would suggest instead of using Python right off he bat, use the Share as a Service wizard in ArcCatalog. Then Analyze the service. Your scripting does no analyzing. Then when it completes right click the results in the results panel and copy python snippet, then you'll have the script that can be run over and over. If it doesn't run, then clear up the ...


Top 50 recent answers are included