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 <osgEarthFeatures/OgrUtils> 00021 #include <osgEarthFeatures/GeometryUtils> 00022 00023 using namespace osgEarth::Features; 00024 using namespace osgEarth::Symbology; 00025 00026 std::string osgEarth::Features::geometryToWkt( Geometry* geometry ) 00027 { 00028 OGRGeometryH g = OgrUtils::createOgrGeometry( geometry ); 00029 std::string result; 00030 if (g) 00031 { 00032 char* buf; 00033 if (OGR_G_ExportToWkt( g, &buf ) == OGRERR_NONE) 00034 { 00035 result = std::string(buf); 00036 OGRFree( buf ); 00037 } 00038 OGR_G_DestroyGeometry( g ); 00039 } 00040 return result; 00041 } 00042 00043 std::string osgEarth::Features::geometryToJson( Geometry* geometry ) 00044 { 00045 OGRGeometryH g = OgrUtils::createOgrGeometry( geometry ); 00046 std::string result; 00047 if (g) 00048 { 00049 char* buf; 00050 buf = OGR_G_ExportToJson( g ); 00051 if (buf) 00052 { 00053 result = std::string(buf); 00054 OGRFree( buf ); 00055 } 00056 OGR_G_DestroyGeometry( g ); 00057 } 00058 return result; 00059 } 00060 00061 std::string osgEarth::Features::geometryToKml( Geometry* geometry ) 00062 { 00063 OGRGeometryH g = OgrUtils::createOgrGeometry( geometry ); 00064 std::string result; 00065 if (g) 00066 { 00067 char* buf; 00068 buf = OGR_G_ExportToKML( g, 0); 00069 if (buf) 00070 { 00071 result = std::string(buf); 00072 OGRFree( buf ); 00073 } 00074 OGR_G_DestroyGeometry( g ); 00075 } 00076 return result; 00077 } 00078 00079 std::string osgEarth::Features::geometryToGml( Geometry* geometry ) 00080 { 00081 OGRGeometryH g = OgrUtils::createOgrGeometry( geometry ); 00082 std::string result; 00083 if (g) 00084 { 00085 char* buf; 00086 buf = OGR_G_ExportToGML( g ); 00087 if (buf) 00088 { 00089 result = std::string(buf); 00090 OGRFree( buf ); 00091 } 00092 OGR_G_DestroyGeometry( g ); 00093 } 00094 return result; 00095 }