LCOV - code coverage report
Current view: top level - ogr - ogrmultilinestring.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 44 46 95.7 %
Date: 2025-10-15 23:46:56 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             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #include "cpl_port.h"
      15             : #include "ogr_geometry.h"
      16             : 
      17             : #include <cstddef>
      18             : 
      19             : #include "cpl_error.h"
      20             : #include "ogr_core.h"
      21             : #include "ogr_p.h"
      22             : 
      23             : /************************************************************************/
      24             : /*           OGRMultiLineString( const OGRMultiLineString& )            */
      25             : /************************************************************************/
      26             : 
      27             : /**
      28             :  * \brief Copy constructor.
      29             :  */
      30             : 
      31             : OGRMultiLineString::OGRMultiLineString(const OGRMultiLineString &) = default;
      32             : 
      33             : /************************************************************************/
      34             : /*                  operator=( const OGRMultiCurve&)                    */
      35             : /************************************************************************/
      36             : 
      37             : /**
      38             :  * \brief Assignment operator.
      39             :  */
      40             : 
      41             : OGRMultiLineString &
      42           5 : OGRMultiLineString::operator=(const OGRMultiLineString &other)
      43             : {
      44           5 :     if (this != &other)
      45             :     {
      46           4 :         OGRMultiCurve::operator=(other);
      47             :     }
      48           5 :     return *this;
      49             : }
      50             : 
      51             : /************************************************************************/
      52             : /*                               clone()                                */
      53             : /************************************************************************/
      54             : 
      55       16287 : OGRMultiLineString *OGRMultiLineString::clone() const
      56             : 
      57             : {
      58       16287 :     auto ret = new (std::nothrow) OGRMultiLineString(*this);
      59       16287 :     if (ret)
      60             :     {
      61       16287 :         if (ret->WkbSize() != WkbSize())
      62             :         {
      63           0 :             delete ret;
      64           0 :             ret = nullptr;
      65             :         }
      66             :     }
      67       16287 :     return ret;
      68             : }
      69             : 
      70             : /************************************************************************/
      71             : /*                          getGeometryType()                           */
      72             : /************************************************************************/
      73             : 
      74       32666 : OGRwkbGeometryType OGRMultiLineString::getGeometryType() const
      75             : 
      76             : {
      77       32666 :     if ((flags & OGR_G_3D) && (flags & OGR_G_MEASURED))
      78        3099 :         return wkbMultiLineStringZM;
      79       29567 :     else if (flags & OGR_G_MEASURED)
      80         283 :         return wkbMultiLineStringM;
      81       29284 :     else if (flags & OGR_G_3D)
      82        4933 :         return wkbMultiLineString25D;
      83             :     else
      84       24351 :         return wkbMultiLineString;
      85             : }
      86             : 
      87             : /************************************************************************/
      88             : /*                          getGeometryName()                           */
      89             : /************************************************************************/
      90             : 
      91        2147 : const char *OGRMultiLineString::getGeometryName() const
      92             : 
      93             : {
      94        2147 :     return "MULTILINESTRING";
      95             : }
      96             : 
      97             : /************************************************************************/
      98             : /*                          isCompatibleSubType()                       */
      99             : /************************************************************************/
     100             : 
     101             : OGRBoolean
     102       52512 : OGRMultiLineString::isCompatibleSubType(OGRwkbGeometryType eGeomType) const
     103             : {
     104       52512 :     return wkbFlatten(eGeomType) == wkbLineString;
     105             : }
     106             : 
     107             : /************************************************************************/
     108             : /*                           importFromWkb()                            */
     109             : /************************************************************************/
     110             : 
     111        1526 : OGRErr OGRMultiLineString::importFromWkb(const unsigned char *pabyData,
     112             :                                          size_t nSize,
     113             :                                          OGRwkbVariant eWkbVariant,
     114             :                                          size_t &nBytesConsumedOut)
     115             : 
     116             : {
     117        1526 :     if (nGeomCount == 1 && nSize >= 9 && flags == 0 && pabyData[0] == wkbNDR &&
     118           3 :         memcmp(pabyData + 1, "\x05\x00\x00\x00\x01\x00\x00\x00", 8) == 0)
     119             :     {
     120             :         // Optimization to import a Intel-ordered 1-part multilinestring on
     121             :         // top of an existing 1-part multilinestring, to save dynamic memory
     122             :         // allocations.
     123           3 :         const size_t nDataOffset = 9;
     124           3 :         size_t nBytesConsumedLineString = 0;
     125             :         // cppcheck-suppress knownConditionTrueFalse
     126           3 :         if (nSize != static_cast<size_t>(-1))
     127           2 :             nSize -= nDataOffset;
     128           3 :         OGRErr eErr = cpl::down_cast<OGRLineString *>(papoGeoms[0])
     129           3 :                           ->OGRLineString::importFromWkb(
     130             :                               pabyData + nDataOffset, nSize, eWkbVariant,
     131             :                               nBytesConsumedLineString);
     132           3 :         if (eErr == OGRERR_NONE)
     133             :         {
     134           2 :             nBytesConsumedOut = nDataOffset + nBytesConsumedLineString;
     135             :         }
     136             :         else
     137             :         {
     138           1 :             empty();
     139             :         }
     140           3 :         return eErr;
     141             :     }
     142             : 
     143        1523 :     return OGRGeometryCollection::importFromWkbInternal(
     144        1523 :         pabyData, nSize, /*nRecLevel=*/0, eWkbVariant, nBytesConsumedOut);
     145             : }
     146             : 
     147             : /************************************************************************/
     148             : /*                            exportToWkt()                             */
     149             : /************************************************************************/
     150             : 
     151         246 : std::string OGRMultiLineString::exportToWkt(const OGRWktOptions &opts,
     152             :                                             OGRErr *err) const
     153             : 
     154             : {
     155         246 :     return exportToWktInternal(opts, err, "LINESTRING");
     156             : }
     157             : 
     158             : /************************************************************************/
     159             : /*                         hasCurveGeometry()                           */
     160             : /************************************************************************/
     161             : 
     162             : OGRBoolean
     163        3487 : OGRMultiLineString::hasCurveGeometry(int /* bLookForNonLinear */) const
     164             : {
     165        3487 :     return false;
     166             : }
     167             : 
     168             : /************************************************************************/
     169             : /*                          CastToMultiCurve()                          */
     170             : /************************************************************************/
     171             : 
     172             : /**
     173             :  * \brief Cast to multicurve.
     174             :  *
     175             :  * The passed in geometry is consumed and a new one returned.
     176             :  *
     177             :  * @param poMLS the input geometry - ownership is passed to the method.
     178             :  * @return new geometry.
     179             :  */
     180             : 
     181           9 : OGRMultiCurve *OGRMultiLineString::CastToMultiCurve(OGRMultiLineString *poMLS)
     182             : {
     183           9 :     OGRMultiCurve *poMLC = new OGRMultiCurve();
     184           9 :     TransferMembersAndDestroy(poMLS, poMLC);
     185           9 :     return poMLC;
     186             : }

Generated by: LCOV version 1.14