Hi Andrea,

I've defined a short GroundControlPoint class and used it to feed the Point2D 
arrays applicable to the constructor of WarpTransform2D, like this:
(I think it's good to have a method "isValid()" for a GCP; perhaps I should 
skip a GCP if it's invalid (src or dst missing) instead terminating with 
"return", I should think of a better solution...)

 final List<GroundControlPoint> gcpList = getTestGcps();

 for (int i = 0; i < gcpList.size(); i++)
 {
 if (!gcpList.get(i).isValid())
 return;
 }

 CoordinateReferenceSystem dstCrs = = CRS.decode("EPSG:3857");

 Point2D.Double src[] = new Point2D.Double[gcpList.size()];
 Point2D dst[] = new DirectPosition2D[gcpList.size()];

 for (int i = 0; i < gcpList.size(); i++)
 {
// src[i] = new 
DirectPosition2D(gcpList.get(i).getSrcX(),gcpList.get(i).getSrcY());
 src[i] = new Point2D.Double(gcpList.get(i).getSrcX(), 
gcpList.get(i).getSrcY());
 dst[i] = new DirectPosition2D(dstCrs, gcpList.get(i).getDstLon(), 
gcpList.get(i).getDstLat());
 }

 // the fixed array of required points with index + 1 as degree of warp.
 // relates directly to the order of warp.
 int[] degPoints = { 3, 6, 10, 15, 21, 28, 36 };
 int deg = 1;
// for (int j = 0; j < degPoints.length; j++)
// {
// if (src.length >= degPoints[j])
// {
//// deg = j; // with degree=1 the image was correctly rectified!
// deg = j + 1;
// }
// }
 WarpTransform2D wt = new WarpTransform2D(src, dst, deg);

 // create a DefaultDerivedCRS for the CRS of the image
 DefaultDerivedCRS derivedCRS = new DefaultDerivedCRS("imageCRS",
 srcCrs, wt, DefaultCartesianCS.GENERIC_2D);

 // create a gridcoverage for the new warped image
 GridCoverageFactory factory = new GridCoverageFactory();

 final RenderedImage bufferedImage;
 try
 {
 bufferedImage = ImageIO.read(new File(imageFileNamePath));
 ReferencedEnvelope ref = new ReferencedEnvelope(0,
 bufferedImage.getWidth(), 0, bufferedImage.getHeight(),
 derivedCRS);

 GridCoverage2D coverage = factory.create("GridCoverage",
 bufferedImage, ref);

 // resample the new image with the world CRS
 GridCoverage2D warpedCoverage = null;

 Operations ops = new Operations(null);
 warpedCoverage = (GridCoverage2D) ops.resample(coverage, srcCrs);

 GeoTiffHelper.writeGeoTiff(warpedCoverage, geotiffFileNamePath);
 }
 catch (IOException e)
 {
 // TODO: decide what to do in error case
 e.printStackTrace();
 return;
 }


What could be done to enhance rectification with WarpTransform2D in this code?
I realized that thin plate spline transformation with GDAL works incredibly 
good. Is there some kind of workflow I could attach to use such transformation 
with WarpTransform2D?

Thanks,
João



----- Ursprüngliche Nachricht -----
Von: Andrea Aime
Gesendet: 18.06.12 22:07 Uhr
An: [email protected]
Betreff: Re: [Geotools-gt2-users] WarpTransform2D vs gdalwarp using GCPs

On Mon, Jun 18, 2012 at 6:28 PM, < [email protected] > wrote:
Hi Daniele, Hi Andrea, Hi GeoTools community,

recently I was trying to geo-rectify a JPG with WarpTransform2D, however, the 
result was not as good as the result of "gdalwarp -tps" with the GCPs used. 
Today I've found the org.geoserver.wps.gs.GeorectifyCoverage class
http://svn.codehaus.org/geoserver/trunk/src/extension/wps/wps-core/src/main/java/org/geoserver/wps/gs/GeorectifyCoverage.java
 

I was wondering if there already exists such kind of Warp Interface to the gdal 
extension available in GeoTools?
I'm using GeoTools 2.7.1

There is not. The above process is just a wrapper around GCP

Somehow, the warped imaged (written to GeoTIFF) by WarpTransform2D with a 
degree > 1 results in a miss-tranformation or an empty image even if I use 
plenty of GCPs. Using degree=1 results in a somehow good 
transformation/rectification (but not as good as gdalwarp on comand line, like 
mentioned).
Has someone experienced equivalent or much better warp transformation with 
WarpTransform2D VS gdalwarp (e.g. when using up to 40 GCPs)?

How did you feed GCPs into a WarpTransform2D?

Cheers
Andrea
-- 
Ing. Andrea Aime
GeoSolutions S.A.S.
Tech lead

Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy

phone: +39 0584 962313
fax: +39 0584 962313
mob: +39 339 8844549

http://www.geo-solutions.it 
http://geo-solutions.blogspot.com/ 
http://www.youtube.com/user/GeoSolutionsIT 
http://www.linkedin.com/in/andreaaime 
http://twitter.com/geowolf 




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to