Search in sources :

Example 11 with GeoPosition

use of org.jdesktop.swingx.mapviewer.GeoPosition in project hale by halestudio.

the class ExtendedMapKit method saveState.

/**
 * @see IPersistable#saveState(IMemento)
 */
@Override
public void saveState(IMemento memento) {
    GeoPosition min = getMainMap().convertPointToGeoPosition(new Point((int) Math.round(getMainMap().getWidth() * 0.1), (int) Math.round(getMainMap().getHeight() * 0.1)));
    GeoPosition max = getMainMap().convertPointToGeoPosition(new Point((int) Math.round(getMainMap().getWidth() * 0.9), (int) Math.round(getMainMap().getHeight() * 0.9)));
    // GeoPosition min = getMainMap().convertPointToGeoPosition(new Point(0,
    // 0));
    // GeoPosition max = getMainMap().convertPointToGeoPosition(new
    // Point(getMainMap().getWidth(), getMainMap().getHeight()));
    int epsg = min.getEpsgCode();
    try {
        if (epsg != max.getEpsgCode())
            max = GeotoolsConverter.getInstance().convert(max, epsg);
        memento.putFloat(MEMENTO_KEY_MIN_X, (float) min.getX());
        memento.putFloat(MEMENTO_KEY_MIN_Y, (float) min.getY());
        memento.putFloat(MEMENTO_KEY_MAX_X, (float) max.getX());
        memento.putFloat(MEMENTO_KEY_MAX_Y, (float) max.getY());
        memento.putInteger(MEMENTO_KEY_EPSG, epsg);
    } catch (IllegalGeoPositionException e) {
        // $NON-NLS-1$
        log.error("Error saving map state: Could not convert GeoPosition", e);
    }
}
Also used : GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) IllegalGeoPositionException(org.jdesktop.swingx.mapviewer.IllegalGeoPositionException) Point(java.awt.Point) Point(java.awt.Point)

Example 12 with GeoPosition

use of org.jdesktop.swingx.mapviewer.GeoPosition in project hale by halestudio.

the class PositionStatus method mouseMoved.

/**
 * @see MouseAdapter#mouseMoved(MouseEvent)
 */
@Override
public void mouseMoved(MouseEvent e) {
    GeoPosition pos = map.convertPointToGeoPosition(e.getPoint());
    // convert if needed and possible
    int target = epsgProvider.getEpsgCode();
    if (target != 0) {
        try {
            pos = GeotoolsConverter.getInstance().convert(pos, target);
        } catch (Exception x) {
        // ignore
        }
    }
    final GeoPosition position = pos;
    // set current GeoPosition
    AreaCalc.getInstance().setCurrentGeoPos(pos);
    site.getShell().getDisplay().asyncExec(new Runnable() {

        @Override
        public void run() {
            site.getActionBars().getStatusLineManager().setMessage(image, // $NON-NLS-1$ //$NON-NLS-2$
            "EPSG:" + position.getEpsgCode() + " - " + format.format(position.getX()) + // $NON-NLS-1$
            " / " + format.format(position.getY()));
        }
    });
}
Also used : GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition)

Example 13 with GeoPosition

use of org.jdesktop.swingx.mapviewer.GeoPosition in project hale by halestudio.

the class AreaCalc method triangulate.

/**
 * Triangulates the polygon.
 *
 * @param pos List of {@link GeoPosition}
 *
 * @return List of {@link Triangle}
 */
private List<Triangle> triangulate(List<GeoPosition> pos) {
    // contains all triangles
    List<Triangle> triangles = new ArrayList<Triangle>(pos.size() - 1);
    // standard epsg code
    int epsg = pos.get(0).getEpsgCode();
    // check if it's already a triangle
    if (pos.size() == 3) {
        triangles.add(new Triangle(pos.get(0), pos.get(1), pos.get(2)));
        return triangles;
    }
    // contains all points from the surface
    List<Point3D> face = new ArrayList<>();
    // convert Point2D to Vertex
    for (int i = 0; i < pos.size(); i++) {
        GeoPosition p = pos.get(i);
        face.add(new Point3D(p.getX(), p.getY(), 0.0));
    }
    // create FaceSet and triangulate
    FaceTriangulation fst = new FaceTriangulation();
    List<List<Point3D>> faces = fst.triangulateFace(face);
    // convert
    for (List<Point3D> f : faces) {
        // create GeoPositions
        GeoPosition p1, p2, p3;
        p1 = new GeoPosition(f.get(0).getX(), f.get(0).getY(), epsg);
        p2 = new GeoPosition(f.get(1).getX(), f.get(1).getY(), epsg);
        p3 = new GeoPosition(f.get(2).getX(), f.get(2).getY(), epsg);
        // add triangle
        triangles.add(new Triangle(p1, p2, p3));
    }
    return triangles;
}
Also used : Point3D(de.fhg.igd.geom.Point3D) ArrayList(java.util.ArrayList) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) ArrayList(java.util.ArrayList) List(java.util.List) FaceTriangulation(de.fhg.igd.geom.algorithm.FaceTriangulation)

Example 14 with GeoPosition

use of org.jdesktop.swingx.mapviewer.GeoPosition in project hale by halestudio.

the class AreaCalc method calculate.

/**
 * This function calculates the area of a polygon.
 */
public void calculate() {
    if (isActive() && this.geoPos.size() > 0 && !this.calculation && /* && this.updated */
    !this.bufferIsFinished) {
        // set calculation to true to prevent double calculating
        this.calculation = true;
        // but allow new position data
        // this.updated = false;
        List<GeoPosition> pos = new ArrayList<GeoPosition>();
        pos.addAll(this.geoPos);
        pos.add(this.currentGeoPos);
        // contains information for the tooltip
        String tip = "";
        // check epsg code and maybe convert to a metric system
        pos = this.checkEPSG(pos);
        // initialize formater
        NumberFormat df = NumberFormat.getNumberInstance();
        // calculate size
        double area = 0.0;
        // rectangle
        if (pos.size() == 2 && this.selectionType.equals("rectangle")) {
            area = this.calculateRectangle(pos.get(0), pos.get(1));
            if (area > 1000000) {
                area /= 1000000;
                tip = df.format(area) + " km\u00B2";
            } else {
                tip = df.format(area) + " m\u00B2";
            }
        } else // distance (polygon tool)
        if (pos.size() == 2 && this.selectionType.equals("polygon")) {
            area = AreaCalc.calculateDistance(pos.get(0), pos.get(1));
            tip = df.format(area) + " m";
        } else // distance (buffer tool)
        if (pos.size() > 1 && this.selectionType.equals("line")) {
            double temp = 0.0;
            for (int i = 0; i < pos.size() - 1; i++) {
                temp += AreaCalc.calculateDistance(pos.get(i), pos.get(i + 1));
            }
            tip = df.format(temp) + " m";
        } else // polygon
        if (pos.size() > 2 && this.selectionType.equals("polygon")) {
            area = this.calculatePolygon(pos);
            if (area > 1000000) {
                area /= 1000000;
                tip = df.format(area) + " km\u00B2";
            } else {
                tip = df.format(area) + " m\u00B2";
            }
        } else // buffer tool
        if (this.selectionType.equals("buffer")) {
            if (pos.size() == 2) {
                area = AreaCalc.calculateDistance(pos.get(0), pos.get(1));
                tip = df.format(area) + " m";
            } else {
                // calculate
                area = this.calculatePolygon(pos);
                if (area > 1000000) {
                    area /= 1000000;
                    tip = df.format(area) + " km\u00B2";
                } else {
                    tip = df.format(area) + " m\u00B2";
                }
            }
        }
        // update tooltip
        this.area = tip;
        fireAreaChanged();
        // calculation has finished
        this.calculation = false;
    }
}
Also used : ArrayList(java.util.ArrayList) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) NumberFormat(java.text.NumberFormat)

Example 15 with GeoPosition

use of org.jdesktop.swingx.mapviewer.GeoPosition in project hale by halestudio.

the class AreaCalc method calculateRectangle.

/**
 * Calculate the area of a rectangle.
 *
 * @param a first {@link GeoPosition}
 * @param b second {@link GeoPosition}
 *
 * @return area
 */
public double calculateRectangle(GeoPosition a, GeoPosition b) {
    double value = 0.0;
    value = AreaCalc.calculateDistance(new GeoPosition(a.getX(), a.getY(), a.getEpsgCode()), new GeoPosition(b.getX(), a.getY(), a.getEpsgCode())) * AreaCalc.calculateDistance(new GeoPosition(a.getX(), a.getY(), a.getEpsgCode()), new GeoPosition(a.getX(), b.getY(), a.getEpsgCode()));
    return Math.abs(value);
}
Also used : GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition)

Aggregations

GeoPosition (org.jdesktop.swingx.mapviewer.GeoPosition)33 BoundingBox (de.fhg.igd.geom.BoundingBox)11 Point (java.awt.Point)10 IllegalGeoPositionException (org.jdesktop.swingx.mapviewer.IllegalGeoPositionException)10 ArrayList (java.util.ArrayList)9 Point2D (java.awt.geom.Point2D)8 Point3D (de.fhg.igd.geom.Point3D)6 HashSet (java.util.HashSet)6 Area (de.fhg.igd.mapviewer.marker.area.Area)5 SelectableWaypoint (de.fhg.igd.mapviewer.waypoints.SelectableWaypoint)5 CRSConverter (eu.esdihumboldt.hale.ui.views.styledmap.util.CRSConverter)5 Rectangle (java.awt.Rectangle)5 Point (com.vividsolutions.jts.geom.Point)4 PixelConverter (org.jdesktop.swingx.mapviewer.PixelConverter)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 Polygon (com.vividsolutions.jts.geom.Polygon)3 PolygonArea (de.fhg.igd.mapviewer.marker.area.PolygonArea)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)2 MultiArea (de.fhg.igd.mapviewer.marker.area.MultiArea)2