use of org.hortonmachine.gears.io.las.core.LasRecord in project hortonmachine by TheHortonMachine.
the class LasInfoController method init.
private void init() {
_inputPathField.setEditable(false);
GuiUtilities.setFileBrowsingOnWidgets(_inputPathField, _loadButton, new String[] { "las", "laz" }, () -> {
new ExecutorIndeterminateGui() {
@Override
public void backGroundWork() throws Exception {
loadNewFile();
}
}.execute();
});
_dtmInputPathField.setEditable(false);
GuiUtilities.setFileBrowsingOnWidgets(_dtmInputPathField, _loadDtmButton, new String[] { "asc", "tiff" }, () -> {
new ExecutorIndeterminateGui() {
@Override
public void backGroundWork() throws Exception {
loadDtm();
}
}.execute();
});
_boundsLoadButton.addActionListener(e -> {
File[] shpFile = GuiUtilities.showOpenFilesDialog(_boundsLoadButton, "Select bounds file...", false, PreferencesHandler.getLastFile(), new GuiUtilities.ShpFileFilter());
if (shpFile != null) {
new ExecutorIndeterminateGui() {
@Override
public void backGroundWork() throws Exception {
loadBoundsFromFile(shpFile[0]);
}
}.execute();
}
});
_samplingField.setText("1000");
constraints.setSampling(1000);
_samplingField.addKeyListener(this);
_classesField.addKeyListener(this);
_impulsesField.addKeyListener(this);
_intensityRangeField.addKeyListener(this);
_westField.addKeyListener(this);
_eastField.addKeyListener(this);
_southField.addKeyListener(this);
_northField.addKeyListener(this);
_minZField.addKeyListener(this);
_maxZField.addKeyListener(this);
_lowerThresField.addKeyListener(this);
_upperThresField.addKeyListener(this);
_elevationRadio.setSelected(true);
_convertButton.addActionListener(e -> {
if (checkReader()) {
File saveFile = GuiUtilities.showSaveFileDialog(this, "Save to file", PreferencesHandler.getLastFile());
if (saveFile != null) {
exportAction(saveFile);
}
}
});
_createOverviewButton.addActionListener(e -> {
if (checkReader()) {
File saveFile = GuiUtilities.showSaveFileDialog(this, "Save to file", PreferencesHandler.getLastFile());
if (saveFile != null) {
createOverviewAction(saveFile);
}
}
});
_previewImageLabel.addMouseListener(new MouseListener() {
private boolean oneTwo = true;
@Override
public void mouseReleased(MouseEvent e) {
if (pixelToWorld != null) {
int px = e.getX();
int py = e.getY();
Point2D fromPoint = new Point2D.Double(px, py);
Point2D toPoint = new Point2D.Double();
pixelToWorld.transform(fromPoint, toPoint);
if (SwingUtilities.isMiddleMouseButton(e)) {
Envelope env = constraints.getFilteredEnvelope();
double expX = env.getWidth() * 0.2 / 2.0;
double expY = env.getHeight() * 0.2 / 2.0;
Envelope newEnv = new Envelope(env);
newEnv.expandBy(expX, expY);
constraints.setWest(newEnv.getMinX());
constraints.setEast(newEnv.getMaxX());
constraints.setSouth(newEnv.getMinY());
constraints.setNorth(newEnv.getMaxY());
// drawPreview();
} else {
if (SwingUtilities.isLeftMouseButton(e)) {
double x = toPoint.getX();
double y = toPoint.getY();
if (oneTwo) {
constraints.setWest(x);
constraints.setSouth(y);
} else {
constraints.setEast(x);
constraints.setNorth(y);
}
oneTwo = !oneTwo;
} else if (SwingUtilities.isRightMouseButton(e)) {
constraints.setEast(null);
constraints.setNorth(null);
constraints.setWest(null);
constraints.setSouth(null);
}
Double[] propBounds = constraints.checkBounds();
_westField.setText(propBounds[0] != null ? propBounds[0].toString() : "");
_eastField.setText(propBounds[1] != null ? propBounds[1].toString() : "");
_southField.setText(propBounds[2] != null ? propBounds[2].toString() : "");
_northField.setText(propBounds[3] != null ? propBounds[3].toString() : "");
drawWithMouseBounds();
}
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
});
_loadPreviewButton.addActionListener(e -> {
if (checkReader()) {
new ExecutorIndeterminateGui() {
@Override
public void backGroundWork() throws Exception {
constraints.applyConstraints(lasReader, false, null);
List<LasRecord> filteredPoints = constraints.getFilteredPoints();
drawPreview(filteredPoints);
}
}.execute();
}
});
_loadDataButton.addActionListener(e -> {
if (checkReader()) {
loadDataAction();
}
});
_load3DButton.setVisible(false);
// _load3DButton.addActionListener(e -> {
// if (checkReader()) {
// AbstractAnalysis abstractAnalysis = new AbstractAnalysis(){
// @Override
// public void init() throws Exception {
// constraints.applyConstraints(lasReader, false, null);
// List<LasRecord> filteredPoints = constraints.getFilteredPoints();
// List<Coord3d> points = new ArrayList<>();
// List<org.jzy3d.colors.Color> colors = new ArrayList<>();
// for( LasRecord dot : filteredPoints ) {
// float x = (float) dot.x;
// float y = (float) dot.y;
// float z = (float) dot.z;
// if (!Double.isNaN(dot.groundElevation)) {
// z = (float) dot.groundElevation;
// }
// points.add(new Coord3d(x, y, z));
// short[] c = dot.color;
// colors.add(new org.jzy3d.colors.Color((int) c[0], (int) c[1], (int) c[2]));
// }
// Coord3d[] coord3ds = points.toArray(new Coord3d[points.size()]);
// org.jzy3d.colors.Color[] colorsArray = colors.toArray(new org.jzy3d.colors.Color[colors.size()]);
// Scatter scatterLas = new Scatter(coord3ds, colorsArray, 7f);
// String text = _pointSizeField.getText();
// int pointSize = 1;
// try {
// pointSize = Integer.parseInt(text.trim());
// } catch (Exception e) {
// // ignore
// }
// scatterLas.setWidth(pointSize);
// chart = AWTChartComponentFactory.chart(Quality.Fastest, "newt");
// chart.getScene().getGraph().add(scatterLas);
// // chart.setAxeDisplayed(false);
// chart.getView().setSquared(false);
// }
// };
// try {
// AnalysisLauncher.open(abstractAnalysis);
// } catch (Exception e1) {
// GuiUtilities.handleError(_boundsLoadButton, e1);
// }
// }
// });
_sliceIntervalField.setText("1");
_sliceWidthField.setText("0.2");
_slicingModeCheck.addActionListener(e -> {
if (checkReader()) {
sliceModeIsOn = _slicingModeCheck.isSelected();
_loadSlicedataButton.setEnabled(sliceModeIsOn);
_slicesCombo.setEnabled(sliceModeIsOn);
}
});
_loadSlicedataButton.addActionListener(e -> {
if (checkReader()) {
new ExecutorIndeterminateGui() {
@Override
public void backGroundWork() throws Exception {
loadSliceData();
}
}.execute();
}
});
_slicesCombo.addActionListener(e -> {
String slice = _slicesCombo.getSelectedItem().toString();
if (slicesMap != null) {
List<LasRecord> lrList = slicesMap.get(slice);
if (lrList != null) {
new ExecutorIndeterminateGui() {
@Override
public void backGroundWork() throws Exception {
drawPreview(lrList);
}
}.execute();
return;
}
}
GuiUtilities.showWarningMessage(this, "No slice data available. ");
});
_circlesMinCellCountField.setText("50");
_circlesExtractButton.addActionListener(e -> {
if (checkReader()) {
new ExecutorIndeterminateGui() {
@Override
public void backGroundWork() throws Exception {
try {
List<Geometry> circles = getCircleGeometries();
BufferedImage withCirclesImage = new BufferedImage(lastDrawnImage.getWidth(), lastDrawnImage.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = (Graphics2D) withCirclesImage.getGraphics();
g2d.drawImage(lastDrawnImage, 0, 0, null);
GeneralPath gp = new GeneralPath();
for (Geometry g : circles) {
Coordinate[] coords = g.getCoordinates();
boolean isNew = true;
for (Coordinate coordinate : coords) {
Coordinate newCoord = TransformationUtils.transformCoordinate(worldToPixel, coordinate);
if (isNew) {
gp.moveTo(newCoord.x, newCoord.y);
isNew = false;
} else {
gp.lineTo(newCoord.x, newCoord.y);
}
}
}
g2d.setColor(Color.red);
g2d.setStroke(new BasicStroke(3));
g2d.draw(gp);
g2d.dispose();
_previewImageLabel.setIcon(new ImageIcon(withCirclesImage));
} catch (Exception e1) {
GuiUtilities.showErrorMessage(LasInfoController.this, null, e1.getMessage());
}
}
}.execute();
}
});
_circlesSaveShpButton.addActionListener(e -> {
if (checkReader()) {
File saveFile = GuiUtilities.showSaveFileDialog(this, "Save circles to shp", PreferencesHandler.getLastFile());
if (saveFile != null) {
new ExecutorIndeterminateGui() {
@Override
public void backGroundWork() throws Exception {
try {
List<Geometry> circles = getCircleGeometries();
ILasHeader header = lasReader.getHeader();
CoordinateReferenceSystem crs = header.getCrs();
if (crs == null) {
crs = DEFAULT_GENERIC;
}
SimpleFeatureCollection fc = FeatureUtilities.featureCollectionFromGeometry(crs, circles.toArray(new Geometry[0]));
OmsVectorWriter.writeVector(saveFile.getAbsolutePath(), fc);
} catch (Exception e1) {
GuiUtilities.showErrorMessage(LasInfoController.this, null, e1.getMessage());
}
}
}.execute();
}
}
});
}
use of org.hortonmachine.gears.io.las.core.LasRecord in project hortonmachine by TheHortonMachine.
the class LasInfoController method loadSliceData.
@SuppressWarnings("unchecked")
private void loadSliceData() {
String text = _sliceIntervalField.getText();
double interval = Double.parseDouble(text);
text = _sliceWidthField.getText();
double width = Double.parseDouble(text);
double[] stats = constraints.getStats();
double minElev = stats[0];
double maxElev = stats[1];
slicesMap = new LinkedHashMap<>();
List<LasRecord> filteredPoints = constraints.getFilteredPoints();
double runningInterval = minElev;
while (runningInterval < maxElev) {
ArrayList<LasRecord> sliceList = new ArrayList<>();
slicesMap.put(String.valueOf(runningInterval), sliceList);
double lower = runningInterval - width / 2.0;
double upper = runningInterval + width / 2.0;
for (LasRecord lr : filteredPoints) {
if (lr.z > lower && lr.z < upper) {
sliceList.add(lr);
}
}
runningInterval += interval;
}
_slicesCombo.setModel(new DefaultComboBoxModel<>(slicesMap.keySet().toArray(new String[0])));
}
use of org.hortonmachine.gears.io.las.core.LasRecord in project hortonmachine by TheHortonMachine.
the class FlightLinesIntensityNormalizer method process.
@Execute
public void process() throws Exception {
checkNull(inLas, inFlightpoints, pDateTimePattern);
int timeType = -1;
if (pGpsTimeType.equals(FlightLinesExtractor.ADJUSTED_STANDARD_GPS_TIME)) {
timeType = 1;
}
if (pGpsTimeType.equals(FlightLinesExtractor.WEEK_SECONDS_TIME)) {
timeType = 0;
}
SimpleFeatureCollection flightPointsFC = OmsVectorReader.readVector(inFlightpoints);
List<SimpleFeature> flightPointsList = FeatureUtilities.featureCollectionToList(flightPointsFC);
SimpleFeatureType schema = flightPointsFC.getSchema();
String dateName = FeatureUtilities.findAttributeName(schema, "date");
String timeName = FeatureUtilities.findAttributeName(schema, "time");
String elevName = FeatureUtilities.findAttributeName(schema, "elev");
if (dateName == null || timeName == null || elevName == null) {
throw new ModelsIllegalargumentException("The shapefile has to contain the fields date time and elev.", this);
}
pm.beginTask("Defining flight intervals and positions...", flightPointsList.size());
DateTimeFormatter formatter = DateTimeFormat.forPattern(pDateTimePattern).withZone(DateTimeZone.UTC);
TreeMap<DateTime, Coordinate> date2pointsMap = new TreeMap<DateTime, Coordinate>();
TreeMap<Coordinate, DateTime> points2dateMap = new TreeMap<Coordinate, DateTime>();
for (int i = 0; i < flightPointsList.size(); i++) {
SimpleFeature flightPoint = flightPointsList.get(i);
Geometry g1 = (Geometry) flightPoint.getDefaultGeometry();
Coordinate c1 = g1.getCoordinate();
double elev1 = ((Number) flightPoint.getAttribute(elevName)).doubleValue();
c1.z = elev1;
String date1 = flightPoint.getAttribute(dateName).toString();
String time1 = flightPoint.getAttribute(timeName).toString();
String dateTime1 = date1 + " " + time1;
DateTime d1 = formatter.parseDateTime(dateTime1);
date2pointsMap.put(d1, c1);
points2dateMap.put(c1, d1);
pm.worked(1);
}
pm.done();
pm.beginTask("Create time index...", flightPointsList.size() - 1);
DateTime minDate = null;
DateTime maxDate = null;
long minLong = Long.MAX_VALUE;
long maxLong = -Long.MAX_VALUE;
STRtree tree = new STRtree(flightPointsList.size());
Set<Entry<DateTime, Coordinate>> pointsSet = date2pointsMap.entrySet();
Entry[] array = pointsSet.toArray(new Entry[0]);
for (int i = 0; i < array.length - 1; i++) {
DateTime d1 = (DateTime) array[i].getKey();
Coordinate c1 = (Coordinate) array[i].getValue();
DateTime d2 = (DateTime) array[i + 1].getKey();
Coordinate c2 = (Coordinate) array[i + 1].getValue();
long millis1 = d1.getMillis();
long millis2 = d2.getMillis();
Envelope timeEnv = new Envelope(millis1, millis2, millis1, millis2);
tree.insert(timeEnv, new Coordinate[] { c1, c2 });
if (millis1 < minLong) {
minLong = millis1;
minDate = d1;
}
if (millis2 > maxLong) {
maxLong = millis2;
maxDate = d2;
}
pm.worked(1);
}
pm.done();
StringBuilder sb = new StringBuilder();
sb.append("Flight data interval: ");
sb.append(minDate.toString(HMConstants.dateTimeFormatterYYYYMMDDHHMMSS));
sb.append(" to ");
sb.append(maxDate.toString(HMConstants.dateTimeFormatterYYYYMMDDHHMMSS));
pm.message(sb.toString());
CoordinateReferenceSystem crs = null;
File lasFile = new File(inLas);
File outLasFile = new File(outLas);
try (//
ALasReader reader = ALasReader.getReader(lasFile, crs);
ALasWriter writer = ALasWriter.getWriter(outLasFile, crs)) {
reader.setOverrideGpsTimeType(timeType);
ILasHeader header = reader.getHeader();
int gpsTimeType = header.getGpsTimeType();
writer.setBounds(header);
writer.open();
pm.beginTask("Interpolating flight points and normalizing...", (int) header.getRecordsCount());
while (reader.hasNextPoint()) {
LasRecord r = reader.getNextPoint();
DateTime gpsTimeToDateTime;
if (timeType == 0) {
gpsTimeToDateTime = GpsTimeConverter.gpsWeekTime2DateTime(r.gpsTime);
} else {
gpsTimeToDateTime = LasUtils.adjustedStandardGpsTime2DateTime(r.gpsTime);
}
long gpsMillis = gpsTimeToDateTime.getMillis();
Coordinate lasCoordinate = new Coordinate(r.x, r.y, r.z);
Envelope pEnv = new Envelope(new Coordinate(gpsMillis, gpsMillis));
List points = tree.query(pEnv);
Coordinate[] flightCoords = (Coordinate[]) points.get(0);
long d1 = points2dateMap.get(flightCoords[0]).getMillis();
long d2 = points2dateMap.get(flightCoords[1]).getMillis();
LineSegment line = new LineSegment(flightCoords[0], flightCoords[1]);
double fraction = (gpsMillis - d1) / (d2 - d1);
Coordinate interpolatedFlightPoint = line.pointAlong(fraction);
// calculate interpolated elevation
double distX = interpolatedFlightPoint.distance(flightCoords[0]);
double dist12 = flightCoords[1].distance(flightCoords[0]);
double interpolatedElev = distX / dist12 * (flightCoords[1].z - flightCoords[0].z) + flightCoords[0].z;
interpolatedFlightPoint.z = interpolatedElev;
double distanceFlightTerrain = GeometryUtilities.distance3d(lasCoordinate, interpolatedFlightPoint, null);
short norm = (short) floor(r.intensity * pow(distanceFlightTerrain, 2.0) / pStdRange + 0.5);
r.intensity = norm;
writer.addPoint(r);
pm.worked(1);
}
pm.done();
}
}
use of org.hortonmachine.gears.io.las.core.LasRecord in project hortonmachine by TheHortonMachine.
the class Las2RasterInterpolator method process.
@Execute
public void process() throws Exception {
checkNull(inIndexFile, inDtm);
GridCoverage2D inDtmGC = getRaster(inDtm);
Polygon polygon = CoverageUtilities.getRegionPolygon(inDtmGC);
CoordinateReferenceSystem crs = inDtmGC.getCoordinateReferenceSystem();
try (ALasDataManager lasData = ALasDataManager.getDataManager(new File(inIndexFile), inDtmGC, pThreshold, crs)) {
lasData.open();
if (pImpulse != null) {
lasData.setImpulsesConstraint(new double[] { pImpulse });
}
List<LasRecord> lasPoints = lasData.getPointsInGeometry(polygon, false);
if (lasPoints.size() == 0) {
pm.message("No points foudn in the given area. Check your input.");
return;
}
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inDtmGC);
double north = regionMap.getNorth();
double south = regionMap.getSouth();
double east = regionMap.getEast();
double west = regionMap.getWest();
if (pXres == null) {
pXres = regionMap.getXres();
}
if (pYres == null) {
pYres = regionMap.getYres();
}
int newRows = (int) round((north - south) / pYres);
int newCols = (int) round((east - west) / pXres);
DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
final SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName("lasdata");
b.setCRS(crs);
b.add("the_geom", Point.class);
b.add("elev", Double.class);
final SimpleFeatureType featureType = b.buildFeatureType();
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
pm.beginTask("Prepare points collection for interpolation...", lasPoints.size());
for (LasRecord r : lasPoints) {
final Point point = gf.createPoint(new Coordinate(r.x, r.y));
final Object[] values = new Object[] { point, r.z };
builder.addAll(values);
final SimpleFeature feature = builder.buildFeature(null);
newCollection.add(feature);
pm.worked(1);
}
pm.done();
OmsRasterGenerator omsRasterGenerator = new OmsRasterGenerator();
omsRasterGenerator.pNorth = north;
omsRasterGenerator.pSouth = south;
omsRasterGenerator.pWest = west;
omsRasterGenerator.pEast = east;
omsRasterGenerator.pXres = (east - west) / newCols;
omsRasterGenerator.pYres = (north - south) / newRows;
omsRasterGenerator.inCrs = crs;
omsRasterGenerator.doRandom = false;
omsRasterGenerator.process();
OmsSurfaceInterpolator idwInterpolator = new OmsSurfaceInterpolator();
idwInterpolator.inVector = newCollection;
idwInterpolator.inGrid = omsRasterGenerator.outRaster;
idwInterpolator.inMask = null;
idwInterpolator.fCat = "elev";
idwInterpolator.pMode = Variables.IDW;
idwInterpolator.pMaxThreads = getDefaultThreadsNum();
idwInterpolator.pBuffer = 10.0;
idwInterpolator.pm = pm;
idwInterpolator.process();
GridCoverage2D outRasterGC = idwInterpolator.outRaster;
dumpRaster(outRasterGC, outRaster);
}
}
use of org.hortonmachine.gears.io.las.core.LasRecord in project hortonmachine by TheHortonMachine.
the class LasElevationHandler method process.
@Execute
public void process() throws Exception {
checkNull(inFile, inDtm);
GridCoverage2D dtm = getRaster(inDtm);
File inLas = new File(inFile);
try (ALasReader reader = ALasReader.getReader(inLas, null)) {
reader.open();
ILasHeader header = reader.getHeader();
long recordsNum = header.getRecordsCount();
ReferencedEnvelope3D env = header.getDataEnvelope();
File outLas = new File(outFile);
try (ALasWriter writer = ALasWriter.getWriter(outLas, env.getCoordinateReferenceSystem())) {
writer.setBounds(header);
writer.open();
pm.beginTask("Normalizing las...", (int) recordsNum);
while (reader.hasNextPoint()) {
LasRecord dot = reader.getNextPoint();
double dtmValue = CoverageUtilities.getValue(dtm, dot.x, dot.y);
if (HMConstants.isNovalue(dtmValue)) {
dtmValue = 0;
}
if (doAdd) {
dot.z += dtmValue;
} else {
dot.z -= dtmValue;
}
writer.addPoint(dot);
pm.worked(1);
}
pm.done();
}
}
}
Aggregations