ArcGIS Python工具读取单个点属性

0 投票
1 回答
887 浏览
提问于 2025-04-17 19:29

我想创建一个Python插件工具,用于ArcGIS,功能类似于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() 

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 

另外,也可以使用插件工具来代替按钮...

撰写回答