LCOV - code coverage report
Current view: top level - ogr - ogrmultilinestring.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 41 41 100.0 %
Date: 2024-05-04 12:52:34 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  The OGRMultiLineString class.
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 1999, Frank Warmerdam
       9             :  * Copyright (c) 2008-2013, Even Rouault <even dot rouault at spatialys.com>
      10             :  *
      11             :  * Permission is hereby granted, free of charge, to any person obtaining a
      12             :  * copy of this software and associated documentation files (the "Software"),
      13             :  * to deal in the Software without restriction, including without limitation
      14             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15             :  * and/or sell copies of the Software, and to permit persons to whom the
      16             :  * Software is furnished to do so, subject to the following conditions:
      17             :  *
      18             :  * The above copyright notice and this permission notice shall be included
      19             :  * in all copies or substantial portions of the Software.
      20             :  *
      21             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27             :  * DEALINGS IN THE SOFTWARE.
      28             :  ****************************************************************************/
      29             : 
      30             : #include "cpl_port.h"
      31             : #include "ogr_geometry.h"
      32             : 
      33             : #include <cstddef>
      34             : 
      35             : #include "cpl_error.h"
      36             : #include "ogr_core.h"
      37             : #include "ogr_p.h"
      38             : 
      39             : /************************************************************************/
      40             : /*                        OGRMultiLineString()                          */
      41             : /************************************************************************/
      42             : 
      43             : /**
      44             :  * \brief Create an empty multi line string collection.
      45             :  */
      46             : 
      47             : OGRMultiLineString::OGRMultiLineString() = default;
      48             : 
      49             : /************************************************************************/
      50             : /*           OGRMultiLineString( const OGRMultiLineString& )            */
      51             : /************************************************************************/
      52             : 
      53             : /**
      54             :  * \brief Copy constructor.
      55             :  *
      56             :  * Note: before GDAL 2.1, only the default implementation of the constructor
      57             :  * existed, which could be unsafe to use.
      58             :  *
      59             :  * @since GDAL 2.1
      60             :  */
      61             : 
      62             : OGRMultiLineString::OGRMultiLineString(const OGRMultiLineString &) = default;
      63             : 
      64             : /************************************************************************/
      65             : /*                       ~OGRMultiLineString()                          */
      66             : /************************************************************************/
      67             : 
      68             : OGRMultiLineString::~OGRMultiLineString() = default;
      69             : 
      70             : /************************************************************************/
      71             : /*                  operator=( const OGRMultiCurve&)                    */
      72             : /************************************************************************/
      73             : 
      74             : /**
      75             :  * \brief Assignment operator.
      76             :  *
      77             :  * Note: before GDAL 2.1, only the default implementation of the operator
      78             :  * existed, which could be unsafe to use.
      79             :  *
      80             :  * @since GDAL 2.1
      81             :  */
      82             : 
      83             : OGRMultiLineString &
      84           5 : OGRMultiLineString::operator=(const OGRMultiLineString &other)
      85             : {
      86           5 :     if (this != &other)
      87             :     {
      88           4 :         OGRMultiCurve::operator=(other);
      89             :     }
      90           5 :     return *this;
      91             : }
      92             : 
      93             : /************************************************************************/
      94             : /*                               clone()                                */
      95             : /************************************************************************/
      96             : 
      97         632 : OGRMultiLineString *OGRMultiLineString::clone() const
      98             : 
      99             : {
     100         632 :     return new (std::nothrow) OGRMultiLineString(*this);
     101             : }
     102             : 
     103             : /************************************************************************/
     104             : /*                          getGeometryType()                           */
     105             : /************************************************************************/
     106             : 
     107       15614 : OGRwkbGeometryType OGRMultiLineString::getGeometryType() const
     108             : 
     109             : {
     110       15614 :     if ((flags & OGR_G_3D) && (flags & OGR_G_MEASURED))
     111        3056 :         return wkbMultiLineStringZM;
     112       12558 :     else if (flags & OGR_G_MEASURED)
     113         256 :         return wkbMultiLineStringM;
     114       12302 :     else if (flags & OGR_G_3D)
     115        4447 :         return wkbMultiLineString25D;
     116             :     else
     117        7855 :         return wkbMultiLineString;
     118             : }
     119             : 
     120             : /************************************************************************/
     121             : /*                          getGeometryName()                           */
     122             : /************************************************************************/
     123             : 
     124        1858 : const char *OGRMultiLineString::getGeometryName() const
     125             : 
     126             : {
     127        1858 :     return "MULTILINESTRING";
     128             : }
     129             : 
     130             : /************************************************************************/
     131             : /*                          isCompatibleSubType()                       */
     132             : /************************************************************************/
     133             : 
     134             : OGRBoolean
     135       27097 : OGRMultiLineString::isCompatibleSubType(OGRwkbGeometryType eGeomType) const
     136             : {
     137       27097 :     return wkbFlatten(eGeomType) == wkbLineString;
     138             : }
     139             : 
     140             : /************************************************************************/
     141             : /*                           importFromWkb()                            */
     142             : /************************************************************************/
     143             : 
     144        1285 : OGRErr OGRMultiLineString::importFromWkb(const unsigned char *pabyData,
     145             :                                          size_t nSize,
     146             :                                          OGRwkbVariant eWkbVariant,
     147             :                                          size_t &nBytesConsumedOut)
     148             : 
     149             : {
     150        1285 :     if (nGeomCount == 1 && nSize >= 9 && flags == 0 && pabyData[0] == wkbNDR &&
     151           3 :         memcmp(pabyData + 1, "\x05\x00\x00\x00\x01\x00\x00\x00", 8) == 0)
     152             :     {
     153             :         // Optimization to import a Intel-ordered 1-part multilinestring on
     154             :         // top of an existing 1-part multilinestring, to save dynamic memory
     155             :         // allocations.
     156           3 :         const size_t nDataOffset = 9;
     157           3 :         size_t nBytesConsumedLineString = 0;
     158             :         // cppcheck-suppress knownConditionTrueFalse
     159           3 :         if (nSize != static_cast<size_t>(-1))
     160           2 :             nSize -= nDataOffset;
     161           3 :         OGRErr eErr = cpl::down_cast<OGRLineString *>(papoGeoms[0])
     162           3 :                           ->OGRLineString::importFromWkb(
     163             :                               pabyData + nDataOffset, nSize, eWkbVariant,
     164             :                               nBytesConsumedLineString);
     165           3 :         if (eErr == OGRERR_NONE)
     166             :         {
     167           2 :             nBytesConsumedOut = nDataOffset + nBytesConsumedLineString;
     168             :         }
     169             :         else
     170             :         {
     171           1 :             empty();
     172             :         }
     173           3 :         return eErr;
     174             :     }
     175             : 
     176        1282 :     return OGRGeometryCollection::importFromWkbInternal(
     177        1282 :         pabyData, nSize, /*nRecLevel=*/0, eWkbVariant, nBytesConsumedOut);
     178             : }
     179             : 
     180             : /************************************************************************/
     181             : /*                            exportToWkt()                             */
     182             : /************************************************************************/
     183             : 
     184         224 : std::string OGRMultiLineString::exportToWkt(const OGRWktOptions &opts,
     185             :                                             OGRErr *err) const
     186             : 
     187             : {
     188         224 :     return exportToWktInternal(opts, err, "LINESTRING");
     189             : }
     190             : 
     191             : /************************************************************************/
     192             : /*                         hasCurveGeometry()                           */
     193             : /************************************************************************/
     194             : 
     195             : OGRBoolean
     196        2798 : OGRMultiLineString::hasCurveGeometry(int /* bLookForNonLinear */) const
     197             : {
     198        2798 :     return false;
     199             : }
     200             : 
     201             : /************************************************************************/
     202             : /*                          CastToMultiCurve()                          */
     203             : /************************************************************************/
     204             : 
     205             : /**
     206             :  * \brief Cast to multicurve.
     207             :  *
     208             :  * The passed in geometry is consumed and a new one returned.
     209             :  *
     210             :  * @param poMLS the input geometry - ownership is passed to the method.
     211             :  * @return new geometry.
     212             :  */
     213             : 
     214           8 : OGRMultiCurve *OGRMultiLineString::CastToMultiCurve(OGRMultiLineString *poMLS)
     215             : {
     216           8 :     OGRMultiCurve *poMLC = new OGRMultiCurve();
     217           8 :     TransferMembersAndDestroy(poMLS, poMLC);
     218           8 :     return poMLC;
     219             : }

Generated by: LCOV version 1.14