Object Model Diagram for ArcPy in ArcGIS 10.2.1
Getting and Setting Values in a Table ArcGIS implementation of the vector spatial data model uses a database-style method of storing data It is a spatial version of a relational database management system (RDBMS) Any given vector dataset is stored in a table, using database terminology Within a table, there is a set of rows, one for each record There is also a set of fields, one for each attribute The characteristics of the spatial part of the data are stored in a special kind of field, where the needed x-y coordinate pair(s) are stored The intersection of a row and a field is a cell, which contains a value, which can be one of many data types
Getting and Setting Values in a Table - Cursors To work with the rows in a table, a cursor is used A cursor is a database technology term for a way of accessing a set of records in a table and can be used to iterate over the set of records in a table to read values, or to insert new records, or to write values in records There are three types of cursors: 1. A search cursor is used to retrieve rows 2. An insert cursor is used to insert rows 3. An update cursor is used to update and delete rows Each type of cursor is created by a function in arcpy.da (the data access module): SearchCursor, InsertCursor, and UpdateCursor
Object Model Diagram for ArcPy in ArcGIS 10.2.1 Data Access Module (arcpy.da) Note: There are functions to create the cursors, and the cursor classes themselves
Methods Supported by Cursor Type ArcGIS 10.2.1 arcpy.da Cursor Type Method Descrip2on Search next reset Gets the next row Returns the cursor to its star2ng posi2on Insert insertrow Inserts a new row into the table deleterow Removes a row from the table Update next reset Retrieves the next row from the table Returns the cursor to its star2ng posi2on updaterow Updates the current row
Getting and Setting Values in a Table - Cursors Cursors move through a table from the 0 th record to the n th record in a forward direction: They cannot go backwards to a previous record If you need to return to a record that is before the cursor s current position, you need to make another pass
Getting and Setting Values in a Table - Cursors A for loop can be used with search and update cursors to iterate through the set of rows in a table Alternatively, a while loop can be used in conjunction with the next method to move from record to record A call to the next method once the last row has been reached will return an exception that lets you know you just asked for a row that does not exist Exceptions result in a fairly specific error message being passed to you in the Results window, which is very useful because this is a case where ArcGIS tells you exactly what went wrong, which makes it a lot easier to figure out, and fix the problem!
Geometries The Spatial Part of the Data Amongst the data types you can manipulate in a table is the spatial data itself, via geometry objects Recall that the set of vertices that defines any given feature in a vector dataset is stored in a particular field in its associated table, and this information can be accessed via a cursor By reading the set of vertices into an appropriate geometry object, one can then manipulate them in any number of ways Likewise, a geometry object can be constructed, and then written into a particular record in an appropriate database table
Object Model Diagram for ArcPy in ArcGIS 10.2.1 Geometry and Spatial Classes Point Geometry Extent Polyline Spatial Reference Point Multipoint Geometry Polygon Functions There is a geometry class for all of the usual geographic primitives that we see represented in ArcGIS vector spatial data model You probably can recognize point, polyline and polygon classes, but may not be familiar with the multipoint class and some of the others
Object Model Diagram for ArcPy in ArcGIS 10.2.1 Geometry and Spatial Classes The Geometry class has methods and properties that the other geometries inherit Most of the functionality you need for points is found in the PointGeometry Class; there are just a few methods and properties in the Point class
Object Model Diagram for ArcPy in ArcGIS 10.2.1 Geometry and Spatial Classes The higher dimension Geometry classes all have very similar methods and properties
Object Model Diagram for ArcPy in ArcGIS 10.2.1 Geometry and Spatial Classes The SpatialReference class is used to deal with coordinate system issues, so ArcGIS knows how to project an x-y pair The Extent class is used to describe the minimum bounding rectangle of a geometry object, and to make comparisons between Extents
Creating Custom Geoprocessing Tools Once you have a useful script, at some point you may want to share it with other ArcGIS users Those other users might not be Python coders You need a way to give them your script without them ever having to see your code; they just want to run it! This is actually fairly easy to do in ArcGIS: 1. Create a new Toolbox where you can save your Script 2. Create a new Tool in your Toolbox using Add Script 3. Set up your Tool, importing your code and setting up Parameters, which users set using the Tool s interface You will need to modify your code a little to pass Parameters properly between the interface and the script
Creating Custom Geoprocessing Tools 1. Create a new Toolbox where you can save your Script
Creating Custom Geoprocessing Tools 2. Create a new Tool in your Toolbox using Add Script
Creating Custom Geoprocessing Tools 3. Set up your Tool, importing your code and setting up Parameters, which users set using the Tool s interface
Creating Custom Geoprocessing Tools 3. Continued: You will need to modify your code a little to pass Parameters properly between the interface and the script
Creating Custom Geoprocessing Tools You can then share the Toolbox file (.tbx) with others, and they will be able to make use of the script / tool you have made (provided they have the right version of ArcGIS so Python versions match!) Through the use of Parameters, and building a little interface for your Tool, it will work and look just like any other Geoprocessing Tool in ArcGIS: Users will be able to set up the input and output (as necessary) for your Tool, and any other required Parameters You have the option of encrypting your code so others cannot see it, or you can leave it available to export so they can access it, and if necessary modify it / improve it!