LCOV - code coverage report
Current view: directory - frmts/pcidsk/sdk - pcidsk_vectorsegment.h (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 6 6 100.0 %
Date: 2011-12-18 Functions: 6 4 66.7 %

       1                 : /******************************************************************************
       2                 :  *
       3                 :  * Purpose:  PCIDSK Vector Segment public interface. Declaration.
       4                 :  * 
       5                 :  ******************************************************************************
       6                 :  * Copyright (c) 2009
       7                 :  * PCI Geomatics, 50 West Wilmot Street, Richmond Hill, Ont, 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                 : namespace PCIDSK
      37                 : {
      38                 :     class ShapeIterator;
      39                 :     
      40                 : /************************************************************************/
      41                 : /*                         PCIDSKVectorSegment                          */
      42                 : /************************************************************************/
      43                 : 
      44                 : /**
      45                 : \brief Interface to PCIDSK vector segment.
      46                 : 
      47                 : The vector segment contains a set of vector features with a common set 
      48                 : of attribute data (fields).   Each feature has a numeric identifier (ShapeId),
      49                 : a set of field values, and a set of geometric vertices.   The layer as a 
      50                 : whole has a description of the attribute fields, and an RST (Representation
      51                 : Style Table).  
      52                 : 
      53                 : The geometry and attribute fields of shapes can be fetched with the 
      54                 : GetVertices() and GetFields() methods by giving the ShapeId of the desired
      55                 : feature.  The set of shapeid's can be identified using the FindFirst(),
      56                 : and FindNext() methods or the STL compatible ShapeIterator (begin() and
      57                 : end() methods).  
      58                 : 
      59                 : The PCIDSKSegment interface for the segment can be used to fetch the
      60                 : LAYER_TYPE metadata describing how the vertices should be interpreted
      61                 : as a geometry.  Some layers will also have a RingStart attribute field
      62                 : which is used in conjunction with the LAYER_TYPE to interprete the
      63                 : geometry.  Some vector segments may have no LAYER_TYPE metadata in which
      64                 : case single vertices are interpreted as points, and multiple vertices
      65                 : as linestrings.  
      66                 : 
      67                 : More details are available in the GDB.HLP description of the GDB vector
      68                 : data model.
      69                 : 
      70                 : Note that there are no mechanisms for fast spatial or attribute searches
      71                 : in a PCIDSK vector segment.  Accessing features randomly (rather than
      72                 : in the order shapeids are returned by FindFirst()/FindNext() or ShapeIterator
      73                 : ) may result in reduced performance, and the use of large amounts of memory
      74                 : for large vector segments.
      75                 : 
      76                 : */
      77                 : 
      78                 :     class PCIDSK_DLL PCIDSKVectorSegment
      79              28 :     {
      80                 :     public:
      81              28 :         virtual ~PCIDSKVectorSegment() {}
      82                 : 
      83                 : /**
      84                 : \brief Fetch RST. 
      85                 : 
      86                 : No attempt is made to parse the RST, it is up to the caller to decode it. 
      87                 : 
      88                 : NOTE: There is some header info on RST format that may be needed to do this 
      89                 : for older RSTs.
      90                 : 
      91                 : @return RST as a string.
      92                 : */
      93                 :         virtual std::string GetRst() = 0;
      94                 : 
      95                 : 
      96                 : /**
      97                 : \brief Fetch Projection
      98                 : 
      99                 : The returned values are the projection parameters in the same form returned
     100                 : by PCIDSKGeoref::GetParameters() and the passed in geosys argument is 
     101                 : updated with the coordinate system string.
     102                 : 
     103                 : @return Projection parameters as a vector.
     104                 : */
     105                 :         virtual std::vector<double> GetProjection( std::string &geosys ) = 0;
     106                 : 
     107                 : /**
     108                 : \brief Get field count.
     109                 : 
     110                 : Note that this includes any system attributes, like RingStart, that would
     111                 : not normally be shown to the user.
     112                 : 
     113                 : @return the number of attribute fields defined on this layer.
     114                 : */
     115                 : 
     116                 :         virtual int         GetFieldCount() = 0;
     117                 : 
     118                 : /**
     119                 : \brief Get field name.
     120                 : 
     121                 : @param field_index index of the field requested from zero to GetFieldCount()-1.
     122                 : @return the field name. 
     123                 : */
     124                 :         virtual std::string GetFieldName(int field_index) = 0;
     125                 : 
     126                 : /**
     127                 : \brief Get field description.
     128                 : 
     129                 : @param field_index index of the field requested from zero to GetFieldCount()-1.
     130                 : @return the field description, often empty.
     131                 : */
     132                 :         virtual std::string GetFieldDescription(int field_index) = 0;
     133                 : 
     134                 : /**
     135                 : \brief Get field type.
     136                 : 
     137                 : @param field_index index of the field requested from zero to GetFieldCount()-1.
     138                 : @return the field type.
     139                 : */
     140                 :         virtual ShapeFieldType GetFieldType(int field_index) = 0;
     141                 : 
     142                 : /**
     143                 : \brief Get field format.
     144                 : 
     145                 : @param field_index index of the field requested from zero to GetFieldCount()-1.
     146                 : @return the field format as a C style format string suitable for use with printf.
     147                 : */
     148                 :         virtual std::string GetFieldFormat(int field_index) = 0;
     149                 : 
     150                 : /**
     151                 : \brief Get field default.
     152                 : 
     153                 : @param field_index index of the field requested from zero to GetFieldCount()-1.
     154                 : @return the field default value.
     155                 : */
     156                 :         virtual ShapeField  GetFieldDefault(int field_index) = 0;
     157                 : 
     158                 : /**
     159                 : \brief Get iterator to first shape.
     160                 : @return iterator.
     161                 : */
     162                 :         virtual ShapeIterator begin() = 0;
     163                 : 
     164                 : /**
     165                 : \brief Get iterator to end of shape lib (a wrapper for NullShapeId).
     166                 : @return iterator.
     167                 : */
     168                 :         virtual ShapeIterator end() = 0;
     169                 : 
     170                 : /**
     171                 : \brief Fetch first shapeid in the layer.
     172                 : @return first shape's shapeid.
     173                 : */
     174                 :         virtual ShapeId     FindFirst() = 0;
     175                 : 
     176                 : /**
     177                 : \brief Fetch the next shape id after the indicated shape id.
     178                 : @param id the previous shapes id.
     179                 : @return next shape's shapeid.
     180                 : */
     181                 :         virtual ShapeId     FindNext(ShapeId id) = 0;
     182                 :         
     183                 : 
     184                 : /**
     185                 : \brief Fetch the number of shapes in this segment.
     186                 : @return the shape count.
     187                 : */
     188                 : 
     189                 :         virtual int         GetShapeCount() = 0;
     190                 : 
     191                 : /**
     192                 : \brief Fetch the vertices for the indicated shape.
     193                 : @param id the shape to fetch
     194                 : @param list the list is updated with the vertices for this shape.
     195                 : */
     196                 :         virtual void        GetVertices( ShapeId id, 
     197                 :                                          std::vector<ShapeVertex>& list ) = 0;
     198                 : 
     199                 : /**
     200                 : \brief Fetch the fields for the indicated shape.
     201                 : @param id the shape to fetch
     202                 : @param list the field list is updated with the field values for this shape.
     203                 : */
     204                 :         virtual void        GetFields( ShapeId id, 
     205                 :                                        std::vector<ShapeField>& list ) = 0;
     206                 : 
     207                 : 
     208                 : /** 
     209                 : \brief Set the projection for the segment. 
     210                 : 
     211                 : For details on the geosys and parms values see the PCIDSKGeoref class.
     212                 : 
     213                 : @param geosys the usual 16 character coordinate system string.
     214                 : @param parms additional parameters needed for user parametrized projection.
     215                 : */
     216                 :         virtual void        SetProjection(std::string geosys,
     217                 :                                           std::vector<double> parms ) = 0;
     218                 : 
     219                 : /** 
     220                 : \brief Create new attribute field.
     221                 : 
     222                 : @param name the field name, should be unique in layer.
     223                 : @param type the field type.
     224                 : @param description the field description.
     225                 : @param format the C style format string or "" for default formatting.
     226                 : @param default_value the default value for this field or NULL for system default.
     227                 : */
     228                 : 
     229                 :         virtual void        AddField( std::string name, ShapeFieldType type,
     230                 :                                       std::string description,
     231                 :                                       std::string format,
     232                 :                                       ShapeField *default_value=NULL ) = 0;
     233                 : 
     234                 : /**
     235                 : \brief Create a new shape.
     236                 : 
     237                 : Newly created shapes have no geometry or attribute values. 
     238                 : 
     239                 : @param id The ShapeId to assign to the new shape, or default to assign the next available shapeid. 
     240                 : 
     241                 : @return the shapeid assigned to the newly created shape.
     242                 : */
     243                 : 
     244                 :         virtual ShapeId     CreateShape( ShapeId id = NullShapeId ) = 0;
     245                 : 
     246                 : /**
     247                 : \brief Delete a shape.
     248                 : 
     249                 : An exception is thrown if the shape does not exist.
     250                 : 
     251                 : @param id the shapeid to delete.
     252                 : 
     253                 : */
     254                 :         virtual void        DeleteShape( ShapeId id ) = 0;
     255                 : 
     256                 : /**
     257                 : \brief Assign vertices to shape. 
     258                 : 
     259                 : @param id the shape to assign vertices to.
     260                 : @param list the list of vertices to assign.
     261                 : */
     262                 : 
     263                 :         virtual void        SetVertices( ShapeId id, 
     264                 :                                          const std::vector<ShapeVertex> &list ) = 0;
     265                 : 
     266                 : 
     267                 : /**
     268                 : \brief Assign attribute value to a shape.
     269                 : 
     270                 : The list of fields should match the types and length from the schema 
     271                 : (GetFieldCount(), GetFieldType()). 
     272                 : 
     273                 : @param id the shape to update.
     274                 : @param list the list of field value to assign.
     275                 : */
     276                 :         virtual void        SetFields( ShapeId id, 
     277                 :                                        const std::vector<ShapeField>& list) = 0;
     278                 : 
     279                 : // Methods needed 
     280                 :         // DeleteField
     281                 :     };
     282                 : 
     283                 : /************************************************************************/
     284                 : /*                            ShapeIterator                             */
     285                 : /************************************************************************/
     286                 : 
     287                 : //! Iterator over shapeids in a vector segment.
     288                 : 
     289                 :     class ShapeIterator : public std::iterator<std::input_iterator_tag, ShapeId>
     290                 :     {
     291                 :         ShapeId id;
     292                 :         PCIDSKVectorSegment *seg;
     293                 :         
     294                 :     public:
     295               7 :         ShapeIterator(PCIDSKVectorSegment *seg_in)
     296               7 :                 : seg(seg_in)  { id = seg->FindFirst(); }
     297             487 :         ShapeIterator(PCIDSKVectorSegment *seg_in, ShapeId id_in )
     298             487 :                 : id(id_in), seg(seg_in)  {}
     299                 :         ShapeIterator(const ShapeIterator& mit) : id(mit.id), seg(mit.seg) {}
     300                 :         ShapeIterator& operator++() { id=seg->FindNext(id); return *this;}
     301                 :         ShapeIterator& operator++(int) { id=seg->FindNext(id); return *this;}
     302                 :         bool operator==(const ShapeIterator& rhs) {return id == rhs.id;}
     303                 :         bool operator!=(const ShapeIterator& rhs) {return id != rhs.id;}
     304                 :         ShapeId& operator*() {return id;}
     305                 :     };
     306                 : 
     307                 : } // end namespace PCIDSK
     308                 : 
     309                 : #endif // __INCLUDE_PCIDSK_VECTORSEGMENT_H

Generated by: LCOV version 1.7