How to read a LAS file using C#

6.4k Views Asked by At

I need to read LAS file using C# and then convert it to xml using C# for my project. Any help would be appreciated.

I need to read the specific headers and Data under them. The headers basically start with ~ in the LAS file. I have worked on creating an XML using C#. But having problem in reading the LAS file using C#. I have tried using libLAS libraries available on net, but getting errors.

@17-06-2010

I am using the libLAS library into my project to read a LAS file and I am getting this error

(Unable to load DLL 'liblas1.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)).  Any help???
3

There are 3 best solutions below

0
On

You can create an XML document quite easily in C# using XmlWriter, contained in the System.Xml namespace. Here's an example of how you can use it:

using System.Xml;
using System.Collections.Generic;

namespace XmlExample
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Student> students = new List<Student>();

            students.Add(new Student { ID = 1, Name = "Ryan", Grade = 99 });
            students.Add(new Student { ID = 2, Name = "Ann", Grade = 84 });
            students.Add(new Student { ID = 3, Name = "Rebecca", Grade = 83 });
            students.Add(new Student { ID = 4, Name = "Jon", Grade = 26 });

            using (XmlWriter xml = XmlWriter.Create("ComputerScience1234.xml"))
            {
                xml.WriteStartDocument();
                xml.WriteStartElement("COSC1234");

                foreach (Student s in students)
                {
                    xml.WriteStartElement("Student");

                    xml.WriteElementString("ID", s.ID.ToString());
                    xml.WriteElementString("Name", s.Name);
                    xml.WriteElementString("Grade", s.Grade.ToString());

                    xml.WriteEndElement();
                }

                xml.WriteEndElement();
                xml.WriteEndDocument();

            }
        }
    }
}
0
On

This links to a c# tutorial on the liblas.org site http://www.liblas.org/tutorial/csharp.html . Hope this helps. The latest release, libLAS-1.7.0b1 installs like a dream compared to the 1.6.1 nightmare (under windows). Chris

1
On

WolfInSpace answered the second part of your question. You can find the answer to the first part in this thread:

Is there an R package to parse geophysical "Log Ascii Standard" Files (.las files)?

Moreover, in case you are into developing yourself, you can read this article on saving LAS files:

http://www.kgs.ku.edu/stratigraphic/PROFILE/HELP/Help-PC-SaveLASFile.html

Please let us know what did u end up doing. I am working on the same project as well. Best