private void Test1() { Console.WriteLine("Starting LasWriter test1"); { // create the reader Options readerOpts = new Options(); Option readerOpt1 = new Option(); readerOpt1.setValue_String("../../test/data/1.2-with-color.las"); readerOpt1.setName("filename"); readerOpts.add(readerOpt1); LasReader reader = new LasReader(readerOpts); Options writerOpts = new Options(); Option writerOpt1 = new Option(); writerOpt1.setValue_String("foo.laz"); writerOpt1.setName("filename"); writerOpts.add(writerOpt1); LasWriter writer = new LasWriter(reader, writerOpts); writer.initialize(); writer.setCompressed(true); writer.setDate(0, 0); writer.setPointFormat(PointFormat.PointFormat3); writer.setSystemIdentifier(""); writer.setGeneratingSoftware("TerraScan"); // how many points do we have? ulong numPoints = reader.getNumPoints(); Debug.Assert(numPoints == 1065); ulong numWritten = writer.write(numPoints); Debug.Assert(numWritten == 1065); } Console.WriteLine("checking output..."); { Options opts = new Options(); Option opt = new Option(); opt.setValue_String("foo.laz"); opt.setName("filename"); opts.add(opt); LasReader reader = new LasReader(opts); reader.initialize(); Debug.Assert(reader.isCompressed() == true); ulong numPoints = reader.getNumPoints(); Debug.Assert(numPoints == 1065); } Console.WriteLine("done!"); return; }
public ILiDARData Open(string fileName) { LasReader reader = new LasReader(fileName); reader.initialize(); // how many points do we have? ulong numPoints = reader.getNumPoints(); // create the point buffer we'll read into // make it only hold 128 points a time, so we can show iterating Schema schema = reader.getSchema(); SchemaLayout layout = new SchemaLayout(schema); PointBuffer data = new PointBuffer(layout, 128); // get the dimensions (fields) of the point record for the X, Y, and Z values int offsetX = schema.getDimensionIndex(Dimension.Field.Field_X, Dimension.DataType.Int32); int offsetY = schema.getDimensionIndex(Dimension.Field.Field_Y, Dimension.DataType.Int32); int offsetZ = schema.getDimensionIndex(Dimension.Field.Field_Z, Dimension.DataType.Int32); Dimension dimensionX = schema.getDimension((uint)offsetX); Dimension dimensionY = schema.getDimension((uint)offsetY); Dimension dimensionZ = schema.getDimension((uint)offsetZ); // make the iterator to read from the file StageSequentialIterator iter = reader.createSequentialIterator(); uint totalRead = 0; while (!iter.atEnd()) { uint numRead = iter.read(data); totalRead += numRead; // did we just read the first block of 128 points? // if so, let's check the first point in the buffer // (which is point number 0 in the file) and make sure // it is correct if (iter.getIndex() == 128) { uint pointIndex = 0; // get the raw data from the 1st point record in the point buffer int x0raw = data.getField_Int32(pointIndex, offsetX); int y0raw = data.getField_Int32(pointIndex, offsetY); int z0raw = data.getField_Int32(pointIndex, offsetZ); // LAS stores the data in scaled integer form: undo the scaling // so we can see the real values as doubles double x0 = dimensionX.applyScaling_Int32(x0raw); double y0 = dimensionY.applyScaling_Int32(y0raw); double z0 = dimensionZ.applyScaling_Int32(z0raw); // make sure the X, Y, Z fields are correct! //Debug.Assert(x0 == 637012.240000); //Debug.Assert(y0 == 849028.310000); //Debug.Assert(z0 == 431.660000); Console.WriteLine("point 0 is correct"); } } return new LiDARData(); }
public LiDARDataSet(string filename) { //here read the maxX, maxY from the las file header //and change the Extent property LasReader Reader = new LasReader(filename); Reader.initialize(); ulong PointNum = Reader.getNumPoints(); int ArrayLength = (int)PointNum; //Range_double range = Reader.getBounds(); //Reader.getBounds //Bounds_double ll = Reader.getBounds(); Schema schema = Reader.getSchema(); PointBuffer data = new PointBuffer(schema, (uint)PointNum); // get the dimensions (fields) of the point record for the X, Y, and Z values int offsetX = schema.getDimensionIndex(DimensionId.Id.X_i32); int offsetY = schema.getDimensionIndex(DimensionId.Id.Y_i32); int offsetZ = schema.getDimensionIndex(DimensionId.Id.Z_i32); Dimension dimensionX = schema.getDimension((uint)offsetX); Dimension dimensionY = schema.getDimension((uint)offsetY); Dimension dimensionZ = schema.getDimension((uint)offsetZ); // make the iterator to read from the file StageSequentialIterator iter = Reader.createSequentialIterator(); uint numRead = iter.read(data); int xraw = data.getField_Int32(0, offsetX); int yraw = data.getField_Int32(0, offsetY); // LAS stores the data in scaled integer form: undo the scaling // so we can see the real values as doubles double MinX, MaxX, MinY, MaxY; MinX = MaxX = dimensionX.applyScaling_Int32(xraw); MinY = MaxY = dimensionY.applyScaling_Int32(yraw); for (int i = 1; i < ArrayLength; i++) { xraw = data.getField_Int32((uint)i, offsetX); yraw = data.getField_Int32((uint)i, offsetY); // LAS stores the data in scaled integer form: undo the scaling // so we can see the real values as doubles double x = dimensionX.applyScaling_Int32(xraw); double y = dimensionY.applyScaling_Int32(yraw); if (x < MinX) MinX = x; if (x > MaxX) MaxX = x; if (y < MinY) MinY = y; if (y > MaxY) MaxY = y; } setupExtent = new Extent(MinX, MinY, MaxX, MaxY); }
/// <summary> /// This method simulates loading the array of points from the LAS file. /// Right now it is generating random points that are within the /// view extent. /// </summary> /// <param name="boundingBox">the view extent</param> /// <returns>array of the points in [x y x y ... order]</returns> public double[] GetPointArray(Extent boundingBox) { LasReader Reader = new LasReader("C:\\Tile_1.las"); Reader.initialize(); ulong numPoints = Reader.getNumPoints(); int ArrayLength = (int)numPoints; double[] pointArray = new double[numPoints]; Random rnd = new Random(); double xMin = boundingBox.MinX; double yMin = boundingBox.MinY; // create the point buffer we'll read into // make it only hold 128 points a time, so we can show iterating Schema schema = Reader.getSchema(); PointBuffer data = new PointBuffer(schema, (uint)numPoints); // get the dimensions (fields) of the point record for the X, Y, and Z values int offsetX = schema.getDimensionIndex(DimensionId.Id.X_i32); int offsetY = schema.getDimensionIndex(DimensionId.Id.Y_i32); int offsetZ = schema.getDimensionIndex(DimensionId.Id.Z_i32); Dimension dimensionX = schema.getDimension((uint)offsetX); Dimension dimensionY = schema.getDimension((uint)offsetY); Dimension dimensionZ = schema.getDimension((uint)offsetZ); // make the iterator to read from the file StageSequentialIterator iter = Reader.createSequentialIterator(); uint numRead = iter.read(data); for (int i = 0; i < ArrayLength; i++) { int xraw = data.getField_Int32((uint)i, offsetX); int yraw = data.getField_Int32((uint)i, offsetY); int zraw = data.getField_Int32((uint)i, offsetZ); // LAS stores the data in scaled integer form: undo the scaling // so we can see the real values as doubles double x = dimensionX.applyScaling_Int32(xraw); double y = dimensionY.applyScaling_Int32(yraw); double z = dimensionZ.applyScaling_Int32(zraw); //double randomX = xMin + rnd.NextDouble() * boundingBox.Width; //double randomY = yMin + rnd.NextDouble() * boundingBox.Height; pointArray[i] = x; i = i + 1; pointArray[i] = y; } return(pointArray); }
private void ReadFromLasFile() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "LAS|*.las"; if (ofd.ShowDialog() != DialogResult.OK) { return; } String Filename = ofd.FileName; LasReader Reader = new LasReader(Filename); Reader.initialize(); ulong numPoints = Reader.getNumPoints(); }
private void ReadFromLasFile() { using (var ofd = new OpenFileDialog { Filter = @"LAS|*.las" }) { if (ofd.ShowDialog() != DialogResult.OK) { return; } string filename = ofd.FileName; LasReader reader = new LasReader(filename); reader.initialize(); ulong numPoints = reader.getNumPoints(); } }
/// <summary> /// This method simulates loading the array of points from the LAS file. /// Right now it is generating random points that are within the /// view extent. /// </summary> /// <param name="boundingBox">the view extent</param> /// <returns>array of the points in [x y x y ... order]</returns> public double[] GetPointArray(Extent boundingBox) { LasReader Reader = new LasReader("C:\\Tile_1.las"); Reader.initialize(); ulong numPoints = Reader.getNumPoints(); int ArrayLength = (int)numPoints; double[] pointArray = new double[numPoints]; Random rnd = new Random(); double xMin = boundingBox.MinX; double yMin = boundingBox.MinY; // create the point buffer we'll read into // make it only hold 128 points a time, so we can show iterating Schema schema = Reader.getSchema(); PointBuffer data = new PointBuffer(schema, (uint)numPoints); // get the dimensions (fields) of the point record for the X, Y, and Z values int offsetX = schema.getDimensionIndex(DimensionId.Id.X_i32); int offsetY = schema.getDimensionIndex(DimensionId.Id.Y_i32); int offsetZ = schema.getDimensionIndex(DimensionId.Id.Z_i32); Dimension dimensionX = schema.getDimension((uint)offsetX); Dimension dimensionY = schema.getDimension((uint)offsetY); Dimension dimensionZ = schema.getDimension((uint)offsetZ); // make the iterator to read from the file StageSequentialIterator iter = Reader.createSequentialIterator(); uint numRead = iter.read(data); for (int i = 0; i < ArrayLength; i++) { int xraw = data.getField_Int32((uint)i, offsetX); int yraw = data.getField_Int32((uint)i, offsetY); int zraw = data.getField_Int32((uint)i, offsetZ); // LAS stores the data in scaled integer form: undo the scaling // so we can see the real values as doubles double x = dimensionX.applyScaling_Int32(xraw); double y = dimensionY.applyScaling_Int32(yraw); double z = dimensionZ.applyScaling_Int32(zraw); //double randomX = xMin + rnd.NextDouble() * boundingBox.Width; //double randomY = yMin + rnd.NextDouble() * boundingBox.Height; pointArray[i] = x; i = i + 1; pointArray[i] = y; } return pointArray; }
private void ReadFromLasFile() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "LAS|*.las"; if (ofd.ShowDialog() != DialogResult.OK) return; String Filename = ofd.FileName; LasReader Reader = new LasReader(Filename); Reader.initialize(); ulong numPoints = Reader.getNumPoints(); }
private void Test1() { Console.WriteLine("Starting LasReader test"); // create the reader LasReader reader = new LasReader("../../test/data/1.2-with-color.las"); reader.initialize(); // how many points do we have? ulong numPoints = reader.getNumPoints(); Debug.Assert(numPoints == 1065); Bounds_double bounds = reader.getBounds(); Debug.Assert(closeTo(bounds.getMinimum().get(0), 635619.85)); Debug.Assert(closeTo(bounds.getMinimum().get(1), 848899.70000000007)); Debug.Assert(closeTo(bounds.getMinimum().get(2), 406.59000000000003)); Debug.Assert(closeTo(bounds.getMaximum().get(0), 638982.55)); Debug.Assert(closeTo(bounds.getMaximum().get(1), 853535.43)); Debug.Assert(closeTo(bounds.getMaximum().get(2), 586.38)); // create the point buffer we'll read into // make it only hold 128 points a time, so we can show iterating Schema schema = reader.getSchema(); PointBuffer data = new PointBuffer(schema, 128); // get the dimensions (fields) of the point record for the X, Y, and Z values int offsetX = schema.getDimensionIndex(DimensionId.Id.X_i32); int offsetY = schema.getDimensionIndex(DimensionId.Id.Y_i32); int offsetZ = schema.getDimensionIndex(DimensionId.Id.Z_i32); Dimension dimensionX = schema.getDimension((uint)offsetX); Dimension dimensionY = schema.getDimension((uint)offsetY); Dimension dimensionZ = schema.getDimension((uint)offsetZ); // make the iterator to read from the file StageSequentialIterator iter = reader.createSequentialIterator(); uint totalRead = 0; while (!iter.atEnd()) { uint numRead = iter.read(data); totalRead += numRead; Console.WriteLine(numRead + " points read this time"); // did we just read the first block of 128 points? // if so, let's check the first point in the buffer // (which is point number 0 in the file) and make sure // it is correct if (iter.getIndex() == 128) { uint pointIndex = 0; // get the raw data from the 1st point record in the point buffer int x0raw = data.getField_Int32(pointIndex, offsetX); int y0raw = data.getField_Int32(pointIndex, offsetY); int z0raw = data.getField_Int32(pointIndex, offsetZ); // LAS stores the data in scaled integer form: undo the scaling // so we can see the real values as doubles double x0 = dimensionX.applyScaling_Int32(x0raw); double y0 = dimensionY.applyScaling_Int32(y0raw); double z0 = dimensionZ.applyScaling_Int32(z0raw); // make sure the X, Y, Z fields are correct! Debug.Assert(x0 == 637012.240000); Debug.Assert(y0 == 849028.310000); Debug.Assert(z0 == 431.660000); Console.WriteLine("point 0 is correct"); } } // make sure we have read all the points in the file Debug.Assert(totalRead == numPoints); return; }
/// <summary> /// Initializes a new instance of the <see cref="LiDarDataSet"/> class. /// </summary> /// <param name="filename">Name of the file that is used in this dataset.</param> public LiDarDataSet(string filename) { // here read the maxX, maxY from the las file header // and change the Extent property LasReader reader = new LasReader(filename); reader.initialize(); ulong pointNum = reader.getNumPoints(); int arrayLength = (int)pointNum; Schema schema = reader.getSchema(); PointBuffer data = new PointBuffer(schema, (uint)pointNum); // get the dimensions (fields) of the point record for the X, Y, and Z values int offsetX = schema.getDimensionIndex(DimensionId.Id.X_i32); int offsetY = schema.getDimensionIndex(DimensionId.Id.Y_i32); int offsetZ = schema.getDimensionIndex(DimensionId.Id.Z_i32); Dimension dimensionX = schema.getDimension((uint)offsetX); Dimension dimensionY = schema.getDimension((uint)offsetY); schema.getDimension((uint)offsetZ); // make the iterator to read from the file StageSequentialIterator iter = reader.createSequentialIterator(); iter.read(data); int xraw = data.getField_Int32(0, offsetX); int yraw = data.getField_Int32(0, offsetY); // LAS stores the data in scaled integer form: undo the scaling // so we can see the real values as doubles double maxX, maxY; var minX = maxX = dimensionX.applyScaling_Int32(xraw); var minY = maxY = dimensionY.applyScaling_Int32(yraw); for (int i = 1; i < arrayLength; i++) { xraw = data.getField_Int32((uint)i, offsetX); yraw = data.getField_Int32((uint)i, offsetY); // LAS stores the data in scaled integer form: undo the scaling // so we can see the real values as doubles double x = dimensionX.applyScaling_Int32(xraw); double y = dimensionY.applyScaling_Int32(yraw); if (x < minX) { minX = x; } if (x > maxX) { maxX = x; } if (y < minY) { minY = y; } if (y > maxY) { maxY = y; } } _setupExtent = new Extent(minX, minY, maxX, maxY); }
public LiDARDataSet(string filename) { //here read the maxX, maxY from the las file header //and change the Extent property LasReader Reader = new LasReader(filename); Reader.initialize(); ulong PointNum = Reader.getNumPoints(); int ArrayLength = (int)PointNum; //Range_double range = Reader.getBounds(); //Reader.getBounds //Bounds_double ll = Reader.getBounds(); Schema schema = Reader.getSchema(); PointBuffer data = new PointBuffer(schema, (uint)PointNum); // get the dimensions (fields) of the point record for the X, Y, and Z values int offsetX = schema.getDimensionIndex(DimensionId.Id.X_i32); int offsetY = schema.getDimensionIndex(DimensionId.Id.Y_i32); int offsetZ = schema.getDimensionIndex(DimensionId.Id.Z_i32); Dimension dimensionX = schema.getDimension((uint)offsetX); Dimension dimensionY = schema.getDimension((uint)offsetY); Dimension dimensionZ = schema.getDimension((uint)offsetZ); // make the iterator to read from the file StageSequentialIterator iter = Reader.createSequentialIterator(); uint numRead = iter.read(data); int xraw = data.getField_Int32(0, offsetX); int yraw = data.getField_Int32(0, offsetY); // LAS stores the data in scaled integer form: undo the scaling // so we can see the real values as doubles double MinX, MaxX, MinY, MaxY; MinX = MaxX = dimensionX.applyScaling_Int32(xraw); MinY = MaxY = dimensionY.applyScaling_Int32(yraw); for (int i = 1; i < ArrayLength; i++) { xraw = data.getField_Int32((uint)i, offsetX); yraw = data.getField_Int32((uint)i, offsetY); // LAS stores the data in scaled integer form: undo the scaling // so we can see the real values as doubles double x = dimensionX.applyScaling_Int32(xraw); double y = dimensionY.applyScaling_Int32(yraw); if (x < MinX) { MinX = x; } if (x > MaxX) { MaxX = x; } if (y < MinY) { MinY = y; } if (y > MaxY) { MaxY = y; } } setupExtent = new Extent(MinX, MinY, MaxX, MaxY); }
public ILiDARData Open(string fileName) { LasReader reader = new LasReader(fileName); reader.initialize(); // how many points do we have? ulong numPoints = reader.getNumPoints(); // create the point buffer we'll read into // make it only hold 128 points a time, so we can show iterating Schema schema = reader.getSchema(); SchemaLayout layout = new SchemaLayout(schema); PointBuffer data = new PointBuffer(layout, 128); // get the dimensions (fields) of the point record for the X, Y, and Z values int offsetX = schema.getDimensionIndex(Dimension.Field.Field_X, Dimension.DataType.Int32); int offsetY = schema.getDimensionIndex(Dimension.Field.Field_Y, Dimension.DataType.Int32); int offsetZ = schema.getDimensionIndex(Dimension.Field.Field_Z, Dimension.DataType.Int32); Dimension dimensionX = schema.getDimension((uint)offsetX); Dimension dimensionY = schema.getDimension((uint)offsetY); Dimension dimensionZ = schema.getDimension((uint)offsetZ); // make the iterator to read from the file StageSequentialIterator iter = reader.createSequentialIterator(); uint totalRead = 0; while (!iter.atEnd()) { uint numRead = iter.read(data); totalRead += numRead; // did we just read the first block of 128 points? // if so, let's check the first point in the buffer // (which is point number 0 in the file) and make sure // it is correct if (iter.getIndex() == 128) { uint pointIndex = 0; // get the raw data from the 1st point record in the point buffer int x0raw = data.getField_Int32(pointIndex, offsetX); int y0raw = data.getField_Int32(pointIndex, offsetY); int z0raw = data.getField_Int32(pointIndex, offsetZ); // LAS stores the data in scaled integer form: undo the scaling // so we can see the real values as doubles double x0 = dimensionX.applyScaling_Int32(x0raw); double y0 = dimensionY.applyScaling_Int32(y0raw); double z0 = dimensionZ.applyScaling_Int32(z0raw); // make sure the X, Y, Z fields are correct! //Debug.Assert(x0 == 637012.240000); //Debug.Assert(y0 == 849028.310000); //Debug.Assert(z0 == 431.660000); Console.WriteLine("point 0 is correct"); } } return(new LiDARData()); }