/** * Polyline - store geographic line-segments */ // Written by James Turner, started 2013. // // Copyright (C) 2013 James Turner // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version. // // This program 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 // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifndef FG_POLY_LINE_HXX #define FG_POLY_LINE_HXX #include #include #include #include namespace flightgear { typedef std::vector SGGeodVec; class PolyLine; typedef SGSharedPtr PolyLineRef; typedef std::vector PolyLineList; /** * @class Store geographical linear data, with a type code. * * This is a basic in-memory model of GIS line data, without support for * many features; especially there is no support for per-node attributes. * * PolyLines are added to the spatial index and can be queried by passing * a search centre and cutoff distance. */ class PolyLine : public SGReferenced { public: virtual ~PolyLine(); enum Type { INVALID = 0, COASTLINE, NATIONAL_BOUNDARY, /// aka a border REGIONAL_BOUNDARY, /// state / province / country / department RIVER, // airspace types in the future LAST_TYPE }; Type type() const { return m_type; } /** * number of points in this line - at least two. */ unsigned int numPoints() const; SGGeod point(unsigned int aIndex) const; const SGGeodVec& points() const { return m_data; } /** * create poly line objects from raw input points and a type. * input points will be subdivided so the bounding area of each * polyline stays within some threshold. * */ static PolyLineList createChunked(Type aTy, const SGGeodVec& aRawPoints); /** * retrieve all the lines within a range of a search point. * lines are returned if any point is near the search location. */ static PolyLineList linesNearPos(const SGGeod& aPos, double aRangeNm, Type aTy); class TypeFilter { public: virtual bool pass(Type aTy) const = 0; }; static PolyLineList linesNearPos(const SGGeod& aPos, double aRangeNm, const TypeFilter& aFilter); private: void addToSpatialIndex() const; PolyLine(Type aTy, const SGGeodVec& aPoints); Type m_type; SGGeodVec m_data; // cache the bounding box? }; } // of namespace flightgear #endif