내 프로그램에 vb.net과 Arcobjects를 사용하고 있습니다. kml을 lyr 파일로 변환하는 ArcMap 10 버튼을 만듭니다.cmd를 통해 python 스크립트로 파일 경로 전달
변수를 파이썬 코드에 전달하는 데 문제가 있습니다. 변수는 파일 경로이며 하드 코드를/대신 사용하면 멋지게 작동합니다. 변수가 동적으로 전달 될 때, 경로 이름에 "/"s의 프로그램 나누기 :
이Dim Filelocation As OpenFileDialog = New OpenFileDialog()
Filelocation.Title = "Please point photo of the owner"
Filelocation.InitialDirectory = "B:\GeoSpatialData\Projects\004402 Griffiths\File Structure\Geospatial\GPS\KML"
If Filelocation.ShowDialog = DialogResult.OK Then
Dim kmlFile As String
kmlFile = Filelocation.FileName
Dim args As String
args = kmlFile & " " & kmlFile.Substring(0, kmlFile.LastIndexOf("\")) & " test"
Dim args2 As String = args.Replace("\", "/")
Dim procStartInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("C:\Python26\python", "C:\Users\KJacobsen\kml_to_shp.py " & args2)
' The following commands are needed to redirect the standard output.
' This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = True
procStartInfo.UseShellExecute = False
' Do not create the black window.
procStartInfo.CreateNoWindow = False
' Now you create a process, assign its ProcessStartInfo, and start it.
Dim proc As New System.Diagnostics.Process()
proc.StartInfo = procStartInfo
proc.Start()
proc.WaitForExit()
' Get the output into a string.
Dim result As String = proc.StandardOutput.ReadToEnd()
' Display the command output.
Console.WriteLine(result)
End If
Catch objException As Exception
' Log the exception and errors.
Console.WriteLine(objException.Message)
End Try
내 파이썬 스크립트는 다음과 같습니다
import os
import arcpy
import sys
import glob
arcpy.KMLToLayer_conversion(sys.argv[1],sys.argv[2],sys.argv[3])
print
내가 문자열 = args.Replace로/ 희미한 args2으로 \ 교체 ("\", "/") 위의 내 코드를 편집. – user1488948
경로에 ""이 있으면 경로 args 주위에 따옴표를 사용해야합니다. – Chachi