2013-11-26 4 views
1

각 피쳐 클래스에 대한 레코드와 요약, 설명 등의 메타 데이터 필드를 포함하는 Excel 파일을 가져 와서 해당 피쳐로 변환 할 수 있기를 바랍니다. 클래스 메타 데이터. 내가 수행 한 연구에서 Excel 테이블의 각 레코드를 xml로 변환 한 다음 XML 파일을 메타 데이터로 가져올 수있는 것처럼 보입니다. ElementTree를 사용할 수있는 것처럼 보이지만 실행 방법에 대해서는 조금 확신하지 못합니다. 이전에 해본 사람이 있습니까? 그렇다면 어떤 지침을 제공 할 수 있습니까?arcpy를 사용하여 프로그래밍 방식으로 피쳐 클래스의 메타 데이터 업데이트하기

답변

2

남자, 이것은 꽤 과정 일 수 있습니다! 요 전날 직장에서 프로젝트의 일부 메타 데이터 정보를 업데이트해야 했으므로 여기서는 아무 것도 볼 수 없습니다. 엑셀 테이블의 모든 메타 데이터 정보를 사전 목록이나 다른 데이터 구조로 저장하는 것이 도움이됩니다 (필자는 CSV로 작업하고 경험상 스프레드 시트에서 벗어나려고 노력합니다).

metaInfo = [{"featureClass":"fc1", 
      "abstract":"text goes here", 
      "description":"text goes here", 
      "tags":["tag1","tag2","tag3"]}, 
      {"featureClass":"fc2", 
      "abstract":"text goes here", 
      "description":"text goes here", 
      "tags":["tag1","tag2","tag3"]},...] 

거기에서, 나는 실제로 FGDC 스키마를 사용하여 XML 파일로 기능 클래스의 메타 데이터를 변환하는 메타 데이터 내보내기 기능을 사용하여 현재 메타 데이터 기능 클래스를 내보내는 것입니다. 다음은 코드 예제입니다.

#Directory containing ArcGIS Install files 
installDir = arcpy.GetInstallInfo("desktop")["InstallDir"] 
#Path to XML schema for FGDC 
translator = os.path.join(installDir, "Metadata/Translator/ARCGIS2FGDC.xml") 
#Export your metadata 
arcpy.ExportMetadata_conversion(featureClassPath, translator, tempXmlExportPath) 

거기에서 xml 모듈을 사용하여 ElementTree 클래스에 액세스 할 수 있습니다. 그러나 lxml 모듈 (http://lxml.de/index.html#download)을 사용하는 것이 좋습니다. 메타 데이터에 줄 바꿈과 같은 특수 요소가 필요한 경우 CDATA 팩토리를 통해 HTML 코드를 메타 데이터에 통합 할 수 있기 때문입니다. 당신은 태그 아래의 코드를 사용 업데이트하려면

import lxml.etree as ET 
tree = ET.parse(tempXmlExportPath) 
root = tree.getroot() 

: 여기에서, 당신은 LXML을 가져온 가정, 해당 지역의 XML 문서를 구문 분석

idinfo = root[0] 

#Create keyworks element 
keywords = ET.SubElement(idinfo, "keywords") 
tree.write(tempXmlExportPath) 

#Create theme child 
theme = ET.SubElement(keywords, "theme") 
tree.write(tempXmlExportPath) 

#Create themekt and themekey grandchildren/insert tag info 
themekt = ET.SubElement(theme, "themekt") 
tree.write(tempXmlExportPath) 
for tag in tags: #tags list from your dictionary 
    themekey = ET.SubElement(theme, "themekey") 
    themekey.text = tag 
    tree.write(tempXmlExportPath) 

요약 태그를 업데이트하려면를, 이것을 사용 코드 : XML에서 태그가 이미 존재하는 경우

#Create descript tag 
descript = ET.SubElement(idinfo, "descript") 
tree.write(tempXmlExportPath) 

#Create purpose child from abstract 
abstract = ET.SubElement(descript, "abstract") 
text = #get abstract string from dictionary 
abstract.text = text 
tree.write(tempXmlExportPath) 

는 parent.find ("아이") 방법을 사용하여 객체로 태그를 저장하고, 위의 코드 예제와 유사한 텍스트를 업데이트합니다. 로컬 xml 파일을 업데이트 한 후에 메타 데이터 가져 오기 방법을 사용하여 xml 파일을 피쳐 클래스로 다시 가져오고 로컬 xml 파일을 제거합니다.

arcpy.ImportMetadata_conversion(tempXmlExportPath, "FROM_FGDC", featureClassPath) 
shutil.rmtree(tempXmlExportPath) 

는 64 비트 배경 geoprocessor을 통해 스크립팅 그래서 만약 아크에서 이러한 도구, 32 비트에 대한 있음을 알아 두셔야이 작동하지 않습니다. ArcMap 10.1에서 작업 중입니다.

LXML 모듈 http://lxml.de/index.html#documentation

수출 메타 데이터 http://resources.arcgis.com/en/help/main/10.1/index.html#//00120000000t000000

메타 데이터 가져 오기를 arcpy http://resources.arcgis.com/en/help/main/10.1/index.html#//00120000000w000000

을 arcpy : 당신은 질문이있는 경우 알려 이하 설명서를 참조하여 주시기 바랍니다