|
POST
|
Thanks, tim. However you are still requiring an input shapefile, but I will go back and see if I can rework things prior to my new approach. I was hoping to avoid this and simply convert the geometry to a different spatial reference (WGS1984). Doesn't look like this is possible, so I came up with an "in_memory" implementation that seems to do what I need. The first click event takes about 3 seconds to build the in_memory FeatureClass but subsequent clicks the Lat/Lon values are reported immediately. Solution:
def onMouseDownMap(self, x, y, button, shift):
print "x: " + str(x) + " y: " + str(y)
## get a layer loaded in the TOC to determine the spatial reference
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
testCount = len(arcpy.mapping.ListLayers(mxd, "", df))
if testCount==0:
msg = "There are no features selected to report"
pythonaddins.MessageBox(msg, 'Report Latitude/Longitude Values', 0)
else:
for lyr in arcpy.mapping.ListLayers(mxd):
dsc = arcpy.Describe(lyr)
spref = dsc.spatialReference
lpoint = arcpy.Point()
lpoint.X = x
lpoint.Y = y
ptGeometry = arcpy.PointGeometry(lpoint, spref)
ptFC = "in_memory\lpoint"
if arcpy.Exists(ptFC):
arcpy.Delete_management(ptFC)
arcpy.CreateFeatureclass_management("in_memory", "lpoint", "POINT", '', "DISABLED", "DISABLED", spref, '')
cursor = arcpy.da.InsertCursor(ptFC, "SHAPE@XY")
cursor.insertRow((lpoint,))
del cursor
to_sr = r'GEOGCS["GCS_WGS_1984",' + \
'DATUM["D_WGS_1984",' + \
'SPHEROID["WGS_1984",6378137,298.257223563]],' + \
'PRIMEM["Greenwich",0],' + \
'UNIT["Degree",0.017453292519943295]]'
flds = ["SHAPE@X", "SHAPE@Y"]
scursor = arcpy.da.SearchCursor(ptFC, flds, '', to_sr)
prjx = 0.00
prjy = 0.00
for row in scursor:
#print "X: " + str(row[0]) + " Y: " + str(row[1])
prjx = row[0]
prjy = row[1]
del scursor
msg = "Latitude: " + str(prjx) + "\n" + "Longitude: " + str(prjy)
pythonaddins.MessageBox(msg, 'Report Latitude/Longitude Values', 0)
this appears to be a good solution, but if anyone can spot any issue with the above, I'd appreciate it.
... View more
05-13-2013
07:05 AM
|
0
|
0
|
3082
|
|
POST
|
I'm attempting to implement some of the functionality found here: http://support.esri.com/en/knowledgebase/techarticles/detail/40730 I need to acquire the x/y values where mouse click occurs, convert the values into Latitude/Longitude and then report these values. The plan is to require a layer to be loaded in the map TOC, so there will be a defined spatial reference to go from. No problem getting these projected x/y values so far but I am not able to project these to WGS1984. Is this even possible? Or will I have to use in_memory in some capacity here? def onMouseDownMap(self, x, y, button, shift): print "x: " + str(x) + " y: " + str(y) ## this reports as expected! ## get a layer loaded in the TOC to determine the spatial reference mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] testCount = len(arcpy.mapping.ListLayers(mxd, "", df)) if testCount==0: msg = "There are no features selected to report" pythonaddins.MessageBox(msg, 'Report Latitude/Longitude Values', 0) else: for lyr in arcpy.mapping.ListLayers(mxd): dsc = arcpy.Describe(lyr) spref = dsc.spatialReference lpoint = arcpy.Point() lpoint.X = x lpoint.Y = y ptGeometry = arcpy.PointGeometry(lpoint) #ptGeom = arcpy.PointGeometery(arcpy.point(x,y),spref, False, False) to_sr = arcpy.SpatialReference('WGS 1984') projectedPoint = ptGeometry.projectAs(to_sr, r'NAD_1983_HARN_To_WGS_1984') prjX = projectedPoint.X prjY = projectedPoint.Y print "X:" + str(prjX) + " Y:" + str(prjY) The code above fails on the line: [INDENT]projectedPoint = ptGeometry.projectAs(to_sr, r'NAD_1983_HARN_To_WGS_1984')[/INDENT] Error msg: "projectedPoint = ptGeometry.projectAs(to_sr, r'NAD_1983_HARN_To_WGS_1984') File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 761, in projectAs return convertArcObjectToPythonObject(self._arc_object.ProjectAs(*gp_fixargs((spatial_reference, transformation_name)))) ValueError: NAD_1983_HARN_To_WGS_1984"
... View more
05-13-2013
05:56 AM
|
0
|
14
|
8537
|
|
POST
|
Have a look at this: http://anothergisblog.blogspot.com/2012/06/working-with-blob-data-at-101-arcpyda.html
... View more
05-13-2013
04:10 AM
|
0
|
0
|
1875
|
|
POST
|
Not sure if this is possible, so I just created my own Create Feature Class implementation.
... View more
05-09-2013
10:20 AM
|
0
|
0
|
657
|
|
POST
|
apologies if this is easy but I cannot seem to find the answer. Is there a way to convert a graphic to feature, ie use the "Convert Graphics to Feature" tool on the toolbar, within arcpy? I need to use a graphic as a selectbylayer feature, so either converting it or using the graphic directly would be nice. Thanks! Any solution to this?
... View more
05-09-2013
10:18 AM
|
0
|
0
|
806
|
|
POST
|
At 10.1, text and graphic elements can be cloned. So you can author a single element with the font, color, etc and clone when needed elsewhere. Arcpy does not allow you to change text color, font and many other properties directly although you can do it by setting the text string to include tags. Jeff Thanks for your input, Jeff. So how exactly would that work? I read thru some presentations from ESRI developer summit, but somethings are not fully clear. 1. Create an existing .mxd with the Text/Graphic elements I wish to have in the "CURRENT" .mxd document 2. Clone each of these. 3. Add to the the "CURRENT". Something like that? If so, how do I actually "add" the elements to the "CURRENT" .mxd? I didn't see this method (or probably just missed it).
... View more
05-09-2013
07:21 AM
|
0
|
0
|
3223
|
|
POST
|
I have a new MyCustomToolbox.tbx that has a couple of "Scripts" I have created and added to it that I can invoke/open with the following: pythonaddins.GPToolDialog('\\\\networklocation\MyCustomToolbox.tbx', 'MyScript') I also added the "Create Feature Class" tool to this .tbx and from my Python Add-In, I am attempting to open this in the same way as above, but fails to open it. Anyone else have this problem?
... View more
05-09-2013
04:55 AM
|
0
|
1
|
1153
|
|
POST
|
Currently the arcpy.mapping module contains no where near the functionality you can achieve with ArcObjects. There is no way I know of to create a new text element using arcpy.mapping. You can take an existing element and change the size, position, text, etc. Thought so. Bummer. I really hate to read things like "Oh, arcpy.mapping is a wrapper for ArcObjects" --- it lends one to believe that, okay I should be able to access X, but just a little differently. VBA ruled! .NET/COM is and was a lot of work but made me much more valuable as a developer. Now I get to instruct the user: "hey, first you need to add a text element. ONLY then can this tool I am building for you work." Okay thanks!
... View more
05-08-2013
07:21 AM
|
0
|
0
|
3223
|
|
POST
|
Is it possible to add a new Text Element to a layout view? I am building a new Python Add-In and this ArcObjects developer is getting frustrated with the amount of limitations I am finding in the arcpy.mapping module. (unfortunately, my development tools have been limited to python) Help is appreciated.
... View more
05-08-2013
06:55 AM
|
0
|
10
|
7048
|
|
POST
|
You can not create or remove layout elements using arcpy.mapping. Jeff Okay. So then just how are we supposed to create new layout elements? I need to create a new Text Element in a layout view where the user clicks. This needs to be done in a Python Add-In.
... View more
05-08-2013
06:51 AM
|
0
|
0
|
4190
|
|
POST
|
...huh. Seems like a get this great "GetCount" thingie, then I am expecting a similar method for zero selected features -- guess not. This works but... well, it works. (solution found 4 pages deep on a Google search!) for lyr in arcpy.mapping.ListLayers(mxd): dsc = arcpy.Describe(lyr) sel_set = dsc.FIDSet if len(sel_set) == 0: print "Nothing selected" else: 'do all the stuff
... View more
05-07-2013
12:16 PM
|
0
|
0
|
903
|
|
POST
|
I just need to be able to determine if nothing is selected. SearchCusors and GetCount_management only return either just the selected features or all of the features. ...pretty sure I am missing the obvious here.
... View more
05-07-2013
12:01 PM
|
0
|
1
|
1020
|
|
POST
|
I'm not completely satisfied with this solution, but it accomplishes what I need --- return the area, acreage for the shape that is drawn in the map display. 1. I Need to add some spatial reference checks on the DataFrame. 2. The <self.shape = "Line"> is not quite doing what I want (interactively draw a polygon). 3. This is drawing a line, I'd rather it draw a polygon (as you click each vertex, the polygon begins to take shape, just like in the SelectByPolygon tool). As it stands, I can tell that the user will be confused on how to close the polygon (really it should only take 4 clicks to create a simple rectangle/polygon, but because it is a line the user will want to "close" the polygon and click that 5th vertex). How about interactively creaing a polygon graphic element? I don't see how this can be converted to such a thing. Anyway -- this returns the correct acreage when the DataFrame's coordinate system properties are correctly set: class ToolClass_AcresByClicks(object): """Implementation for EOCTools_addin.tool (Tool)""" def __init__(self): self.enabled = True self.shape = "Line" def onLine(self, line_geometry): array = arcpy.Array() part = line_geometry.getPart(0) for pt in part: array.add(pt) t_polygon = arcpy.Polygon(array) parea = t_polygon.area p_acreage = parea / 43560 print p_acreage
... View more
05-07-2013
10:49 AM
|
0
|
0
|
640
|
|
POST
|
I need to replicate the Select By Polygon tool (minus the selecting step). I simply need to be able to draw a temporary polygon to 'do stuff' with. What am I missing here? --- I see a way to set self.shape to Line, Circle or Rectanlge but there is no Polygon. I can set self.shape to "Line" and then create an array of points in the onLine def, but this is not what the SelectByPolygon tool is doing. Please help with this seemingly simple process. Thanks! j
... View more
05-07-2013
07:14 AM
|
0
|
1
|
791
|
|
POST
|
thanks for answer. but in this script just one date or time is given to be automated. my problem is bit complicated. i have two columns in my attribute table (Start_time, Total_time). another blank column with alis Finish_Time. I want to add these two to get finish_time column automated. remember the total time is in hours format not in date format. e.g.. Start_time+Total_time = finish_time Please be VERY specific here. What are the exact field types for all 3 fields? (I don't quite understand what your "Total_time" field type is). I just tested the code below and it updates field "finish_time" just fine by adding "Total_time" field to the "Start_time" field, with the output as a new datetime. However, it is important to know what the field types are: Start_time: Date Total_time: Short Integer finish_time: Date import arcpy import datetime import timedelta fc = r"H:\Documents\ArcGIS\Default.gdb\TimeDelta" cursor = arcpy.UpdateCursor(fc) for row in cursor: startdate = row.Start_time totaltime = row.Total_time upddate = datetime.timedelta(hours = totaltime) later = startdate + upddate row.setValue("finish_time", later) cursor.updateRow(row)
... View more
05-03-2013
04:40 AM
|
0
|
0
|
3404
|
| 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
|