|
POST
|
I prefer using the math module.
import math
# In the use of the 'math.pow' method, the value x is raised to the power of y
math.pow(x, y)
... View more
02-25-2014
12:46 PM
|
0
|
2
|
2319
|
|
POST
|
Discovered a quazi-solution to this. It turns out that when a combobox is populated with values, if you hit the drop-down and then click inside the combobox to type in a value, the drop down remains displayed and will jump to exact value matches when you type them. Not really an auto-complete like I wanted, but an interesting discovery nonetheless. Still, what I want to try to implement is a way for the combobox to suggest values as you type, similar to the way google suggests search queries as you type them into google's searchbox.
... View more
02-25-2014
11:56 AM
|
0
|
0
|
938
|
|
POST
|
You can make a reference dictionary with the alias name as the key. dict = {f.aliasName: f.name for f in arcpy.ListFields(layer)} oooooooooo I had actually just figured out an alternative solution by creating another list and iterating back through it and interrogating every aliasName to see if it matched the selection, but this is much more elegant! Thanks Matthew!
... View more
02-24-2014
01:20 PM
|
0
|
0
|
963
|
|
POST
|
Perhaps I'm thinking a little too hard about this but I can't really figure out if there is a way to determine which field a particular field alias resolves to. My situation is that I've got a series of python add-in comboboxes. The first allows a user to select a layer, the next a field, the next specify a search value. For the second combobox, it autopopulates on focus with the aliasName of each field returned from FieldList. The question is, once a user makes a selection from this field, how do I resolve that back to the actual field? class MAPSearch_item(object): """Implementation for MAPSearch.item (ComboBox)""" def __init__(self): self.items = ["Stores", "Customers"] self.editable = False self.enabled = true self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' def onSelChange(self, selection): global SearchItem SearchItem = selection global SearchLayer if selection == "Stores": try: SearchLayer = arcpy.mapping.Layer(r"C:applicationDeployment\\" + \ "MAPS 1.5\Layers\Stores.lyr") except Exception as e: pythonaddins.MessageBox("\ An unexpected error occured. Please contact the GIS Manager with the \ following error message: \ " + e.message, "ERROR", 0) return elif selection == "Customers": try: SearchLayer = arcpy.mapping.Layer(r"C:applicationDeployment\\" + \ "MAPS 1.5\Layers\Customers.lyr") except Exception as e: pythonaddins.MessageBox("\ An unexpected error occured. Please contact the GIS Manager with the \ following error message: \ " + e.message, "ERROR", 0) return else: pythonaddins.MessageBox("Item is not a valid selection.", "ERROR", 0) return def onEditChange(self, text): pass def onFocus(self, focused): pass def onEnter(self): pass def refresh(self): self.refresh() class MAPSearch_field(object): """Implementation for MAPSearch.field (ComboBox)""" def __init__(self): self.editable = False self.enabled = True self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' def onSelChange(self, selection): global SearchField # The question is, once the user makes a selection, the selection is actually an aliasName for a field as # specified in the onFocus function. So 'selection' returns an aliasName. How do I resolve the given aliasName # back to the actual field in order to complete the below Query? SearchField = selection global SearchSet try: SearchSet = set([r[0] for r in arcpy.da.SearchCursor(SearchLayer, SearchField)]) except Exception as e: pythonaddins.MessageBox("\ An unexpected error occured. Please contact the GIS Manager with the \ following error message: \ " + e.message, "ERROR", 0) return def onEditChange(self, text): pass def onFocus(self, focused): # When user gives focus to combobox, dynamically populate the combobox with the aliasName # of every 'Text' field in the 'SearchLayer' established in the 'MAPSearch_item' self.items = [] for Field in arcpy.ListFields(SearchLayer, "*", "TEXT"): self.items.append(Field.aliasName) def onEnter(self): pass def refresh(self): self.refresh()
... View more
02-24-2014
12:58 PM
|
0
|
2
|
1161
|
|
POST
|
Where are you establishing a reference to the 'dataSource_lyr' variable? As it shows,you have clearly established a reference to it above this section of code since you're using the 'dataSource_lyr' to call the layer in your 'MakeFeatureLayer_management()' function.
... View more
02-21-2014
05:52 AM
|
0
|
0
|
903
|
|
POST
|
Any good ideas on implementing an Auto-Complete function within a combobox?? I have three comboboxes: MAPSearch_item: Allows the user to select from a drop down, a layer to to execute the search against MAPSearch_field: Allows the user to select from a drop down, the attribute field in the 'MAPSearch_item' to search within MAPSearch_query: Allows the user to enter the value to search for in the selected field of the selected item. Once they hit enter, if the 'search value' is found, a select_analysis is executed and a feature class is added to the MXD containing the selected features. To prevent users from misspelling a search value which would result in an error being raised, I'd like the 'MAPSearch_query' combobox to try and autocomplete the search term as they type it into the combobox. Any nifty ideas here? Here's my code thus far:
class MAPSearch_item(object):
"""Implementation for MAPSearch.item (ComboBox)"""
def __init__(self):
self.items = ["Stores", "Customers"]
self.editable = False
self.enabled = True
self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
def onSelChange(self, selection):
global SearchItem
SearchItem = selection
if selection == "Stores":
try:
SearchLayer = arcpy.mapping.Layer(r"C:\ArcGIS\SYSTEM\COF\Data\Layers\
Stores.lyr")
except Exception as e:
pythonaddins.MessageBox("\
An unexpected error occured. Please contact the GIS Manager with the \
following error message: \
" + e.message, "ERROR", 0)
return
elif selection == "Customers":
try:
SearchLayer = arcpy.mapping.Layer(r"C:\ArcGIS\SYSTEM\COF\Data\Layers\
Customers.lyr")
except Exception as e:
pythonaddins.MessageBox("\
An unexpected error occured. Please contact the GIS Manager with the \
following error message: \
" + e.message, "ERROR", 0)
return
else:
pythonaddins.MessageBox("Item is not a valid selection.", "ERROR", 0)
return
def onEditChange(self, text):
pass
def onFocus(self, focused):
pass
def onEnter(self):
pass
def refresh(self):
self.refresh()
class MAPSearch_field(object):
"""Implementation for MAPSearch.field (ComboBox)"""
def __init__(self):
self.items = ["Name", "Store ID", "Street Address", "District", "Region", \
"Market", "Project Number", "Project Action", "Project Timing"]
self.editable = False
self.enabled = True
self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
def onSelChange(self, selection):
global SearchField
SearchField = selection
global SearchSet
try:
SearchSet = set(r[0] for r in arcpy.da.SearchCursor(SearchLayer,
SearchField))
except Exception as e:
pythonaddins.MessageBox("\
An unexpected error occured. Please contact the GIS Manager with the \
following error message: \
" + e.message, "ERROR", 0)
return
def onEditChange(self, text):
pass
def onFocus(self, focused):
pass
def onEnter(self):
pass
def refresh(self):
self.refresh()
class MAPSearch_query(object):
"""Implementation for MAPSearch.query (ComboBox)"""
def __init__(self):
self.items = []
self.editable = True
self.enabled = True
self.dropdownWidth = ''
self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
def onSelChange(self, selection):
pass
def onEditChange(self, text):
pass
def onFocus(self, focused):
pass
def onEnter(self):
SearchTerm = selection
if SearchTerm in SearchSet:
try:
ResultName = SearchItem + "_" + SearchTerm
Select_analysis(SearchLayer, ResultName,
'"' + SearchField + '" = ' + "'" + SearchTerm + "'")
except Exception as e:
pythonaddins.MessageBox("\
An unexpected error occured. Please contact the GIS Manager with the \
following error message: \
"+ e.message, "ERROR", 0)
else:
pythonaddins.MessageBox("\
The search term entered was not found in the selected attribute field for \
the selected item. Please check your spelling and ensure you have the \
correct search dataset and attribute field selected. If you need \
assistance with this issue, please contact the GIS Manager.", "ERROR", 0)
def refresh(self):
self.refresh()
... View more
02-21-2014
05:43 AM
|
0
|
1
|
2164
|
|
POST
|
I completely empathize with your situation here, but I've personally found working with FieldMap objects to be a nightmare unless you're doing just a handful of fields. There's just way too much code required to do it with ESRI's current arcpy implementation (maybe I'm doing it wrong, but I haven't seen any simple/elegant ways to do it) What you have in your second posting is the python snippet of the TableToTable_conversion function, I'm assuming for that same table you want to repeatedly convert. Why don't you just establish variables for the inTable and outTable parameters, do a find and replace on the script to replace the inTable and outTable to replace the paths and roll with it? ESRI really needs to simplify the FieldMap objects implementation. It's bananas how much code has to be written to map a single field.
... View more
02-18-2014
03:12 AM
|
0
|
0
|
1136
|
|
POST
|
Would you say that python Add-Ins and python scripts perform different operations? If not, which option would be the easiest to deploy? Python Addins are mostly for when you need to interact with the Map or Table of Contents in a dynamic manner (click on a point in the map and get the coordinates) or build some sort of custom GUI element (toolbar, button, combobox, tool, or tool palette) or listen for events within the session (item added to TOC, item removed from TOC, start/end an editing session, ect) and perform some sort of custom logic when those events occur. I've found they're also really useful for neatly packaging and distributing Toolboxes as well as you can ship toolboxes and supporting datasets with it and then raise those toolboxes through a button you create on a python addin toolbar. This has very much simplified deploying tools for me as I no longer have to keep track of who has what version of the tool. I just edit the tool, sign it, post to to a common share and the next time they restart, ArcGIS automatically installs the update on their system. Everyone is on the same page of music (for good or bad) and they can get to the tools through a simple button that raises them instead of the convoluted 'My Toolboxes' menu buried way way way down in the Catalog Window. I think the end result is a much more professional and polished presentation and simplified deployment. Python addins are definately not for building custom script tools or python toolboxes (that's what script tools and python toolboxes are for, duh), but it definately makes deployment a whole lot easier. The GUI Functions are still kind of limited for now. No dockable windows (no ability to get user text input except through a combobox, no way to create custom gui elements outside of the methods they provide, limited interrogation of existing gui elements). I am hopeful that in time it will become much more robust with a form builder and ability to create dockable windows Hope that helps.
... View more
02-12-2014
09:26 AM
|
0
|
0
|
2961
|
|
POST
|
Hi Dave, The Python Addins module has a function specifically for this purpose.
import pythonaddins
SelectedLayer = pythonaddins.GetSelectedTOCLayerOrDataFrame()
print SelectedLayer
That should return the name of the layer the user has selected from the TOC, as it appears in the TOC.
... View more
02-12-2014
07:16 AM
|
0
|
0
|
2961
|
|
POST
|
Unfortunately the commands you suggested are not available in 10.0. Sorry Elliot, I didn't notice the 10.0 in parenthesis in your title. In that case, I would just use the MakeQueryTable tool, but omit any type of query. Kind of a workaround but a pretty elegant solution that could even be condensed to a single line if you just insert the path directly into the function instead of referring to a variable like I did. You don't even need to specify the MXD or DF with this tool and it will automatically switch your TOC view over to 'List by Source' once the Table is added.
theTable = r'C:\Documents and Settings\jdk588\My Documents\ArcGIS\Default.gdb\MyTable'
arcpy.MakeQueryTable_management(theTable, "TableNameinTOC", "NO_KEY_FIELD")
Only limitation here is that QueryTables are in-memory, so they won't persist after the session has ended. So if you run calculations or manipulate the table in any way, you'll need to write the result out again using 'TableToTable_conversion()' in order to keep it.
... View more
02-12-2014
06:08 AM
|
0
|
0
|
1353
|
|
POST
|
So is 'Test_FC' a Table or a Feature Class? You indicate Table: I'm trying to add a table to the table of contents from a arcpy script. But FC indicates it might be a Feature Class... If it is actually a GDB Table, you should be using:
mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
TableView = arcpy.mapping.TableView(r'C:\Documents and Settings\jdk588\My Documents\ArcGIS\Default.gdb\MyTable')
arcpy.mapping.AddTableView(df, TableView)
You'll then need to manually switch the Table of Contents from the default 'List Layers by Drawing Order' view to the 'List By Source' view which is the only view under which you can see the table in the Table of Contents window. I had hoped the 'arcpy.RefreshTOC()' function would automatically change the view based on the dataType of the last item added, but I found it doesn't and I don't know of any method in arcpy to change the TOC view, so you're probably stuck with the manual change now. Though, you could add a messagebox from the pythonaddins module to let you know the table was added.
mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
try:
TableView = arcpy.mapping.TableView(r'C:\Documents and Settings\jdk588\My Documents\ArcGIS\Default.gdb\MyTable')
arcpy.mapping.AddTableView(df, TableView)
pythonaddins.MessageBox("Table Added to TOC. Switch TOC to 'List By Source' view to access Table.", "Table Added", 0)
except Exception as e:
pythonaddins.Messagebox("An error occured: " + e.message, "ERROR", 0)
... View more
02-12-2014
03:47 AM
|
0
|
0
|
1353
|
|
POST
|
This isn't really a python question, but I figured this was probably the best forum to pose the question since it involved code. My End Users wanted to be able to view photos of our locations inside of ArcMap by clicking on a given point, which of course is possible but they actually wanted multiple photos displayed like an image gallery that they can flip through. I don't know of any way to dynamically create a photo gallery to review the photo attachments of a point in the attribute table. To complicate matters a little more, we don't even have the neccessary license to create the attachments. So as a compromise, we agreed it was acceptable if I just iFramed Microsoft Birds Eye imagery of the location into an HTML Popup, which gives them a good view idea of what the location's surroundings look like, even if the imagery is a bit dated. What I'm currently doing to accomplish this is calculating a field in the attribute tables to hold the bird's eye link:
"http://dev.virtualearth.net/embeddedMap/v1/ajax/BirdseyeWithLabels?zoomLevel=18¢er=" + str(!LAT!) + "_" + str(!LON!) + "&pushpins=" + str(!LAT!) + "_" + str(!LON!) + "&culture=en-us"
Then I used this XSL Template from Ed Dempsey (thanks Ed, wherever you are) to iframe the link held in the 'Birds Eye View' field in the attribute table and display the result in the HTML Popup.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:variable name="ignoreFieldNames" select="'|OBJECTID|Shape|Shape_Length|Shape_Area|ATTACHMENTID|REL_OBJECTID|CONTENT_TYPE|ATT_NAME|DATA_SIZE|DATA|'"/>
<xsl:variable name="headerRowColor" select="'#000066'"/>
<xsl:variable name="headerFontColor" select="'FFFFFF'"/>
<xsl:variable name="alternateRowColor" select="'#FFFFFF'"/>
<xsl:variable name="alternateFontColor" select="'#000000'"/>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
</head>
<body>
<xsl:variable name="nameCol" select="FieldsDoc/Fields/Field/FieldName"/>
<table border="1" width="600" cellpadding="5" cellspacing="0">
<tr bgcolor="#66CCFF">
<xsl:if test="string-length($nameCol) != 0">
<th width="50%" align="left">Field Name</th>
</xsl:if>
<th width="50%" align="left">Field Value</th>
</tr>
<xsl:variable name="index" select="1"/>
<xsl:for-each select="FieldsDoc/Fields/Field">
<tr>
<xsl:if test="(position() +1) mod 2">
<xsl:attribute name="bgcolor">#66CCFF</xsl:attribute>
<xsl:attribute name="fontcolor">#FFFFFF</xsl:attribute>
</xsl:if>
<xsl:if test="string-length($nameCol) != 0">
<td>
<xsl:value-of select="FieldName"/>
</td>
</xsl:if>
<td>
<xsl:choose>
<xsl:when test="FieldName[starts-with(., 'Birds Eye View')]">
<xsl:variable name="BirdsEyeLink" select="FieldValue"/>
<iframe src="{$BirdsEyeLink}" width="550" height="450">An Internet Connection is required to view Bird's Eye</iframe>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="FieldValue"/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</table>
<br/>
</body>
</html>
</xsl:template>
<xsl:template match="Field">
<tr>
<xsl:if test="(position() +1) mod 2">
<xsl:attribute name="bgcolor">
<xsl:value-of select="$alternateRowColor"/>
</xsl:attribute>
<xsl:attribute name ="color">
<xsl:value-of select ="$alternateFontColor"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="(position() +0)">
<xsl:attribute name="bgcolor">
<xsl:value-of select="$headerRowColor"/>
</xsl:attribute>
<xsl:attribute name="color">
<xsl:value-of select="$headerFontColor"/>
</xsl:attribute>
</xsl:if>
</tr>
</xsl:template>
</xsl:stylesheet>
However, what I'd like to get away from is whenever the user uses the identify tool, the actual Birds Eye link appears in the Identify Window. I don't really want to show the actual link. The same thing goes with raising the attribute table. When the user views the attribute table, they see the Bird's Eye Link for the given record. I just want to not show the field in the attribute table or identify window. If I turn the field off, then the iFrame doesn't work because the XSL Template can't find the field holding the link. If I turn off the field visibility, same thing happens (I had always thought turning a field off was different from turning off field visibility, but they appear to be the same thing). So what I'm wondering now, is whether or not it is possible to just do this dynamically within the XSL Template. I did some googling and discovered there is a tag <xsl: value-of> tag that can probably used to dynamically grab the LAT and LON and populate them into the appropriate place in the Link, but I'm not sure how to insert the resulting link into the top of the table produced by the XSL Template. Admitedly, I'm not very well versed at all with XSL, so any help is appreciated.
... View more
02-12-2014
03:23 AM
|
0
|
0
|
459
|
|
POST
|
Jason is right. You can't. The documentation is not wrong per-se, it's just misleading. deactivate() is not a function that's intended for you (the programmer) to leverage. It's a function leveraged by the application so that ESRI tools can deactive it when they are selected. Otherwise, you'd never be able to select another tool. In order to do what you're trying to do, you'd also need some sort of activate() function in order to default back to another tool like the cursor or pan tool because one tool always has to be active. Currently, there is no programmatic way to switch between tools that I know of.
... View more
02-11-2014
04:29 AM
|
0
|
0
|
1462
|
|
POST
|
I'm not positive, but I think the answer here is going to be to create a script tool and then run it in process. This help article should get you going. Give it a shot and let us know if it helps.
... View more
02-05-2014
05:35 AM
|
0
|
0
|
860
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-11-2015 12:02 PM | |
| 2 | 02-04-2016 02:35 PM | |
| 1 | 04-11-2017 12:51 PM | |
| 1 | 08-07-2015 11:00 AM | |
| 4 | 06-19-2015 01:44 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|