Ice Sheet System Model  4.18
Code documentation
Functions
ShpRead.cpp File Reference
#include "./ShpRead.h"

Go to the source code of this file.

Functions

void ShpReadUsage (void)
 
 WRAPPER (ShpRead_python)
 

Function Documentation

◆ ShpReadUsage()

void ShpReadUsage ( void  )

Definition at line 16 of file ShpRead.cpp.

16  {/*{{{*/
17  _printf0_("ShpRead - Read shapefile\n");
18  _printf0_("\n");
19  _printf0_(" This module reads shapefiles and converts them to matlab/python structures\n");
20  _printf0_("\n");
21  _printf0_(" Usage:\n");
22  _printf0_(" ShpRead(filename);\n");
23  _printf0_(" filexp file name of exp file to be written\n");
24  _printf0_("\n");
25  _printf0_(" Examples:\n");
26  _printf0_(" ShpRead('file.shp');\n");
27 }/*}}}*/

◆ WRAPPER()

WRAPPER ( ShpRead_python  )

Definition at line 28 of file ShpRead.cpp.

28  {
29 
30  /*input: */
31  char *filename= NULL;
32 
33  /*Boot module: */
34  MODULEBOOT();
35 
36  #ifndef _HAVE_SHAPELIB_ //only works if shapelib library has been compiled in.
37  _error_("Shapelib not available! Cannot carry out shp file translation!");
38  #else
39 
40  /*checks on arguments on the matlab side: */
41  if(nlhs != NLHS){ShpReadUsage(); _error_("ShpRead usage error");}
42  if(nrhs != NRHS){ShpReadUsage(); _error_("ShpRead usage error");}
43 
44  /*Input datasets: */
45  FetchData(&filename,SHP_IN);
46 
47  /*Open shapefile*/
48  SHPHandle hSHP = SHPOpen( filename, "rb" );
49  if(!hSHP) _error_("Error opening shp/shx files.");
50 
51  /*read header and print out file bounds*/
52  int nShapeType,nEntities;
53  IssmPDouble adfMinBound[4], adfMaxBound[4];
54  SHPGetInfo( hSHP, &nEntities, &nShapeType, adfMinBound, adfMaxBound );
55  _printf_("Shapefile Type: "<<SHPTypeName(nShapeType)<<" number of Shapes: "<< nEntities<<"\n\n");
56 
57  /*Initialize output*/
58  Contours* contours = new Contours();
59 
60  /*Read all objects*/
61  for(int i=0; i<nEntities;i++ ){
62 
63  SHPObject* psShape = SHPReadObject(hSHP,i);
64  _printf_( "Shape #"<<i<<" ("<<SHPTypeName(psShape->nSHPType)<<") nVertices="<<psShape->nVertices<<", nParts="<<psShape->nParts<<"\n");
65 
66  Contour<double> *contour = NULL;
67 
68  switch(psShape->nSHPType){
69  case SHPT_ARC:
70  contour=new Contour<double>(0,psShape->nVertices,psShape->padfX,psShape->padfY,false);
71  break;
72  default:
73  _printf_("Shape type "<<SHPTypeName(psShape->nSHPType)<<"not supported yet, skipping...\n");
74  }
75 
76  /*Add to contours and clean up*/
77  if(contour) contours->AddObject(contour);
78  SHPDestroyObject(psShape);
79  }
80 
81  /*Write output*/
82  WriteData(SHP_OUT,contours);
83 
84  /*Clean-up*/
85  delete contours;
86  xDelete<char>(filename);
87 
88  #endif
89  /*end module: */
90  MODULEEND();
91 }
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
WriteData
void WriteData(IssmPDouble **pmatrix, int *pnel, int *matrix, int M, int N)
Definition: WriteJavascriptData.cpp:16
DataSet::AddObject
int AddObject(Object *object)
Definition: DataSet.cpp:252
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
NRHS
#define NRHS
Definition: BamgConvertMesh.h:52
Contours
Declaration of Contours class.
Definition: Contours.h:10
Contour
Definition: Contour.h:15
ShpReadUsage
void ShpReadUsage(void)
Definition: ShpRead.cpp:16
FetchData
void FetchData(char **pstring, char *stringin)
Definition: FetchJavascriptData.cpp:16
NLHS
#define NLHS
Definition: BamgConvertMesh.h:50
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
IssmPDouble
IssmDouble IssmPDouble
Definition: types.h:38