use of gov.nasa.worldwind.geom.Sector in project hortonmachine by TheHortonMachine.
the class SectorSelector method determineAdjustmentSide.
protected int determineAdjustmentSide(Movable dragObject, double factor) {
if (dragObject instanceof SurfaceSector) {
SurfaceSector quad = (SurfaceSector) dragObject;
// TODO: go over all sectors
Sector s = quad.getSector();
Position p = this.getWwd().getCurrentPosition();
if (p == null) {
return NONE;
}
double dN = abs(s.getMaxLatitude().subtract(p.getLatitude()).degrees);
double dS = abs(s.getMinLatitude().subtract(p.getLatitude()).degrees);
double dW = abs(s.getMinLongitude().subtract(p.getLongitude()).degrees);
double dE = abs(s.getMaxLongitude().subtract(p.getLongitude()).degrees);
double sLat = factor * s.getDeltaLatDegrees();
double sLon = factor * s.getDeltaLonDegrees();
if (dN < sLat && dW < sLon)
return NORTHWEST;
if (dN < sLat && dE < sLon)
return NORTHEAST;
if (dS < sLat && dW < sLon)
return SOUTHWEST;
if (dS < sLat && dE < sLon)
return SOUTHEAST;
if (dN < sLat)
return NORTH;
if (dS < sLat)
return SOUTH;
if (dW < sLon)
return WEST;
if (dE < sLon)
return EAST;
}
return NONE;
}
use of gov.nasa.worldwind.geom.Sector in project hortonmachine by TheHortonMachine.
the class SectorSelector method resizeShape.
protected Sector resizeShape(Movable dragObject, int side) {
if (dragObject instanceof SurfaceSector) {
SurfaceSector quad = (SurfaceSector) dragObject;
// TODO: go over all sectors
Sector s = quad.getSector();
Position p = this.getWwd().getCurrentPosition();
if (p == null || this.getPreviousPosition() == null) {
return null;
}
Angle dLat = p.getLatitude().subtract(this.getPreviousPosition().getLatitude());
Angle dLon = p.getLongitude().subtract(this.getPreviousPosition().getLongitude());
Angle newMinLat = s.getMinLatitude();
Angle newMinLon = s.getMinLongitude();
Angle newMaxLat = s.getMaxLatitude();
Angle newMaxLon = s.getMaxLongitude();
if (side == NORTH) {
newMaxLat = s.getMaxLatitude().add(dLat);
} else if (side == SOUTH) {
newMinLat = s.getMinLatitude().add(dLat);
} else if (side == EAST) {
newMaxLon = s.getMaxLongitude().add(dLon);
} else if (side == WEST) {
newMinLon = s.getMinLongitude().add(dLon);
} else if (side == NORTHWEST) {
newMaxLat = s.getMaxLatitude().add(dLat);
newMinLon = s.getMinLongitude().add(dLon);
} else if (side == NORTHEAST) {
newMaxLat = s.getMaxLatitude().add(dLat);
newMaxLon = s.getMaxLongitude().add(dLon);
} else if (side == SOUTHWEST) {
newMinLat = s.getMinLatitude().add(dLat);
newMinLon = s.getMinLongitude().add(dLon);
} else if (side == SOUTHEAST) {
newMinLat = s.getMinLatitude().add(dLat);
newMaxLon = s.getMaxLongitude().add(dLon);
}
return new Sector(newMinLat, newMaxLat, newMinLon, newMaxLon);
}
return null;
}
use of gov.nasa.worldwind.geom.Sector in project hortonmachine by TheHortonMachine.
the class GeopaparazziController method selectGpsLog.
private void selectGpsLog(GpsLog selectedLog) {
try {
checkLoadedProject();
String startDateTimeString = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(selectedLog.startTime));
String endDateTimeString = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(selectedLog.endTime));
String picInfo = //
"<b>Gps log:</b> " + GeopaparazziUtilities.escapeHTML(selectedLog.text) + "<br/>" + "<b>Start time:</b> " + startDateTimeString + //
"<br/>" + "<b>End time:</b> " + endDateTimeString + "<br/>";
_infoArea.setText(picInfo);
loadGpsLogChart(selectedLog, currentSelectedProject.databaseFile);
Envelope env = null;
for (GpsPoint gpsPoint : selectedLog.points) {
if (env == null) {
env = new Envelope(new Coordinate(gpsPoint.lon, gpsPoint.lat));
} else {
env.expandToInclude(gpsPoint.lon, gpsPoint.lat);
}
}
env.expandBy(0.01);
Sector sector = NwwUtilities.envelope2Sector(new ReferencedEnvelope(env, NwwUtilities.GPS_CRS));
if (wwjPanel != null)
wwjPanel.goTo(sector, false);
} catch (Exception e) {
Logger.INSTANCE.insertError("", "error", e);
setNoProjectLabel();
}
}
use of gov.nasa.worldwind.geom.Sector in project hortonmachine by TheHortonMachine.
the class GeopaparazziController method loadProjectData.
/**
* Extract data from the db and add them to the map view.
*
* @param projectTemplate
* @return
* @throws Exception
*/
public void loadProjectData(ProjectInfo currentSelectedProject, boolean zoomTo) throws Exception {
if (geopapDataLayer != null)
geopapDataLayer.removeAllRenderables();
Envelope bounds = new Envelope();
File dbFile = currentSelectedProject.databaseFile;
try (Connection connection = DriverManager.getConnection("jdbc:sqlite:" + dbFile.getAbsolutePath())) {
// NOTES
List<String[]> noteDataList = GeopaparazziUtilities.getNotesText(connection);
StringBuilder sb = new StringBuilder();
sb.append("\n\n// GP NOTES\n");
int index = 0;
PointPlacemarkAttributes notesAttributes = new PointPlacemarkAttributes();
// notesAttributes.setLabelMaterial(mFillMaterial);
// notesAttributes.setLineMaterial(mFillMaterial);
// notesAttributes.setUsePointAsDefaultImage(true);
notesAttributes.setImage(ImageCache.getInstance().getBufferedImage(ImageCache.NOTE));
notesAttributes.setLabelMaterial(new Material(Color.BLACK));
// notesAttributes.setScale(mMarkerSize);
for (String[] noteData : noteDataList) {
// [lon, lat, altim, dateTimeString, text, descr]
double lon = Double.parseDouble(noteData[0]);
double lat = Double.parseDouble(noteData[1]);
String altim = noteData[2];
String date = noteData[3];
String text = noteData[4];
String descr = noteData[5];
PointPlacemark marker = new PointPlacemark(Position.fromDegrees(lat, lon, 0));
marker.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
marker.setLabelText(text + " (" + date + ")");
marker.setAttributes(notesAttributes);
if (geopapDataLayer != null)
geopapDataLayer.addRenderable(marker);
bounds.expandToInclude(lon, lat);
}
/*
* IMAGES
*/
PointPlacemarkAttributes imageAttributes = new PointPlacemarkAttributes();
imageAttributes.setImage(ImageCache.getInstance().getBufferedImage(ImageCache.DBIMAGE));
imageAttributes.setLabelMaterial(new Material(Color.GRAY));
for (org.hortonmachine.gears.io.geopaparazzi.geopap4.Image image : currentSelectedProject.images) {
double lon = image.getLon();
double lat = image.getLat();
PointPlacemark marker = new PointPlacemark(Position.fromDegrees(lat, lon, 0));
marker.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
marker.setLabelText(image.getName());
marker.setAttributes(imageAttributes);
if (geopapDataLayer != null)
geopapDataLayer.addRenderable(marker);
bounds.expandToInclude(lon, lat);
}
try (Statement statement = connection.createStatement()) {
// set timeout to 30 sec.
statement.setQueryTimeout(30);
String sql = //
"select " + GpsLogsTableFields.COLUMN_ID.getFieldName() + //
"," + GpsLogsTableFields.COLUMN_LOG_STARTTS.getFieldName() + //
"," + GpsLogsTableFields.COLUMN_LOG_ENDTS.getFieldName() + //
"," + //
GpsLogsTableFields.COLUMN_LOG_TEXT.getFieldName() + " from " + //
TABLE_GPSLOGS;
boolean useGpsElev = _useGpsElevationsCheckbox.isSelected();
int altitudeMode = WorldWind.CLAMP_TO_GROUND;
if (useGpsElev) {
altitudeMode = WorldWind.ABSOLUTE;
}
// first get the logs
ResultSet rs = statement.executeQuery(sql);
while (rs.next()) {
long id = rs.getLong(1);
long startDateTime = rs.getLong(2);
String startDateTimeString = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(startDateTime));
long endDateTime = rs.getLong(3);
String endDateTimeString = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(endDateTime));
String text = rs.getString(4);
// points
String query = //
"select " + GpsLogsDataTableFields.COLUMN_DATA_LAT.getFieldName() + "," + GpsLogsDataTableFields.COLUMN_DATA_LON.getFieldName() + "," + GpsLogsDataTableFields.COLUMN_DATA_ALTIM.getFieldName() + "," + //
GpsLogsDataTableFields.COLUMN_DATA_TS.getFieldName() + " from " + TABLE_GPSLOG_DATA + //
" where " + GpsLogsDataTableFields.COLUMN_LOGID.getFieldName() + " = " + id + " order by " + GpsLogsDataTableFields.COLUMN_DATA_TS.getFieldName();
List<Position> verticesList = new ArrayList<>();
try (Statement newStatement = connection.createStatement()) {
newStatement.setQueryTimeout(30);
ResultSet result = newStatement.executeQuery(query);
while (result.next()) {
double lat = result.getDouble(1);
double lon = result.getDouble(2);
double elev = 0.0;
if (useGpsElev)
elev = result.getDouble(3);
Position pos = Position.fromDegrees(lat, lon, elev);
verticesList.add(pos);
bounds.expandToInclude(lon, lat);
}
}
// color
String colorQuery = //
"select " + GpsLogsPropertiesTableFields.COLUMN_PROPERTIES_COLOR.getFieldName() + "," + GpsLogsPropertiesTableFields.COLUMN_PROPERTIES_WIDTH.getFieldName() + " from " + TABLE_GPSLOG_PROPERTIES + //
" where " + GpsLogsPropertiesTableFields.COLUMN_LOGID.getFieldName() + " = " + id;
String colorStr = RED_HEXA;
int lineWidth = 3;
try (Statement newStatement = connection.createStatement()) {
newStatement.setQueryTimeout(30);
ResultSet result = newStatement.executeQuery(colorQuery);
if (result.next()) {
colorStr = result.getString(1);
lineWidth = result.getInt(2);
if (colorStr.equalsIgnoreCase("red")) {
colorStr = RED_HEXA;
}
}
if (colorStr == null || colorStr.length() == 0) {
colorStr = RED_HEXA;
}
}
Color color = Color.RED;
try {
color = Color.decode(colorStr);
} catch (Exception e) {
// ignore Logger.INSTANCE.insertError("","Could not convert color: " +
// colorStr, e);
}
BasicShapeAttributes lineAttributes = new BasicShapeAttributes();
lineAttributes.setOutlineMaterial(new Material(color));
lineAttributes.setOutlineWidth(lineWidth);
Path path = new Path(verticesList);
path.setAltitudeMode(altitudeMode);
path.setFollowTerrain(true);
path.setAttributes(lineAttributes);
if (geopapDataLayer != null)
geopapDataLayer.addRenderable(path);
}
}
}
if (zoomTo) {
bounds.expandBy(0.001);
Sector sector = NwwUtilities.envelope2Sector(new ReferencedEnvelope(bounds, NwwUtilities.GPS_CRS));
if (wwjPanel != null)
wwjPanel.goTo(sector, false);
}
currentLoadedProject = currentSelectedProject;
}
use of gov.nasa.worldwind.geom.Sector in project hortonmachine by TheHortonMachine.
the class NwwUtilities method envelope2Sector.
public static Sector envelope2Sector(ReferencedEnvelope env) throws Exception {
CoordinateReferenceSystem sourceCRS = env.getCoordinateReferenceSystem();
CoordinateReferenceSystem targetCRS = GPS_CRS;
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
Envelope envLL = JTS.transform(env, transform);
ReferencedEnvelope llEnv = new ReferencedEnvelope(envLL, targetCRS);
Sector sector = Sector.fromDegrees(llEnv.getMinY(), llEnv.getMaxY(), llEnv.getMinX(), llEnv.getMaxX());
return sector;
}
Aggregations