1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
/**********************************************************************
* $Id: EnhancedPrecisionOp.cpp 1820 2006-09-06 16:54:23Z mloskot $
*
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
*
* Copyright (C) 2005-2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: precision/EnhancedPrecisionOp.java rev. 1.9 (JTS-1.7)
*
**********************************************************************/
#include <geos/precision/EnhancedPrecisionOp.h>
#include <geos/precision/CommonBitsOp.h>
#include <geos/precision/CommonBitsRemover.h> // for auto_ptr composition
#include <geos/geom/Geometry.h>
#include <geos/util/GEOSException.h>
#ifndef GEOS_DEBUG
#define GEOS_DEBUG 0
#endif
#ifdef GEOS_DEBUG
#include <iostream>
#endif
using namespace geos::geom;
namespace geos {
namespace precision { // geos.precision
/*public static*/
Geometry*
EnhancedPrecisionOp::intersection(
const Geometry *geom0,
const Geometry *geom1)
{
util::GEOSException originalEx;
try
{
Geometry *result = geom0->intersection(geom1);
return result;
}
catch (const util::GEOSException& ex)
{
originalEx = ex;
}
/*
* If we are here, the original op encountered a precision problem
* (or some other problem). Retry the operation with
* enhanced precision to see if it succeeds
*/
try
{
CommonBitsOp cbo(true);
Geometry *resultEP = cbo.intersection(geom0, geom1);
// check that result is a valid geometry after
// the reshift to orginal precision
if (! resultEP->isValid())
{
#if GEOS_DEBUG
std::cerr << "Reduced operation result is invalid"
<< std::endl;
#endif
throw originalEx;
}
return resultEP;
}
catch (const util::GEOSException& ex2 )
{
#if GEOS_DEBUG
std::cerr << "Reduced operation exception: "
<< ex2.what() << std::endl;
#endif
throw originalEx;
}
}
/*public static*/
Geometry*
EnhancedPrecisionOp::Union(
const Geometry *geom0,
const Geometry *geom1)
{
util::GEOSException originalEx;
try
{
Geometry* result = geom0->Union(geom1);
return result;
}
catch (const util::GEOSException& ex)
{
originalEx = ex;
}
/*
* If we are here, the original op encountered a precision problem
* (or some other problem)-> Retry the operation with
* enhanced precision to see if it succeeds
*/
try
{
CommonBitsOp cbo(true);
Geometry *resultEP = cbo.Union(geom0, geom1);
// check that result is a valid geometry after
// the reshift to orginal precision
if (! resultEP->isValid())
throw originalEx;
return resultEP;
}
catch (const util::GEOSException& /* ex2 */)
{
throw originalEx;
}
}
/*public static*/
Geometry*
EnhancedPrecisionOp::difference(
const Geometry *geom0,
const Geometry *geom1)
{
util::GEOSException originalEx;
try
{
Geometry *result = geom0->difference(geom1);
return result;
}
catch (const util::GEOSException& ex)
{
originalEx = ex;
}
/*
* If we are here, the original op encountered a precision problem
* (or some other problem). Retry the operation with
* enhanced precision to see if it succeeds
*/
try
{
CommonBitsOp cbo(true);
Geometry *resultEP = cbo.difference(geom0, geom1);
// check that result is a valid geometry after
// the reshift to orginal precision
if (! resultEP->isValid())
throw originalEx;
return resultEP;
}
catch (const util::GEOSException& /* ex2 */)
{
throw originalEx;
}
}
/*public static*/
Geometry*
EnhancedPrecisionOp::symDifference(
const Geometry *geom0,
const Geometry *geom1)
{
util::GEOSException originalEx;
try
{
Geometry *result = geom0->symDifference(geom1);
return result;
}
catch (const util::GEOSException& ex)
{
originalEx = ex;
}
/*
* If we are here, the original op encountered a precision problem
* (or some other problem). Retry the operation with
* enhanced precision to see if it succeeds
*/
try
{
CommonBitsOp cbo(true);
Geometry* resultEP = cbo.symDifference(geom0, geom1);
// check that result is a valid geometry after
// the reshift to orginal precision
if (! resultEP->isValid())
throw originalEx;
return resultEP;
}
catch (const util::GEOSException& /* ex2 */)
{
throw originalEx;
}
}
/*public static*/
Geometry*
EnhancedPrecisionOp::buffer(const Geometry *geom, double distance)
{
util::GEOSException originalEx;
try
{
Geometry *result = geom->buffer(distance);
return result;
}
catch (const util::GEOSException& ex)
{
originalEx = ex;
}
/*
* If we are here, the original op encountered a precision problem
* (or some other problem)-> Retry the operation with
* enhanced precision to see if it succeeds
*/
try
{
CommonBitsOp cbo(true);
Geometry *resultEP = cbo.buffer(geom, distance);
// check that result is a valid geometry
// after the reshift to orginal precision
if (! resultEP->isValid())
throw originalEx;
return resultEP;
}
catch (const util::GEOSException& /* ex2 */)
{
throw originalEx;
}
}
} // namespace geos.precision
} // namespace geos
/**********************************************************************
* $Log$
* Revision 1.9 2006/04/07 08:31:37 strk
* Debugging lines
*
* Revision 1.8 2006/04/06 14:36:51 strk
* Cleanup in geos::precision namespace (leaks plugged, auto_ptr use, ...)
*
* Revision 1.7 2006/03/23 09:17:19 strk
* precision.h header split, minor optimizations
*
**********************************************************************/
|