osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 00020 #include <osgUtil/Optimizer> 00021 #include <osgDB/ReadFile> 00022 00023 #include <osgDB/ReadFile> 00024 #include <osgDB/WriteFile> 00025 00026 #include <osgEarth/Map> 00027 #include <osgEarth/Registry> 00028 00029 #include <osgEarthDrivers/gdal/GDALOptions> 00030 #include <osgEarthDrivers/arcgis/ArcGISOptions> 00031 #include <osgEarthDrivers/tms/TMSOptions> 00032 00033 #include <iostream> 00034 00035 using namespace osg; 00036 using namespace osgDB; 00037 using namespace osgEarth; 00038 using namespace osgEarth::Drivers; 00039 00040 int main(int argc, char** argv) 00041 { 00042 osg::ArgumentParser arguments(&argc,argv); 00043 00044 //One to one test. Read a single 1 to 1 tile out of a MapLayer 00045 { 00046 GDALOptions driverOpt; 00047 driverOpt.url() = "../data/world.tif"; 00048 00049 ImageLayerOptions layerOpt; 00050 layerOpt.driver() = driverOpt; 00051 layerOpt.name() = "test_simple"; 00052 00053 osg::ref_ptr<ImageLayer> layer = new ImageLayer( layerOpt ); 00054 00055 TileKey key(0, 0, 0, layer->getProfile()); 00056 GeoImage image = layer->createImage( key ); 00057 osgDB::writeImageFile(*image.getImage(), layer->getName()+key.str() + std::string(".png")); 00058 } 00059 00060 //Mosaic test. Request a tile in the global geodetic profile from a layer with a geographic SRS but a different tiling scheme. 00061 { 00062 ArcGISOptions driverOpt; 00063 driverOpt.url() = "http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer"; 00064 00065 ImageLayerOptions layerOpt; 00066 layerOpt.driver() = driverOpt; 00067 layerOpt.name() = "test_mosaic"; 00068 00069 osg::ref_ptr<ImageLayer> layer = new ImageLayer( layerOpt ); 00070 00071 TileKey key(0, 0, 0, osgEarth::Registry::instance()->getGlobalGeodeticProfile()); 00072 GeoImage image = layer->createImage( key ); 00073 osgDB::writeImageFile(*image.getImage(), layer->getName()+key.str() + std::string(".png")); 00074 } 00075 00076 //Reprojection. Request a UTM image from a global geodetic profile 00077 { 00078 ArcGISOptions driverOpt; 00079 driverOpt.url() = "http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer"; 00080 00081 ImageLayerOptions layerOpt; 00082 layerOpt.name() = "test_reprojected_utm"; 00083 layerOpt.driver() = driverOpt; 00084 layerOpt.reprojectedTileSize() = 512; 00085 00086 osg::ref_ptr<ImageLayer> layer = new ImageLayer( layerOpt ); 00087 00088 TileKey key(0, 0, 0, Profile::create("epsg:26917", 560725, 4385762, 573866, 4400705)); 00089 GeoImage image = layer->createImage( key ); 00090 osgDB::writeImageFile(*image.getImage(), layer->getName()+key.str() + std::string(".png")); 00091 } 00092 00093 00094 //Mercator. Request a geodetic reprojected image from a mercator source 00095 { 00096 TMSOptions driverOpt; 00097 driverOpt.url() = "http://tile.openstreetmap.org"; 00098 driverOpt.format() = "png"; 00099 driverOpt.tileSize() = 256; 00100 driverOpt.tmsType() = "google"; 00101 00102 ImageLayerOptions layerOpt; 00103 layerOpt.driver() = driverOpt; 00104 layerOpt.name() = "test_mercator_reprojected"; 00105 layerOpt.reprojectedTileSize() = 256; 00106 layerOpt.exactCropping() = true; 00107 layerOpt.profile() = ProfileOptions( "global-mercator" ); 00108 00109 osg::ref_ptr<ImageLayer> layer = new ImageLayer( layerOpt ); 00110 00111 //Request an image from the mercator source. Should be reprojected to geodetic 00112 TileKey key(0, 0, 0, osgEarth::Registry::instance()->getGlobalGeodeticProfile()); 00113 GeoImage image = layer->createImage( key ); 00114 if (!image.getSRS()->isGeographic()) 00115 { 00116 OE_NOTICE << "Error: Should have reprojected image to geodetic but returned SRS is " << image.getSRS()->getWKT() << std::endl; 00117 } 00118 osgDB::writeImageFile(*image.getImage(), layer->getName()+key.str() + std::string(".png")); 00119 } 00120 00121 return 0; 00122 } 00123