arcpy.CutFeatures_management

Idea created by johnmdye on May 28, 2013
    New
    Score10
    • johnmdye

         We can create features, copy features and delete features through arcpy, it would be nice to see a CutFeatures or MoveFeatures function so that after copying, I don't have to go back and delete the original features.

         I suppose there is some risk involved in this though as it could mean if your function fails then your original data is ruined, I don't know. Just seems logical to me.
          

              Summary

              Cuts features from the input feature class using an SQL Expression to select features. If not ExpressionIf the input is a layer which has a selection, only the selected features will be copied. If the out_feature_class is located inside a Feature Dataset, the features will be projected to match the spatial reference of the Feature Dataset.

              Usage

              The select or SQL expression gets built with the Query Builder, or is simply typed in. For details on the expression syntax see Building an SQL Expression or SQL Reference.

              If a layer is used for Input Features and no expression is entered, all features are written to the output feature class and the Input Feature Class is deleted. If a layer is used for Input Features and already has a selection applied, the expression is only executed against the selected features, and the expression-based subset of the selected set is written to the output feature class.
               
              Both the geometry and attributes of the Input Features will be copied to the output feature class.
               
              This tool can be used for data conversion as it can read many feature formats (any you can add to ArcMap) and write these to shapefile or geodatabase (File, Personal, or ArcSDE).

              Syntax

              CutFeatures_management (in_features, out_feature_class, {where_clause}, {config_keyword}, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3})
                             Parameter                          Explanation                          Data Type
                             
                                  in_features
                        
                             

                                  The features to be copied.

                        
                             Feature Layer;Raster Catalog Layer
                             
                                  out_feature_class
                        
                             

                                  The feature class which will be created and to which the features will be copied. If the output feature class already exists and the overwrite option is set to true, the output will be deleted first. If the output feature class already exists and the overwrite option is set to false, the operation will fail.

                        
                             Feature Class
                             
                                  where_clause
                             
                                  (Optional)
                        
                             

                                  An SQL expression used to select a subset of features. The syntax for the expression differs slightly depending on the data source. For example, if you're querying file or ArcSDE geodatabases, shapefiles, or coverages, enclose field names in double quotes:

                             

    "MY_FIELD"

                             

                                  If you're querying personal geodatabases, enclose fields in square brackets:

                             

    [MY_FIELD]

                             

                                  In Python, strings are enclosed in matching single or double quotes. To create a string that contains quotes (as is common with a WHERE clause in SQL expressions), you can escape the quotes (using a backslash) or triple quote the string. For example, if the intended WHERE clause is

                             

    "CITY_NAME" = 'Chicago'

                             

                                  you could enclose the entire string in double quotes, then escape the interior double quotes like this:

                             

    " \"CITY_NAME\" = 'Chicago' "

                             

                                  Or you could enclose the entire string in single quotes, then escape the interior single quotes like this:

                             

    ' "CITY_NAME" = \'Chicago\' '

                             

                                  Or you could enclose the entire string in triple quotes without escaping:

                             

    """ "CITY_NAME" = 'Chicago' """

                             

                                  For more information on SQL syntax and how it differs between data sources, see the help topic SQL reference for query expressions used in ArcGIS.

                        
                             SQL Expression
                             
                                  config_keyword
                             
                                  (Optional)
                        
                             

                                  Geodatabase configuration keyword to be applied if the output is an ArcSDE geodatabase or file geodatabase.

                        
                             String
                             
                                  spatial_grid_1
                             
                                  (Optional)
                        
                             

                                  The Spatial Grid 1, 2, and 3 parameters apply only to file geodatabases and certain ArcSDE geodatabase feature classes. If you are unfamiliar with setting grid sizes, leave these options as 0,0,0 and ArcGIS will compute optimal sizes for you. For more information about this parameter, refer to the Add Spatial Indextool documentation.

                        
                             Double
                             
                                  spatial_grid_2
                             
                                  (Optional)
                        
                             

                                  Cell size of the second spatial grid. Leave the size at 0 if you only want one grid. Otherwise, set the size to at least three times larger than Spatial Grid 1.

                        
                             Double
                             
                                  spatial_grid_3
                             
                                  (Optional)
                        
                             

                                  Cell size of the third spatial grid. Leave the size at 0 if you only want two grids. Otherwise, set the size to at least three times larger than Spatial Grid 2.

                        
                             Double

              Code Sample

    CutFeatures example (Python window)

                             The following Python window script demonstrates how to use the CutFeatures tool in immediate mode.

    importarcpyfromarcpyimportenvenv.workspace="C:/data"arcpy.CutFeatures_management (climate.shp","C:/output/output.gdb/climate, '"ID" = ' + "Cloudy with a chance of Meatballs")