Example #1
0
def ExportFGDCtoFGDC(InputXMLFile, OutputXMLFile):
    try:
        if os.path.exists(OutputXMLFile):
            os.remove(OutputXMLFile) 
    except:
        raise Exception, "Error. This tool requires read/write access to the directories where the temporary and final outputs are saved. Please choose another directory for the tool outputs."
    
#Implement the USGSMPTranslator tool to export to FGDC (effectively, this is an FGDC to FGDC translation). 
#Usage: USGSMPTranslator_conversion (source, config, conversion, output, error log)     
    arcpy.USGSMPTranslator_conversion(InputXMLFile, "", "xml", OutputXMLFile)
Example #2
0
def ReRunFGDCTranslator(InputXML):
    #Implement the USGSMPTranslator tool to re-export the FGDC record.
    #This should fix the problem of any child elements being in the wrong order.
    #User will need write access to wherever the input is coming from. Input is replaced with output.
    OutputXML = os.path.splitext(InputXML)[0] + "xx.xml"

    try:
        if os.path.exists(OutputXML):
            os.remove(OutputXML)
    except:
        raise Exception, "Error. This tool requires read/write access to the directories where the temporary and final outputs are saved. Please choose another directory for the tool outputs."

    arcpy.USGSMPTranslator_conversion(InputXML, "#", "xml", OutputXML)
    os.remove(InputXML)  #Remove original input
    shutil.copy(
        OutputXML, InputXML
    )  #Copy re-ordered output ("_xx.xml" file) back to original input file location.
    os.remove(OutputXML)  #Get rid of re-ordered tool output ("_xx.xml" file).
Example #3
0
def writeDomToFile(workDir,dom,fileName):
    if debug:
        addMsgAndPrint(arcpy.env.workspace)
        addMsgAndPrint('fileName='+fileName)
    addMsgAndPrint('    Writing XML to '+fileName)
    
    tempxml = os.path.join(workDir, 'xml_temp.xml')
    outxml = os.path.join(workDir, fileName)
    
    for f_path in [tempxml, outxml]:
        if os.path.exists(f_path):
            os.remove(f_path)
        
    with codecs.open(tempxml, "w", encoding="utf-8", errors="xmlcharrefreplace") as out:
        dom.writexml(out, encoding="utf-8", addindent="\t")
    
    # mp.exe (called through USGSMPTranslator) does an excellent job of 
    # 1) sorting out of order elements
    # 2) removing unnecessary new lines
    # 3) adding newline characters after the closing tag for each element
    arcpy.USGSMPTranslator_conversion(tempxml, "", "XML", outxml)
    os.remove(tempxml)
Example #4
0
## fix title
domMR = cleanTitle(domMR)
##  ensure that there is an eainfo node
try:
    eanode = domMR.getElementsByTagName('eainfo')[0]
except:
    rtNode = domMR.getElementsByTagName('metadata')[0]
    eanode = domMR.createElement('eainfo')
    rtNode.appendChild(eanode)

gdbDesc1 = writeGdbDesc1(inGdb)
writeDomToFile(workDir, domMR, xmlFileMR)
addMsgAndPrint('  Running mp on master metadata record ' + xmlFileMR + ':')
if os.path.exists(logFileName):
    os.remove(logFileName)
arcpy.USGSMPTranslator_conversion(os.path.join(workDir, xmlFileMR), '#', '#',
                                  '#', logFileName)
for aline in open(logFileName, 'r').readlines():
    addMsgAndPrint(aline[:-1])
addMsgAndPrint(' ')

logFile = open(logFileName, 'a')

# import to geodatabase as whole
arcpy.env.workspace = workDir
supplementaryInfo = gdb + gdbDesc0a + gdbDesc1 + gdbDesc2
dom = addSupplinf(domMR, supplementaryInfo)
addMsgAndPrint('  Importing XML to metadata for GDB as a whole')
writeDomToFile(workDir, dom, xmlFileGdb)
try:
    arcpy.ImportMetadata_conversion(os.path.join(workDir, xmlFileGdb),
                                    'FROM_FGDC', inGdb, 'ENABLED')