Can I add Z value from a window, after got XY from mouse click

2988
4
01-04-2016 10:54 PM
SebahatT_K
New Contributor II

Hi all,

I would like to create a point shape with Z value in ArcMap, for that I was created a tool using python addin toolbar. The tool can get XY coordinates from mouse click on datafreme. Now I want to add Z value as manuel for this point. Can I add Z value from a window by created QWidget or other PyQt4 windows, after got the XY position on dataframe for my point shape. Is there any way to do this using python? Can you kindly give any advices?

My current code:

There is global z in my code, it is just a simple solution and I dont want to use it. You know it isn't useful way.

import arcpy
import pythonaddins
arcpy.env.overwriteOutput = True
arcpy.env.addOutputsToMap = True
arcpy.CheckExtension('3D')


class Observation_Point(object):
    """Implementation for addin5_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "NONE"
    def onMouseDown(self, x, y, button, shift):
        pass
    def onMouseDownMap(self, x, y, button, shift):
        #choose XY on dataframe
        mxd = arcpy.mapping.MapDocument("current")
        dataframe = arcpy.mapping.ListDataFrames(mxd)[0]
        global z
        z= 20
        PointGeom = arcpy.PointGeometry(arcpy.Point(x,y,z), None, True, False)
        global A
        A = "C:\\Users\\Casper\\Desktop\\DENEMELER\\obs_point_fromAddin5.shp"
        arcpy.CopyFeatures_management(PointGeom, A)
        print "saved as a point.shp..."
    def onMouseUp(self, x, y, button, shift):
        pass
    def onMouseUpMap(self, x, y, button, shift):
        pass
    def onMouseMove(self, x, y, button, shift):
        pass
    def onMouseMoveMap(self, x, y, button, shift):
        pass
    def onDblClick(self):
        pass
    def onKeyDown(self, keycode, shift):
        pass
    def onKeyUp(self, keycode, shift):
        pass
    def deactivate(self):
        pass
    def onCircle(self, circle_geometry):
        pass
    def onLine(self, line_geometry):
        pass
    def onRectangle(self, rectangle_geometry):
        pass
0 Kudos
4 Replies
LukeSturtevant
Occasional Contributor III

After you get your point you might be able to run extract values to points​ or extract multi values to points​ or Add Surface Information. Then you could either run a quick update cursor​ or  Feature To 3D By Attribute​ to insert the Z value.

SebahatT_K
New Contributor II

Thank you very much for your reply, it can be a alternative way. But I want to add Z from a window. Maybe you know that  there is Create Line of Sight button which when you click this button opens a window in 3D Analyst Toolbar in ArcMap. I want to create like this windows and want to manually write Z value. So, unfortunately I dont know what I do.

0 Kudos
LukeSturtevant
Occasional Contributor III

Yes, I do know about the Create Line of Sight button on the 3D Analyst toolbar, but I'm not sure how you would use python with this tool. There is a Construct Sight Lines​ tool that you might be able to use, but it looks like the tool assumes the points have Z values already? I have not played around with that tool before. Let us know what you find out.

0 Kudos
JamesCrandall
MVP Frequent Contributor

Have you attempted to use raw_input?  I don't know if it'd work in this context, but give it a go!

def onMouseDownMap(self, x, y, button, shift):  
        #choose XY on dataframe  
        mxd = arcpy.mapping.MapDocument("current")  
        dataframe = arcpy.mapping.ListDataFrames(mxd)[0]  
        global z
        var = raw_input("Enter Z-Value: ")
        z= int(var)  
        PointGeom = arcpy.PointGeometry(arcpy.Point(x,y,z), None, True, False)  
        global A  
        A = "C:\\Users\\Casper\\Desktop\\DENEMELER\\obs_point_fromAddin5.shp"  
        arcpy.CopyFeatures_management(PointGeom, A)  
        print "saved as a point.shp..."