// // Copyright (C) 2007 Refractions Research, Inc. // // This library is free software; you can redistribute it and/or // modify it under the terms of version 2.1 of the GNU Lesser // General Public License as published by the Free Software Foundation. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // #include #include #include #include #include #include #include "fdoutility.h" using namespace fdoutility; void make_geometry_from_wkb(std::string const& inputWkt, std::string const& inputHex) { // Convert hex encoded string to bytes array std::vector bytes; hex_to_bytes(inputHex, bytes); assert(!bytes.empty()); // Convert vector of bytes to FDO array FdoPtr fdoBytes( FdoByteArray::Create(&bytes[0], static_cast(bytes.size()))); assert(NULL != fdoBytes); assert(fdoBytes->GetCount() > 0); // Get geometry factory FdoPtr gf(FdoFgfGeometryFactory::GetInstance()); assert(NULL != gf); // Create geometry FdoPtr fdoGeom(gf->CreateGeometryFromWkb(fdoBytes)); assert(NULL != fdoGeom); // Get WKT representation FdoStringP outputWkt(fdoGeom->GetText()); std::cout << "\nInput WKT : " << inputWkt << "\nOutput WKT: " << static_cast(outputWkt) << std::endl; } int main(int argc, char* argv[]) { try { make_geometry_from_wkb( "POINT(0 0)", "010100000000000000000000000000000000000000" ); make_geometry_from_wkb( "POINT(15.123 21.456)", "0101000000e5d022dbf93e2e40dbf97e6abc743540" ); make_geometry_from_wkb( "MULTIPOINT(-69.0769002280329 47.0705005369186,-70.7421001982805 44.6369002086428,-68.4458998663268 44.5597013552039,-70.2375000738775 43.8641978974915)", "0104000000040000000101000000361defeeeb4451c040355e29068947400101000000107ed4917eaf51c0d5772ff285514640010100000088ca979f891c51c05210444ba4474640010100000080868233338f51c0b97f65099eee4540" ); //FdoByteArray* gstr = gf->GetFgf(point); //assert(0 != gstr); } catch (FdoException* ex) { std::wcout << L"*** FDO Error:\n"; int i = 5; FdoException* nex = ex; while (nex) { const wchar_t* msg = nex->GetExceptionMessage(); if (NULL == msg) { msg = L"NO MESSAGE"; } std::wcout << std::setw(++i) << L"*** " << msg << std::endl; nex = nex->GetCause(); } ex->Release(); } catch(std::exception& ex) { std::cout << "*** Std Error: " << ex.what() << std::endl; } catch(...) { std::cout << "*** Undefined error!\n" << std::endl; } return 0; }