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 the 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 extract the schema only for a specified spatial reference 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.

    Note:

    The Output Coordinate System environment will be ignored in the following scenarios:

    • The Extract parameter is set to Data.
    • The Output Type parameter is set to XML file.

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.
  • New mobile geodatabaseThe data will be extracted to a new mobile geodatabase. Specify the location and name of the new mobile 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 or mobile geodatabase that will be created for the extracted data. This parameter is required when the Output Type parameter is set to New file geodatabase or New mobile geodatabase.

Folder
Geodatabase Name
(Optional)

The name of the file or mobile geodatabase that will be created for the extracted data. This parameter is required when the Output Type parameter is set to New file geodatabase or New mobile 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 when the Output Type parameter is set to Geodatabase, New file geodatabase, or New mobile geodatabase.

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.
  • NEW_MOBILE_GEODATABASEThe data will be extracted to a new mobile geodatabase. Specify the location and name of the new mobile 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 or mobile geodatabase that will be created for the extracted data. This parameter is required when the out_type parameter is set to NEW_FILE_GEODATABASE or NEW_MOBILE_GEODATABASE.

Folder
out_name
(Optional)

The name of the file or mobile geodatabase that will be created for the extracted data. This parameter is required when the out_type parameter is set to NEW_FILE_GEODATABASE or NEW_MOBILE_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 when the out_type parameter is set to GEODATABASE, NEW_FILE_GEODATABASE, or NEW_MOBILE_GEODATABASE.

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)
ExtractDataFromGeodatabase example 5 (stand-alone script)

The following stand-alone Python script demonstrates how to use the ExtractDataFromGeodatabase tool and extracting schema into an XML file and then load data using the ImportXMLWorkspaceDocument tool.

# Name: ExtractDataFromGeodatabase_Example5.py
# Description: Extract schema of multiple feature classes and import the
#              schema into an enterprise geodatabase

# 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"

# Export the schema as an XML file from a feature class
result = arcpy.management.ExtractDataFromGeodatabase(
    ["FC1", "FC2"], "SCHEMA_ONLY", "XML_FILE", "",
    "C:/MyProject/MyXMLWkspDoc.xml")

# Get the path to the output XML file
out_xml = result[0]

# Pass the output XML into the Import XML Workspace Document tool
arcpy.management.ImportXMLWorkspaceDocument("C:/MyProject/mySDEConnection.sde", 
                                            out_xml, 
                                            "SCHEMA_ONLY", "DEFAULTS")
ExtractDataFromGeodatabase example 6 (stand-alone script)

The following stand-alone Python script demonstrates how to use the ExtractDataFromGeodatabase tool to extract data to a new mobile geodatabase and create a domain for the new output geodatabase.

# Name: ExtractDataFromGeodatabase_Example6.py
# Description: Extract data and create a domain on output workspace

# Import system modules
import arcpy

# Export data to a new mobile geodatabase
result = arcpy.management.ExtractDataFromGeodatabase(
    "C:/MyProject/mySDEConnection.sde/myGDB.USER1.FC1", "DATA", "NEW_MOBILE_GEODATABASE", "", "",
    "C:/MyProject", "newMobileGDB")

# Get the path to the output mobile geodatabase
out_mobile_gdb = result[1]

# Pass the output geodatbase to the CreateDomain tool
arcpy.management.CreateDomain(out_mobile_gdb, "MyDomain", "My domain description", "SHORT", "CODED")

Licensing information

  • Basic: No
  • Standard: Yes
  • Advanced: Yes

Related topics