📄 fuzzypointlocator.cpp
字号:
/********************************************************************** * $Id: FuzzyPointLocator.cpp 1941 2006-12-13 10:55:55Z strk $ * * GEOS - Geometry Engine Open Source * http://geos.refractions.net * * Copyright (C) 2006 Refractions Research 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: operation/overlay/validate/FuzzyPointLocator.java rev. 1.1 * (we should move in GEOS too, probably) * **********************************************************************/#include <geos/operation/overlay/FuzzyPointLocator.h>#include <geos/geom/Geometry.h>#include <geos/geom/Point.h> // for Point upcast#include <geos/geom/GeometryFactory.h>#include <geos/geom/Location.h> // for Location::Value enum#include <cassert>#include <functional>#include <vector>#include <sstream>#include <memory> // for auto_ptr#ifndef GEOS_DEBUG#define GEOS_DEBUG 0#endif#define COMPUTE_Z 1#define USE_ELEVATION_MATRIX 1#define USE_INPUT_AVGZ 0using namespace std;using namespace geos::geom;using namespace geos::algorithm;namespace geos {namespace operation { // geos.operationnamespace overlay { // geos.operation.overlayFuzzyPointLocator::FuzzyPointLocator(const geom::Geometry& geom, double nTolerance) : g(geom), tolerance(nTolerance), ptLocator(), linework(extractLineWork(g)){}/*private*/std::auto_ptr<Geometry>FuzzyPointLocator::extractLineWork(const geom::Geometry& geom){ vector<Geometry*>* lineGeoms = new vector<Geometry*>(); try { // geoms array will leak if an exception is thrown for (size_t i=0, n=g.getNumGeometries(); i<n; ++i) { const Geometry* gComp = g.getGeometryN(i); Geometry* lineGeom = NULL; // only get linework for polygonal components if (gComp->getDimension() == 2) { lineGeom = gComp->getBoundary(); lineGeoms->push_back(lineGeom); } } return std::auto_ptr<Geometry>(g.getFactory()->buildGeometry(lineGeoms)); } catch (...) { // avoid leaks for (size_t i=0, n=lineGeoms->size(); i<n; ++i) { delete (*lineGeoms)[i]; } delete lineGeoms; throw; } }/*private*/std::auto_ptr<Geometry>FuzzyPointLocator::getLineWork(const geom::Geometry& geom){ vector<Geometry*>* lineGeoms = new vector<Geometry*>(); try { // geoms array will leak if an exception is thrown for (size_t i=0, n=g.getNumGeometries(); i<n; ++i) { const Geometry* gComp = g.getGeometryN(i); Geometry* lineGeom; if (gComp->getDimension() == 2) { lineGeom = gComp->getBoundary(); } else { lineGeom = gComp->clone(); } lineGeoms->push_back(lineGeom); } return std::auto_ptr<Geometry>(g.getFactory()->buildGeometry(lineGeoms)); } catch (...) { // avoid leaks for (size_t i=0, n=lineGeoms->size(); i<n; ++i) { delete (*lineGeoms)[i]; } delete lineGeoms; throw; } }/* public */Location::ValueFuzzyPointLocator::getLocation(const Coordinate& pt){ auto_ptr<Geometry> point(g.getFactory()->createPoint(pt)); double dist = linework->distance(point.get()); // if point is close to boundary, it is considered // to be on the boundary if (dist < tolerance) return Location::BOUNDARY; // now we know point must be clearly inside or outside geometry, // so return actual location value // (the static_cast is needed because PointLocator doesn't cleanly // return a Location::Value - it should !!) return static_cast<Location::Value>(ptLocator.locate(pt, &g));}} // namespace geos.operation.overlay} // namespace geos.operation} // namespace geos/********************************************************************** * $Log$ **********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -