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 40 #include <memory> 41 42 class OGRGeometry; 43 using OGRGeometryH = void *; 44 using OGRSpatialReferenceH = void *; 45 46 namespace pdal 47 { 48 49 class BOX3D; 50 51 class PDAL_DLL Geometry 52 { 53 protected: 54 Geometry(); 55 Geometry(const Geometry&); 56 Geometry(Geometry&&); 57 Geometry(const std::string& wkt_or_json, 58 SpatialReference ref = SpatialReference()); 59 Geometry(OGRGeometryH g); 60 Geometry(OGRGeometryH g, const SpatialReference& srs); 61 62 public: 63 Geometry& operator=(const Geometry&); 64 virtual ~Geometry(); 65 getOGRHandle()66 OGRGeometryH getOGRHandle() 67 { return m_geom.get(); } 68 69 virtual void update(const std::string& wkt_or_json); 70 virtual bool valid() const; 71 virtual void clear() = 0; 72 virtual void modified(); 73 bool srsValid() const; 74 void setSpatialReference(const SpatialReference& ref); 75 SpatialReference getSpatialReference() const; 76 Utils::StatusWithReason transform(SpatialReference ref); 77 78 std::string wkt(double precision=15, bool bOutputZ=false) const; 79 std::string json(double precision=15) const; 80 81 BOX3D bounds() const; 82 operator bool() const83 operator bool () const 84 { return m_geom != NULL; } 85 static void throwNoGeos(); 86 87 protected: 88 std::unique_ptr<OGRGeometry> m_geom; 89 90 friend PDAL_DLL std::ostream& operator<<(std::ostream& ostr, 91 const Geometry& p); 92 friend PDAL_DLL std::istream& operator>>(std::istream& istr, 93 Geometry& p); 94 }; 95 96 } // namespace pdal 97 98