Sunday, December 7, 2014

From Python to .OCD files

I have been experimenting with the OCAD libary from Open Orienteering Mapper and have written a small wrapper for it.
The wrapper is available here.
What can you do with it?
You can import symbols and polygons automagically from python into OCD files for OCAD.
Here is an example:
h_writer=CreateOcadWriter(c_double(1),c_double(1), c_double(10000))

col=AddColor(h_writer, c_char_p("some color"))
sym1=AddAreaSymbol(h_writer,c_char_p("symone"), 4100, col)
sym2=AddAreaSymbol(h_writer,c_char_p("symtwo"), 4010, col)

TYPE=(POINT*3)
t=TYPE()
array=((10,100),(100,10),(100,100))
for i in range(len(array)):
    t[i].x=array[i][0]
    t[i].y=array[i][1]

re = ExportArea(h_writer, t, 3, 4010)

WriteOcadFile(h_writer, c_char_p("c:\\projekti\\WriteODLL\\a.ocd"))
CleanWriter(h_writer)

What does this do?
  1. Creates a 1:10000 map with offset of (1,1)
  2. Create a color
  3. Creates 2 symbols (4100 is 410.0 and 4010 is 401.0)
  4. Creates a triangle of 401.0 symbol. 
  5. Writes to OCAD file.
The color is not a real color and the symbols are neither. To use this one would have to _import_ the OCD file into one which has real symbols. 
Why is this useful? If you want to experiment with larger data sets and visualize them in OCAD file, you need to automate it.

No comments:

Post a Comment