Exemple #1
0
        Float3 IReader.GetXYZ()
        {
            var f = new Float3();

            f.hasError = false;

            // Read point
            lazReader.laszip_read_point();

            // check for received errors
            var err = lazReader.laszip_get_error();

            if (err != null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Failed to read until end of file, partial data is kept.");
                Console.WriteLine("ErrorCode: " + err);
                Console.ForegroundColor = ConsoleColor.White;
                f.hasError = true;
            }

            // Get precision coordinates
            var coordArray = new double[3];

            lazReader.laszip_get_coordinates(coordArray);
            f.x = coordArray[0];
            f.y = coordArray[1];
            f.z = coordArray[2];

            return(f);
        }
Exemple #2
0
        private static void WriteLaz()
        {
            // --- Write Example
            var point  = new Point3D();
            var points = new List <Point3D>();

            point.X = 1000.0;
            point.Y = 2000.0;
            point.Z = 100.0;
            points.Add(point);

            point.X = 5000.0;
            point.Y = 6000.0;
            point.Z = 200.0;
            points.Add(point);

            var lazWriter = new laszip_dll();
            var err       = lazWriter.laszip_clean();

            if (err == 0)
            {
                // Number of point records needs to be set
                lazWriter.header.number_of_point_records = (uint)points.Count;

                // Header Min/Max needs to be set to extents of points
                lazWriter.header.min_x = points[0].X;                 // LL Point
                lazWriter.header.min_y = points[0].Y;
                lazWriter.header.min_z = points[0].Z;
                lazWriter.header.max_x = points[1].X;                 // UR Point
                lazWriter.header.max_y = points[1].Y;
                lazWriter.header.max_z = points[1].Z;

                // Open the writer and test for errors
                err = lazWriter.laszip_open_writer(FileName, true);
                if (err == 0)
                {
                    double[] coordArray = new double[3];
                    foreach (var p in points)
                    {
                        coordArray[0] = p.X;
                        coordArray[1] = p.Y;
                        coordArray[2] = p.Z;

                        // Set the coordinates in the lazWriter object
                        lazWriter.laszip_set_coordinates(coordArray);

                        // Set the classification to ground
                        lazWriter.point.classification = 2;

                        // Write the point to the file
                        err = lazWriter.laszip_write_point();
                        if (err != 0)
                        {
                            break;
                        }
                    }

                    // Close the writer to release the file (OS lock)
                    err       = lazWriter.laszip_close_writer();
                    lazWriter = null;
                }
            }

            if (err != 0)
            {
                // Show last error that occurred
                Debug.WriteLine(lazWriter.laszip_get_error());
            }
            // --- Upon completion, file should be 389 bytes
        }