Java源码示例:com.jhlabs.map.proj.Projection

示例1
private void projectMoveTo(double x, double y, MapLine projectedLine, Projection projection) {

        // test if the point is outside of lon0 +/- 180deg
        final double lon0 = projection.getProjectionLongitudeDegrees();
        final double xlon0 = x - lon0;
        final boolean pointOutOfRange = xlon0 < -180 || xlon0 > 180;

        // project the point
        if (projection.inside(x, y)) {
            Point2D.Double dst = new Point2D.Double();
            try {
                projection.transform(x, y, dst);
            } catch (ProjectionException exc) {
                return;
            }
            if (Double.isNaN(dst.x) || Double.isNaN(dst.y)) {
                return;
            }
            projectedLine.addPoint(dst.x, dst.y);
        }
        prevPointOutOfRange = pointOutOfRange;

    }
 
示例2
/**
 * Project the end point of a straight line segment.
 *
 * @param lonEnd The x coordinate of the end point of the straight line
 * segment.
 * @param latEnd The y coordinate of the end point of the straight line
 * segment.
 * @param lonStart The x coordinate of the start point of the straight line
 * segment. This is only used when the line segment intersects the bounding
 * meridian of graticule to compute the intersection point.
 * @param latStart The y coordinate of the start point of the straight line
 * segment. This is only used when the line segment intersects the bounding
 * meridian of graticule to compute the intersection point.
 * @param projPath The path that will receive the projected point(s).
 */
private MapLine projectLineTo(double lonEnd, double latEnd,
        double lonStart, double latStart,
        MapLine projPath,
        ArrayList<MapLine> lines,
        Projection projection) {

    // test if the point is outside of lon0 +/- 180deg
    final double lon0 = projection.getProjectionLongitudeDegrees();
    final double xlon0 = lonEnd - lon0;
    final boolean pointOutOfRange = xlon0 < -180 || xlon0 > 180;

    if (prevPointOutOfRange != pointOutOfRange) {
        prevPointOutOfRange = pointOutOfRange;
        projPath = projectIntersectingLineTo(lonEnd, latEnd,
                lonStart, latStart,
                projPath, lines, projection);
    } else {
        lineTo(lonStart, latStart, lonEnd, latEnd, projPath, projection);
    }

    return projPath;
}
 
示例3
private void lineTo(double lonStart, double latStart,
        double lonEnd, double latEnd,
        MapLine projPath,
        Projection projection) {

    if (lonStart == lonEnd && latStart == latEnd) {
        return;
    }

    if (addIntermediatePointsAlongCurves) {
        curvedLineTo(lonStart, latStart, lonEnd, latEnd, projPath, projection);
    } else {
        straightLineTo(lonEnd, latEnd, projPath, projection);
    }

}
 
示例4
private void straightLineTo(double lonEnd, double latEnd,
        MapLine projPath,
        Projection projection) {

    MapPoint xy = projectPoint(lonEnd, latEnd, projection);
    if (xy == null) {
        return;
    }

    // don't add the same coordinates twice
    if (projPath.size() > 0) {
        MapPoint endPoint = projPath.getPoint(projPath.size() - 1);
        if (endPoint != null && endPoint.equals(xy)) {
            return;
        }
    }

    projPath.addPoint(xy);
}
 
示例5
private MapPoint projectPoint(double lon, double lat, Projection projection) {
    if (!projection.inside(lon, lat)) {
        return null;
    }

    // project the point
    Point2D.Double dst = new Point2D.Double();
    try {
        projection.transform(lon, lat, dst);
    } catch (ProjectionException exc) {
        return null;
    }
    if (Double.isNaN(dst.x) || Double.isNaN(dst.y)) {
        return null;
    }
    return new MapPoint(dst.x, dst.y);
}
 
示例6
/**
 * Projects a vector of lines.
 *
 * @param lines The lines to project.
 * @return A vector with the projected lines.
 */
public void projectLines(ArrayList<MapLine> src, ArrayList<MapLine> dst, Projection projection) {

    if (src == null || dst == null) {
        return;
    }
    
    this.addIntermediatePointsAlongCurves = false;

    // loop over all lines to project
    int nbrLines = src.size();
    for (int lineID = 0; lineID < nbrLines; lineID++) {
        MapLine line = (MapLine) src.get(lineID);
        project(line, projection, dst);
    }

}
 
示例7
public static MapIndex loadIndex(File file) throws Throwable
{
	//com.esotericsoftware.minlog.Log.DEBUG();
	Kryo kryo = new Kryo();
	kryo.register(MapIndex.class);
	kryo.register(BaseMap.class);
	kryo.register(OzfMap.class);
	kryo.register(ForgeMap.class);
	kryo.register(Grid.class);
	kryo.register(MapPoint.class);
	kryo.register(MapPoint[].class);
	kryo.register(Projection.class);
	kryo.register(Integer.class);
	kryo.register(String.class);
	kryo.register(ArrayList.class);
	kryo.register(HashSet.class);
	kryo.register(HashMap.class);
	Input input = new Input(new FileInputStream(file));
	MapIndex index = kryo.readObject(input, MapIndex.class);
	input.close();
	for (BaseMap map : index.getMaps())
		map.initialize();
	return index;
}
 
示例8
public static void saveIndex(MapIndex index, File file) throws Throwable
{
	Kryo kryo = new Kryo();
	kryo.register(MapIndex.class);
	kryo.register(BaseMap.class);
	kryo.register(OzfMap.class);
	kryo.register(ForgeMap.class);
	kryo.register(Grid.class);
	kryo.register(MapPoint.class);
	kryo.register(MapPoint[].class);
	kryo.register(Projection.class);
	kryo.register(Integer.class);
	kryo.register(String.class);
	kryo.register(ArrayList.class);
	kryo.register(HashSet.class);
	kryo.register(HashMap.class);
	Output output = new Output(new FileOutputStream(file));
	kryo.writeObject(output, index);
	output.close();
}
 
示例9
private void curvedLineTo(double lonStart, double latStart, double lonEnd, double latEnd, MapLine projPath, Projection projection) {
    MapPoint xyEnd = projectPoint(lonEnd, latEnd, projection);
    if (xyEnd == null) {
        return;
    }
    double lonStartNorm = normalizeLongitude(lonStart, projection);
    double lonEndNorm = normalizeLongitude(lonEnd, projection);
    final double lon0Deg = projection.getProjectionLongitudeDegrees();

    // project the intermediate point between the start and the end point
    double lonMean = (lonStartNorm + lonEndNorm) * 0.5 + lon0Deg;
    double latMean = (latStart + latEnd) * 0.5;
    MapPoint xyMean = projectPoint(lonMean, latMean, projection);
    if (xyMean == null) {
        return;
    }

    if (projPath.size() == 0) {
        return;
    }
    final MapPoint xyStart = projPath.getPoint(projPath.size() - 1);

    // compute the orthogonal distance of the mean point to the line
    // between the start and the end point
    double dsq = pointLineDistanceSquare(xyMean, xyStart, xyEnd);
    if (dsq > curveTolerance * curveTolerance) {
        curvedLineTo(lonStart, latStart, lonMean, latMean, projPath, projection);
        projPath.addPoint(xyMean);
        curvedLineTo(lonMean, latMean, lonEnd, latEnd, projPath, projection);
    }
    projPath.addPoint(xyEnd);
}
 
示例10
public ArrayList<MapLine> inverse(ArrayList<MapLine> lines, Projection projection) {

        if (lines == null) {
            return null;
        }

        // create a new array to store the new lines.
        ArrayList<MapLine> projectedLines = new ArrayList<MapLine>();

        // loop over all lines to inverse-project
        for (MapLine line : lines) {
            MapLine projectedLine = new MapLine();

            // loop over all points of the line
            for (MapPoint p : line.getPoints()) {
                Point2D.Double point = new Point2D.Double(p.x, p.y);
                projection.inverseTransform(point, point);
                projectedLine.addPoint(new MapPoint(point.x, point.y));
            }

            // add the projected line to the array of projected lines
            if (projectedLine.size() > 1) {
                projectedLines.add(projectedLine);
            }
        }

        // return the vector with the projected lines.
        return projectedLines;

    }
 
示例11
public void project(MapLine line, Projection projection, ArrayList<MapLine> projectedLines) {

        if (line.size() < 1) {
            return;
        }

        // create a new line for the projected coordinates.
        MapLine projectedLine = new MapLine();

        // loop over all points of the line
        int nbrPoints = line.size();

        prevPointOutOfRange = false;
        MapPoint point = line.getPoint(0);
        double prevLon = point.x;
        double prevLat = point.y;
        projectMoveTo(point.x, point.y, projectedLine, projection);

        for (int pointID = 1; pointID < nbrPoints; pointID++) {
            point = line.getPoint(pointID);
            final double lon = point.x;
            final double lat = point.y;
            projectedLine = projectLineTo(lon, lat, prevLon, prevLat,
                    projectedLine, projectedLines, projection);
            prevLon = lon;
            prevLat = lat;
        }

        // add the projected line to the array of projected lines
        if (projectedLine.size() > 1) {
            projectedLines.add(projectedLine);
        }

    }
 
示例12
private void project() {

        boolean inverse = inverseCheckBox.isSelected();
        try {
            // find the selected name, create the corresponding projection.
            String projName = (String) projectionComboBox.getSelectedItem();
            Projection projection = ProjectionFactory.getNamedProjection(projName);

            // use the selected projection to project the lines,
            // and pass the projected lines to the map to display.
            if (projection != null) {
                projection.setProjectionLongitudeDegrees(lon0Slider.getValue());
                projection.setEllipsoid(Ellipsoid.SPHERE);
                projection.initialize();

                LineProjector projector = new LineProjector();
                ArrayList<MapLine> projectedLines = new ArrayList<>();
                projector.constructGraticule(projectedLines, projection);
                projector.projectLines(lines, projectedLines, projection);
                if (inverse && projection.hasInverse()) {
                    projectedLines = projector.inverse(projectedLines, projection);
                }

                map.setLines(projectedLines);
            } else {
                map.setLines(null);
            }

            // write some descriptive information about the selected projection.
            updateProjectionInfo(projection);

        } catch (Exception exc) {
            String msg = exc.getMessage();
            String title = "Error";
            JOptionPane.showMessageDialog(selectionPanel, msg, title, JOptionPane.ERROR_MESSAGE);
            Logger.getLogger(ProjectionSelectionPanel.class.getName()).log(Level.SEVERE, null, exc);
        }
    }
 
示例13
/**
 * Write basic information about the projection to the graphical user
 * interface.
 *
 * @projection The Projection that provides the information.
 */
private void updateProjectionInfo(Projection projection) {
    if (projection == null) {
        descriptionLabel.setText("-");
    } else {
        descriptionLabel.setText(projection.getDescription());
        if (projection.hasInverse()) {
            System.out.println("Found inverse equation for " + projection.getName() + ".");
        } else {
            System.out.println("No inverse equation for " + projection.getName() + ".");
        }
    }
}
 
示例14
/**
 * Computes two intersection points for a straight line segment that crosses
 * the bounding meridian at +/-180 degrees from the central meridian.
 * Projects and adds the two intersection points and the next end point to a
 * path.
 *
 * @param lonEnd The longitude of the end point of the line segment.
 * @param latEnd The latitude of the end point of the line segment.
 * @param lonStart The longitude of the start point of the line segment.
 * @param latStart The latitude of the start point of the line segment.
 * @param projPath This path will receive three new projected points.
 */
private MapLine projectIntersectingLineTo(double lonEnd, double latEnd,
        double lonStart, double latStart,
        MapLine projPath,
        ArrayList<MapLine> lines,
        Projection projection) {

    final double dLon = lonEnd - lonStart;
    final double dLat = latEnd - latStart;

    // compute intersection point in geographic coordinates
    final double lon0 = projection.getProjectionLongitudeDegrees();
    final double maxLon = 180 + lon0;
    final double minLon = -180 + lon0;

    // FIXME: intersections are not detected for projections that have not
    // a graticule covering 360 degrees in longitude
    // FIXME: intersections with min latitude and max latitude missing.
    final double lon1; // the longitude of the intermediate end point
    final double lon2; // the longitude of the intermediate start point
    final double lat; // the latitude of both intermediate points
    if (lonEnd > maxLon) {   // leaving graticule towards east
        lon1 = maxLon;
        lat = latStart + dLat * (maxLon - lonStart) / dLon;
        lon2 = minLon;
    } else if (lonStart > maxLon) { // entering graticule from east
        lon1 = minLon;
        lat = latStart + dLat * (maxLon - lonStart) / dLon;
        lon2 = maxLon;
    } else if (lonEnd < minLon) { // leaving graticule towards west
        lon1 = minLon;
        lat = latStart + dLat * (minLon - lonStart) / dLon;
        lon2 = maxLon;
    } else if (lonStart < minLon) { // entering graticule from west
        lon1 = maxLon;
        lat = latStart + dLat * (minLon - lonStart) / dLon;
        lon2 = minLon;
    } else {
        return projPath;  // project the intermediate end point
    }

    // add line from start of line to intersection
    lineTo(lonStart, latStart, lon1, lat, projPath, projection);

    // store the line and create a new one
    lines.add(projPath);
    projPath = new MapLine();

    // add start point to new line, which is the intersection point
    MapPoint xy = projectPoint(lon2, lat, projection);
    if (xy != null) {
        projPath.addPoint(xy);
    }

    // add line to end of line
    lineTo(lon2, lat, lonEnd, latEnd, projPath, projection);

    return projPath;
}
 
示例15
/**
 * Normalizes a longitude in degrees.
 */
private double normalizeLongitude(double lon, Projection projection) {
    lon *= MapMath.DTR;
    final double lon0Rad = projection.getProjectionLongitude();
    return MapMath.normalizeLongitude(lon - lon0Rad) * MapMath.RTD;
}
 
示例16
/**
 * @param args
 */
public static void main(String[] args) {
	// TODO Auto-generated method stub

	Projection aProj = ProjectionFactory.getNamedPROJ4CoordinateSystem("nad83:2001");
	
	
	Point2D.Double aSrc = new Point2D.Double(240678.76, 886748.07);
	Point2D.Double aDst = new Point2D.Double();
	
	aProj.inverseTransform(aSrc, aDst);
	
	System.out.println(aDst.x);
	System.out.println(aDst.y);
	
}