wjbzone

Using Corpscon6.dll with python to convert State Plane to Lat/Long

Discussion created by wjbzone on Oct 22, 2013
Latest reply on Oct 23, 2013 by wjbzone
Hi. first post here. (running Windows 7)
I am a beginner in python, but I have a working version of this function in visual basic that I want to use in python.

I use the corpscon6.dll library to convert coordinates from state plane to Latitude/Longitude. My next step will be to write a shapefile using the shapefile.py

The corpscon.dll, Nadcon,Vertcon and Geoid data are a free download from http://www.agc.army.mil/Missions/Corpscon.aspx. I put these downloaded files in "C:\Program Files\Corpscon6" as suggested.


The following setup code seems to work (all the test variables return 1, a negative value means error)
Note: you can paste it into your IDLE and run as one line...
exec('''
from ctypes import* 
corpslib = windll.LoadLibrary("c:\program files\corpscon6\corpscon_v6.dll")
test00=corpslib.corpscon_default_config()
test1=corpslib.SetNadconPath("C:\Program Files\Corpscon6\Nadcon")
test2=corpslib.SetVertconPath("C:\Program Files\Corpscon6\Vertcon")
test3=corpslib.SetGeoidPath("C:\Program Files\Corpscon6\Geoid")
x10=2
test10 =  corpslib.SetInSystem(x10)
x11=1927
test11 =  corpslib.SetInDatum(x11)
x12=3
test12= corpslib.SetOutSystem(x12)
x14=x27=1602
test27 =  corpslib.SetInZone(x27)     #NAD83 or NAD27 zone (1602 is Ky South)
test14 =  corpslib.SetOutZone(x14)     #' NAD83 or NAD27 zone (1602 is Ky South)
x15=x28=1
test28 =  corpslib.SetInUnits(x28)        # 1=USFT, 2=IFT, 3=Meter
test15 =  corpslib.SetOutUnits(x15)      # 1=USFT, 2=IFT, 3=Meter
x22=x23=1929
test22 = corpslib.SetInVDatum(x22)   # Vdatum 1929, 1988, 1980
test23 =  corpslib.SetOutVDatum(x23)  # Vdatum 1929, 1988, 1980
x24=x25=1
test24 =  corpslib.SetInVUnits(x24)     #  1=USFT, 2=IFT, 3=Meter
test25 =  corpslib.SetOutVUnits(x25)    # 1=USFT, 2=IFT, 3=Meter
x26=2003
test26 =  corpslib.SetGeoidCodeBase(x26)
''')


Next I initilize the conversion

test16=corpslib.corpscon_initialize_convert()



Then entering the coordinates should go like this...

exec('''
xVal=2790955
yVal=503380
zVal=1000
test17 =  corpslib.SetXIn(xVal)
test18 =  corpslib.SetYIn(yVal)
test18 =  corpslib.SetZIn(zVal)
test19 = corpslib.corpscon_convert()
longOut = corpslib.GetXOut()
latOut = corpslib.GetYOut()
zOut = corpslib.GetZOut()
''')


however the line
corpslib.SetXin(xVal)
seems to be a problem... I get this error...

Traceback (most recent call last):
  File "<pyshell#35>", line 1, in <module>
    corpslib.SetXIn(xVal)
ValueError: Procedure probably called with not enough arguments (4 bytes missing)

My VBA application runs this code ok. Does anyone know what I might be missing??
Thanks
Billy

Outcomes