|
POST
|
I have a somewhat long python script (run as a geoprocessing tool from Toolbox) and I am not getting any errors during or completion of the script execution and all outcome is correct. However, when shutting down ArcMap 10.1, I get a C++ Runtime Library Error that pops up immediately after it closes. Is there anything common that would cause this? (not releasing references, database connections not closed, etc...) Or has anyone experienced this and what process you went through to uncover the offender? TIA! [ATTACH=CONFIG]25312[/ATTACH]
... View more
06-17-2013
10:10 AM
|
0
|
1
|
1435
|
|
POST
|
Hi Matt -- I verified the same thing you are experiencing. Ran from a Toolbox script and it did not uncheck th SpatialAnalyst extension in the Customize-->Extensions dialog. Not sure how to remedy this. Sorry I am not much help on this one! j
... View more
06-17-2013
07:42 AM
|
0
|
0
|
2495
|
|
POST
|
I am unsure about loggin file usage, but you should be able to set up a simple if...else statement to check for availability, peform the nececssary processing and finally check the extension back in.
### see if spatial analyst extension is available for use
availability = arcpy.CheckExtension("Spatial")
if availability=="Available":
arcpy.CheckOutExtension("Spatial")
arcpy.AddMessage("SA Extension Checked out")
else:
arcpy.AddError("%s extension is not available (%s)"%("Spatial Analyst Extension",availability))
arcpy.AddError("Please ask someone who has it checked out but not using to turn off the extension")
return
#depending upon where this is located, you could also use sys.Exit() or pass/continue
#.... do the necessary processing with the extension
arcpy.CheckInExtension("Spatial")
arcpy.AddMessage("SA Checked back in")
... View more
06-17-2013
03:17 AM
|
0
|
0
|
2495
|
|
POST
|
It is a date type but that did not work, I got a null value Add another "datetime" to the line: #current date
d1 = datetime.datetime.today()
print str(d1) I get: 2013-06-13 16:04:42.57100
... View more
06-13-2013
12:05 PM
|
0
|
0
|
3244
|
|
POST
|
Thank you James, but I tried your code and I get a null value for the date field. I am not sure if the calculate field management method is recognizing as a string, a real expression. Here is my code
#Calculate Date Field
import time
import datetime
#current date
d1 = datetime.today()
_currdate = datetime.strftime(d1, "%Y-%m-%d")
arcpy.CalculateField_management("Boundary", "Date", _currdate, "PYTHON")
If it is a date type field, then just use d1 variable in your calculate process. arcpy.CalculateField_management("Boundary", "Date", d1, "PYTHON")
... View more
06-13-2013
11:20 AM
|
0
|
0
|
3244
|
|
POST
|
I am not entirely clear on what the issue is and what your desired result should be, but here is how you get a current date #current date d1 = datetime.today() _currdate = datetime.strftime(d1, "%Y-%m-%d") #date of 15 days ago from the current date d2 = d1 - timedelta(15) _pastdate = datetime.strftime(d2, "%Y-%m-%d")
... View more
06-13-2013
10:07 AM
|
2
|
6
|
7619
|
|
POST
|
I think I've angered the GIS gods...
arcpy.da.FeatureClassToNumPyArray(ODCM_LYR, "*")
Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> RuntimeError: cannot open 'C:\ArcGIS\SYSTEM\COF\Data\BG2Branches.lyr' Is there a BG2Branches Feature Class (not a .lyr)?
... View more
06-11-2013
11:52 AM
|
0
|
0
|
2262
|
|
POST
|
Hey James, any insight is useful. The ODCM_Table should just be holding the result object from the OD Cost Matrix in Network Analyst. The OD Cost Matrix analysis layer 'outNALayer' is composed of six network analyst classes, one of which is 'Lines' which stores the path information, like Total Length from Origin to Destination. So really the question here is how can I convert the an NA Class to a Table, or Feature Layer outside of an ArcMap Session. It doesn't seem possible. There is a FeatureClassToNumPyArray function (http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000015000000) that you could try to pass in this NA Class as it accepts a feature class, layer, table, or table view as input parameter. In my previous example, just replace arcpy.da.TableToNumPyArray with this FeatureClassToNumPyArray. Are you writing this outNALayer to disk somewhere? Just specifiy this as the input FeatureLayer rather than how you have it in your OP: outNALayer = outNALayer.getOutput(0) Again, sorry if this is way off. I guess worth a try though.
... View more
06-11-2013
11:08 AM
|
0
|
0
|
3173
|
|
POST
|
I have a table being returned from the Network Analyst OD Cost Matrix... I want to convert the result object to a GDB Table and I tried using this..
ODCM_Table = arcpy.na.Solve(outNALayer) #Solves the Origin-Destination Cost Matrix and produces the ODCM_Table
arcpy.TableToTable_conversion(ODCM_Table, workspace + "\Default.gdb", "ODCM") # Thought this should convert result to GDB Table
But it throws an error: Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\conversion.py", line 1904, in TableToTable raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Rows: Dataset GPL0 does not exist or is not supported Failed to execute (TableToTable). I thought maybe the cause of the error was the formatting of the result object being held on the 'ODCM_Table' variable, so I printed it to see what it returns...
print ODCM_Table
GPL0
No problem I can see there. So how can I convert this result object to an actual table? I'm not sure what your source table is (.dbf?), but another possible solution is to convert this source into a NumPyArray first then convert this nparray into a gdb table. This could very easily be done by implementing arcpy.da.TableToNumPyArray (http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000018000000), then issue arcpy.da.NumPyArrayToTable on that nparray (http://resources.arcgis.com/en/help/main/10.1/index.html#/NumPyArrayToTable/018w00000016000000/). I tested this with a dbf table (numpytab_out.dbf) and converted it to the Default.gdb as a table with the above described method. import arcpy
import numpy as np
oLoc = r"C:\Documents\ArcGIS\Default.gdb"
tLoc = r"C:\Documents\ArcGIS"
datasource = r"H:\Documents\ArcGIS\numpytab_out.dbf"
#list out your fieldnames
flds = ['staname', 'change']
#convert the dbf to a numpyarray obj
numpytab = arcpy.da.TableToNumPyArray(datasource, flds)
##check to see if intermediate table numpytab exists and delete it if so
arcpy.env.workspace = oLoc
arcpy.env.overwriteOutput = True
tabs2 = arcpy.ListTables()
for tab2 in tabs2:
if tab2=="numpytab_out":
arcpy.Delete_management(r"H:\Documents\ArcGIS\Default.gdb\numpytab_out")
arcpy.AddMessage("....Deleted numpytab_out")
##now covert the numpyarray to the gdb table in the default.gdb
arcpy.da.NumPyArrayToTable(numpytab, r"H:\Documents\ArcGIS\Default.gdb\numpytab_out") Sorry if this is way off base or sets you off into an unecessary direction, but it is an option. And I do have some similar methodology in production now.
... View more
06-11-2013
09:58 AM
|
0
|
0
|
3173
|
|
POST
|
I should clarify that statement. Python has several advantages, with the greatest being a low learning curve and a powerful syntax that greatly reduces the amount of code that has to be written to perform an operation. Also it does not require an application as costly as the full version of Visual Studio to use it (although the free Visual Studio Express version is somewhat usable). That being said, when a GUI is integral to an application, Python is severely limited. .Net will perform much better, but that does assume that the learning curve can be overcome. One thing not discussed in all of this is the value of the developer changes too. Coming from the ArcObjects/COM environments and application dev (along with lots n-Tier architecture with .NET, ADO.NET app and business tier dev and RDBMS integration and Procedural code development) Python is extremely limited in comparison. With that, my value as a developer decreases too --- well, if the only environment available is now Python, then my value only resides there. But as those other skills are not being employed, they tend to get lost eventually or new technologies and methods come up. Of course, this is also highly dependent upon the overall tech-direction of an organization. Should cost become prohibitive to development options, the ArcObjects/.NET/RDBMS stack is simply not available. I will say that you can get creative (you have to) in order to get things done with Python. Things like connecting to and using attribute databases (non spatial RDBMS like Oracle or SQL Server) is possible and we do that now with libraries like cx_Oracle. The advantage is in overcoming administrative barriers such as change control (I don't need to wait 2 weeks for adding a PL/SQL package and just write the SQL into the Python tool).
... View more
06-11-2013
06:36 AM
|
1
|
0
|
2397
|
|
POST
|
Vilmantas Alekna, There isn't a specific item in ArcGIS Online for reporting feedback on the Light Gray Canvas basemap, so you can just post what you notice in these forums. Thanks, Mike When the Light Gray Canvas basemap is loaded into ArcMap 10.1 and then attempts to remove it (right-click-->remove in TOC) will hang ArcMap and must force close. Environment: Citrix 3.1.0.64091 ArcGIS 10.1 Any info is appreciated. James
... View more
06-11-2013
06:15 AM
|
0
|
0
|
569
|
|
POST
|
I have similarly used the tools schema configurations to customize standard tool input dialogs (for example populate a combobox based on a selection in another combobox). It, however, suffers performance degradation if you have too many interacting items on a dialog (I had about 15) especially if they perform database queries in response to user inputs (which mine did). The degredation affected opening the tool and making dialog selections. I ended up using VB.Net to rebuild the interface as an Add-In and was much happier with the performance and GUI flexibility. Completely agree with this. And not just an issue with performance, there are lots of limitations to the Python Add-In. Since my .NET dev environment has been limited, I've had to get creative with the Python Add-In and Geoprocessor object development. It is a pain to get it all integrated and implemented, but comes with the advantage in distribution compared to a COM/ArcObject component that requires installer packages and such.
... View more
06-11-2013
03:42 AM
|
0
|
0
|
2397
|
|
POST
|
Although I would love to be proved wrong, I believe that ESRI has not found a way to get GUI interfaces developed in Python to interact compatibly with ArcMap. They both compete for OS attention and identical resources and generate errors or crashes. So I have not heard of a way to make a python GUI part of an ArcMap extension. As an alternative, we are integrating Toolbox/Scripts that have the various parameters predefined and launch these toolboxes per the appropriate Python Add-In event and button, tool or menu. That is, the Toolbox acts as the GUI and is opened at opportune moments (during specific events of the various tools we employ in the Python Add-Ins). For example, here is a ToolClass that implements the onRectangle def that we 'do some stuff', then launch a Toolbox .tbx".
class ToolClass2(object):
"""Implementation for my_addin.tool (Tool)"""
def __init__(self):
self.enabled = True
self.shape = "Rectangle"
def onRectangle(self, rectangle_geometry):
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
ext = rectangle_geometry
thepoly = arcpy.Polygon(arcpy.Array([ext.lowerLeft, ext.lowerRight, ext.upperRight, ext.upperLeft]),df.spatialReference)
# '...do stuff
#open the .tbx
pythonaddins.GPToolDialog('\\\\theUNCpath\ToolShare\geoproc\MyToolbox.tbx', 'TheScriptToRun') "TheScriptToRun" has been predefined with the desired input parameter types. The code in this Toolbox script peforms the required processing using the parameters input by the user (Dates, Date Ranges, Folders, FGDB's and all kinds of other things such as combo box drop downs and radio button lists).
... View more
06-10-2013
11:12 AM
|
0
|
0
|
2397
|
|
POST
|
I've tried this .... def onEnter(self): mxd = arcpy.mapping.MapDocument("CURRENT") df = mxd.activeDataFrame Lots = arcpy.mapping.ListLayers(mxd, "Lots", df) plan = SearchPlanNumber_1.value query = '\"PlanNumber\" = \'' + str(plan) + '\'' print plan print query arcpy.SelectLayerByAttribute_management(Lots, "NEW_SELECTION", query) df.zoomToSelectedFeatures for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name == "LotSelection": lyr.definitionQuery = '"PlanNumber" = \'' + plan + "'" arcpy.RefreshActiveView() arcpy.RefreshTOC() If I comment out the SelectByAttribute and df.zoomToSelectedFeatures, I can manipulate the definition query. However, It looks like there is something wrong with the where clause in the SelectByAttribute tool. It fails with the following error ... Traceback (most recent call last): File "C:\Users\dchaboya\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{7657B98A-A37F-CA5E-A8E1-C6CEF093100B}\SearchPlanNumber_addin.py", line 32, in onEnter arcpy.SelectLayerByAttribute_management(Lots, "NEW_SELECTION", query) File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6435, in SelectLayerByAttribute raise e RuntimeError: Object: Error in executing tool Both print statements are returning the values that i'm expecting. For example, if I type in VIP88129 in the combo box, the python window in ArcMap returns VIP88129. Also, it returns the query with the syntanx that I believe should work in the SelectByAttribute tool, which is "PlanNumber" = 'VIP88129'. Not sure what's going on there. I think your error when attempting to execute the SelectByAttributes is because of the way you are setting the "Lots" layer. If you say the definition query is working correctly, then use the same process to set the layer: Instead of: Lots = arcpy.mapping.ListLayers(mxd, "Lots", df) Use: for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name == "Lots": lyr.definitionQuery = '"PlanNumber" = \'' + plan + "'" arcpy.SelectLayerByAttribute_management(Lots, "NEW_SELECTION", query)
... View more
06-10-2013
06:35 AM
|
0
|
0
|
2141
|
|
POST
|
Thanks for the reply. I had sent a inquiry through the online form regarding this. Yes, the report output(s) are great (and are used now!) but we'd like to incorporate the percentile ranking chart(s) into our datasources for internal reporting. Since this effort is about focusing in on specific sites, navigating thru the USGS site and generating these kind of focused report can be a bit time consuming. By incorporating the XML webservice into arcpy, it allows us to internalize the data much more efficiently. Our apps generate url's (we've paramaterized these url's) and use other Python libraries to process the connection and return xml. matplotlib and pandas libraries shape the return data and create hydrographs and arcpy is used to incorporate everything into FGDB's, .mxd's and in some instances we might publish select .mxd's to ArcGIS Server. Anyway -- thanks for your input. j
... View more
06-10-2013
03:35 AM
|
0
|
0
|
845
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|