In this example, a shapefile will be created from outside of ArcMap and will have a projection. There will be no attributes created for this file. The construction of the shapefile/feature class file is done using an IDE in program mode. The Cursor and List commands were not used but could have been used to populate the shapefile. Therefore, what is created is an empty shapefile/feature class file. The tool used in this example is the CreateFeatureclass tool, which is located in the management toolbox and the SpatialReference command. An existing projection file (localrds) is used to set the projection for the new feature class file. This example will use a geodatabase as the storage location. The code is shown in Figure 10.
- Arcpy is imported and the environment is set.
- Three variables are defined; the third is the pathway to the projection file that will be used.
- The fourth variable projectionFile defines the projection of the created file to be the same as that of the localrds file; it uses the SpatialReference command.
- The print command is not required it is used only to show that the operation is working properly.
- The final command is the CreateFeatureclass, which is a tool in the management toolbox.
- The first parameter is the pathway to where the new file will be created
- The next parameter is the name of the file that will be created
- The third parameter is the type of file that will be created and for this case it is a line file
- The next three parameters are not defined and thus are skipped; the final parameter is the projection type, which is defined in the projectionFile variable.