简体   繁体   中英

MathTransform doesn't work in Android project: “The type java.awt.geom.Point2D$Double cannot be resolved.”

I need to transform coordinates using GeoTools. My code works fine in a Java project but when I put it in the Android I get the error at the mathTransform.transform(...) line: "The type java.awt.geom.Point2D$Double cannot be resolved. It is indirectly referenced from required .class files". Here's my code:

CoordinateReferenceSystem sourceCrs = CRS.decode("EPSG:3765");
    CoordinateReferenceSystem targetCrs = CRS.decode("EPSG:4326");
    boolean lenient = true;
    double x, y;
    MathTransform mathTransform = CRS.findMathTransform(sourceCrs, targetCrs, lenient);

    parts = result.split(" ");
    String coors = "";
    for (int i = 0; i < parts.length; i += 2) {
        x = Double.parseDouble(parts[i]);
        y = Double.parseDouble(parts[i+1]);

        DirectPosition2D srcDirectPosition2D = new DirectPosition2D(sourceCrs, x, y);
        DirectPosition2D destDirectPosition2D = new DirectPosition2D();

        mathTransform.transform(srcDirectPosition2D, destDirectPosition2D);

        x = destDirectPosition2D.x;
        y = destDirectPosition2D.y;

        coors += x + " " + y + " ";
    }

    System.out.println(coors + ";");

Now I found this question which explains the reasons for it: Can't import Java awt in Eclipse , but what would be the solution?

what would be the solution?

You could not use this JAR, but instead find some other similar library that is ready for Android.

Or you could read up on prior attempts to get GeoTools working on Android .

Or you could contribute code changes back to the project that eliminate references to java.awt classes, replacing that code with algorithms implemented in the library itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM