Skip to content

sunank200/arcpy_metadata

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arcpy Metadata Editor (arcpy_metadata)

Whether you create it or not, metadata is a critical part of GIS analysis. ArcGIS includes a built-in GUI metadata editor, but has scant access to metadata properties from Python. The arcpy_metadata package provides this access, allowing large Python packages that generate their own geospatial outputs in ArcGIS to properly document the data.

Code Issues

Getting arcpy_metadata

arcpy_metadata is pure Python and its only dependency is arcpy (installed with ArcGIS). It's available on the Python Package Index so you can get arcpy_metadata via pip (pip install arcpy_metadata).

If you don't have or don't know how to use pip, you can install arcpy_metadata by cloning/downloading this repository and running setup.py install in the root folder

Using arcpy_metadata

Creating the Metadata Editor

import arcpy_metadata as md
metadata = md.MetadataEditor(path_to_some_feature_class)  # currently supports Shapefiles, FeatureClasses, RasterDatasets and Layers

Get text items (returns string)

title = metadata.title
abstract = metadata.abstract

Change text items

metadata.title = "The new title"
metadata.abstract = "This is the abstract"

Get list items (returns list)

tags = metadata.tags
for tag in tags:
    print tag

Change list items

metadata.tags = ["tag1", "tag2"]

Get numeric items (return int or float)

min_scale = metadata.min_scale
max_scale = metadata.max_scale

Change numeric items

metadata.min_scale = 500000
metadata.max_scale = 500

Get date items (returns date object)

last_update = metadata.last_update
last_update_year = metadata.last_update.year

Change date items (takes both date objects and formated string (yyyymmdd)

from datetime import date
today = date.today()
metadata.last_update = today
metadata.last_update = "20160221"

Get contact items (returns contact object)

contact = metadata.point_of_contact
contact_name = metadata.point_of_contact.contact_name
contact_email = metadata.point_of_contact.email

Change contact items (all contact items are string)

metadata.point_of_contact.contact_name = "First and Last Name"
metadata.point_of_contact.email = "email@address.com"

Saving the changes back to the file

metadata.finish()  # save the metadata back to the original source feature class and cleanup. Without calling finish(), your edits are NOT saved!

If you want to enable automatic updates of your metadata (feature classes only) call.

metadata.finish(True) 

This might overwrite some of your recent edits including the title.

The code is based on a set of core classes that provide set/append/prepend operations, and we would love pull requests that add classes or attributes to cover additional portions of metadata specs.

Supported items

Item description Internal name Type Location in ArcCatalog Path in ArcGIS XML file
Title title String Overview/ Item Description/ Title dataIdInfo/idCitation/resTitle
Abstract abstract String Overview/ Item Description/ Description dataIdInfo/idAbs
Purpose purpose String Overview/ Item Description/ Summery dataIdInfo/idPurp
Tags tags List Overview/ Item Description/ Tags dataIdInfo/searchKeys/keyword
Place Keywords place_keywords List Overview/ Topics & Keywords/ Place Keyword dataIdInfo/placeKeys/keyword
Extent Description extent_description String Resource/ Extents/ Extent/ Description dataIdInfo/dataExt/exDesc
Temporal Extent Description temporal_extent_description String dataIdInfo/dataExt/tempDesc
Temporal Extent Instance temporal_extent_instance Date Resource/ Extents/ Temporal Instance Extent/ Instance Date dataIdInfo/dataExt/tempEle/exTemp/TM_Instant/tmPosition
Temporal Extent Start Date temporal_extent_start Date Resource/ Extents/ Temporal Period Extent/ Begin Date dataIdInfo/dataExt/tempEle/exTemp/TM_Period/tmBegin
Temporal Extent End Date temporal_extent_end Date Resource/ Extents/ Temporal Period Extent/ End Date dataIdInfo/dataExt/tempEle/exTemp/TM_Period/tmEnd
Minimum Scale min_scale Integer Item Description/ Appropriate Scale Range/ Min Scale Esri/scaleRange/minScale
Maximum Scale max_scale Integer Item Description/ Appropriate Scale Range/ Max Scale Esri/scaleRange/maxScale
Scale Resolution scale_resolution String Resource/ Details/ Scale Resolution dataIdInfo/dataScale/equScale/rfDenom
Last Update last_update Date Overview/ Citation/ Dates/ Revised dataIdInfo/idCitation/date/reviseDate
Update Frequency Description update_frequency_description String Resource/ Maintenance/ Custom Frequency dataIdInfo/resMaint/usrDefFreq/duration
Credits credits String Overview/ Item Description/ Credits dataIdInfo/idCredit
Citation citation String Overview/ Citation/ Other Details dataIdInfo/idCitation/otherCitDet
Limitation limitation String Overview/ Item Description/ Use Limitation dataIdInfo/resConst/Consts/useLimit
Supplemental Information supplemental_information String Resource/ Supplemental Information dataIdInfo/suppInfo
Source source String Resource/ Lineage/ Data Source/ Source Description dqInfo/dataLineage/dataSource/srcDesc
Points of contact point_of_contact ContactObj Resource/ Details/ Points of Contact/ Contact/ dataIdInfo/idPoC
Maintenance Contacts maintenance_contact ContactObj Resource/ Maintenance/ Maintenance Contact/ dataIdInfo/maintCont
Citation Contacts citation_contact ContactObj Overview/ Citation Contact/ Contact/ dataIdInfo/idCitation/citRespParty
Language language String Resource/ Detail/ Languages/ Language dataIdInfo/dataLang
Metadata Language metadata_language String Metadata/ Detail/ Language dataIdInfo/mdLang

Contact items

Item description Internal name Type Relative path in ArcGIS XML file
Contact Name contact_name String rpIndName
Position position String rpPosName
Organization organization String rpOrgName
Email email String rpCntInfo/eMailAdd
Address address String rpCntInfo/cntAddress/delPoint
City city String rpCntInfo/cntAddress/City
State state String rpCntInfo/cntAddress/adminArea
Zip zip String rpCntInfo/cntAddress/postCode
Country country String rpCntInfo/cntAddress/country
Phone Nb phone_nb String rpCntInfo/cntPhone/voiceNum
Fax Nb fax_nb String rpCntInfo/cntPhone/faxNum
Hours hours String rpCntInfo/cntHours
Instructions instructions String rpCntInfo/cntInstr
Website Link link String rpCntInfo/cntOnlineRes/linkage
Protocol protocol String rpCntInfo/cntOnlineRes/protocol
Profile profile String rpCntInfo/cntOnlineRes/appProfile
Website Name or_name String rpCntInfo/cntOnlineRes/orName
Website Description or_desc String rpCntInfo/cntOnlineRes/orDesc

Under the hood

arcpy_metadata uses the strategy of exporting the metadata from the layer, then edits the xml export based on your method calls. When you're done, use finish() to save your data back to the source.

Known limitations

Does not yet support all metadata items.

arcpy_metadata only works with 32-bit Python. We use arcpy.XSLTransform_conversion() to extract metadata from geodatabases. 64bit arcpy python bindings for background processing do not support tools inside the metadata conversion toolset.

Acknowledgements

arcpy_metadata was initially a project of the UC Davis Center for Watershed Sciences and has received significant contributions from the World Resources Institute. It was created as part of a larger project funded by the California Department of Fish and Wildlife Biogeographic Data Branch and further developed for Global Forest Watch. We thank our funders for their support and their commitment to high quality geospatial data.

About

Python metadata editing classes for ArcGIS feature classes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%