从父多边形创建和编辑多个闭合多边形

时间:2016-11-20 02:20:47

标签: python tkinter gis polygon

我需要绘制多个闭合多边形,其中一旦创建了第一个多边形,后续多边形就连接到先前创建的多边形的一部分并由其组成。因此我需要: 1.创建闭合多边形。 (说右键单击关闭打开Poly) 2.单击现有多边形的节点(线段的终点)以开始下一个新多边形....并在现有多边形上完成,以便新多边形具有由现有多边形的一部分形成的点。 如图2(a)所示,当光标悬停在现有节点上时,光标形状从十字线变为DOT 在下面的Mock up图片中,它显示了一个红色的封闭多边形和一个与Red One相连的新绿色折线,应该用它来创建一个新的蓝色封闭多边形 enter image description here 新的封闭多边形 enter image description here 现在有两个来自Original Red One的新PolyLines,Blue One和Green One: enter image description here 此外应该能够点击移动重合节点,或在重合多边形中插入新点......

这最初似乎很简单......但很快就显得更复杂了?

我找到了允许绘制线条的基本代码,必须将其修改为1.关闭折线以形成多边形(线条在关闭时不能交叉)2。选择节点以创建新的多边形等。

`# Simple Canvas example
#
from Tkinter import *

#We define a drawing class here:
class Drawing():

    #This is the constructor. It draws the window with the canvas.
    def __init__(self, tkMainWin):
        frame = Frame(tkMainWin)
        frame.pack()

        self.lines = []
        self.lastX = None
        self.lastY = None
        self.redLine = None

        self.canvas = Canvas(frame)
        self.canvas.bind("<Button-1>",self.clicked)
        self.canvas.bind("<Button-3>",self.rightClicked)
        self.canvas.bind("<Motion>",self.mouseMoved)
        self.canvas.pack()

    #This event handler (callback) will draw lines, saving their ID
    #in a list.
    def clicked(self, event):

        print("Button down!")

        if self.lastX != None:
            l = self.canvas.create_line(self.lastX,self.lastY,event.x,event.y)
            self.lines.append(l)

        self.lastX = event.x
        self.lastY = event.y
        pass

    #This handler deals with "right-click" events, which cause the
    #last line drawn to be deleted!
    def rightClicked(self,event):
        print("rightClicked!")
        self.lastX = None
        self.lastY = None
        if (len( self.lines) > 0):
            self.canvas.delete( self.lines[-1])
            del self.lines[-1]  #Need to keep our data structure in
                            #sync with the canvas
        #Manage the red line!
        if self.redLine != None:
            self.canvas.delete(self.redLine)
            self.redLine = None


    #This handler deals with "mouse motion" events, and draws a red
    # "rubber-band" line illustrating where the next line will be
    # drawn if the user clicks now...
    def mouseMoved(self, event):
        print("Mouse Moved!")

        if self.lastX != None:
            if self.redLine != None:
                 self.canvas.delete(self.redLine);
            self.redLine = self.canvas.create_line(self.lastX, self.lastY,
                                        event.x, event.y, fill="red")
    #NEED a handler that deals with "mouse motion" that is close to an   existing X,Y point and changes the Cursor
    # to Allow Lock onto the point to create Coincident point in New Polygon
    # 
    def mousenearExistpoint(self, event):
        pass


#This code starts up TK and creates a main window.
mainWin = Tk()
#This code creates an instance of the TTT object.
ttt = Drawing( mainWin)
#This line starts the main event handling loop and sets us on our way...
mainWin.mainloop()`

在以后的日期,我想添加简单的属性,例如每个多边形的区域或名称...... 目的是协助建立Catchment模型。它就像一个非常简单的GIS应用程序。

0 个答案:

没有答案