官术网_书友最值得收藏!

  • ArcGIS Blueprints
  • Eric Pimpler
  • 624字
  • 2021-07-30 09:50:02

Creating the Import Collar Data tool

The following steps will help you to create Import Collar Data tool:

  1. Right-click on MigrationPatterns.pyt and select Edit. This will open your development environment, as shown in the following screenshot. Your environment will vary depending upon the editor that you defined in Chapter 1, Extracting Real-Time Wildfire Data from ArcGIS Server with the ArcGIS REST API:
  2. Remember that you will not be changing the name of the class, which is Toolbox. However, you will rename the Tool class to reflect the name of the tool you want to create.
  3. Find the class named Tool in your code and change the name of this tool to ImportCollarData, and set the label and description properties:
    class ImportCollarData(object):
        def __init__(self):
            """Define the tool (tool name is the name of the class)."""
            self.label = "Import Collar Data"
            self.description = "Import Elk Collar Data"
            self.canRunInBackground = False

    You can use the Tool class as a template for other tools you'd like to add to the toolbox by copying and pasting the class and its methods. We'll do this in a later step, when we create the tool that enables the display of the elk migration patterns over time.

  4. You will need to add each tool to the tools property (the Python list) in the Toolbox class. Add the ImportCollarData tool, as shown in the following code:
    def __init__(self):
            """Define the toolbox (the name of the toolbox is the name of the
            .pyt file)."""
            self.label = "Toolbox"
            self.alias = ""
    
            # List of tool classes associated with this toolbox
            self.tools = [ImportCollarData]
    
  5. Assuming that you don't have any syntax errors, you should see the following Toolbox or Tool structure:
  6. In this step, we'll set the parameters for the tool. The ImportCollarData tool will need parameters that accept the csv file to be imported along with an output feature class, where the data will be written, and an input feature class to be used for schema purposes. Use the getParameterInfo() method to define the parameters for your tool. Individual parameter objects are created as part of this process. Add the following parameters, and then we'll discuss what the code is doing:
    def getParameterInfo(self):
            param0 = arcpy.Parameter(displayName = "CSV File to                      Import", \
                            name="fileToImport", \
                            datatype="DEFile", \
                            parameterType="Required",\
                            direction="Input")
    
            param1 = arcpy.Parameter(displayName = "Output Feature Class", \
                            name="out_fc", \
                            datatype="DEFeatureClass",\
                            parameterType="Required",\
                            direction="Output")
    
            param2 = arcpy.Parameter(displayName = "Schema Feature Class", \
                            name="schema_fc", \
                            datatype="DEFeatureClass",\
                            parameterType="Required",\
                            direction="Input")

    Each Parameter object is created using arcpy.Parameter and is passed a number of arguments that define the object.

    For the first parameter object (param0), we are going to capture a file reference that, in this case, will be a reference to a csv file containing the elk migration data. We give it a display name (CSV File to Import), which will be displayed on the dialog box for the tool, a name for the parameter, a datatype, a parameter type (required), and a direction.

    For the second parameter, we're going to define an output feature class, where the elk migration data that is read from the file will be written. Our tool will create this feature class.

    The final parameter is also a feature class but has a direction of input and will be used to specify an existing feature class from which we'll pull the schema.

  7. Next, we'll add both the parameters to a Python list called params and return the list to the calling function. Add the following code:
    def getParameterInfo(self):
            param0 = arcpy.Parameter(displayName = "CSV File to Import", \
                            name="fileToImport", \
                            datatype="DEFile", \
                            parameterType="Required",\
                            direction="Input")
    
            param1 = arcpy.Parameter(displayName = "Output Feature Class", \
                            name="out_fc", \
                            datatype="DEFeatureClass",\
                            parameterType="Required",\
                            direction="Output")
    
            param2 = arcpy.Parameter(displayName = "Schema Feature Class", \
                            name="schema_fc", \
                            datatype="DEFeatureClass",\
                            parameterType="Required",\
                            direction="Input")
    
            params = [param0, param1, param2]
     return params
    
主站蜘蛛池模板: 钟祥市| 通化市| 兰坪| 教育| 绥化市| 桑植县| 柘城县| 德庆县| 华坪县| 余庆县| 阆中市| 西藏| 凤山县| 顺平县| 汉阴县| 新乡县| 彰化市| 宁明县| 太仓市| 治县。| 新营市| 江口县| 疏附县| 泸水县| 子洲县| 疏勒县| 绍兴县| 横峰县| 西安市| 老河口市| 信丰县| 廊坊市| 贺兰县| 乡城县| 富裕县| 遵义县| 安新县| 紫阳县| 宣恩县| 固安县| 罗城|