Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Has anyone succeeded in programmatically updating metadata in ArcGIS 10? Considering using Python/arcpy but ArcObjects (C# or Python/comtypes) is also a possibility.

I need to update both the FGDC and the ArcGIS-ISO format metadata, and whatever solution is used needs to be able to retain the existing (non-blank) elements along with the added elements, except where they are in conflict in which case the added elements overwrite the existing elements.

share|improve this question

5 Answers 5

up vote 6 down vote accepted

The easiest way to do this from arcpy is to create an xml file using python and then invoking Import Metadata (Conversion). However, this will overwrite everything.

An alternative is to use ArcObjects to obtain an IName to the dataset, cast to IMetadata, and edit the IPropertyset.

share|improve this answer

We have been struggling with this and solved it by having a simple python library built around the arcobjects metadata functions. It's based on a xml-file where the metadata values have been replaced with keywords. You can use these keywords in your python code to get or set the value of a metadata field. Code woud look something like this:

import dataprocessing
DP = dataprocessing.create()

md = DP.OpenMetadata("C:/MyShapefile.shp") # Works also on geodatabases
myKeyword = "%FGDC.abstract" # Keywords have to start with '%' but the rest is up to you

if md.GetValue(myKeyword) == "Not what I want":
    md.SetValue(myKeyword, "New value that suits me better")

The tool can be found here: http://www.aris.nl/dataprocessing_arcgis and is freely available. The version on the website is for arcgis 9.3. An arcgis 10 version will be available but it will no longer be free.

(Full disclosure: I work for a dutch government agency where we had the current version of this tool built partly from taxpayers money and partly from time donated by the programmer. That's why it's available for free but not open source. As of 2013 we will not be funding any new versions. I'm not making any money out of it in any way. I just hope it gets put to more use.)

share|improve this answer

A third option I'm looking into now is to use an XSLT file along with the XSLT Transformation (Conversion) tool. I'm pretty much having to learn the language as I go though, and they don't make it easy on you by using the .NET implementation which uses the older XSLT/XPath 1.0 standards.

share|improve this answer
    
And Python doesn't even include an XSL Transformer for some crazy reason! –  James Schek Mar 23 '11 at 15:54
1  
There aren't pure python implementations of many libraries, its fairly common to have something which is just a wrapper to a much faster C/C++ library, which I think is the case here: stackoverflow.com/questions/138502/pure-python-xslt-library –  scw May 15 '11 at 6:38

I have some code that uses ArcPy and DOM for conversion of existing MD, creation from scratch (if none exists) and update of certain elements using DOM. It's a bit clunky, with quite a lot of hardcoded pathnames and so on.

share|improve this answer
1  
It's a kind offer, Steve, and much appreciated, but it's not consistent with this site's aims or structure. Please read our FAQ for more information. Unless the code is really long, you should be able to post it in a reply. –  whuber Feb 15 '12 at 16:30

I realize this is quite a while after the question, but we just had a big need for a similar capability and ended up building a general, free, open source Python library for the purpose. You can find it at https://github.com/ucd-cws/arcpy_metadata or by running a "pip install metadata" - documentation is still to come, but we tried to keep things relatively Pythonic. Here's an example:

import arcpy_metadata as md
import datetime

metadata = md.MetadataEditor(path_to_some_feature_class)  # also has a feature_layer parameter if you're working with one, but edits get saved back to the source feature class
metadata.title.set("The metadata title!")

generated_time = "This layer was generated on {0:s}".format(datetime.datetime.now().strftime("%m/%d/%Y %I:%M %p"))

metadata.purpose.set("Layer represents locations of the rare Snipe.")

metadata.abstract.append("generated by ___ software")
metadata.abstract.append(generated_time)  # .prepend also exists
metadata.tags.add(["foo", "bar", "baz"])  # tags.extend is equivalent to maintain list semantics

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

It still has plenty that could be added, but is pretty extensible if you subclass the items that are already there, or configure them correctly. It's still about alpha quality software, but it works and we're happy with it. Feedback and contributions are certainly welcome.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.