POST
|
the class constructor unittest.TextTestRunner has an argument stream, which can be initialized to sys.stdout. In this case the problem with failing tools does not exist.
... View more
10-30-2023
01:42 AM
|
0
|
0
|
293
|
POST
|
thank you Luke, the situation is like you pointed out.
... View more
10-25-2023
01:26 AM
|
0
|
0
|
329
|
POST
|
In Module FileCount.py I have a simple Python Unittest, which tests that the number of files in current directory is greater than zero, so the test should never fail. import unittest
import pathlib
class Test(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_file_count(self):
self.assertGreater(
len(list(pathlib.Path().cwd().glob('*'))), 0)
pass The Python Tool-Class referencing the Unittest is like: class DemoUnittest(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Demo_Unittest"
self.description = "Execute a Unittest"
self.canRunInBackground = True
def getParameterInfo(self):
"""Define parameter definitions"""
params = None
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
try:
self.result = unittest.TextTestRunner().run(
unittest.TestLoader().loadTestsFromModule(
module = FileCount))
arcpy.AddMessage(self.result)
except Exception as e:
arcpy.AddMessage(str(e))
return True
def postExecute(self, parameters):
arcpy.AddMessage(self.result)
"""This method takes place after outputs are processed and added to the display."""
return When running the Python Tool in ArcGIS Pro I get the following result: So from the screen dump above, I conclude the Unittest performed as expected (OK). But why is ArcGIS Pro telling me erroneously "Failed to execute (DemoUnittest)"? Thank You for your attention.
... View more
10-24-2023
01:35 AM
|
0
|
3
|
442
|
POST
|
From Eclipse I run C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy.bat provided by the Installation of ArcGIS Pro. the following python script: import arcpy
import sys
print(sys.executable)
print(sys.version)
for p in sys.path:
print(p)
for k, v in arcpy.GetInstallInfo().items():
print (k, v)
from argis.gis import GIS # @UnresolvedImport
g = GIS()
g.map()
generates the following Output: C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe 3.5.3 |Continuum Analytics, Inc.| (default, Feb 22 2017, 21:28:42) [MSC v.1900 64 bit (AMD64)] Q:\_EclipseWorkspaces\b.e\Geoprocessing_py3\src\test Q:\_EclipseWorkspaces\b.e\Geoprocessing_py3\src C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\DLLs C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3 C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages C:\Program Files\ArcGIS\Pro\bin C:\Program Files\ArcGIS\Pro\Resources\ArcPy C:\Program Files\ArcGIS\Pro\Resources\ArcToolbox\Scripts C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\future-0.16.0-py3.5.egg C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pytz-2017.2-py3.5.egg C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\setuptools-27.2.0-py3.5.egg C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\sympy-1.0-py3.5.egg C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python35.zip C:\Program Files\ArcGIS\Pro\bin C:\Program Files\ArcGIS\Pro\Resources\ArcPy C:\Program Files\ArcGIS\Pro\Resources\ArcToolbox\Scripts Installer xxxxxx.xxxxx InstallType N/A BuildNumber 8933 InstallDate 18.09.2017 SourceDir Y:\ESRI\ArcGIS_10.5.1\ArcGIS-Pro_2.0\ArcGISPro\ Version 2.0 SPNumber N/A InstallDir c:\program files\arcgis\pro\ InstallTime 16:27:40 SPBuild N/A ProductName ArcGISPro Traceback (most recent call last): File "Q:\_EclipseWorkspaces\b.e\Geoprocessing_py3\src\test\test.py", line 19, in <module> from argis.gis import GIS # @UnresolvedImport ImportError: No module named 'argis' I would like to know if this behaviour is by design or do expecting something impossible? How do I proceed to use the ArcGIS Python API in "classic"-Geoprocessing?
... View more
09-28-2017
07:46 AM
|
0
|
3
|
3273
|
POST
|
Jake, you are right: the FeatureLayer/GetCount recipe has excellent performance. Thank You, Bernhard sde_connection = r'O:\_______.sde' tiles = [u'2710_1253', u'2727_1227', u'2666_1193', u'2780_1170', u'2740_1214', u'2670_1263', u'2737_1235', u'2764_1215', u'2623_1217', u'2621_1190'] if __name__ == '__main__': def f1(): for name in tiles: con = arcpy.ArcSDESQLExecute(sde_connection) n = con.execute('SELECT COUNT (NAME) FROM ISOLINES WHERE NAME = \'{0}\''.format(name)) return def f2(): for name in tiles: arcpy.Delete_management('out_layer') arcpy.MakeFeatureLayer_management(in_features=sde_isolinien_FC, out_layer='out_layer', where_clause='NAME = \'{0}\''.format(name)) n = arcpy.GetCount_management('out_layer').getOutput(0) return r1 = timeit.repeat(stmt='f1()', setup='from __main__ import f1',repeat=5,number=1) r2 = timeit.repeat(stmt='f2()', setup='from __main__ import f2',repeat=5,number=1) print r1 print r2 the output: [2.3578824236148948, 0.663463898293061, 0.6561606928581454, 0.6562781213256437, 0.6874187019173439] [12.34176151757427, 0.5830196624761683, 0.6405659508762618, 0.6435843756744966, 0.5681143976659193]
... View more
09-08-2017
02:35 AM
|
0
|
0
|
1328
|
POST
|
thank you for your reply Luke. So I found a undocumented feature (the working sql_clause=('MAX (NAME)', None))?
... View more
09-06-2017
07:23 AM
|
1
|
1
|
1328
|
POST
|
Joshua thank for your reply. Actually for example "select count(name) from isolines where name='2620_1159'" works perfectly against Oracle. Since I only need to know if there are records or not, the SQL statement select max(name) from isolines where name='2620_1159' is a usefull alternative (by checking for empty results as shown in python below). if [row[0] for row in arcpy.da.SearchCursor(in_table=sde_isolinien_FC, field_names=['NAME', ], where_clause='NAME=\'{0}\''.format(name), sql_clause=('MAX (NAME)', None))][0] is None: print 'empty tile: ', name else: print 'finished tile: ', Name Since both SQL statements are homologous I conclude there is a bug/limitation in arcpy.da.SearchCursor.
... View more
09-06-2017
01:44 AM
|
1
|
7
|
1328
|
POST
|
thank you Jake, and yes creating a intermediate FeatureLayer and counting its features is a usefull alternative
... View more
09-06-2017
12:50 AM
|
0
|
0
|
1328
|
POST
|
Thank You for your reply Christopher, in my opinion getcount is not an optimal solution because of the where_clause, and I am not interested in transfering a possibly large number of features to the arcpy-client.
... View more
09-05-2017
07:14 AM
|
1
|
3
|
1328
|
POST
|
I am working with ArcGIS 10.4.1. The following statement: [row[0] for row in arcpy.da.SearchCursor(in_table=sde_isolinien_FC, field_names=['NAME', ], where_clause='NAME=\'{0}\''.format(name), sql_clause=('COUNT (NAME)', None))] forces c:\Python27\ArcGISx6410.4\python.exe to crash. However, since I am only interested in if there are records or not, the following statement is a workaround: [row[0] for row in arcpy.da.SearchCursor(in_table=sde_isolinien_FC, field_names=['NAME', ], where_clause='NAME=\'{0}\''.format(name), sql_clause=('MAX (NAME)', None)) Is this a error/missunderstanding on my side or a bug in arcpy? Thank You Bernhard
... View more
09-05-2017
06:06 AM
|
0
|
14
|
3837
|
POST
|
If you publish FME's logfile Parameter, maybe with the solution outlined here: http://stackoverflow.com/questions/28348503/python-monitor-a-log-file-non-blocking you could watch FME's growing log-file?
... View more
09-02-2016
05:09 AM
|
0
|
0
|
332
|
POST
|
with ArcGIS 10.2 I obtain: Traceback (most recent call last): File "_____________________\jsonarc.py", line 16, in <module> ln = arcpy.AsShape(esri_json, True) File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\geometries.py", line 164, in AsShape return convertArcObjectToPythonObject(gp.fromEsriJson(geojson_struct)) File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 483, in fromEsriJson return self._gp.FromEsriJson(json) ValueError: Invalid geometry type for method with ArcGIS 10.3 I obtain your result. So thank you Yoshua for helping isolating my Problem.
... View more
08-16-2016
11:06 PM
|
0
|
3
|
866
|
POST
|
I observed, that calling the distanceTo - Method on Polygons containing circular Arcs can cause python.exe to crash without throwing a exception. After processing (linearizing the arcs) the polygon featureclass with: arcpy.Densify_edit(in_features='in_Memory/fc', densification_method='OFFSET', max_deviation=0.001) it is possible to process the featureclass with "distanceTo" without problems. I would like to know if this is a bug or a feature? Are there other options of circumventing the problem? Thank you Bernhard
... View more
08-16-2016
06:04 AM
|
0
|
6
|
2235
|
POST
|
this is very interesting and helpful. thank you Joshua
... View more
08-01-2016
11:14 PM
|
0
|
0
|
952
|
Title | Kudos | Posted |
---|---|---|
1 | 09-06-2017 01:44 AM | |
1 | 09-05-2017 07:14 AM | |
1 | 09-06-2017 07:23 AM |
Online Status |
Offline
|
Date Last Visited |
10-30-2023
09:43 AM
|