CS Center
지열자료실
홈 < 자료실 < 일반자료실

{GIS] python 스크립트로 단순 작업을 빠르게
 작성자 : 관리자
Date : 2022-10-07 10:34  |  Hit : 709  

파이썬을 이용해 단순 작업을 간편하게 할 수 있다.
일종의 매크로처럼 처리 가능한데 쉬운 작업은 아니어서 자세한 내용은 아래를 참고 하시길...

여기에 설명을 안하는 이유는 파이썬이라는 프로그램 언어에 대한 이해가 필요하기 때문이다.
해당 언어를 다뤄본 사람이라면 아래 내용을 살펴보면 arcmap 에서 활용 가능할 것이다.

아래 코드는 arcGIS 파일을 읽어 jpg로 출력하는 스크립트다.
원래 arcGIS 는 640 x 480이 기본이어서 그 사이즈를 바꾸려면 약간의 작업이 필요한데 그게 두번째 코드이다.

Code Sample
ExportToJPEG example 1
This script opens a map document and exports the page layout to a JPEG file using default values for all options.

    import arcpy
    mxd = arcpy.mapping.MapDocument(r
    "C:\Project\Project.mxd")
    arcpy.mapping.ExportToJPEG(mxd, r
    "C:\Project\Output\Project.jpg")
    del mxd

ExportToJPEG example 2
This script will export a single data frame instead of the entire page layout, similar to exporting from data view in the ArcMap application. The default values for df_export_width and df_export_height are 640 and 480. By passing larger values for these parameters, we are able to produce an output image with higher detail. Setting world_file = True generates a georeferenced world file in the same directory as the output file.

    import arcpy
    mxd = arcpy.mapping.MapDocument(r
    "C:\Project\Project.mxd")
    df = arcpy.mapping.ListDataFrames(mxd,
    "Transportation")[0]
    arcpy.mapping.ExportToJPEG(mxd, r
    "C:\Project\Output\ProjectDataFrame.jpg", df,
      df_export_width=1600,
      df_export_height=1200,
      world_file=True)
    del mxd

다만, r"로 시작하는 폴더명 부분은 10.8 버전에서 테스트할 때는 r' 이었다.

자, 이번엔 현재 오픈된 레이어를 zoom select 기능으로 보여주는 코드이다.

ExportToJPEG example 3
    import arcpy
    mxd = arcpy.mapping.MapDocument('CURRENT')
    df = arcpy.mapping.ListDataFrames(mxd,
    "Layers") [0]
    df.zoomToSelectedFeatures()
    arcpy.RefreshActiveView()

한가지 팁, df.scale = 12000 이 구문을 arcpy.RefreshActiveView() 라인 전에 넣어주면 1:12,000 스케일로 뷰가 조정된다.