1 /****************************************************************************** 2 * Copyright (c) 2016, Howard Butler (howard@hobu.co) 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following 8 * conditions are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided 15 * with the distribution. 16 * * Neither the name of Hobu, Inc. nor the 17 * names of its contributors may be used to endorse or promote 18 * products derived from this software without specific prior 19 * written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 * OF SUCH DAMAGE. 33 ****************************************************************************/ 34 #pragma once 35 36 #include <pdal/Log.hpp> 37 #include <pdal/PointRef.hpp> 38 #include <pdal/SpatialReference.hpp> 39 #include <pdal/Geometry.hpp> 40 41 namespace pdal 42 { 43 44 class BOX2D; 45 class BOX3D; 46 47 class PDAL_DLL Polygon : public Geometry 48 { 49 using Point = std::pair<double, double>; 50 using Ring = std::vector<Point>; 51 struct PrivateData; 52 53 public: 54 Polygon(); 55 virtual ~Polygon(); 56 57 Polygon(const std::string& wkt_or_json, 58 SpatialReference ref = SpatialReference()); 59 Polygon(const BOX2D&); 60 Polygon(const BOX3D&); 61 Polygon(OGRGeometryH g); 62 Polygon(OGRGeometryH g, const SpatialReference& srs); 63 Polygon(const Polygon& poly); 64 Polygon& operator=(const Polygon& src); 65 66 virtual void modified() override; 67 virtual void clear() override; 68 void simplify(double distance_tolerance, double area_tolerance, 69 bool preserve_topology = true); 70 double area() const; 71 std::vector<Polygon> polygons() const; 72 73 bool covers(const PointRef& ref) const; 74 bool equal(const Polygon& p) const; 75 bool overlaps(const Polygon& p) const; 76 bool contains(double x, double y) const; 77 bool contains(const Polygon& p) const; 78 bool intersects(const Polygon& p) const; 79 bool disjoint(const Polygon& p) const; 80 bool touches(const Polygon& p) const; 81 bool within(const Polygon& p) const; 82 bool crosses(const Polygon& p) const; 83 Ring exteriorRing() const; 84 std::vector<Ring> interiorRings() const; 85 86 private: 87 void init(); 88 void removeSmallRings(double tolerance); 89 void removeSmallHoles(double tolerance); 90 91 std::unique_ptr<PrivateData> m_pd; 92 }; 93 94 } // namespace pdal 95 96