LCOV - code coverage report
Current view: top level - frmts/pcidsk/sdk - pcidsk_vectorsegment.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 8 8 100.0 %
Date: 2024-05-04 12:52:34 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Purpose:  PCIDSK Vector Segment public interface. Declaration.
       4             :  *
       5             :  ******************************************************************************
       6             :  * Copyright (c) 2009
       7             :  * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada.
       8             :  *
       9             :  * Permission is hereby granted, free of charge, to any person obtaining a
      10             :  * copy of this software and associated documentation files (the "Software"),
      11             :  * to deal in the Software without restriction, including without limitation
      12             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      13             :  * and/or sell copies of the Software, and to permit persons to whom the
      14             :  * Software is furnished to do so, subject to the following conditions:
      15             :  *
      16             :  * The above copyright notice and this permission notice shall be included
      17             :  * in all copies or substantial portions of the Software.
      18             :  *
      19             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      20             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      21             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      22             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      23             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      24             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      25             :  * DEALINGS IN THE SOFTWARE.
      26             :  ****************************************************************************/
      27             : 
      28             : #ifndef INCLUDE_PCIDSK_VECTORSEGMENT_H
      29             : #define INCLUDE_PCIDSK_VECTORSEGMENT_H
      30             : 
      31             : #include <string>
      32             : #include <vector>
      33             : #include <iterator>
      34             : #include "pcidsk_shape.h"
      35             : 
      36             : #define ATT_RINGSTART "RingStart"
      37             : 
      38             : namespace PCIDSK
      39             : {
      40             :     class ShapeIterator;
      41             : 
      42             : /************************************************************************/
      43             : /*                         PCIDSKVectorSegment                          */
      44             : /************************************************************************/
      45             : 
      46             : /**
      47             : \brief Interface to PCIDSK vector segment.
      48             : 
      49             : The vector segment contains a set of vector features with a common set
      50             : of attribute data (fields).   Each feature has a numeric identifier (ShapeId),
      51             : a set of field values, and a set of geometric vertices.   The layer as a
      52             : whole has a description of the attribute fields, and an RST (Representation
      53             : Style Table).
      54             : 
      55             : The geometry and attribute fields of shapes can be fetched with the
      56             : GetVertices() and GetFields() methods by giving the ShapeId of the desired
      57             : feature.  The set of shapeid's can be identified using the FindFirst(),
      58             : and FindNext() methods or the STL compatible ShapeIterator (begin() and
      59             : end() methods).
      60             : 
      61             : The PCIDSKSegment interface for the segment can be used to fetch the
      62             : LAYER_TYPE metadata describing how the vertices should be interpreted
      63             : as a geometry.  Some layers will also have a RingStart attribute field
      64             : which is used in conjunction with the LAYER_TYPE to interpret the
      65             : geometry.  Some vector segments may have no LAYER_TYPE metadata in which
      66             : case single vertices are interpreted as points, and multiple vertices
      67             : as linestrings.
      68             : 
      69             : More details are available in the GDB.HLP description of the GDB vector
      70             : data model.
      71             : 
      72             : Note that there are no mechanisms for fast spatial or attribute searches
      73             : in a PCIDSK vector segment.  Accessing features randomly (rather than
      74             : in the order shapeids are returned by FindFirst()/FindNext() or ShapeIterator
      75             : ) may result in reduced performance, and the use of large amounts of memory
      76             : for large vector segments.
      77             : 
      78             : */
      79             : 
      80             : class PCIDSK_DLL PCIDSKVectorSegment
      81             : {
      82             :     public:
      83        1185 :         virtual ~PCIDSKVectorSegment() {}
      84             : 
      85             : /**
      86             : \brief Fetch RST.
      87             : 
      88             : No attempt is made to parse the RST, it is up to the caller to decode it.
      89             : 
      90             : NOTE: There is some header info on RST format that may be needed to do this
      91             : for older RSTs.
      92             : 
      93             : @return RST as a string.
      94             : */
      95             :         virtual std::string GetRst() = 0;
      96             : 
      97             : 
      98             : /**
      99             : \brief Fetch Projection
     100             : 
     101             : The returned values are the projection parameters in the same form returned
     102             : by PCIDSKGeoref::GetParameters() and the passed in geosys argument is
     103             : updated with the coordinate system string.
     104             : 
     105             : @return Projection parameters as a vector.
     106             : */
     107             :         virtual std::vector<double> GetProjection( std::string &geosys ) = 0;
     108             : 
     109             : /**
     110             : \brief Get field count.
     111             : 
     112             : Note that this includes any system attributes, like RingStart, that would
     113             : not normally be shown to the user.
     114             : 
     115             : @return the number of attribute fields defined on this layer.
     116             : */
     117             : 
     118             :         virtual int         GetFieldCount() = 0;
     119             : 
     120             : /**
     121             : \brief Get field name.
     122             : 
     123             : @param field_index index of the field requested from zero to GetFieldCount()-1.
     124             : @return the field name.
     125             : */
     126             :         virtual std::string GetFieldName(int field_index) = 0;
     127             : 
     128             : /**
     129             : \brief Get field description.
     130             : 
     131             : @param field_index index of the field requested from zero to GetFieldCount()-1.
     132             : @return the field description, often empty.
     133             : */
     134             :         virtual std::string GetFieldDescription(int field_index) = 0;
     135             : 
     136             : /**
     137             : \brief Get field type.
     138             : 
     139             : @param field_index index of the field requested from zero to GetFieldCount()-1.
     140             : @return the field type.
     141             : */
     142             :         virtual ShapeFieldType GetFieldType(int field_index) = 0;
     143             : 
     144             : /**
     145             : \brief Get field format.
     146             : 
     147             : @param field_index index of the field requested from zero to GetFieldCount()-1.
     148             : @return the field format as a C style format string suitable for use with printf.
     149             : */
     150             :         virtual std::string GetFieldFormat(int field_index) = 0;
     151             : 
     152             : /**
     153             : \brief Get field default.
     154             : 
     155             : @param field_index index of the field requested from zero to GetFieldCount()-1.
     156             : @return the field default value.
     157             : */
     158             :         virtual ShapeField  GetFieldDefault(int field_index) = 0;
     159             : 
     160             : /**
     161             : \brief Get iterator to first shape.
     162             : @return iterator.
     163             : */
     164             :         virtual ShapeIterator begin() = 0;
     165             : 
     166             : /**
     167             : \brief Get iterator to end of shape lib (a wrapper for NullShapeId).
     168             : @return iterator.
     169             : */
     170             :         virtual ShapeIterator end() = 0;
     171             : 
     172             : /**
     173             : \brief Fetch first shapeid in the layer.
     174             : @return first shape's shapeid.
     175             : */
     176             :         virtual ShapeId     FindFirst() = 0;
     177             : 
     178             : /**
     179             : \brief Fetch the next shape id after the indicated shape id.
     180             : @param id the previous shapes id.
     181             : @return next shape's shapeid.
     182             : */
     183             :         virtual ShapeId     FindNext(ShapeId id) = 0;
     184             : 
     185             : 
     186             : /**
     187             : \brief Fetch the number of shapes in this segment.
     188             : @return the shape count.
     189             : */
     190             : 
     191             :         virtual int         GetShapeCount() = 0;
     192             : 
     193             : /**
     194             : \brief Fetch the vertices for the indicated shape.
     195             : @param id the shape to fetch
     196             : @param list the list is updated with the vertices for this shape.
     197             : */
     198             :         virtual void        GetVertices( ShapeId id,
     199             :                                          std::vector<ShapeVertex>& list ) = 0;
     200             : 
     201             : /**
     202             : \brief Fetch the fields for the indicated shape.
     203             : @param id the shape to fetch
     204             : @param list the field list is updated with the field values for this shape.
     205             : */
     206             :         virtual void        GetFields( ShapeId id,
     207             :                                        std::vector<ShapeField>& list ) = 0;
     208             : 
     209             : 
     210             : /**
     211             : \brief Set the projection for the segment.
     212             : 
     213             : For details on the geosys and params values see the PCIDSKGeoref class.
     214             : 
     215             : @param geosys the usual 16 character coordinate system string.
     216             : @param params additional parameters needed for user parametrized projection.
     217             : */
     218             :         virtual void        SetProjection(const std::string& geosys,
     219             :                                           const std::vector<double>& params ) = 0;
     220             : 
     221             : /**
     222             : \brief Create new attribute field.
     223             : 
     224             : @param name the field name, should be unique in layer.
     225             : @param type the field type.
     226             : @param description the field description.
     227             : @param format the C style format string or "" for default formatting.
     228             : @param default_value the default value for this field or NULL for system default.
     229             : */
     230             : 
     231             :         virtual void        AddField( const std::string& name, ShapeFieldType type,
     232             :                                       const std::string& description,
     233             :                                       const std::string& format,
     234             :                                       ShapeField *default_value=nullptr ) = 0;
     235             : 
     236             : /**
     237             : \brief Create a new shape.
     238             : 
     239             : Newly created shapes have no geometry or attribute values.
     240             : 
     241             : @param id The ShapeId to assign to the new shape, or default to assign the next available shapeid.
     242             : 
     243             : @return the shapeid assigned to the newly created shape.
     244             : */
     245             : 
     246             :         virtual ShapeId     CreateShape( ShapeId id = NullShapeId ) = 0;
     247             : 
     248             : /**
     249             : \brief Delete a shape.
     250             : 
     251             : An exception is thrown if the shape does not exist.
     252             : 
     253             : @param id the shapeid to delete.
     254             : 
     255             : */
     256             :         virtual void        DeleteShape( ShapeId id ) = 0;
     257             : 
     258             : /**
     259             : \brief Assign vertices to shape.
     260             : 
     261             : @param id the shape to assign vertices to.
     262             : @param list the list of vertices to assign.
     263             : */
     264             : 
     265             :         virtual void        SetVertices( ShapeId id,
     266             :                                          const std::vector<ShapeVertex> &list ) = 0;
     267             : 
     268             : 
     269             : /**
     270             : \brief Assign attribute value to a shape.
     271             : 
     272             : The list of fields should match the types and length from the schema
     273             : (GetFieldCount(), GetFieldType()).
     274             : 
     275             : @param id the shape to update.
     276             : @param list the list of field value to assign.
     277             : */
     278             :         virtual void        SetFields( ShapeId id,
     279             :                                        const std::vector<ShapeField>& list) = 0;
     280             : 
     281             : // Methods needed
     282             :         // DeleteField
     283             :     };
     284             : 
     285             : /************************************************************************/
     286             : /*                            ShapeIterator                             */
     287             : /************************************************************************/
     288             : 
     289             : //! Iterator over shapeids in a vector segment.
     290             : 
     291             :     class ShapeIterator
     292             :     {
     293             :         ShapeId id;
     294             :         PCIDSKVectorSegment *seg;
     295             : 
     296             :     public:
     297             :         using iterator_category = std::input_iterator_tag;
     298             :         using value_type = ShapeId;
     299             :         using difference_type = std::ptrdiff_t;
     300             :         using pointer = ShapeId*;
     301             :         using reference = ShapeId&;
     302             : 
     303          10 :         ShapeIterator(PCIDSKVectorSegment *seg_in)
     304          10 :                 : seg(seg_in)  { id = seg->FindFirst(); }
     305          20 :         ShapeIterator(PCIDSKVectorSegment *seg_in, ShapeId id_in )
     306          20 :                 : id(id_in), seg(seg_in)  {}
     307             :         ShapeIterator(const ShapeIterator& mit) : id(mit.id), seg(mit.seg) {}
     308             :         ShapeIterator& operator++() { id=seg->FindNext(id); return *this;}
     309          10 :         ShapeIterator& operator++(int) { id=seg->FindNext(id); return *this;}
     310             :         friend bool operator==(const ShapeIterator& lhs, const ShapeIterator& rhs);
     311             :         friend bool operator!=(const ShapeIterator& lhs, const ShapeIterator& rhs);
     312          10 :         ShapeId& operator*() {return id;}
     313             :     };
     314             : 
     315             :     inline bool operator==(const ShapeIterator& lhs, const ShapeIterator& rhs) {return lhs.id == rhs.id;}
     316          20 :     inline bool operator!=(const ShapeIterator& lhs, const ShapeIterator& rhs) {return lhs.id != rhs.id;}
     317             : 
     318             : } // end namespace PCIDSK
     319             : 
     320             : #endif // INCLUDE_PCIDSK_VECTORSEGMENT_H

Generated by: LCOV version 1.14