otbOGRGeometryWrapper.h 6.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
20

21 22
#ifndef otbOGRGeometryWrapper_h
#define otbOGRGeometryWrapper_h
23

24 25 26
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
27
#include <boost/interprocess/smart_ptr/unique_ptr.hpp>
28 29 30 31 32
#pragma GCC diagnostic pop
#else
#include <boost/interprocess/smart_ptr/unique_ptr.hpp>
#endif

33 34
#include "OTBGdalAdaptersExport.h"

35 36 37 38
class OGRGeometry;

namespace otb { namespace ogr {
namespace internal {
Luc Hermitte's avatar
Luc Hermitte committed
39 40 41 42 43 44 45 46 47 48
/**\ingroup GeometryInternals
 * Deleter dedicated to \c OGRGeometry.
 * \internal
 * Unlike OGR, works as a no-op on null geometries.
 *
 * Unlike the other deleters used, the type of this one needs to be known in the
 * header file in order to define the type \c UniqueGeometryPtr. As a
 * consequence, it is not in an anonymous namespace , but in \c
 * otb::ogr::internal.
 */
49
struct OTBGdalAdapters_EXPORT GeometryDeleter
50 51 52
  {
  void operator()(OGRGeometry* p);
  };
Luc Hermitte's avatar
Luc Hermitte committed
53
} // internal namespace
54 55 56 57


// we don't encapsulate OGRGeometry, but please, don't create new geometries with a new.

58
/**\ingroup gGeometry
59
 * \defgroup OGRGeometryWrapper OGRGeometry Wrappers
60
 * %Helper definition to handle \c OGRGeometry objects.
61
 *
62
 * \note %OTB doesn't provide anything on top of \c OGRGeometryFactory to create
63 64 65 66 67 68 69
 * new factories. Please, never create new \c OGRGeometry by hand with
 * <tt>new</tt> operator as there is no garanty they'll get destroyed within the
 * proper memory context when released from an owning \c OGRFeature.
 *
 * Thus, always use \c OGRGeometryFactory functions to create new geometries.
 * You can then manage their lifetime manually or rely on \c UniqueGeometryPtr
 * that provides a non-copyable, but movable RAII wrapper around \c OGRGeometry.
70
 * \since OTB v 3.14.0
71 72
 * @{
 */
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

/**
 * Smart-pointer over \c OGRGeometry, with \em move-semantics.
 * In a few words:
 * - When a function receives a \em unique_ptr<>, it implicitly assumes
 * responsibility of the received pointer.
 * - When a function returns a \em unique_ptr<>, the client code implicitly
 * assumes responsibility of the returned pointer.
 * - When exiting a scope, the pointer is destroyed. Which means, as long as we
 * keep using \em unique_ptr<> around functions calls, there is no need to
 * burden our mind with the lifetime of the encapsulated pointers.
 * - Moreover, we can specify how pointers are deleted; property that we
 * exploit to use the ad'hoc destruction function from OGR API, see \c
 * GeometryDeleter.
 *
 * \see http://www2.research.att.com/~bs/C++0xFAQ.html#rval about \em move-semantics.
 * \see http://www2.research.att.com/~bs/C++0xFAQ.html#std-unique_ptr about \c
 * std::unique_ptr<>
 * \see GOTW \#103, \#104 about \c unique_ptr<> as well: http://herbsutter.com/gotw/_103/
 *
93 94
 * \note You may experiment difficulties to copy \c UniqueGeometryPtr. This is
 * likelly to be normal. You'll have to emulate \c std::move() with \c
95 96 97
 * boost::move() (with Boost v1.48+, or with \c boost::interprocess::move()
 * otherwise). Check for instance \c Feature::StealGeometry(), or \c
 * Feature::SetGeometryDirectly() to see examples.
98
 *
99 100 101 102 103 104
 * \internal
 * This should be defined on top of C++11 \c std::unique_ptr<>. By the mean
 * time, we are using an emulation provided in boost.interprocess.
 * \todo When CMake provides a way to detect C++11 features, use a \c #ifdef to
 * use the correct type.
 */
105 106
typedef boost::interprocess::unique_ptr<OGRGeometry, internal::GeometryDeleter> UniqueGeometryPtr;
///Do these features intersect?
107
OTBGdalAdapters_EXPORT bool Intersects (OGRGeometry const& lhs, OGRGeometry const& rhs);
108
/// Returns wheither if two geometries are equivalent.
109
OTBGdalAdapters_EXPORT bool Equals (OGRGeometry const& lhs, OGRGeometry const& rhs);
110
/// Tests for disjointness.
111
OTBGdalAdapters_EXPORT bool Disjoint (OGRGeometry const& lhs, OGRGeometry const& rhs);
112
/// Tests for touching.
113
OTBGdalAdapters_EXPORT bool Touches (OGRGeometry const& lhs, OGRGeometry const& rhs);
114
/// Tests for crossing.
115
OTBGdalAdapters_EXPORT bool Crosses (OGRGeometry const& lhs, OGRGeometry const& rhs);
116
/// Tests for containment.
117
OTBGdalAdapters_EXPORT bool Within (OGRGeometry const& lhs, OGRGeometry const& rhs);
118
/// Tests for containment.
119
OTBGdalAdapters_EXPORT bool Contains (OGRGeometry const& lhs, OGRGeometry const& rhs);
120
/// Tests for overlap.
121
OTBGdalAdapters_EXPORT bool Overlaps (OGRGeometry const& lhs, OGRGeometry const& rhs);
122
/// Computes distance between two geometries.
123
OTBGdalAdapters_EXPORT double Distance (OGRGeometry const& lhs, OGRGeometry const& rhs);
124 125

/// Computes intersection.
126
OTBGdalAdapters_EXPORT UniqueGeometryPtr Intersection (OGRGeometry const& lhs, OGRGeometry const& rhs);
127
/// Computes union.
128
OTBGdalAdapters_EXPORT UniqueGeometryPtr Union (OGRGeometry const& lhs, OGRGeometry const& rhs);
129
/// Computes union using cascading.
130
OTBGdalAdapters_EXPORT UniqueGeometryPtr UnionCascaded (OGRGeometry const& this_);
131
/// Computes difference.
132
OTBGdalAdapters_EXPORT UniqueGeometryPtr Difference (OGRGeometry const& lhs, OGRGeometry const& rhs);
133
/// Computes symmetric difference.
134
OTBGdalAdapters_EXPORT UniqueGeometryPtr SymDifference (OGRGeometry const& lhs, OGRGeometry const& rhs); // -1.8
135

136 137 138 139 140 141 142 143 144
/** Simplifies Geometry.
 * This function tries to uses the best simplication algorithm available in the
 * current version of GDAL. <em>Best</em> in the sense of topology preservation.
 * i.e. With GDAL v1.8.0, \c OGRGeometry::Simplify() is used; with GDAL v1.9.0+,
 * \c OGRGeometry::SimplifyPreserveTopology() is used.
 * \pre Requires GDAL 1.8.0
 * \sa \c OGRGeometry::Simplify()
 * \sa \c OGRGeometry::SimplifyPreserveTopology()
 */
145
OTBGdalAdapters_EXPORT UniqueGeometryPtr Simplify(OGRGeometry const& g, double tolerance);
146 147 148 149 150

/** Simplifies Geometry with no guarantee of preserving the geometry.
 * \pre Requires GDAL 1.8.0
 * \sa \c OGRGeometry::Simplify()
 */
151
OTBGdalAdapters_EXPORT UniqueGeometryPtr SimplifyDontPreserveTopology(OGRGeometry const& g, double tolerance);
152 153 154 155 156

/** Simplifies Geometry while preserving topology.
 * \pre Requires GDAL 1.9.0
 * \sa \c OGRGeometry::SimplifyPreserveTopology()
 */
157
OTBGdalAdapters_EXPORT UniqueGeometryPtr SimplifyPreserveTopology(OGRGeometry const& g, double tolerance);
158

159 160 161 162 163
/** @} */

} } // end namespace otb::ogr

#ifndef OTB_MANUAL_INSTANTIATION
164
// #include "otbOGRGeometryWrapper.hxx"
165 166
#endif

167
#endif // otbOGRGeometryWrapper_h