20 use,
INTRINSIC :: iso_c_binding
24 INTEGER,
PARAMETER :: lencharattr=40, nshp=4, tshp=shpt_polygonz
29 CHARACTER(len=1024) :: filename
31 INTEGER :: nshpr, tshpr, nfield, nrec, nd
32 REAL(kind=c_double) :: minbound(4), maxbound(4)
33 CHARACTER(len=lencharattr) :: charattrr
35 REAL(kind=c_double) :: doubleattrr
42 filename =
'testshape' 48 shphandle = shpcreate(trim(filename), tshp)
50 IF (shpfileisnull(shphandle) .OR. dbffileisnull(shphandle))
THEN 51 print*,
'Error opening ',trim(filename),
' for writing' 56 j = dbfaddfield(shphandle,
'name', ftstring, lencharattr, 0)
58 print*,
'Error in dbfaddfield',0,j
61 j = dbfaddfield(shphandle,
'number', ftinteger, 10, 0)
63 print*,
'Error in dbfaddfield',1,j
66 j = dbfaddfield(shphandle,
'size', ftdouble, 30, 20)
68 print*,
'Error in dbfaddfield',2,j
74 print*,
'Creating shape',i
79 shpobj = shpcreatesimpleobject(tshp, &
80 SIZE(makesimpleshp(i, 0)), &
81 makesimpleshp(i, 0), &
82 makesimpleshp(i, 1), &
87 j = shpwriteobject(shphandle, -1, shpobj)
89 print*,
'Error in shpwriteobject',i,j
94 CALL shpdestroyobject(shpobj)
102 print*,
'Error in dbfwriteattribute, char',j
107 print*,
'Error in dbfwriteattribute, int',j
112 print*,
'Warning in dbfwriteattribute, double',j
118 CALL shpclose(shphandle)
125 shphandle = shpopen(trim(filename),
'rb')
127 IF (shpfileisnull(shphandle) .OR. dbffileisnull(shphandle))
THEN 128 print*,
'Error opening ',trim(filename),
' for reading' 133 CALL shpgetinfo(shphandle, nshpr, tshpr, minbound, maxbound, nfield, nrec)
134 IF (nshpr /= nshp)
THEN 135 print*,
'Error in shpgetinfo, wrong number of shapes',nshp,nshpr
138 IF (tshpr /= tshp)
THEN 139 print*,
'Error in shpgetinfo, wrong type of shapes',tshp,tshpr
142 IF (nfield /= 3)
THEN 143 print*,
'Error in shpgetinfo, wrong number of fields',3,nfield
146 IF (nrec /= nshp)
THEN 147 print*,
'Error in shpgetinfo, wrong number of records',nshp,nrec
153 print*,
'Checking shape',i
155 shpobj = shpreadobject(shphandle, i)
157 IF (shpisnull(shpobj))
THEN 158 print*,
'Error in shpreadobject',i
164 IF (shpobj%nvertices /=
SIZE(makesimpleshp(i,0)))
THEN 165 print*,
'Error in shpreadobject, wrong number of vertices',i,&
166 SIZE(makesimpleshp(i,0)),shpobj%nvertices
170 IF (any(shpobj%padfx(:) /= makesimpleshp(i,0)))
THEN 171 print*,
'Error in shpreadobject, discrepancies in x',i
172 print*,makesimpleshp(i,0)
173 print*,shpobj%padfx(:)
177 IF (any(shpobj%padfy(:) /= makesimpleshp(i,1)))
THEN 178 print*,
'Error in shpreadobject, discrepancies in y',i
179 print*,makesimpleshp(i,1)
180 print*,shpobj%padfy(:)
184 IF (any(shpobj%padfz(:) /= makesimpleshp(i,2)))
THEN 185 print*,
'Error in shpreadobject, discrepancies in z',i
186 print*,makesimpleshp(i,2)
187 print*,shpobj%padfz(:)
193 CALL shpdestroyobject(shpobj)
198 IF (charattrr /= makechardbf(i))
THEN 199 print*,
'Error in dbfreadattribute, discrepancies in char' 200 print*,makechardbf(i)
206 IF (intattrr /= makeintdbf(i))
THEN 207 print*,
'Error in dbfreadattribute, discrepancies in int' 214 IF (doubleattrr /= makedoubledbf(i))
THEN 216 print*,
'Warning in dbfreadattribute, discrepancies in double' 217 print*,makedoubledbf(i)
224 CALL shpclose(shphandle)
229 FUNCTION makesimpleshp(nshp, ncoord) RESULT(shp)
230 INTEGER,
INTENT(in) :: nshp, ncoord
231 REAL(kind=c_double) :: shp(nshp+2)
235 shp(:) = (/(-100.0_c_double + &
236 10.0_c_double*i + 100.0_c_double*nshp + 1000.0_c_double*ncoord, &
239 END FUNCTION makesimpleshp
241 FUNCTION makechardbf(nshp) RESULT(dbf)
242 INTEGER,
INTENT(in) :: nshp
243 CHARACTER(len=lencharattr) :: dbf
248 dbf(i:i) = char(32 + mod(i+2*nshp,32))
251 END FUNCTION makechardbf
253 FUNCTION makeintdbf(nshp) RESULT(dbf)
254 INTEGER,
INTENT(in) :: nshp
259 END FUNCTION makeintdbf
261 FUNCTION makedoubledbf(nshp) RESULT(dbf)
262 INTEGER,
INTENT(in) :: nshp
263 REAL(kind=c_double) :: dbf
265 dbf = -5.894823e+12_c_double + 8.4827943e+11*nshp
267 END FUNCTION makedoubledbf
269 END PROGRAM shapelib_test
Interface to FUNCTIONs for setting dbf attributes.
Interface to SUBROUTINEs for reading dbf attributes.
Object describing the geometrical properties of a shape.
Fortran 2003 interface to the shapelib http://shapelib.maptools.org/ library.
Object describing a shapefile dataset.