Wednesday, December 17, 2014

Trying to find cliffs from point grid

The ask is simple: you are given vertices on a regular grid and need to return cliffs: lines where steepness gets larger than some given constant.
I tried algorithm like this:

  • mark all cells for which the borders are steep, 
  • connect 2 steepest sides with cliff segment
  • join segments where possible
End result is best described by this picture:
The small white lines are my calculated cliffs. The background is OCAD 11 generated steepness where black is 45degree steepness. My lines are calculated in a smaller subregion than the whole picture. 

This algorithm does not work without some additional improvements. Something better is needed.

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.