0

我希望为 ArcGIS 创建一个 python 插件工具,其工作方式类似于使用 python 的 ArcGIS 识别工具。该工具必须是这样的,当我单击一个点或要素时,它会从要素中读取特定属性。

具体来说,我希望开发一个超链接工具。但目前只能从要素类或图层的字段中读取超链接。我还可以创建一个带有按钮的 GUI,这些按钮充当打开我的照片和已链接到我的功能的全景图的超链接。

我已经包含我的代码来澄清我的问题。亲切的问候。以下是我目前拥有的代码:

    #!/usr/bin/env python
import PyQt4
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
import Image
import os, sys
import webbrowser
import arcpy

class HyperlinkWindow(QtGui.QMainWindow):

    def __init__(self, win_parent = None):
        #Init the base class
        QtGui.QMainWindow.__init__(self, win_parent)
        self.create_widgets()


    def create_widgets(self):
        #Widgets
       self.panorama_button = QtGui.QPushButton("Panorama")
       self.photo_button = QtGui.QPushButton("Photo")

#connect signal
       QtCore.QObject.connect(self.panorama_button
           , QtCore.SIGNAL("clicked()")
           , self.on_hello_clicked)
       QtCore.QObject.connect(self.photo_button
                   , QtCore.SIGNAL("clicked()")
                   , self.on_photo_clicked)


#Horizontal layout
        h_box = QtGui.QHBoxLayout()
        h_box.addWidget(self.panorama_button)
        h_box.addWidget(self.photo_button)
#Create central widget, add layout and set
        central_widget = QtGui.QWidget()
        central_widget.setLayout(h_box)
        self.setCentralWidget(central_widget)

    def on_hello_clicked(x):

            featureClass = "My_Featureclass"
            rows = arcpy.SearchCursor(featureClass)
            row = rows.next()

            while row:
                webbrowser.open(row.Panorama)
                print row.panorama
                row = rows.next()
    def on_photo_clicked(y):
            featureClass1 = "My_Featureclass"

            rows1 = arcpy.SearchCursor(featureClass1)
            row1 = rows1.next()


            while row1:

                webbrowser.open (row1.Photo)
                print row1.Photo
                row1 = rows1.next() 
4

1 回答 1

0

对不起。我已经意识到,要实现这一点,必须选择功能。如果选择了特征/点,则脚本仅读取此类点的属性。我已经设法编写了一个我认为应该如我所愿的脚本。但问题是每当我运行加载项 ArcGIS 时,总是崩溃......

我将在此处附上脚本以供任何希望使用它的人使用....:

    import arcpy
    import pythonaddins
    import PyQt4
    import sys
    from PyQt4 import QtGui
    from PyQt4 import QtCore
    import Image
    import os, sys
    import webbrowser

    class HyperlinkWindow(QtGui.QMainWindow, HyperlinkXAButton):

         def __init__(self, win_parent = None):
    #Init the base class
            QtGui.QMainWindow.__init__(self, win_parent)
            self.create_widgets()


         def create_widgets(self):
    #Widgets
             self.panorama_button = QtGui.QPushButton("Panorama")
             self.photo_button = QtGui.QPushButton("Photo")

    #connect signal
             QtCore.QObject.connect(self.panorama_button
                , QtCore.SIGNAL("clicked()")
                , self.on_hello_clicked)
             QtCore.QObject.connect(self.photo_button
                        , QtCore.SIGNAL("clicked()")
                        , self.on_photo_clicked)


    #Horizontal layout
            h_box = QtGui.QHBoxLayout()
            h_box.addWidget(self.panorama_button)
            h_box.addWidget(self.photo_button)
    #Create central widget, add layout and set
            central_widget = QtGui.QWidget()
            central_widget.setLayout(h_box)
            self.setCentralWidget(central_widget)

        def on_hello_clicked(x):
        #x = "Push Me!"
                if x:
                    arcpy.env.workspace = "MyDatabase"
                    featureClass = arcpy.MakeFeatureLayer_management("MyFeatureClass","q")
                    fld = "Panorama"
                    rows = arcpy.SearchCursor(featureClass)
                    for row in rows:
                        webbrowser.open (row.getValue(fld))


        def on_photo_clicked(y):
                if y:
                    arcpy.env.workspace = "MyDatabase"
                    featureClass = arcpy.MakeFeatureLayer_management(MyFeatureClass","u")
                    fld = "Photo"
                    rows = arcpy.SearchCursor(featureClass)
                    for row in rows:
                        webbrowser.open (row.getValue(fld))

     if __name__ == "__main__":
# Someone is launching this directly
# Create the QApplication
        app = QtGui.QApplication(sys.argv)
#The Main window
        main_window = HyperlinkWindow()
        main_window.show()
# Enter the main loop
        app.exec_()


    class HyperlinkButton(object):
        """Implementation for HyperlinkButton_addin.button (Button)"""
        def __init__(self):
            self.enabled = True
            self.checked = False
        def onClick(self):
                 self.w = HyperlinkWindow()
                 self.w.show()
            return 

或者,可以使用插件工具代替按钮...

于 2013-03-28T10:18:53.987 回答