|
POST
|
Yes, I am going with the centroid approach. I took your advice on adding the above script into the add in. But, when clicking on the button, I get the message stating the tool has no parameters. I have been unable to get buttons to work without input parameters. What are the parameters? You could also try to simplify the script (untested):
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
df.zoomToSelectedFeatures()
... View more
08-12-2013
05:40 AM
|
0
|
0
|
1329
|
|
POST
|
Is it possible to select the polygon, hit a python addin button and zoom to centroid? Or am I required to run the tool by selecting the polygon, entering input parameters, and then zoom to the centroid? I would like to perform the operation without having to enter input parameters. But, I am unsure if Python has this capability. Yes, and if that is the workflow you decide on then the df.zoomToSelectedFeatures() will work out just fine. It will zoom to the extent of the selected feature though, not the cetnroid so not sure if that affects your requirement. Just code the onClick event of your Python Add-In button:
class ButtonClass_WorkSelection(object):
"""Implementation for MyTools_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd):
tlyr = lyr
dsc = arcpy.Describe(tlyr)
sel_set = dsc.FIDSet
if len(sel_set) > 0:
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
... View more
08-12-2013
05:24 AM
|
0
|
0
|
3036
|
|
POST
|
To follow up with Waynes contribution, if all you want to do is zoom to a selected feature -- you could just do that too and not even worry about centroids or extents of anything. for lyr in arcpy.mapping.ListLayers(mxd): tlyr = lyr dsc = arcpy.Describe(tlyr) sel_set = dsc.FIDSet if dsc.shapeType == "Polygon": if len(sel_set) > 0: df.zoomToSelectedFeatures() arcpy.RefreshActiveView() Or, if you are still wanting to use the individual rows of the cursor for some reason, you could get the extent of each SHAPE@ value of the row object (this does exactly what the above code does, so I am not sure if it will benefit you. I just thought it is more inline with your OP code): for lyr in arcpy.mapping.ListLayers(mxd): tlyr = lyr dsc = arcpy.Describe(tlyr) sel_set = dsc.FIDSet if dsc.shapeType == "Polygon": if len(sel_set) > 0: with arcpy.da.SearchCursor(tlyr, ("SHAPE@")) as cursor: for row in cursor: shape = row[0] zoomextent = shape.extent df.extent = zoomextent arcpy.RefreshActiveView()
... View more
08-09-2013
09:48 AM
|
0
|
0
|
3036
|
|
POST
|
This seems to give me the SHAPE@XY value of a selected polygon feature in a FGDB FeatureClass I have loaded into ArcMap 10.1 -- ignore the first "if" statement if you are not concerned about checking for GroupLayer data.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.isGroupLayer:
for sublyr in lyr:
if dsc.shapeType == "Polygon":
with arcpy.da.SearchCursor(sublyr, "SHAPE@XY")) as cursor:
for row in cursor:
arcpy.AddMessage(str(row))
else:
tlyr = lyr
if dsc.shapeType == "Polygon":
with arcpy.da.SearchCursor(tlyr, ("SHAPE@XY")) as cursor:
for row in cursor:
arcpy.AddMessage(str(row))
... View more
08-09-2013
07:29 AM
|
0
|
0
|
3036
|
|
POST
|
Are you opposed or comfortable using a different library? You can EASILY acheive what you want with Pandas:
import arcpy
from pandas import *
ws = "H:\Documents\ArcGIS\Default.gdb"
arcpy.env.workspace = ws
fc = "MyFC"
fields = ["_currentvalue", "_pastvalue", "_curDate"]
array = []
for field in fields:
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
array.append(row)
df = DataFrame(array, columns = ["_currentvalue", "_pastvalue", "_curDate"])
maxDate = df._curDate.max()
print maxDate #<--- this gives me the correct max date
I have found many other uses for the pandas library too -- very powerful and a welcomed addition to my codebase! Good luck, james
... View more
08-08-2013
09:48 AM
|
0
|
0
|
1834
|
|
POST
|
I saw your post earlier and was attempting some possible approaches. I thought about using NumPy to arrive at the max() statistic you are interested in, and it looked promising. arcpy.da.FeatureClassToNumPyArray However, it doesn't allow for Date fields! arrggghhh! Sorry. j
... View more
08-08-2013
09:39 AM
|
0
|
0
|
1834
|
|
POST
|
da.SearchCursor has some options too:
fields = ['fld1', 'fld2', 'fld3']
for field in fields:
where = field + " IS NOT NULL"
try:
with arcpy.da.SearchCursor(fc, fields, where) as cursor:
for row in cursor:
value = row[0]
print field + ": " + str(value) #or use "value" to do something
except Error:
pass
del row, cursor
note: I first tested for "IS NULL" values and simply printed them out and it correctly listed/printed the fields and the null value. So then I just altered it to "IS NOT NULL" to get the opposite result, printing all values for each field that is not null. I did not fully research this for better option, do additional testing or determine if this is actually incorrect --- so I am very open to critique of the above!
... View more
08-08-2013
05:21 AM
|
0
|
0
|
1390
|
|
POST
|
Thanks folks. I couldn't find a way to do what I needed, so I just ended up creating a table (in a GDB) using the arcpy.Statistics_analysis tool, extracting the value from the table using a searchcursor, and then overwriting the table each time. A bit of a go-around, but it works. If anyone can think of a better way then I'd be keen to hear. Thanks I didn't think of it at the time, but yes there is a much better solution -- especially if you are not wanting to write to disk.... FeatureClassToNumPyArray http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000015000000 The example even has your requirement to sum a field! Good luck, james
... View more
08-06-2013
03:50 AM
|
0
|
0
|
4353
|
|
POST
|
Cannot create FeatureClass 'C:\Users\<AGS SERVICE ACCOUNT>\AppData\Local\Temp\extractdatatools\jsontofc_gpserver\j631f8a7a49c34355a03361601e636c75\scratch\scratch.gdb\DATA_EXTRACT_130805_095310'
Just a complete shot in the dark here and I have absolutely zero experience with this method, but... Have you attempted to write the FC to in_memory instead of the Scratch.gdb? Really not sure if this is going to anything at all for you, but maybe worth a try.
... View more
08-05-2013
09:16 AM
|
0
|
0
|
2341
|
|
POST
|
I use the Pandas Package for getting summary stuff. The DataFrame (not an ArcGIS "DataFrame" concept) is really powerful for building and shaping data to meet your needs --- I incorporate it into matplotlib Package for generating hydrographs, but there is just a ton of functionality. https://pypi.python.org/pypi/pandas Example below shows a normal array/list that was populated with some data and getting min/max values from the date field:
#set the pandas dataframe to the array
dbhydDF = DataFrame(datArray, columns=['site', 'value', 'dateread'])
#get min/max date values
dmax = dbhydDF.dateread.max()
dmin = dbhydDF.dateread.min()
#not tested, but I think you just issue .sum to get a sum value from the appropriate field
dsum = dbhydDF.value.sum()
... View more
08-05-2013
05:58 AM
|
0
|
0
|
4353
|
|
POST
|
Oh. I just need to use Copy_management instead to bring over any related items. Sorry. j
... View more
08-02-2013
07:07 AM
|
0
|
0
|
680
|
|
POST
|
As the title says, I need to perform what is a very simple operation when completed manually in the ArcCatalog tree --- move data from a 10.1 FGDB to a 10.0 FGDB. This is now done by simply selecting everthing in the 10.0 FGDB and deleting, then selecting and pasting everything from the 10.1 FGDB into the 10.0 FGDB. The catch: there are "Attachments" in 10.1 FGDB that need to come across too. Again, not an issue by doing this manually I say above. I have attempted to peform this with FeatureClassToGeodatabase_conversion and TableToGeodatabase_conversion, which works fine to bring almost everything over! However, it does not pickup the attachments or the attachments relationship class. Solutions? Alternatives? TIA! james
... View more
08-02-2013
07:00 AM
|
0
|
1
|
858
|
|
POST
|
I copied the data from the Type field to a new field, named Classification. The Regions layer is a feature class. print RMS print Classification After running the print RMS & Classification the script completes with no errors or results. I just receive the typical start time, end time, running, and completed notifications. If I add arcpy.AddMessage("Good") after the RMS = arcpy.GetParameterAsText(0) Classification = arcpy.GetParameterAsText(1) Then, I receive the same as before with "Good" added. So, the input parameters seem to be ok. Just to follow up with Rhett's suggestion of the print/addmessage statements... I am not sure if both are seen (in PythonWin and the Geoprocessor results window maybe?). But rather than:
arcpy.AddMessage("Good")
do this instead:
arcpy.AddMessage(str(RMS))
arcpy.AddMessage(str(Classification))
...and see if these values are seen in the results window.
... View more
07-31-2013
04:03 AM
|
0
|
0
|
1640
|
|
POST
|
Just a shot in the dark (I've seen all kinds of database design quirks), but... Is the "TYPECBN" field really type integer? If it is actually a string, then = 3 would fail without the quotes around '3'. Also, you really should list the fields you wish to include in your result. Using "Select *" is just a poor habit to get into.
... View more
07-31-2013
03:50 AM
|
0
|
0
|
2885
|
|
POST
|
Is perhaps putting an "r" in front of strings new to Arcpython under version 10? I don't recall this from 9.3, and it doesn't seem to be in my sample scripts from then. Steve, From a quick look at some examples, the "r" in front of a quoted string indicates a string literal -- for example any escape characters will not be evaluated. So,
print r'testing \n'
Would print the entire quoted string "testing \n"
print 'testing \n'
Would print "testing" and a newline space.
... View more
07-25-2013
04:12 AM
|
0
|
0
|
2760
|
| 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
|