Extract Data From Geodatabase (Data Management)

Summary

Extracts a subset of data from one geodatabase to another geodatabase or an .xml file.

Learn more about extracting data from a geodatabase

Usage

  • This tool provides similar functionality to copying data from one geodatabase to another but supports copying a subset of data by setting the Extent environment, specifying a Extract Using Geometry Features parameter value, or using a selection. You can also extract the schema and data or schema only.

  • This tool can also be used to extract the schema only for a specified spatial reference by using the Output Coordinate System environment. Once the schema is obtained in the desired spatial reference, you can use the Reuse Schema parameter's Reuse option to extract the data to the new schema. The Output Coordinate System environment is ignored when the data extract type is used.

Parameters

LabelExplanationData Type
Datasets to Extract

The data that will be extracted.

Table View; Dataset
Extract
(Optional)

Specifies whether the schema and rows of the data or only the schema will be extracted.

  • DataThe schema and rows will be extracted. This is the default.
  • Schema onlyOnly the schema will be extracted.
String
Output Type
(Optional)

Specifies the output type the data will be extracted to.

  • GeodatabaseThe data will be extracted to an existing geodatabase. This is the default.
  • XML fileThe data will be extracted to an XML workspace document.
  • New file geodatabaseThe data will be extracted to a new file geodatabase. Specify the location and name of the new file geodatabase using the Geodatabase Location and Geodatabase Name parameters.
String
Geodatabase to Extract Data to
(Optional)

The geodatabase that will contain the extracted data when the Output Type parameter is set to Geodatabase.

Workspace
XML File to Extract Data to
(Optional)

The name and location of the .xml file that will be created when the Output Type parameter is set to XML file.

File
Geodatabase Location
(Optional)

The location of the file geodatabase that will be created for the extracted data. This parameter is required when the Output Type parameter is set to New file geodatabase.

Folder
Geodatabase Name
(Optional)

The name of the file geodatabase that will be created for the extracted data. This parameter is required when the Output Type parameter is set to New file geodatabase.

String
Expand Feature Classes and Tables
(Optional)

Specifies whether expanded feature classes and tables—such as those in networks, topologies, or relationship classes—will be added.

  • Use defaultsThe expanded feature classes and tables related to the feature classes and tables in the input datasets will be added. The default for feature classes is to extract all features intersecting the spatial filter. If no spatial filter has been provided, all features will be included. The default for tables is to extract the schema only. This is the default.
  • Add with schema onlyOnly the schema for the expanded feature classes and tables will be added.
  • All rowsAll rows for expanded feature classes and tables will be added.
  • Do not addNo expanded feature classes or tables will be added.
String
Reuse Schema
(Optional)

Specifies whether a geodatabase that contains the schema of the data to be extracted will be reused. Reusing the schema reduces the amount of time required to extract the data.

  • Do not reuseThe schema will not be reused. This is the default.
  • ReuseThe schema will be reused.
String
Extract Related Data
(Optional)

Specifies whether rows related to rows existing in the data will be extracted. For example, a feature (f1) is inside the geometry filter and a related feature (f2) from another class is outside the filter. Feature f2 will be included in the extracted data if you choose to get related data.

  • Do not get relatedRelated data will not be extracted.
  • Get relatedRelated data will be extracted. This is the default.
String
Extract Using Geometry Features
(Optional)

The features that will be used to define the area to extract.

Feature Layer
Geometry Filter Type
(Optional)

Specifies the spatial relationship between the Extract Using Geometry Features and Input Datasets parameter values and how that relationship will be filtered. The spatial relationship is applied to data in an extent defined by the area of interest (AOI) specified in the Extract Using Geometry Features parameter.

  • IntersectsFeatures in the Input Datasets parameter value that intersect features in the Extract Using Geometry Features parameter value will be extracted.
  • ContainsFeatures in the Input Datasets parameter value that are contained by the selected feature in the Extract Using Geometry Features parameter value will be extracted.
String
All records for tables
(Optional)

Specifies whether all records or only the schema will be extracted for tables that do not have filters applied (such as selections or definition queries).

Tables with applied filters will be honored.

  • Checked—All records will be extracted to the geodatabase. This option will override the Expand Feature Classes and Tables parameter value.
  • Unchecked—Only the schema will be extracted to the geodatabase for tables. This is the default.

Boolean

Derived Output

LabelExplanationData Type
Output Geodatabase

The output workspace.

Workspace

arcpy.management.ExtractDataFromGeodatabase(in_data, {extract_type}, {out_type}, {out_geodatabase}, {out_xml}, {out_folder_path}, {out_name}, {expand_feature_classes_and_tables}, {reuse_schema}, {get_related_data}, {extract_using_geometry_features}, {geometry_filter_type}, {all_records_for_tables})
NameExplanationData Type
in_data
[in_data,...]

The data that will be extracted.

Table View; Dataset
extract_type
(Optional)

Specifies whether the schema and rows of the data or only the schema will be extracted.

  • DATAThe schema and rows will be extracted. This is the default.
  • SCHEMA_ONLYOnly the schema will be extracted.
String
out_type
(Optional)

Specifies the output type the data will be extracted to.

  • GEODATABASEThe data will be extracted to an existing geodatabase. This is the default.
  • XML_FILEThe data will be extracted to an XML workspace document.
  • NEW_FILE_GEODATABASEThe data will be extracted to a new file geodatabase. Specify the location and name of the new file geodatabase using the out_folder_path and out_name parameters.
String
out_geodatabase
(Optional)

The geodatabase that will contain the extracted data when the out_type parameter is set to GEODATABASE.

Workspace
out_xml
(Optional)

The name and location of the .xml file that will be created when the out_type parameter is set to XML_FILE.

File
out_folder_path
(Optional)

The location of the file geodatabase that will be created for the extracted data. This parameter is required when the out_type parameter is set to NEW_FILE_GEODATABASE.

Folder
out_name
(Optional)

The name of the file geodatabase that will be created for the extracted data. This parameter is required when the out_type parameter is set to NEW_FILE_GEODATABASE.

String
expand_feature_classes_and_tables
(Optional)

Specifies whether expanded feature classes and tables—such as those in networks, topologies, or relationship classes—will be added.

  • USE_DEFAULTSThe expanded feature classes and tables related to the feature classes and tables in the input datasets will be added. The default for feature classes is to extract all features intersecting the spatial filter. If no spatial filter has been provided, all features will be included. The default for tables is to extract the schema only. This is the default.
  • ADD_WITH_SCHEMA_ONLYOnly the schema for the expanded feature classes and tables will be added.
  • ALL_ROWSAll rows for expanded feature classes and tables will be added.
  • DO_NOT_ADDNo expanded feature classes or tables will be added.
String
reuse_schema
(Optional)

Specifies whether a geodatabase that contains the schema of the data to be extracted will be reused. Reusing the schema reduces the amount of time required to extract the data.

  • DO_NOT_REUSEThe schema will not be reused. This is the default.
  • REUSEThe schema will be reused.
String
get_related_data
(Optional)

Specifies whether rows related to rows existing in the data will be extracted. For example, a feature (f1) is inside the geometry filter and a related feature (f2) from another class is outside the filter. Feature f2 will be included in the extracted data if you choose to get related data.

  • DO_NOT_GET_RELATEDRelated data will not be extracted.
  • GET_RELATEDRelated data will be extracted. This is the default.
String
extract_using_geometry_features
(Optional)

The features that will be used to define the area to extract.

Feature Layer
geometry_filter_type
(Optional)

Specifies the spatial relationship between the extract_using_geometry_features and in_data parameter values and how that relationship will be filtered. The spatial relationship is applied to data in an extent defined by the area of interest (AOI) specified in the extract_using_geometry_features parameter.

  • INTERSECTSFeatures in the in_data parameter value that intersect features in the extract_using_geometry_features parameter value will be extracted.
  • CONTAINSFeatures in the in_data parameter value that are contained by the selected feature in the extract_using_geometry_features parameter value will be extracted.
String
all_records_for_tables
(Optional)

Specifies whether all records or only the schema will be extracted for tables that do not have filters applied (such as selections or definition queries).

Tables with applied filters will be honored.

  • ALL_RECORDS_FOR_TABLESAll records will be extracted to the geodatabase. This option will override the expand_feature_classes_and_tables parameter value.
  • SCHEMA_ONLY_FOR_TABLESOnly the schema will be extracted to the geodatabase. This is the default.
Boolean

Derived Output

NameExplanationData Type
out_workspace

The output workspace.

Workspace

Code sample

ExtractDataFromGeodatabase example 1 (Python window)

The following Python window script demonstrates how to use the ExtractDataFromGeodatabase function with a single input feature class and a new output file geodatabase.

import arcpy
arcpy.management.ExtractDataFromGeodatabase(
    r"C:\MyProject\MyGDB.gdb\Bridges", "DATA", "NEW_FILE_GEODATABASE", "", "",
   r"C:\MyProject", "MyNewGDB")
ExtractDataFromGeodatabase example 2 (Python window)

The following Python window script demonstrates how to use the ExtractDataFromGeodatabase function with multiple layers and extracting schema only to an XML workspace document.

import arcpy
arcpy.management.ExtractDataFromGeodatabase(
    ["Layer1", "Layer2"], "SCHEMA_ONLY", "XML_FILE", "",
    r"C:\MyProject\MyXMLWkspDoc.xml")
ExtractDataFromGeodatabase example 3 (stand-alone script)

The following stand-alone Python script demonstrates how to use the ExtractDataFromGeodatabase function with multiple input datasets to an existing geodatabase using the Extent environment.

# Name: ExtractDataFromGeodatabase_Example3.py
# Description: Extract a subset of data by providing an extent using the Extent
#              environment setting.

# Import system modules
import arcpy

# Set the current workspace (to avoid having to specify the full path to each 
# input dataset)
arcpy.env.workspace = "C:\MyProject\MyData.gdb"

# Set the extent environment using the Extent class
arcpy.env.extent = arcpy.Extent(-107.0, 38.0, -104.0, 40.0)

# Set local variables
in_data = ["FC1", "FC2", "FC3"]
extract_type = "DATA"
out_type = "GEODATABASE"
out_geodatabase = "C:\MyProject\MyGDB.gdb"
out_folder_path = ""
out_name = ""
expand_fcs = "USE_DEFAULTS"
reuse_schema = "DO_NOT_REUSE"
get_related_data = "GET_RELATED"
extract_using_geom = ""
geom_filter = ""
all_records = "ALL_RECORDS_FOR_TABLES"

# Run ExtractDataFromGeodatabase
arcpy.management.ExtractDataFromGeodatabase(in_data,
                                            extract_type,
                                            out_type,
                                            out_geodatabase,
                                            out_xml,
                                            out_folder_path,
                                            out_name,
                                            expand_fcs,
                                            reuse_schema,
                                            get_related_data,
                                            extract_using_geom,
                                            geom_filter,
                                            all_records)
ExtractDataFromGeodatabase example 4 (stand-alone script)

The following stand-alone Python script demonstrates how to use the ExtractDataFromGeodatabase function to extract data to a new file geodatabase with a new coordinate system by using the Output Coordinate System environment.

# Name: ExtractDataFromGeodatabase_Example4.py
# Description: Extract data to use a new coordinate system by using the
#              Output Coordinate System environment setting. Then run the tool a second
#              time to load the data using the reuse_schema option

# Import system modules
import arcpy

# Set the Output Coordinate System environment
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference("GCS_North_American_1983_HARN")
arcpy.env.geographicTransformations = "NAD_1983_HARN_To_WGS_1984_2"

# Set local variables
in_data = "C:/MyProject/MyGDB.gdb/FC1"
extract_type = "SCHEMA_ONLY"
out_type = "NEW_FILE_GEODATABASE"
out_geodatabase = ""
out_xml = ""
out_folder_path = "C:\MyProject"
out_name = "MyOutputGDB.gdb"
expand_fcs = "USE_DEFAULTS"
reuse_schema = "DO_NOT_REUSE"
get_related_data = "GET_RELATED"
extract_using_geom = ""
geom_filter = ""
all_records = "SCHEMA_ONLY_FOR_TABLES"

# Run ExtractDataFromGeodatabase with the schema only option
arcpy.management.ExtractDataFromGeodatabase(in_data,
                                            extract_type,
                                            out_type,
                                            out_geodatabase,
                                            out_xml,
                                            out_folder_path,
                                            out_name,
                                            expand_fcs,
                                            reuse_schema,
                                            get_related_data,
                                            extract_using_geom,
                                            geom_filter,
                                            all_records)

# Rest the Output Coordinate System environment
arcpy.ClearEnvironment("outputCoordinateSystem")
arcpy.ClearEnvironment("geographicTransformations")

# Set variables that we are changing to load the data into the newly created schema in 
# the different coordinate system.
extract_type = "DATA"
out_type = "GEODATABASE"
out_geodatabase = "C:\MyProject\MyOutputGDB.gdb"
out_folder_path = ""
out_name = ""
reuse_schema = "REUSE"
all_records = "ALL_RECORDS_FOR_TABLES"

# Run ExtractDataFromGeodatabase with the data and reuse schema option
arcpy.management.ExtractDataFromGeodatabase(in_data,
                                            extract_type,
                                            out_type,
                                            out_geodatabase,
                                            out_xml,
                                            out_folder_path,
                                            out_name,
                                            expand_fcs,
                                            reuse_schema,
                                            get_related_data,
                                            extract_using_geom,
                                            geom_filter,
                                            all_records)

Related topics