All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GeometryConverters.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/geometry/GeometryConverters.h
22 
23  \brief A set of function that convert a Geometry type to other types and vice-versa.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "../datatype/ByteArray.h"
29 #include "../datatype/Enums.h"
30 #include "../datatype/SimpleData.h"
31 #include "Exception.h"
32 #include "Geometry.h"
33 #include "GeometryConverters.h"
34 #include "WKBReader.h"
35 #include "WKTReader.h"
36 
38 {
39  if(d->getTypeCode() != te::dt::GEOMETRY_TYPE)
40  throw Exception(TE_TR("The input data type is not a geometry!"));
41 
42  std::size_t size = 0;
43  char* wkb = static_cast<const Geometry*>(d)->asBinary(size);
44 
45  return new te::dt::ByteArray(wkb, size);
46 }
47 
49 {
50  if(d->getTypeCode() != te::dt::GEOMETRY_TYPE)
51  throw Exception(TE_TR("The input data type is not a geometry!"));
52 
53  return new te::dt::String(static_cast<const Geometry*>(d)->asText());
54 }
55 
57 {
59  throw Exception(TE_TR("The input data type is not a byte array!"));
60 
61  return WKBReader::read(static_cast<const te::dt::ByteArray*>(d)->getData());
62 }
63 
65 {
67  throw Exception(TE_TR("The input data type is not a string!"));
68 
69  return WKTReader::read(static_cast<const te::dt::String*>(d)->getValue().c_str());
70 }
A set of function that convert a Geometry type to other types and vice-versa.
SimpleData< std::string, STRING_TYPE > String
Definition: SimpleData.h:229
te::dt::AbstractData * GeometryToByteArrayConverter(te::dt::AbstractData *d)
It converts a Geometry data value to a ByteArray data value.
virtual int getTypeCode() const =0
It returns the data type code associated to the data value.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
te::dt::AbstractData * GeometryToStringConverter(te::dt::AbstractData *d)
It converts a Geometry data value to a String data value.
te::dt::AbstractData * ByteArrayToGeometryConverter(te::dt::AbstractData *d)
It converts a ByteArray data value to a Geometry data value.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
An exception class for the Geometry module.
A class that deserializes a geometry from a valid WKB.
te::dt::AbstractData * StringToGeometryConverter(te::dt::AbstractData *d)
It converts a String data value to a Geometry data value.
A class that deserializes a geometry from a valid WKT.
A class for representing binary data.
Definition: ByteArray.h:51