Skip to content

Commit

Permalink
bufix access check at create_raster; refactor BufferedDataOuputStream…
Browse files Browse the repository at this point in the history
…; update java dependencies; fix for new node.js version
  • Loading branch information
swoellauer committed Dec 15, 2022
1 parent 36fdc97 commit de6e25b
Show file tree
Hide file tree
Showing 14 changed files with 21,827 additions and 3,017 deletions.
15 changes: 8 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ dependencies {
implementation group: 'org.json', name: 'json', version: '20220924'
implementation group: 'org.yaml', name: 'snakeyaml', version: '1.33'
//implementation group: 'com.opencsv', name: 'opencsv', version: '4.6' // warning: API at v5.0 breaks
implementation group: 'com.opencsv', name: 'opencsv', version: '5.7.0'
implementation group: 'com.opencsv', name: 'opencsv', version: '5.7.1'
implementation group: 'com.github.mreutegg', name: 'laszip4j', version: '0.11'
implementation group: 'ar.com.hjg', name: 'pngj', version: '2.1.0'
implementation group: 'com.samskivert', name: 'jmustache', version: '1.15'
Expand All @@ -81,19 +81,20 @@ dependencies {

implementation group: 'org.antlr', name: 'antlr4-runtime', version: '4.9.3' // caution: newer versions may break with generated DSL Java source files

implementation group: 'org.eclipse.jetty', name: 'jetty-server', version: '11.0.12'
implementation group: 'org.eclipse.jetty', name: 'jetty-security', version: '11.0.12'
implementation group: 'org.eclipse.jetty.http2', name: 'http2-server', version: '11.0.12'
implementation group: 'org.eclipse.jetty', name: 'jetty-alpn-java-server', version: '11.0.12'
implementation group: 'org.eclipse.jetty', name: 'jetty-client', version: '11.0.12'
implementation group: 'org.eclipse.jetty', name: 'jetty-server', version: '11.0.13'
implementation group: 'org.eclipse.jetty', name: 'jetty-security', version: '11.0.13'
implementation group: 'org.eclipse.jetty.http2', name: 'http2-server', version: '11.0.13'
implementation group: 'org.eclipse.jetty', name: 'jetty-alpn-java-server', version: '11.0.13'
implementation group: 'org.eclipse.jetty', name: 'jetty-client', version: '11.0.13'

implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-gson:0.11.5'

compileOnly group: 'org.gdal', name: 'gdal', version: '2.2.0' // compileOnly because gdal library from executing system is needed; caution: newer versions may break compatibility
implementation group: 'org.locationtech.jts', name: 'jts-core', version: '1.19.0'
implementation group: 'org.locationtech.proj4j', name: 'proj4j', version: '1.1.5'
implementation group: 'org.locationtech.proj4j', name: 'proj4j', version: '1.2.2'
implementation group: 'org.locationtech.proj4j', name: 'proj4j-epsg', version: '1.2.2'

//implementation group: 'org.imintel', name: 'mbtiles4j', version: '1.0.6' // mbtiles currently not used

Expand Down
2 changes: 1 addition & 1 deletion r-package/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: RSDB
Type: Package
Title: R to RSDB Server Connection Package
Version: 1.2.5
Version: 1.2.6
Author: woellauer
Maintainer: woellauer <email@email>
Description: RSDB (Remote Sensing Database) manages (hyperspectral) rasters and (LiDAR) point-clouds as well as vector data and auxiliary ROIs (regions of interest as named polygons) and POIs (points of interest as named points). Contained data can be queried, processed and analysed.
Expand Down
2 changes: 1 addition & 1 deletion r-package/R/RSDB-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#'
#' Central class is \code{\link{RemoteSensing}} that connects to remote sensing database.
#' Methods of \code{\link{RemoteSensing}} provide access to raster (\code{\link{RasterDB}}),
#' to point clouds (\code{\link{PointCloud}}), (deprecated \code{\link{PointDB}}), to vector (\code{\link{VectorDB}}), to region of interest (ROI) and to poin of interest (POI) (at \code{\link{RemoteSensing}}) layers and meta data.
#' to point clouds (\code{\link{PointCloud}}), to voxels (\code{\link{VoxelDB}}), (deprecated \code{\link{PointDB}}), to vector (\code{\link{VectorDB}}), to region of interest (ROI) and to poin of interest (POI) (at \code{\link{RemoteSensing}}) layers and meta data.
#'
#' @name RSDB-package
#' @docType package
Expand Down
4 changes: 2 additions & 2 deletions src/broker/Broker.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public synchronized void refreshPoiGroupMap() {
PoiGroup poiGroup = new PoiGroup(vectordb.getName(), vectordb.informal(), acl_read, details.epsg, details.proj4, pois);
map.put(poiGroup.name, poiGroup);
} catch(Exception e) {
Logger.warn(e);
Logger.warn(e.getMessage());
}
});

Expand Down Expand Up @@ -161,7 +161,7 @@ public synchronized void refreshRoiGroupMap() {
RoiGroup roiGroup = new RoiGroup(vectordb.getName(), vectordb.informal(), acl_read, details.epsg, details.proj4, rois);
map.put(roiGroup.name, roiGroup);
} catch(Exception e) {
Logger.warn(e);
Logger.warn(e.getMessage());
}
});

Expand Down
154 changes: 76 additions & 78 deletions src/pointcloud/LasWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.time.LocalDate;
import java.util.Arrays;

import util.BufferedDataOuputStreamLE;
import util.LittleEndianDataOutputStream;
import util.Receiver;

Expand Down Expand Up @@ -89,68 +90,65 @@ public static void writePoints(PointTable[] pointTables, Receiver receiver, LAS_
double yoff = ((int)ymin);
double zoff = ((int)zmin);

receiver.setContentType("application/octet-stream");
LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(receiver.getOutputStream());



out.writeInt(LASF_SIGNATUR); //File Signature (“LASF”) char[4] 4 bytes
out.writeShort(0); //File Source ID unsigned short 2 bytes
out.writeShort(0); //Global Encoding unsigned short 2 bytes
out.writeInt(0);//Project ID - GUID data 1 unsigned long 4 bytes
out.writeShort(0);//Project ID - GUID data 2 unsigned short 2 byte
out.writeShort(0);//Project ID - GUID data 3 unsigned short 2 byte
out.writeLong(0);//Project ID - GUID data 4 unsigned char[8] 8 bytes
out.writeByte(header.version_major);//Version Major unsigned char 1 byte
out.writeByte(header.version_minor);//Version Minor unsigned char 1 byte
out.write(SYSTEM_IDENTIFIER);//System Identifier char[32] 32 bytes
out.write(GENERATING_SOFTWARE);//Generating Software char[32] 32 bytes
out.writeShort(date.getDayOfYear());//File Creation Day of Year unsigned short 2 bytes
out.writeShort(date.getYear());//File Creation Year unsigned short 2 bytes
out.writeShort(header.size);//Header Size unsigned short 2 bytes
out.writeInt(header.size);//Offset to point data unsigned long 4 bytes
out.writeInt(0);//Number of Variable Length Records unsigned long 4 bytes
out.writeByte(pointDataRecord.id);//Point Data Record Format unsigned char 1 byte
out.writeShort(pointDataRecord.size);//Point Data Record Length unsigned short 2 bytes
out.writeInt(pointCount > Integer.MAX_VALUE ? 0 : (int) pointCount);//Legacy Number of point records unsigned long 4 bytes
out.writeUint32OverflowZero(numberOfPointsByReturn, 5);//Legacy Number of points by return unsigned long [5] 20 bytes
out.writeDouble(SCALE_FACTOR);//X scale factor double 8 bytes
out.writeDouble(SCALE_FACTOR);//Y scale factor double 8 bytes
out.writeDouble(SCALE_FACTOR);//Z scale factor double 8 bytes
out.writeDouble(xoff);//X offset double 8 bytes
out.writeDouble(yoff);//Y offset double 8 bytes
out.writeDouble(zoff);//Z offset double 8 bytes
out.writeDouble(xmax);//Max X double 8 bytes
out.writeDouble(xmin);//Min X double 8 byte
out.writeDouble(ymax);//Max Y double 8 bytes
out.writeDouble(ymin);//Min Y double 8 bytes
out.writeDouble(zmax);//Max Z double 8 bytes
out.writeDouble(zmin);//Min Z double 8 bytes
if((header.version_major == 1 && header.version_minor >= 3) || header.version_major >= 2) {
out.writeLong(0);//Start of Waveform Data Packet Record Unsigned long long 8 bytes
if((header.version_major == 1 && header.version_minor >= 4) || header.version_major >= 2) {
out.writeLong(0);//Start of first Extended Variable Length Record unsigned long long 8 bytes
out.writeInt(0);//Number of Extended Variable Length Records unsigned long 4 bytes
out.writeLong(pointCount);//Number of point records unsigned long long 8 bytes
out.writeUint64(numberOfPointsByReturn);//Number of points by return unsigned long long [15] 120 bytes
receiver.setContentType("application/octet-stream");
//LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(receiver.getOutputStream());
try(BufferedDataOuputStreamLE out = new BufferedDataOuputStreamLE(receiver.getOutputStream())) {
out.putInt(LASF_SIGNATUR); //File Signature (“LASF”) char[4] 4 bytes
out.putShort((short) 0); //File Source ID unsigned short 2 bytes
out.putShort((short) 0); //Global Encoding unsigned short 2 bytes
out.putInt(0);//Project ID - GUID data 1 unsigned long 4 bytes
out.putShort((short) 0);//Project ID - GUID data 2 unsigned short 2 byte
out.putShort((short) 0);//Project ID - GUID data 3 unsigned short 2 byte
out.putLong(0);//Project ID - GUID data 4 unsigned char[8] 8 bytes
out.putByte((byte) header.version_major);//Version Major unsigned char 1 byte
out.putByte((byte) header.version_minor);//Version Minor unsigned char 1 byte
out.putBytes(SYSTEM_IDENTIFIER);//System Identifier char[32] 32 bytes
out.putBytes(GENERATING_SOFTWARE);//Generating Software char[32] 32 bytes
out.putShort((short) date.getDayOfYear());//File Creation Day of Year unsigned short 2 bytes
out.putShort((short) date.getYear());//File Creation Year unsigned short 2 bytes
out.putShort((short) header.size);//Header Size unsigned short 2 bytes
out.putInt(header.size);//Offset to point data unsigned long 4 bytes
out.putInt(0);//Number of Variable Length Records unsigned long 4 bytes
out.putByte((byte) pointDataRecord.id);//Point Data Record Format unsigned char 1 byte
out.putShort((short) pointDataRecord.size);//Point Data Record Length unsigned short 2 bytes
out.putInt(pointCount > Integer.MAX_VALUE ? 0 : (int) pointCount);//Legacy Number of point records unsigned long 4 bytes
out.putIntsOverflowZero(numberOfPointsByReturn, 5);//Legacy Number of points by return unsigned long [5] 20 bytes
out.putDouble(SCALE_FACTOR);//X scale factor double 8 bytes
out.putDouble(SCALE_FACTOR);//Y scale factor double 8 bytes
out.putDouble(SCALE_FACTOR);//Z scale factor double 8 bytes
out.putDouble(xoff);//X offset double 8 bytes
out.putDouble(yoff);//Y offset double 8 bytes
out.putDouble(zoff);//Z offset double 8 bytes
out.putDouble(xmax);//Max X double 8 bytes
out.putDouble(xmin);//Min X double 8 byte
out.putDouble(ymax);//Max Y double 8 bytes
out.putDouble(ymin);//Min Y double 8 bytes
out.putDouble(zmax);//Max Z double 8 bytes
out.putDouble(zmin);//Min Z double 8 bytes
if((header.version_major == 1 && header.version_minor >= 3) || header.version_major >= 2) {
out.putLong(0);//Start of Waveform Data Packet Record Unsigned long long 8 bytes
if((header.version_major == 1 && header.version_minor >= 4) || header.version_major >= 2) {
out.putLong(0);//Start of first Extended Variable Length Record unsigned long long 8 bytes
out.putInt(0);//Number of Extended Variable Length Records unsigned long 4 bytes
out.putLong(pointCount);//Number of point records unsigned long long 8 bytes
out.putLongs(numberOfPointsByReturn);//Number of points by return unsigned long long [15] 120 bytes
}
}
}

switch(pointDataRecord) {
case FORMAT_0:
writePointDataRecordFormat0(out, pointTables, xoff, yoff, zoff);
break;
case FORMAT_6:
writePointDataRecordFormat6(out, pointTables, xoff, yoff, zoff);
break;
default:
throw new RuntimeException();
switch(pointDataRecord) {
case FORMAT_0:
writePointDataRecordFormat0(out, pointTables, xoff, yoff, zoff);
break;
case FORMAT_6:
writePointDataRecordFormat6(out, pointTables, xoff, yoff, zoff);
break;
default:
throw new RuntimeException();
}
}


}

private static void writePointDataRecordFormat0(LittleEndianDataOutputStream out, PointTable[] pointTables, double xoff, double yoff, double zoff) throws IOException {
private static void writePointDataRecordFormat0(BufferedDataOuputStreamLE out, PointTable[] pointTables, double xoff, double yoff, double zoff) throws IOException {
for(PointTable p:pointTables) {
int len = p.rows;
double[] xs = p.x == null ? new double[len] : p.x;
Expand All @@ -162,19 +160,19 @@ private static void writePointDataRecordFormat0(LittleEndianDataOutputStream out
byte[] cs = p.classification == null ? new byte[len] : p.classification;
byte[] sars = p.scanAngleRank == null ? new byte[len] : p.scanAngleRank;
for (int i = 0; i < len; i++) {
out.writeInt((int) ((xs[i] - xoff) * 1000d)); //X long 4 bytes
out.writeInt((int) ((ys[i] - yoff) * 1000d)); //Y long 4 bytes
out.writeInt((int) ((zs[i] - zoff) * 1000d)); //Z long 4 bytes
out.writeChar(is[i]);//Intensity unsigned short 2 bytes
out.putInt((int) ((xs[i] - xoff) * 1000d)); //X long 4 bytes
out.putInt((int) ((ys[i] - yoff) * 1000d)); //Y long 4 bytes
out.putInt((int) ((zs[i] - zoff) * 1000d)); //Z long 4 bytes
out.putChar(is[i]);//Intensity unsigned short 2 bytes
//Return Number 3 bits (bits 0 – 2) 3 bits
//Number of Returns (given pulse) 3 bits (bits 3 – 5) 3 bits
//Scan Direction Flag 1 bit (bit 6) 1 bit
//Edge of Flight Line 1 bit (bit 7) 1 bit
out.writeByte(getFormat0Flag(rns[i], rs[i]));
out.writeByte(cs[i]);//Classification unsigned char 1 byte
out.writeByte(sars[i]);//Scan Angle Rank (-90 to +90) – Left side char 1 byte
out.writeByte(0);//User Data unsigned char 1 byte
out.writeShort(0);//Point Source ID unsigned short 2 bytes
out.putByte((byte) getFormat0Flag(rns[i], rs[i]));
out.putByte(cs[i]);//Classification unsigned char 1 byte
out.putByte(sars[i]);//Scan Angle Rank (-90 to +90) – Left side char 1 byte
out.putByte((byte) 0);//User Data unsigned char 1 byte
out.putShort((short) 0);//Point Source ID unsigned short 2 bytes
}
}
}
Expand All @@ -185,7 +183,7 @@ private static int getFormat0Flag(int returnNumber, int returns) {
return rn & (rs << 3);
}

private static void writePointDataRecordFormat6(LittleEndianDataOutputStream out, PointTable[] pointTables, double xoff, double yoff, double zoff) throws IOException {
private static void writePointDataRecordFormat6(BufferedDataOuputStreamLE out, PointTable[] pointTables, double xoff, double yoff, double zoff) throws IOException {
for(PointTable p:pointTables) {
int len = p.rows;
double[] xs = p.x == null ? new double[len] : p.x;
Expand All @@ -197,23 +195,23 @@ private static void writePointDataRecordFormat6(LittleEndianDataOutputStream out
byte[] cs = p.classification == null ? new byte[len] : p.classification;
byte[] sars = p.scanAngleRank == null ? new byte[len] : p.scanAngleRank;
for (int i = 0; i < len; i++) {
out.writeInt((int) ((xs[i] - xoff) * 1000d)); //X long 4 bytes
out.writeInt((int) ((ys[i] - yoff) * 1000d)); //Y long 4 bytes
out.writeInt((int) ((zs[i] - zoff) * 1000d)); //Z long 4 bytes
out.writeChar(is[i]);//Intensity unsigned short 2 bytes
out.putInt((int) ((xs[i] - xoff) * 1000d)); //X long 4 bytes
out.putInt((int) ((ys[i] - yoff) * 1000d)); //Y long 4 bytes
out.putInt((int) ((zs[i] - zoff) * 1000d)); //Z long 4 bytes
out.putChar(is[i]);//Intensity unsigned short 2 bytes
//Return Number 4 bits (bits 0 - 3) 4 bits
//Number of Returns (given pulse) 4 bits (bits 4 - 7) 4 bits
out.writeByte(getFormat6ReturnFlag(rns[i], rs[i]));
out.putByte((byte) getFormat6ReturnFlag(rns[i], rs[i]));
//Classification Flags 4 bits (bits 0 - 3) 4 bits
//Scanner Channel 2 bits (bits 4 - 5) 2 bits
//Scan Direction Flag 1 bit (bit 6) 1 bit
//Edge of Flight Line 1 bit (bit 7) 1 bit
out.writeByte(0);
out.writeByte(cs[i]);//Classification unsigned char 1 byte
out.writeByte(0);//User Data unsigned char 1 byte
out.writeShort((int) (sars[i] / 0.006d));//Scan Angle short 2 bytes
out.writeShort(0);//Point Source ID unsigned short 2 bytes
out.writeDouble(0);//GPS Time double 8 bytes
out.putByte((byte) 0);
out.putByte(cs[i]);//Classification unsigned char 1 byte
out.putByte((byte) 0);//User Data unsigned char 1 byte
out.putShort((short) (sars[i] / 0.006d));//Scan Angle short 2 bytes
out.putShort((short) 0);//Point Source ID unsigned short 2 bytes
out.putDouble(0);//GPS Time double 8 bytes
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/pointcloud/RdatWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,4 @@ public static void writePoints(PointTable[] pointTables, AttributeSelector selec
}
df.write(receiver, pointTables);
}

}
29 changes: 22 additions & 7 deletions src/server/api/main/APIHandler_create_raster.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public APIHandler_create_raster(Broker broker) {
@Override
protected void handle(String target, Request request, Response response) throws IOException {
UserIdentity userIdentity = Web.getUserIdentity(request);
String name = request.getParameter("name");
if(name==null) {
String rasterdbName = request.getParameter("name");
if(rasterdbName==null) {
throw new RuntimeException("missing name parameter");
}
boolean transaction = true;
Expand All @@ -54,13 +54,28 @@ protected void handle(String target, Request request, Response response) throws
}

boolean create_new = Web.getBoolean(request, "create_new", true);
boolean newRasterdb = true;

RasterDB rasterdb = create_new ? broker.createNewRasterdb(name, transaction, storage_type): broker.createOrGetRasterdb(name, transaction, storage_type);
if(userIdentity != null) {
String username = userIdentity.getUserPrincipal().getName();
rasterdb.setACL_owner(ACL.ofRole(username));
if(broker.hasRasterdb(rasterdbName)) {
newRasterdb = false;
RasterDB rasterdb = broker.getRasterdb(rasterdbName);
rasterdb.checkMod(userIdentity, "task rasterdb create of existing name");
rasterdb.close();
}

RasterDB rasterdb;
if(create_new) {
rasterdb = broker.createNewRasterdb(rasterdbName, transaction, storage_type);
newRasterdb = true;
} else {
rasterdb = broker.createOrGetRasterdb(rasterdbName, transaction, storage_type);
}
if(newRasterdb) {
if(userIdentity != null) {
String username = userIdentity.getUserPrincipal().getName();
rasterdb.setACL_owner(ACL.ofRole(username));
}
}
if(proj4 != null && !proj4.isEmpty()) {
rasterdb.setProj4(proj4);
}
Expand All @@ -77,7 +92,7 @@ protected void handle(String target, Request request, Response response) throws
JSONWriter json = new JSONWriter(response.getWriter());
json.object();
json.key("result");
json.value("created raster "+name);
json.value("created raster "+rasterdbName);
json.endObject();
}
}
5 changes: 1 addition & 4 deletions src/server/api/pointclouds/PointProcessor.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package server.api.pointclouds;

import java.io.IOException;
import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Stream;


import org.tinylog.Logger;
import org.eclipse.jetty.server.Request;
import org.tinylog.Logger;

import pointcloud.AttributeSelector;
import pointcloud.CellTable.ChainedFilterFunc;
Expand All @@ -19,7 +17,6 @@
import pointdb.processing.geopoint.Normalise;
import pointdb.subsetdsl.Region;
import util.Receiver;
import util.Util;
import util.Web;

public class PointProcessor {
Expand Down
Loading

0 comments on commit de6e25b

Please sign in to comment.