Hi!

Since I'm new here, I would first like to thank all GeoTools developers for 
their hard work and an excellent product! I already successfully use it to 
import and export vector spatial data into my application.

Now, I want to implement a functionality to georeference drone imagery (with no 
location or orientation data). I haven't found a tutorial on how to do this, so 
I essentially copied the process as coded for the uDig application: 
http://www.programcreek.com/java-api-examples/index.php?source_dir=udig-community-master/axios/udig-image-georeferencing/plugins/es.axios.udig.georeferencing/src/es/axios/udig/georeferencing/internal/process/GeoReferencingProcess.java

Here is my code:

    public void startGeoreferencing(HashMap<Point, Placemark> 
georeferencingMap, RenderedImage image)
    {
        // georeferencingMap is a map of user collected anchor points on the 
image
        // (hashmap keys) and on the map (hashmap values)

        if (georeferencingMap == null || georeferencingMap.size() < 3) {
            return;
        }

        Point2D[] srcCoords = new Point2D[georeferencingMap.size()];
        Point2D[] dstCoords = new Point2D[georeferencingMap.size()];

        Iterator<Point> iterator = georeferencingMap.keySet().iterator();
        for (int i = 0; i < georeferencingMap.size(); i++) {
            if (!iterator.hasNext()) {
                break;
            }

            Point p = iterator.next();
            Placemark pl = georeferencingMap.get(p);
            List<Coordinate> c = ((KmlPoint)pl.getGeometry()).getCoordinates();

            srcCoords[i] = p;
            dstCoords[i] = new Point2D.Double(c.get(0).getLatitude(), 
c.get(0).getLongitude());
        }

        WarpTransform2D warpTransform = new WarpTransform2D(srcCoords, 
dstCoords, 1);
        CoordinateReferenceSystem baseCrs = null;
        try {
            baseCrs = CRS.decode("EPSG:4326");
        } catch (FactoryException ex) {
            Exceptions.printStackTrace(ex);
        }

        DefaultDerivedCRS derivedCRS = new DefaultDerivedCRS("imageCRS", 
baseCrs, warpTransform, DefaultCartesianCS.GENERIC_2D);
        GridCoverageFactory factory = new GridCoverageFactory();
        ReferencedEnvelope envelope = new ReferencedEnvelope(0, 
image.getWidth(), 0, image.getHeight(), derivedCRS);
        GridCoverage2D coverage = factory.create("GridCoverage", image, 
envelope);

        // Resample the image with the world CRS
        GridCoverage2D warpedCoverage = null;
        try {
            System.setProperty("com.sun.media.jai.disableMediaLib", "true");
            Operations ops = new Operations(null);
            Coverage resample = ops.resample(coverage, baseCrs);
            warpedCoverage = (GridCoverage2D) resample;
        } catch (Exception e) {
            return;
        }

        saveImage(warpedCoverage);
    }



I get no errors, but the resulting geoTiff is always highly skewed and waaaay 
too large (download example tiff: http://x.k00.fr/6eb39). I'm not sure what I'm 
doing wrong and I'm kindly asking you to help me out.

Best regards,
Marko

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to