Commit 277526f1 authored by Reza  ANSARI's avatar Reza ANSARI
Browse files

ajout classe / methode lecture GeoShapeCollection a partir de shapefile, Reza

parent fc72b812
......@@ -15,6 +15,85 @@
namespace SOPHYA {
/*!
\class SHPReader
\ingroup ShapeLib
\brief a class with static methods to read shapefiles and fill GeoShapeCollection object
\sa SOPHYA::SLI_SHP_Interface
\sa SOPHYA::SLI_DBF_Interface
*/
/* --Methode-- */
GeoShapeType SHPReader::convert2GST(int type)
{
GeoShapeType gst=GST_unknown;
switch (type) {
case SHPT_POINT:
case SHPT_POINTZ:
case SHPT_POINTM:
gst=GST_point;
break;
case SHPT_ARC:
case SHPT_ARCZ:
case SHPT_ARCM:
gst=GST_Arc;
break;
case SHPT_POLYGON:
case SHPT_POLYGONZ:
case SHPT_POLYGONM:
gst=GST_Polygon;
break;
case SHPT_MULTIPOINT:
case SHPT_MULTIPOINTZ:
case SHPT_MULTIPOINTM:
gst=GST_MultiPoint;
break;
default:
gst=GST_unknown;
break;
}
return gst;
}
/* --Methode-- */
size_t SHPReader::Read(GeoShapeCollection & gsc, const std::string& shp_path)
{
if (prtlev_>0) std::cout<<"SHPReader::Read()/Info opening file:"<<shp_path<<std::endl;
SLI_SHP_Interface shp(shp_path);
if (prtlev_>2) shp.printHeader(std::cout);
for(int i=0;i<shp.getNShapes();i++) {
shp.selectShape(i);
int sht=shp.getShapeType();
GeoShapeType gst=convert2GST(sht);
if (sht == GST_unknown) {
std::cout << "SHPReader::Read() Shape type="<<sht<<" ("<<shp.ShapeType2Name(sht)<<") not handled "<<std::endl;
continue;
}
if (prtlev_>0)
std::cout << "SHPReader::Read() shape["<<i<<"] Type="<<shp.ShapeType2Name(sht)<<std::endl;
for(int iPart=0;iPart<shp.getNParts();iPart++) {
if (shp.getPartType(iPart) != SHPP_RING) {
int ptyp=shp.getPartType(iPart);
std::cout << " Part["<<iPart<<"] partType="<<ptyp<<" -> "<<shp.ShapePartType2Name(ptyp)<<std::endl;
continue;
}
int jbeg, jend;
shp.getVertexRange(iPart,jbeg,jend);
GeoShape gs(gst);
gsc.append(gs);
GeoShape& mgs=gsc[gsc.size()-1];
for(int j=jbeg;j<jend;j++) {
LongitudeLatitude ll(Angle(shp.getX(j), Angle::Degree), Angle(shp.getY(j), Angle::Degree), true);
GeoCoord gc(ll, shp.getZ(j));
mgs.append(gc);
}
}
}
return gsc.size();
}
/*!
\class SLI_SHP_Interface
\ingroup ShapeLib
......@@ -66,7 +145,7 @@ SLI_SHP_Interface::SLI_SHP_Interface(const std::string& a_path)
::SHPGetInfo( hSHP_, &nEntities_, &nShapeType_, adfMinBound_, adfMaxBound_ );
numShape_=-1;
psShape_=nullptr;
if (nEntities_>0) selectShape(0);
if (nEntities_>0) selectShape(0);
}
/* --Methode-- */
......
......@@ -16,7 +16,25 @@
namespace SOPHYA {
//--------------------------------------------------------------
//!
//--- reads in shapefile (and attribute file) and fills a GeoShapeCollection objet
class SHPReader {
public:
static GeoShapeType convert2GST(int typ);
//! default constructor -
explicit SHPReader(int prtlev=0) : prtlev_(prtlev) { }
//! read the shape file specified shapefile (shp_path) and fills the GeoShapeCollection object gsc
size_t Read(GeoShapeCollection & gsc, const std::string& shp_path);
inline size_t Read(GeoShapeCollection & gsc, const char * path)
{
std::string spath=path;
return Read(gsc, spath);
}
protected:
int prtlev_;
};
//--------------------------------------------------------------
//-- Interface to shape lib reading of shapelib
class SLI_SHP_Interface {
public:
......
......@@ -206,19 +206,22 @@ inline PInPersist& operator >> (PInPersist& is, GeoShape& gsh)
\class GeoShapeCollection
\ingroup SkyMap
\brief A collection of GeoShapes.
\brief A collection of GeoShapes, implemented as an extension of std::vector< GeoShape >
Although each GeoShape Object includes a DVList Info() object, the collection provides
also a global DVList object accessible through the GeoShapeCollection::Info() method
that can hold pairs of (key,value).
PPF I/O is provided through ObjFileIO<GeoShapeCollection>.
Most, possibly all std::vector< T > methods, such as size(), resize(), clear() can be used,
as well as element access operator [size_t k].
\sa SOPHYA::GeoShape
\sa SOPHYA::GeoCoord
\sa SOPHYA::ObjFileIO<GeoShapeCollection>
*/
class GeoShapeCollection : public AnyDataObj {
class GeoShapeCollection : public AnyDataObj , public std::vector< GeoShape > {
//! PPF handler helper class
// friend class ObjFileIO<GeoShape>;
public:
......@@ -227,30 +230,22 @@ public:
{ }
//! constructor with size (number of shapes) specification
GeoShapeCollection(size_t sz)
: v_shapes_(sz)
: std::vector<GeoShape>(sz)
{ }
//! copy constructor
GeoShapeCollection(GeoShapeCollection& a)
: v_shapes_(a.v_shapes_), info_(a.info_)
: std::vector<GeoShape>(a), info_(a.info_)
{ }
//! copy (or equal) operator
GeoShapeCollection& operator = (GeoShapeCollection& a)
{ v_shapes_=a.v_shapes_; info_=a.info_; return *this; }
//! return the size or the number of shapes in the collection
inline size_t size() const { return v_shapes_.size(); }
//! change the size or number of coordinate points in the objet
inline void resize(size_t sz) { v_shapes_.resize(sz); }
{ std::vector< GeoShape >::operator = (a); info_=a.info_; return *this; }
//! append a shape to the collection
inline void append(GeoShape const& gs)
{ v_shapes_.push_back(gs); }
{ this->push_back(gs); }
//! return a reference to the specified shape - NO bound checking performed
inline GeoShape& get(size_t k) { return v_shapes_[k]; }
inline GeoShape& get(size_t k) { return (*this)[k]; }
//! return the specified shape, const version - NO bound checking performed
inline GeoShape get(size_t k) const { return v_shapes_[k]; }
//! Element access operator (reference to) - NO bound checking performed
inline GeoShape& operator[] (size_t k) { return v_shapes_[k]; }
//! Element access operator, (reference to), const version - NO bound checking performed
inline GeoShape operator[] (size_t k) const { return v_shapes_[k]; }
inline GeoShape get(size_t k) const { return (*this)[k]; }
//! Return a reference to the associated DVList object
inline DVList& Info() const { return info_; }
/*! \brief print the object (ascii representation) on stream os - print level lev=0,1,2,3
......@@ -259,7 +254,7 @@ public:
std::ostream& print(std::ostream& os, int lev=0) const;
protected:
std::vector< GeoShape > v_shapes_;
// std::vector< GeoShape > v_shapes_;
mutable DVList info_;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment