Table of Contents
When writing markers out to a geometry file its important to recognize that the markers are grouped according to their attribute names. This HowTo discusses how to write markers out to a file.
It is assumed that you are familiar with,
- how markers work within the MineSight®-3D context.
- understand how element attribution works with geometry data.
- understand how the basics of grail.data.geometry module.
Before we proceed into the details of how to write out the markers to a Comma Delimited File (CSV) it is important to note a point made within the grail.data.geometry documentation. The documentation states,
Note that when methods refer to "markers", that includes the entire set of points in the markers element and not individual points.
To get the marker's points we will use the following two Geometry methods,
- get3dmarkerspointsat()
- get2dmarkerspointsat()
Both these calls will return a list of points of the form,
[[x0, y0, z0], [x1, y1, z1], ..., [xN, yN, zN]]
Where each "point at" corresponds to an attributed element name. Therefore, if we have no names within our MineSight® Resource (MSR) file, then we can at most expect only one "point at". However that "point at" will contain as many unnamed markers as there are within the MSR file.
Assuming that we have a Geometry object already created called gmsr and we have an output stream (either a file or sys.stdout [1]) called output, we can write the following python script to extract the contents of the MSR file and generate a CSV file,
def _write_point(output, num, p)
output.write("%d, %f, %f, %f\n" % (num, p[0], p[1], p[2])
def to_csv(gmsr, output):
count = 1
# Traverse the 3D markers.
for i in range(gmsr.get3dmarkerscount()):
for p in gmsr.get3dmarkerspointsat(i):
_write_point(output, num, p)
# Traverse the 2D markers.
for i in range(gmsr.get2dmarkerscount()):
for p in gmsr.get3dmarkerspointsat(i):
_write_point(output, num, p)
Our to_csv function can be called as,
from grail.data import geometry
g = geometry.Geometry("markers.msr")
output = file.open("markers.csv", "w")
to_csv(g, output)
The most important point to take away from this example, is that the "points at" does not refer to the individual markers within the Geometry object, but rather refers to the groupings of markers, where each group is defined with a name. In the above example, we traversed each listing of names with,
for i in range(msr.get3dmarkerscount()):
and then traversed the points within each group with the,
for p in msr.get3dmarkerspointsat(i):
line.
[1] | "sys -- System-specific parameters and functions". Python Library Reference. 21 December 2001. 18 May 2004. <http://www.python.org/doc/2.2/lib/module-sys.html> |