Search in sources :

Example 1 with Path

use of gov.nasa.worldwind.render.Path in project mapton by trixon.

the class PhotosLayerBundle method plotTrack.

private void plotTrack(BasicShapeAttributes attributes, ArrayList<Position> positions) {
    Path path = new Path(positions);
    path.setFollowTerrain(true);
    path.setAttributes(attributes);
    path.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
    mRenderableLayer.addRenderable(path);
}
Also used : Path(gov.nasa.worldwind.render.Path)

Example 2 with Path

use of gov.nasa.worldwind.render.Path 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;
}
Also used : ArrayList(java.util.ArrayList) LineString(org.locationtech.jts.geom.LineString) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(org.locationtech.jts.geom.Envelope) BasicShapeAttributes(gov.nasa.worldwind.render.BasicShapeAttributes) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) PointPlacemark(gov.nasa.worldwind.render.PointPlacemark) ResultSet(java.sql.ResultSet) IHMResultSet(org.hortonmachine.dbs.compat.IHMResultSet) Path(gov.nasa.worldwind.render.Path) TreePath(javax.swing.tree.TreePath) Position(gov.nasa.worldwind.geom.Position) IHMStatement(org.hortonmachine.dbs.compat.IHMStatement) Statement(java.sql.Statement) Sector(gov.nasa.worldwind.geom.Sector) Color(java.awt.Color) Connection(java.sql.Connection) Material(gov.nasa.worldwind.render.Material) GpsPoint(org.hortonmachine.gears.io.geopaparazzi.geopap4.DaoGpsLog.GpsPoint) Date(java.util.Date) PointPlacemarkAttributes(gov.nasa.worldwind.render.PointPlacemarkAttributes) File(java.io.File) Image(org.hortonmachine.gears.io.geopaparazzi.geopap4.Image)

Example 3 with Path

use of gov.nasa.worldwind.render.Path in project hortonmachine by TheHortonMachine.

the class NwwUtilities method addGeometries.

public static void addGeometries(RenderableLayer layer, Geometry geometry) {
    Material mFillMaterial = Material.BLUE;
    Material mStrokeMaterial = Material.RED;
    double mFillOpacity = 0.8;
    double mStrokeWidth = 2;
    double mMarkerSize = 15d;
    BasicShapeAttributes polyghonAttributes = new BasicShapeAttributes();
    polyghonAttributes.setInteriorMaterial(mFillMaterial);
    polyghonAttributes.setInteriorOpacity(mFillOpacity);
    polyghonAttributes.setOutlineMaterial(mStrokeMaterial);
    polyghonAttributes.setOutlineWidth(mStrokeWidth);
    BasicShapeAttributes lineAttributes = new BasicShapeAttributes();
    lineAttributes.setOutlineMaterial(mStrokeMaterial);
    lineAttributes.setOutlineWidth(mStrokeWidth);
    PointPlacemarkAttributes pointAttributes = new PointPlacemarkAttributes();
    pointAttributes.setLabelMaterial(mFillMaterial);
    pointAttributes.setLineMaterial(mFillMaterial);
    pointAttributes.setUsePointAsDefaultImage(true);
    pointAttributes.setScale(mMarkerSize);
    int mElevationMode = WorldWind.CLAMP_TO_GROUND;
    for (int i = 0; i < geometry.getNumGeometries(); i++) {
        Geometry geometryN = geometry.getGeometryN(i);
        if (geometryN instanceof org.locationtech.jts.geom.Polygon) {
            Coordinate[] coordinates = geometryN.getCoordinates();
            int numVertices = coordinates.length;
            if (numVertices < 4)
                continue;
            org.locationtech.jts.geom.Polygon poly = (org.locationtech.jts.geom.Polygon) geometryN;
            Polygon polygon = new Polygon();
            Coordinate[] extCoords = poly.getExteriorRing().getCoordinates();
            int extSize = extCoords.length;
            List<Position> verticesList = new ArrayList<>(extSize);
            for (int n = 0; n < extSize; n++) {
                Coordinate c = extCoords[n];
                verticesList.add(Position.fromDegrees(c.y, c.x));
            }
            verticesList.add(verticesList.get(0));
            polygon.setOuterBoundary(verticesList);
            int numInteriorRings = poly.getNumInteriorRing();
            for (int k = 0; k < numInteriorRings; k++) {
                LineString interiorRing = poly.getInteriorRingN(k);
                Coordinate[] intCoords = interiorRing.getCoordinates();
                int internalNumVertices = intCoords.length;
                List<Position> internalVerticesList = new ArrayList<>(internalNumVertices);
                for (int j = 0; j < internalNumVertices; j++) {
                    Coordinate c = intCoords[j];
                    internalVerticesList.add(Position.fromDegrees(c.y, c.x));
                }
                polygon.addInnerBoundary(internalVerticesList);
            }
            polygon.setAltitudeMode(mElevationMode);
            polygon.setAttributes(polyghonAttributes);
            layer.addRenderable(polygon);
        } else if (geometryN instanceof LineString) {
            Coordinate[] coordinates = geometryN.getCoordinates();
            if (coordinates.length < 2)
                return;
            if (geometryN instanceof LineString) {
                LineString line = (LineString) geometryN;
                Coordinate[] lineCoords = line.getCoordinates();
                int numVertices = lineCoords.length;
                List<Position> verticesList = new ArrayList<>(numVertices);
                for (int j = 0; j < numVertices; j++) {
                    Coordinate c = lineCoords[j];
                    verticesList.add(Position.fromDegrees(c.y, c.x));
                }
                Path path = new Path();
                path.setAltitudeMode(mElevationMode);
                path.setAttributes(lineAttributes);
                layer.addRenderable(path);
            }
        } else if (geometryN instanceof Point) {
            Point point = (Point) geometryN;
            PointPlacemark marker = new PointPlacemark(Position.fromDegrees(point.getY(), point.getX(), 0));
            marker.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
            marker.setAttributes(pointAttributes);
            layer.addRenderable(marker);
        }
    }
}
Also used : Path(gov.nasa.worldwind.render.Path) Position(gov.nasa.worldwind.geom.Position) ArrayList(java.util.ArrayList) Material(gov.nasa.worldwind.render.Material) Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point) BasicShapeAttributes(gov.nasa.worldwind.render.BasicShapeAttributes) Geometry(org.locationtech.jts.geom.Geometry) PointPlacemark(gov.nasa.worldwind.render.PointPlacemark) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) PointPlacemarkAttributes(gov.nasa.worldwind.render.PointPlacemarkAttributes) LayerList(gov.nasa.worldwind.layers.LayerList) List(java.util.List) ArrayList(java.util.ArrayList) Polygon(gov.nasa.worldwind.render.Polygon)

Aggregations

Path (gov.nasa.worldwind.render.Path)3 Position (gov.nasa.worldwind.geom.Position)2 BasicShapeAttributes (gov.nasa.worldwind.render.BasicShapeAttributes)2 Material (gov.nasa.worldwind.render.Material)2 PointPlacemark (gov.nasa.worldwind.render.PointPlacemark)2 PointPlacemarkAttributes (gov.nasa.worldwind.render.PointPlacemarkAttributes)2 ArrayList (java.util.ArrayList)2 LineString (org.locationtech.jts.geom.LineString)2 Sector (gov.nasa.worldwind.geom.Sector)1 LayerList (gov.nasa.worldwind.layers.LayerList)1 Polygon (gov.nasa.worldwind.render.Polygon)1 Color (java.awt.Color)1 File (java.io.File)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Date (java.util.Date)1 List (java.util.List)1 TreePath (javax.swing.tree.TreePath)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1