David,While this is the reverse of what you want, I think it should be able to give you some ideas. I will need to do the same as you soon, but just havn't had the opportunity to do so just yet.I think you will need get the properties of the DataFrame to convert from page units to preferred projected coordinates.http://gis.stackexchange.com/questions/21514/convert-point-xy-to-page-units-xy-using-arcpy
class Sel_Property(object): """Implementation for Notifications_addin.selectproperty (Tool)""" def __init__(self): self.enabled = False self.shape = "NONE" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks. def onMouseDownMap(self, x, y, button, shift): thisMap = arcpy.mapping.MapDocument("CURRENT") data_frame = arcpy.mapping.ListDataFrames(thisMap)[0] page_x = x page_y = y """Convert page coordinates to projected coordinates""" #get the data frame dimensions in page units df_page_w = data_frame.elementWidth df_page_h = data_frame.elementHeight df_page_x_min = data_frame.elementPositionX df_page_y_min = data_frame.elementPositionY df_page_x_max = df_page_w + df_page_x_min df_page_y_max = df_page_h + df_page_y_min #get the data frame projected coordinates df_min_x = data_frame.extent.XMin df_min_y = data_frame.extent.YMin df_max_x = data_frame.extent.XMax df_max_y = data_frame.extent.YMax df_proj_w = data_frame.extent.width df_proj_h = data_frame.extent.height #ensure the coordinates are in the dataframe if page_x < df_page_x_min or page_x > df_page_x_max: raise ValueError ('X coordinate is not within map portion of the page.') if page_y < df_page_y_min or page_y > df_page_y_max: raise ValueError ('Y coordinate is not within map portion of the page.') #scale the projected coordinates to map units from the lower left of the data frame scale = data_frame.scale/12 # converting scale factor to feet per inch map_x = df_min_x + ((page_x - df_page_x_min)*scale) map_y = df_min_y + ((page_y - df_page_y_min)*scale) # pythonaddins.MessageBox("Coordiantes are" + str(map_x) + " and " + str(map_y),"Title") pointGeom = arcpy.PointGeometry(arcpy.Point(map_x,map_y), thisMap.activeDataFrame.spatialReference) layers = arcpy.mapping.ListLayers(thisMap) for lyr in layers: if lyr.name == "Cadastre": arcpy.SelectLayerByLocation_management(lyr,"INTERSECT",pointGeom) thisMap.activeView = "PAGE_LAYOUT" arcpy.RefreshActiveView() data_frame.zoomToSelectedFeatures() data_frame.scale = data_frame.scale * 5.2
I'm getting the code to work for onMouseDownMap, but while in layout view the value I'm getting back is still in page coordinates and not map coordinates ... unless I go to the data view. Then I get map coordinates.Is this how it's supposed to work, or is there a was to focus the data frame and get map coordinates.class Sel_Property(object): """Implementation for Notifications_addin.selectproperty (Tool)""" def __init__(self): self.enabled = True self.shape = "NONE" # Can set to "Line", "Circle" or "Rectangle" ... def onMouseDownMap(self, x, y, button, shift): pythonaddins.MessageBox("Your mouse clicked at " + str(x) + " , " + str(y),"My Coordinates:")
class Sel_Property(object): """Implementation for Notifications_addin.selectproperty (Tool)""" def __init__(self): self.enabled = True self.shape = "NONE" # Can set to "Line", "Circle" or "Rectangle" ... def onMouseDownMap(self, x, y, button, shift): pythonaddins.MessageBox("Your mouse clicked at " + str(x) + " , " + str(y),"My Coordinates:")
import arcpy import pythonaddins class XY(object): """Implementation for xy_addin.tool (Tool)""" def __init__(self): self.enabled = True self.cursor=3 def onMouseDownMap(self, x, y, button, shift): mxd=arcpy.mapping.MapDocument("current") df = arcpy.mapping.ListDataFrames(mxd)[0] pt=arcpy.PointGeometry(arcpy.Point(x,y)) #ptfeat=arcpy.management.CopyFeatures(pt,r"in_memory\pt") print x,y pythonaddins.MessageBox("Long" + " " + str(x) + '\n'+ "Lat"+ " " + str(y), 'Coordinates', 0)
import arcpy import pythonaddins class XY(object): """Implementation for xy_addin.tool (Tool)""" def __init__(self): self.enabled = True self.cursor=3 def onMouseDownMap(self, x, y, button, shift): mxd=arcpy.mapping.MapDocument("current") df = arcpy.mapping.ListDataFrames(mxd)[0] pt=arcpy.PointGeometry(arcpy.Point(x,y)) #ptfeat=arcpy.management.CopyFeatures(pt,r"in_memory\pt") print x,y pythonaddins.MessageBox (arcpy.Point(x,y) ,'Location','0') pass
import arcpy import pythonaddins class XYTool(object): """Implementation for xy_addin.XYTool (Tool)""" def __init__(self): self.enabled = True self.cursor=3 def onMouseDownMap(self, x, y, button, shift): mxd=arcpy.mapping.MapDocument("current") df = arcpy.mapping.ListDataFrames(mxd)[0] pt=arcpy.PointGeometry(arcpy.Point(x,y)) #ptfeat=arcpy.management.CopyFeatures(pt,r"in_memory\pt") print x,y pythonaddins.MessageBox(str(x) + ", " + str(y), 'Coordinates', 0)
import arcpy import pythonaddins class XYTool(object): """Implementation for xy_addin.XYTool (Tool)""" def __init__(self): self.enabled = True self.cursor=3 def onMouseDownMap(self, x, y, button, shift): mxd=arcpy.mapping.MapDocument("current") df = arcpy.mapping.ListDataFrames(mxd)[0] pt=arcpy.PointGeometry(arcpy.Point(x,y)) #ptfeat=arcpy.management.CopyFeatures(pt,r"in_memory\pt") print x,y
import arcpy input = arcpy.GetParameterAsText(0) cur = arcpy.SearchCursor(input) for row in cur: geom = row.Shape X = geom.centroid.X Y = geom.centroid.Y XY = str(X) + ", " + str(Y) del row, cur arcpy.AddMessage(XY)
import win32ui,win32con for i in range(32) : ok = win32ui.MessageBox("type"+str(i),"Message Title",i) print "Form type",i,"Button",ok
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.