Geotiff render&scrolling problem

4 messages Options
Embed this post
Permalink
kamys

Geotiff render&scrolling problem

Reply Threaded More More options
Print post
Permalink
Hello,

I'm using following code to render geotiff file from http://srtm.csi.cgiar.org/SELECTION/inputCoord.asp:

/** Read tiffFile file */
File tiffFile = new File("B:\\srtm_39_02(1)\\srtm_39_02.tif");
AbstractGridCoverage2DReader rdr = new GeoTiffReader(tiffFile);
CoordinateReferenceSystem crs = rdr.getCrs();
map = new DefaultMapContext(crs);
ReferencedEnvelope dataEnvelope = new ReferencedEnvelope(rdr.getOriginalEnvelope().toRectangle2D(), crs);

/** Add GeoTiffLayer layer */
map.addLayer(rdr, getRasterStyle());
map.setAreaOfInterest(dataEnvelope);

/** Now display the map */
JMapFrame.showMap(map);


The file is rendering, but in wrong place and scrolling map in frame doesn't work correctly. The map is moved by quite different vector, which implies from drag&drop scrolling. I haven't got these problems when I try to render this geotiff: http://avn.faa.gov/index.asp?xml=naco/catalog/charts/digital/Raster_Sectional_Sample/Raster 

I've published my test projects (JMapViewer and SwingWidgets, which include JMapFrame), so you can quickly reproduce problem:
http://www.ii.uj.edu.pl/~laskowsk/GeotiffProblemReproduceProjects.rar

My question: Is it right method to load and render geotiff file? If above code is correct is there bug in geotools (I'm start thinking that some coordinate reference systems is unsupported)?

Thanks in advance,
Kamys
mbedward

Re: Geotiff render&scrolling problem

Reply Threaded More More options
Print post
Permalink
Hello Kamys,

I see that you're using GeoTools 2.6-M2. Some raster display problems
in JMapPane have been fixed since that milestone was released.

I just tried the latest code with a GeoTIFF from the CGIAR site. The
image was displayed in the correct position and zooming and panning
worked properly.

We are just about to release a new GeoTools version: 2.6-RC1 which
contains the fixes for JMapPane. Meanwhile, if you need to work on it
prior to that release you can switch over to using the development
version 2.6-SNAPSHOT.  For this, you will need to add the following
repository to your pom.xml

<repository>
  <id>osgeo-snapshots</id>
  <name>OSGeo Snapshot Repository</name>
  <snapshots>
    <enabled>true</snapshots>
  </snapshots>
  <url>http://repo.opengeo.org/</url>
</repository>

Hope this helps,
Michael

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
kamys

Re: Geotiff render&scrolling problem

Reply Threaded More More options
Print post
Permalink
In reply to this post by kamys
Hello,

Thank you for you aswer, Michael. With 2.6-SNAPSHOT version of GeoTools positioning & scrolling problems with geotiffs have gone.
On occasion I would like to inform that layer item lists don't show in the layer table of JMapFrame, if you don't follow this order:
1. create map context and map frame based on this context
2. set map frame properties
3. call initComponent() method of map frame object
4. add layers to map context
Example code:
            /** Create map context */
            map = new DefaultMapContext();
            /** Create map frame base on map context */
            JMapFrame jMapFrame = new JMapFrame(map, getStreamingRenderer());
            /** Set map frame properties */
            jMapFrame.enableStatusBar(true);
            jMapFrame.enableToolBar(true);
            jMapFrame.enableLayerTable(true);
            jMapFrame.setSize(800,600);
            jMapFrame.setVisible(true);
            /** init components */
            jMapFrame.initComponents();
 
             /** Add GeoTiff layer */
        	File tiffFile = new File("B:\\srtm_39_02(1)\\srtm_39_02.tif");
            AbstractGridCoverage2DReader rdr = new GeoTiffReader(tiffFile);
            map.addLayer(rdr, getRasterStyle());

            /** Add GeoTiff layer */
        	tiffFile = new File("B:\\srtm_40_02(1)\\Z_40_2.TIF");
            rdr = new GeoTiffReader(tiffFile);
            map.addLayer(rdr, getRasterStyle());
            
            /** Add ShapeFile layer */
            File shapeFile = new File("B:\\POL_adm\\POL_adm2.shp");
            DataStore store = FileDataStoreFinder.getDataStore(shapeFile.toURI().toURL());
            String[] typeNames=store.getTypeNames();
            String typeName=typeNames[0];
            FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = store.getFeatureSource(typeName);
            FeatureType featureType = featureSource.getSchema();
            map.addLayer(featureSource, getFeaturesStyle(typeName));


Helper methods:
    public static StreamingRenderer getStreamingRenderer() {
        StreamingRenderer sr=new StreamingRenderer(); // to prevent warning: "Assuming rendering buffer  = " + rbe.getBuffer() + ", 
//        but estimation is not accurate, you may want to set a buffer manually"
        Map hints=new HashMap<Object, Object>();
        hints.put("renderingBuffer",1);
        sr.setRendererHints(hints);
        return sr;
	}
    public static Style getFeaturesStyle(String typeName) {
        StyleBuilder styleBuilder = new StyleBuilder();
        RasterSymbolizer rastSymbolizer = styleBuilder.createRasterSymbolizer();       
        Style style = styleBuilder.createStyle();
        
        LineSymbolizer lineSymbolizer=styleBuilder.createLineSymbolizer(Color.BLACK);
        lineSymbolizer.getStroke().setWidth(ConstantExpression.TWO);
        Rule lineRule = styleBuilder.createRule(lineSymbolizer);            
        style.featureTypeStyles().add(styleBuilder.createFeatureTypeStyle(typeName, lineRule));
        return style;
	} 
    public static Style getRasterStyle() {
        StyleBuilder styleBuilder = new StyleBuilder();
        RasterSymbolizer rastSymbolizer = styleBuilder.createRasterSymbolizer();       
        Style style = styleBuilder.createStyle(rastSymbolizer);       
        return style;
    }


Regards,
Kamys
mbedward

Re: Geotiff render&scrolling problem

Reply Threaded More More options
Print post
Permalink
Hi Kamys,

> Thank you for you aswer, Michael. With 2.6-SNAPSHOT version of GeoTools
> positioning & scrolling problems with geotiffs have gone.

That's good to hear. If you like you can now swap to using GeoTools
2.6-RC1 which has just been released. That will save you from the
daily snapshot downloads.

> On occasion I would like to inform that layer item lists don't show in the
> layer table of JMapFrame, if you don't follow this order:
> 1. create map context and map frame based on this context
> 2. set map frame properties
> 3. call initComponent() method of map frame object
> 4. add layers to map context

Many thanks for reporting that - I'll work out what's going wrong there.

Michael

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users