Commit 07f476e7 authored by Reza  ANSARI's avatar Reza ANSARI
Browse files

Suite mise en place du module ShapeLib , Reza 04/05/2022

parent b1fa72bc
......@@ -4,7 +4,9 @@
=========================================================================
(C) LAL , CNRS/IN2P3 1998-2020
(C) Université Paris-Sud 2001-2020
(C) Irfu , CEA 1998-2020
(C) Irfu , CEA 1998-2022
(C) IJCLab , CNRS/IN2P3 2020-2022
(C) Université Paris-Saclay 2020-2022
-------------------------------------------------------------------------
SOPHYA is a collection of C++ classes designed for data analysis,
......@@ -19,16 +21,21 @@ licence. See the licence files in this directory:
Check http://www.sophya.org for more information on SOPHYA and installation instructions.
-------------------------------------------------------------------------
The code and documentation are grouped in 4 GIT reprositories:
The code and documentation are grouped in several GIT reprositories.
- The Sophya git repository group the following software modules,
grouped in a single repository in April 2022.
( https://gitlab.in2p3.fr/SOPHYA/Sophya )
* SophyaLib : SOPHYA foundation classes, stand-alone modules
(independent of external libraries) and the BuildMgr (Code management
scripts and tools)
* SophyaExtLibs : classes or functions which rely on external libraries
* SophyaProgs : Test programs and some utility codes which uses the SOPHYA library.
* SophyaProgs : Test programs and some utility codes which uses the SOPHYA library
- Two other repositories contains documentation and the related PI project:
* ProjectPI : the PI GUI and graphic framework and piapp, the interactive data
analysis tool
analysis tool ( https://gitlab.in2p3.fr/SOPHYA/ProjectPI )
* DocSophya : documentation, manual and example codes and scripts
( https://gitlab.in2p3.fr/SOPHYA/DocSophya )
-------------------------------------------------------------------------
SophyaExtLibs
-------------------------------------------------------------------------
......@@ -43,4 +50,6 @@ The code and documentation are grouped in 4 GIT reprositories:
* ISharp/ : interface module with the fast Spherical Harmonics Transform
c-library libsharp
* HDF5IOServer/ : Classes for handling SOPHYA objects read/write in HDF5 format
* ShapeLib/ : The shapelib c-library for reading ESRI shapefiles and interface
classes to ease their use in SOPHYA environment
(see http://shapelib.maptools.org for shapelib c-library )
......@@ -3,10 +3,10 @@ include ../../SophyaLib/BuildMgr/sophyamake.inc
all: $(SOPHYALIBP)libShapeLib.a
clean:
rm -f $(SOPHYAOBJP)dbfopen.o $(SOPHYAOBJP)safileio.o $(SOPHYAOBJP)sbnsearch.o $(SOPHYAOBJP)shpopen.o $(SOPHYAOBJP)shptree.o
rm -f $(SOPHYAOBJP)dbfopen.o $(SOPHYAOBJP)safileio.o $(SOPHYAOBJP)sbnsearch.o $(SOPHYAOBJP)shpopen.o $(SOPHYAOBJP)shptree.o $(SOPHYAOBJP)sopshapelintf.o
rm -f $(SOPHYALIBP)libShapeLib.a
$(SOPHYALIBP)libShapeLib.a : $(SOPHYAOBJP)dbfopen.o $(SOPHYAOBJP)safileio.o $(SOPHYAOBJP)sbnsearch.o $(SOPHYAOBJP)shpopen.o $(SOPHYAOBJP)shptree.o
$(SOPHYALIBP)libShapeLib.a : $(SOPHYAOBJP)dbfopen.o $(SOPHYAOBJP)safileio.o $(SOPHYAOBJP)sbnsearch.o $(SOPHYAOBJP)shpopen.o $(SOPHYAOBJP)shptree.o $(SOPHYAOBJP)sopshapelintf.o
$(AR) $(ARFLAGS) $@ $?
touch $(SOPHYAINCP)/SophyaConfInfo/libextsophya.objlist
......@@ -25,3 +25,23 @@ $(SOPHYAOBJP)shpopen.o: shpopen.c shapefil.h
$(SOPHYAOBJP)shptree.o: shptree.c shapefil.h
$(CCOMPILE) -o $@ shptree.c
$(SOPHYAOBJP)sopshapelintf.o: sopshapelintf.cc \
$(SOPHYAINCP)pexceptions.h \
$(SOPHYAINCP)machdefs.h sopshapelintf.h shapefil.h \
$(SOPHYAINCP)geoshape.h \
$(SOPHYAINCP)longlat.h \
$(SOPHYAINCP)angle.h \
$(SOPHYAINCP)sunitpcst.h \
$(SOPHYAINCP)pqnumber.h \
$(SOPHYAINCP)ppersist.h \
$(SOPHYAINCP)gnumd5.h \
$(SOPHYAINCP)ppfbinstream.h \
$(SOPHYAINCP)rawstream.h \
$(SOPHYAINCP)ppfnametag.h \
$(SOPHYAINCP)objfio.h \
$(SOPHYAINCP)anydataobj.h \
$(SOPHYAINCP)dvlist.h \
$(SOPHYAINCP)mutyv.h \
$(SOPHYAINCP)timestamp.h
$(CXXCOMPILE) $(CXXTEMPFLG) -o $@ sopshapelintf.cc
......@@ -7,6 +7,7 @@
#include "histinit.h"
#include "histats.h"
#include "skymap.h"
#include "sopshapelintf.h"
......@@ -33,7 +34,14 @@ DataTable shapelib_read(const std::string& a_path)
dt.AddFloatColumn("x");
dt.AddFloatColumn("y");
dt.AddFloatColumn("z");
dt.AddFloatColumn("xmol");
dt.AddFloatColumn("ymol");
dt.AddFloatColumn("xmercat");
dt.AddFloatColumn("ymercat");
MollweideProjection mollproj(Angle(0.));
MercatorProjection mercatproj(Angle(0.));
SLI_SHP_Interface shp(a_path);
shp.printHeader(a_out);
......@@ -41,7 +49,7 @@ DataTable shapelib_read(const std::string& a_path)
dbf.listFields(a_out);
int jfname = dbf.findFieldNum("NAME");
int jfcontinent = dbf.findFieldNum("CONTINENT");
MuTyV rec[10];
MuTyV rec[15];
int bValidate = 0;
int nInvalidCount = 0;
......@@ -87,6 +95,20 @@ DataTable shapelib_read(const std::string& a_path)
rec[6]=(float)shp.getX(j);
rec[7]=(float)shp.getY(j);
rec[8]=(float)shp.getZ(j);
// cout << "*DBG* LongitudeLatitude longit="<<Angle(shp.getX(j), Angle::Degree).ToDegree()
// <<" Lat="<<Angle(shp.getY(j), Angle::Degree).ToDegree()<<endl;
LongitudeLatitude ll(Angle(shp.getX(j), Angle::Degree), Angle(shp.getY(j), Angle::Degree), true);
double xp, yp;
bool fgokproj=mollproj.SphToPlane(ll,xp,yp);
if (fgokproj) {
rec[9]=xp; rec[10]=yp;
}
else { rec[9]=rec[10]=-99999.; }
fgokproj=mercatproj.SphToPlane(ll,xp,yp);
if (fgokproj) {
rec[11]=xp; rec[12]=yp;
}
else { rec[11]=rec[12]=-99999.; }
dt.AddLine(rec);
}
}
......@@ -101,7 +123,7 @@ DataTable shapelib_read(const std::string& a_path)
int main(int narg, char* arg[])
{
int rc=0;
cout << " ---- gbread.cc : Test de SimGaz (simulation d'un gaz de particules) ---- "<<endl;
cout << " ---- gbread.cc : Test de lecture de fichiers ESRI shapefile ---- "<<endl;
if (narg<3) {
cout<<" Usage: gbread InPath OutPPF \n"<<endl;
return 1;
......
......@@ -9,8 +9,9 @@ clean :
rm -f Objs/*.o Objs/gbread Objs/shptest Objs/dbfadd Objs/dbfcreate Objs/dbfdump Objs/shpadd
rm -f Objs/shpcreate Objs/shpdump Objs/shprewind Objs/shptreedump Objs/shputils
PKGHLIST = sopshapelintf.h shapefil.h
PKGOLIST = Objs/dbfopen.o Objs/shpopen.o Objs/shptree.o Objs/safileio.o Objs/sbnsearch.o
PKGHLIST = ../sopshapelintf.h ../shapefil.h
# PKGOLIST = Objs/dbfopen.o Objs/shpopen.o Objs/shptree.o Objs/safileio.o Objs/sbnsearch.o
PKGOLIST =
CXXCOPT = $(CXXCOMPILE)
# CXXCOPT = $(CXXCOMPILE) -ffast-math
......@@ -28,8 +29,8 @@ EXTLIBDIRLIB = $(EXTLIBBASEDIR)/lib/
## Link des programmes test
gbread : Objs/gbread
echo 'gbread made'
Objs/gbread : Objs/gbread.o $(PKGOLIST)
$(CXXLINK) -o Objs/gbread Objs/gbread.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
Objs/gbread : Objs/gbread.o
$(CXXLINK) -o Objs/gbread Objs/gbread.o $(SOPHYAEXTSLBLIST)
Objs/gbread.o : gbread.cc $(PKGHLIST)
$(CXXCOMPILE) -o Objs/gbread.o -I. gbread.cc
......@@ -85,36 +86,40 @@ Objs/shputils : Objs/shputils.o $(PKGOLIST)
$(CXXLINK) -o Objs/shputils Objs/shputils.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
###########
## Compilation des programmes test et des fichiers formant la librairie
## Compilation des fichiers formant la librairie
Objs/dbfopen.o : ../dbfopen.c $(PKGHLIST)
$(CCOMPILE) -o Objs/dbfopen.o -I. ../dbfopen.c
Objs/shpopen.o : ../shpopen.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shpopen.o -I. ../shpopen.c
Objs/shptree.o : ../shptree.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shptree.o -I. ../shptree.c
Objs/safileio.o : ../safileio.c $(PKGHLIST)
$(CCOMPILE) -o Objs/safileio.o -I. ../safileio.c
Objs/sbnsearch.o : ../sbnsearch.c $(PKGHLIST)
$(CCOMPILE) -o Objs/sbnsearch.o -I. ../sbnsearch.c
## Compilation des programmes test
Objs/shptest.o : shptest.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shptest.o -I. shptest.c
Objs/dbfadd.o : dbfadd.c $(PKGHLIST)
$(CCOMPILE) -o Objs/dbfadd.o -I. dbfadd.c
Objs/dbfcreate.o : dbfcreate.c $(PKGHLIST)
$(CCOMPILE) -o Objs/dbfcreate.o -I. dbfcreate.c
Objs/dbfdump.o : dbfdump.c $(PKGHLIST)
$(CCOMPILE) -o Objs/dbfdump.o -I. dbfdump.c
Objs/dbfopen.o : dbfopen.c $(PKGHLIST)
$(CCOMPILE) -o Objs/dbfopen.o -I. dbfopen.c
Objs/safileio.o : safileio.c $(PKGHLIST)
$(CCOMPILE) -o Objs/safileio.o -I. safileio.c
Objs/sbnsearch.o : sbnsearch.c $(PKGHLIST)
$(CCOMPILE) -o Objs/sbnsearch.o -I. sbnsearch.c
Objs/shpadd.o : shpadd.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shpadd.o -I. shpadd.c
Objs/shpcreate.o : shpcreate.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shpcreate.o -I. shpcreate.c
Objs/shpdump.o : shpdump.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shpdump.o -I. shpdump.c
Objs/shpopen.o : shpopen.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shpopen.o -I. shpopen.c
Objs/shprewind.o : shprewind.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shprewind.o -I. shprewind.c
Objs/shptree.o : shptree.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shptree.o -I. shptree.c
Objs/shptreedump.o : shptreedump.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shptreedump.o -I. shptreedump.c
Objs/shputils.o : shputils.c $(PKGHLIST)
......
# Makefile for various test and evaluation programs
# R. Ansari , (C) LAL+UPS , Jan 2019 / Feb. 2022
include $(SOPHYABASE)/include/sophyamake.inc
# Define our target list
all : gbread shptest dbfadd dbfcreate dbfdump shpadd shpcreate shpdump shprewind shptreedump shputils
clean :
rm -f Objs/*.o Objs/gbread Objs/shptest Objs/dbfadd Objs/dbfcreate Objs/dbfdump Objs/shpadd
rm -f Objs/shpcreate Objs/shpdump Objs/shprewind Objs/shptreedump Objs/shputils
PKGHLIST = ../sopshapelintf.h ../shapefil.h
PKGOLIST = Objs/dbfopen.o Objs/shpopen.o Objs/shptree.o Objs/safileio.o Objs/sbnsearch.o
CXXCOPT = $(CXXCOMPILE)
# CXXCOPT = $(CXXCOMPILE) -ffast-math
# CXXCOPT = c++ -DDarwin -I/usr/local/Sophya/include/ -O3 -fast -ffast-math -c
SOPHYAEXTLIBDIR = $(EXTBASE)
#### path for external libraries include and lib files
EXTLIBBASEDIR = $(SOPHYAEXTLIBDIR)
EXTLIBDIRINC = $(EXTLIBBASEDIR)/include/
EXTLIBDIRLIB = $(EXTLIBBASEDIR)/lib/
###########
## Link des programmes test
gbread : Objs/gbread
echo 'gbread made'
Objs/gbread : Objs/gbread.o $(PKGOLIST)
$(CXXLINK) -o Objs/gbread Objs/gbread.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
Objs/gbread.o : gbread.cc $(PKGHLIST)
$(CXXCOMPILE) -o Objs/gbread.o -I. gbread.cc
shptest : Objs/shptest
echo 'shptest made'
Objs/shptest : Objs/shptest.o $(PKGOLIST)
$(CXXLINK) -o Objs/shptest Objs/shptest.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
dbfadd : Objs/dbfadd
echo 'dbfadd made'
Objs/dbfadd : Objs/dbfadd.o $(PKGOLIST)
$(CXXLINK) -o Objs/dbfadd Objs/dbfadd.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
dbfcreate : Objs/dbfcreate
echo 'dbfcreate made'
Objs/dbfcreate : Objs/dbfcreate.o $(PKGOLIST)
$(CXXLINK) -o Objs/dbfcreate Objs/dbfcreate.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
dbfdump : Objs/dbfdump
echo 'dbfdump made'
Objs/dbfdump : Objs/dbfdump.o $(PKGOLIST)
$(CXXLINK) -o Objs/dbfdump Objs/dbfdump.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
shpadd : Objs/shpadd
echo 'shpadd made'
Objs/shpadd : Objs/shpadd.o $(PKGOLIST)
$(CXXLINK) -o Objs/shpadd Objs/shpadd.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
shpcreate : Objs/shpcreate
echo 'shpcreate made'
Objs/shpcreate : Objs/shpcreate.o $(PKGOLIST)
$(CXXLINK) -o Objs/shpcreate Objs/shpcreate.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
shpdump : Objs/shpdump
echo 'shpdump made'
Objs/shpdump : Objs/shpdump.o $(PKGOLIST)
$(CXXLINK) -o Objs/shpdump Objs/shpdump.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
shprewind : Objs/shprewind
echo 'shprewind made'
Objs/shprewind : Objs/shprewind.o $(PKGOLIST)
$(CXXLINK) -o Objs/shprewind Objs/shprewind.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
shptreedump : Objs/shptreedump
echo 'shptreedump made'
Objs/shptreedump : Objs/shptreedump.o $(PKGOLIST)
$(CXXLINK) -o Objs/shptreedump Objs/shptreedump.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
shputils : Objs/shputils
echo 'shputils made'
Objs/shputils : Objs/shputils.o $(PKGOLIST)
$(CXXLINK) -o Objs/shputils Objs/shputils.o $(PKGOLIST) $(SOPHYAEXTSLBLIST)
###########
## Compilation des fichiers formant la librairie
Objs/dbfopen.o : ../dbfopen.c $(PKGHLIST)
$(CCOMPILE) -o Objs/dbfopen.o -I. ../dbfopen.c
Objs/shpopen.o : ../shpopen.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shpopen.o -I. ../shpopen.c
Objs/shptree.o : ../shptree.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shptree.o -I. ../shptree.c
Objs/safileio.o : ../safileio.c $(PKGHLIST)
$(CCOMPILE) -o Objs/safileio.o -I. ../safileio.c
Objs/sbnsearch.o : ../sbnsearch.c $(PKGHLIST)
$(CCOMPILE) -o Objs/sbnsearch.o -I. ../sbnsearch.c
## Compilation des programmes test
Objs/shptest.o : shptest.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shptest.o -I. shptest.c
Objs/dbfadd.o : dbfadd.c $(PKGHLIST)
$(CCOMPILE) -o Objs/dbfadd.o -I. dbfadd.c
Objs/dbfcreate.o : dbfcreate.c $(PKGHLIST)
$(CCOMPILE) -o Objs/dbfcreate.o -I. dbfcreate.c
Objs/dbfdump.o : dbfdump.c $(PKGHLIST)
$(CCOMPILE) -o Objs/dbfdump.o -I. dbfdump.c
Objs/shpadd.o : shpadd.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shpadd.o -I. shpadd.c
Objs/shpcreate.o : shpcreate.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shpcreate.o -I. shpcreate.c
Objs/shpdump.o : shpdump.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shpdump.o -I. shpdump.c
Objs/shprewind.o : shprewind.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shprewind.o -I. shprewind.c
Objs/shptreedump.o : shptreedump.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shptreedump.o -I. shptreedump.c
Objs/shputils.o : shputils.c $(PKGHLIST)
$(CCOMPILE) -o Objs/shputils.o -I. shputils.c
//------------------------------------------------------------------------------------
// SOPHYA class library - (C) UPS+LAL IN2P3/CNRS , CEA-Irfu
// Interface to shapelib functions to read GIS files
// http://shapelib.maptools.org https://github.com/OSGeo/shapelib
// Avril 2022 - R. Ansari
// Version originale header-only - gardee pour memoire , et pour Guy Barrand
//------------------------------------------------------------------------------------
#ifndef SOPSHAPELINTF_H_SEEN
#define SOPSHAPELINTF_H_SEEN
#include <iostream>
#include <string>
#include <vector>
#include "shapefil.h"
namespace SOPHYA {
//--------------------------------------------------------------
//! Interface to attribute (DBF) reading part of shapelib
class SLI_SHP_Interface {
public:
//! convert the shape type to its string representation
static inline std::string ShapeType2Name(int st)
{
return ::SHPTypeName(st);
}
//! convert the shape part type to its string representation
static inline std::string ShapePartType2Name(int spt)
{
return ::SHPPartTypeName(spt);
}
//! constructor , opens the specified path using SHPOpen() - can throw SOPHYA::IOExc in case of failure of SHPOpen()
SLI_SHP_Interface(const std::string& a_path)
{
hSHP_ = ::SHPOpen(a_path.c_str(),"rb");
if( hSHP_ == nullptr ) {
cerr << "SLI_SHP_Interface(() ERROR SHPOpen(" << a_path << ") -> returned null" << std::endl;
throw SOPHYA::IOExc("SLI_SHP_Interface() - SHPOpen() returned null pointer");
}
::SHPGetInfo( hSHP_, &nEntities_, &nShapeType_, adfMinBound_, adfMaxBound_ );
numShape_=-1;
psShape_=nullptr;
if (nEntities_>0) selectShape(0);
}
//! destructor - calls SHPClose()
virtual ~SLI_SHP_Interface()
{
::SHPClose( hSHP_ );
if (psShape_) ::SHPDestroyObject(psShape_);
}
//! return the global shape type (for the whole file )
inline int getGlobalShapeType()
{
return nShapeType_;
}
//! return the global shape type name (string representation, for the whole file )
inline std::string getGlobalShapeTypeName()
{
return ::SHPTypeName(nShapeType_);
}
//! return the global min-max bound (the complete file) for coordinate i (0:x, 1:y, 2:z, 3:M)
inline void getGlobalBound(int i, double& bndmin, double& bndmax)
{
bndmin=adfMinBound_[i]; bndmax=adfMaxBound_[i];
}
//! return the global minimum bound for coordinate i
inline double getGlobalBoundMinimum(int i)
{
return adfMinBound_[i];
}
//! return the global maximum bound for coordinate i
inline double getGlobalBoundMaximum(int i)
{
return adfMaxBound_[i];
}
//! return the number of entities or shapes in the .shp file (alias for getNShapes() )
inline int getNEntities()
{
return nEntities_;
}
//! return the number of entities or shapes in the .shp file (alias for getNEntities() )
inline int getNShapes()
{
return nEntities_;
}
//! select the shape specified by the argument *num* - can throw ParmError or IOExc exceptions
int selectShape(int num)
{
//DBG cout<<"*DBG*selectShape("<<num<<")"<<" psShape_="<<hex<<psShape_<<" hsp= " << hex<<hSHP_<<dec<<endl;
if (num == numShape_) return num;
if ((num<0)||(num>=nEntities_))
throw SOPHYA::ParmError("SLI_SHP_Interface::selectShape(num) - num<0 || num>NEntities");
if (psShape_) ::SHPDestroyObject(psShape_);
psShape_ = nullptr;
psShape_ = ::SHPReadObject( hSHP_, num );
if (!psShape_)
throw SOPHYA::IOExc("SLI_DBF_FileHandler() - SHPOpen() returned null pointer");
numShape_=num;
return numShape_;
}
//! return the number of parts in the selected shape
inline int getNParts()
{
if (psShape_) return psShape_->nParts;
return -1;
}
//! return the shape type for the selected shape
inline int getShapeType()
{
return psShape_->nSHPType;
}
//! return the total number of vertices in the shape (for all its parts)
inline int getNVertices()
{
return psShape_->nVertices;
}
//! return the minimum bound for coordinate X
inline double getBoundMinimumX() { return psShape_->dfXMin; }
//! return the maximum bound for coordinate X
inline double getBoundMaximumX() { return psShape_->dfXMax; }
//! return the minimum bound for coordinate Y
inline double getBoundMinimumY() { return psShape_->dfYMin; }
//! return the maximum bound for coordinate Y
inline double getBoundMaximumY() { return psShape_->dfYMax; }
//! return the minimum bound for coordinate Z
inline double getBoundMinimumZ() { return psShape_->dfZMin; }
//! return the maximum bound for coordinate Z
inline double getBoundMaximumZ() { return psShape_->dfZMax; }
//! return the vertex range for part iPart (jvmin <= jv < jvmax)
void getVertexRange(int iPart, int& jvmin, int& jvmax)
{
jvmin=0; jvmax=psShape_->nVertices;
if ((psShape_->nParts>0)&&(iPart>=0)&&(iPart<psShape_->nParts)) {
jvmin=psShape_->panPartStart[iPart];
if (iPart<psShape_->nParts-1) jvmax=psShape_->panPartStart[iPart+1];
}
}
//! return the shape type for part iPart ( SHPP_RING if not SHPT_MULTIPATCH )
int getPartType(int iPart)
{
int rt=SHPP_RING;
if ((psShape_->nParts>0)&&(iPart>=0)&&(iPart<psShape_->nParts))
rt=psShape_->panPartType[iPart];
return rt;
}
//! return the X-ccordinate for vertex k
inline double getX(int k) { return psShape_->padfX[k]; }
//! return the Y-ccordinate for vertex k
inline double getY(int k) { return psShape_->padfY[k]; }
//! return the Z-ccordinate for vertex k
inline double getZ(int k) { return psShape_->padfY[k]; }
//! prints the file header information (number of shapes, type and bounds)
ostream& printHeader(ostream& os)
{
os << " SLI_SHP_Interface::printHeader() N-shapes="<<getNShapes()<<" Type="<<getGlobalShapeTypeName()
<<" Bounds: \n X: "<<getGlobalBoundMinimum(0)<<"-"<<getGlobalBoundMaximum(0)
<<" Y: "<<getGlobalBoundMinimum(1)<<"-"<<getGlobalBoundMaximum(1)
<<" Z: "<<getGlobalBoundMinimum(2)<<"-"<<getGlobalBoundMaximum(2)<<std::endl;
return os;
}
protected:
SHPHandle hSHP_;
int nShapeType_, nEntities_;
double adfMinBound_[4], adfMaxBound_[4];
int numShape_;
SHPObject* psShape_;
};
/* \brief Shape Types definition , from file shapefil.h :
\verbatim
SHPT_NULL 0
# 2D Shape Types (pre ArcView 3.x):
SHPT_POINT 1 Points
SHPT_ARC 3 Arcs (Polylines, possible in parts)
SHPT_POLYGON 5 Polygons (possible in parts)
SHPT_MULTIPOINT 8 MultiPoint (related points)
# 3D Shape Types (may include "measure" values for vertices):
SHPT_POINTZ 11
SHPT_ARCZ 13
SHPT_POLYGONZ 15
SHPT_MULTIPOINTZ 18
# 2D + Measure Types:
SHPT_POINTM 21
SHPT_ARCM 23
SHPT_POLYGONM 25
SHPT_MULTIPOINTM 28
# Complex (TIN-like) with Z, and Measure:
SHPT_MULTIPATCH 31
\endverbatim
*/
//--------------------------------------------------------------
//! Interface to attribute (DBF) reading part of shapelib
class SLI_DBF_Interface {
public:
//! constructor , opens the specified path using DBFOpen() - can throw SOPHYA::IOExc in case of failure of DBFOpen()
SLI_DBF_Interface(const std::string& a_path)
{
hDBF_ = ::DBFOpen( a_path.c_str(), "rb" );
if( hDBF_ == nullptr ) {
cerr << "SLI_DBF_Interface() ERROR DBFOpen(" << a_path << ") -> returned null" << std::endl;
throw SOPHYA::IOExc("SLI_DBF_Interface() - DBFOpen() returned null pointer");
}
n_fields_ = ::DBFGetFieldCount(hDBF_ );
n_records_ = ::DBFGetRecordCount(hDBF_);
}
//! destructor , calls DBFClose()
virtual ~SLI_DBF_Interface()
{
DBFClose( hDBF_ );
}
//! return the number of fields in the .dbf attribute file
inline int getNFields()
{
return n_fields_;
}
//! return the number of records in the .dbf attribute file . Each record contains nf=getNFields() fields
inline int getNRecords()
{
return n_records_;
}
//! return the type and title of the field *jfield*
DBFFieldType getFieldInfo(int jfield, std::string & Title, int& nWidth, int& nDecimals)
{
char title[24]; // minimum taille 12 d'apres la doc
const DBFFieldType eType = ::DBFGetFieldInfo( hDBF_, jfield, title, &nWidth, &nDecimals );
Title = title;
return eType;
}
//! return the field number matching the specified title, -1 if not found
int findFieldNum(std::string title)
{
std::string tit;
int nWidth, nDecimals;
for( int j = 0; j < n_fields_; j++ ) {
DBFFieldType eType = getFieldInfo(j, tit, nWidth, nDecimals);
if (tit == title) return j;
}
return -1;
}
//! return the value for record number irec and field number jfield
MuTyV getFieldValue(int irec, int jfield)
{
MuTyV mtv;
getFieldValue(irec, jfield, mtv);
return mtv;
}
//! return true if the value for record number irec and field number jfield exist , and its value in mtv
bool getFieldValue(int irec, int jfield, MuTyV & mtv)
{
mtv = MuTyV((int_4)0);
if ((irec<0)||(irec>=n_records_)||(jfield<0)||(jfield>=n_fields_)) return false;
char szTitle[24];
int nWidth;
int nDecimals;
const DBFFieldType eType = ::DBFGetFieldInfo( hDBF_, jfield, szTitle, &nWidth, &nDecimals );
if( ::DBFIsAttributeNULL( hDBF_, irec, jfield ) ) return false;
string sv;
int iv;
double dv;
switch( eType ) {
case FTString:
sv=::DBFReadStringAttribute( hDBF_, irec, jfield );
mtv=sv;
break;
case FTInteger:
iv=::DBFReadIntegerAttribute( hDBF_, irec, jfield );
mtv=iv;
break;
case FTDouble:
dv=::DBFReadDoubleAttribute( hDBF_, irec, jfield );
break;
default:
break;