20use,
INTRINSIC :: iso_c_binding
24INTEGER,
PARAMETER :: lencharattr=40, nshp=4, tshp=shpt_polygonz
26TYPE(shpfileobject) :: shphandle
27TYPE(shpobject) :: shpobj
29CHARACTER(len=1024) :: filein, fileout, filereg
31INTEGER :: nshpr, tshpr, nfield, nrec, nd
32REAL(kind=c_double) :: minbound(4), maxbound(4)
33CHARACTER(len=lencharattr) :: charattrr
35REAL(kind=c_double) :: doubleattrr
37CALL get_command_argument(1,filein)
38CALL get_command_argument(2,fileout)
39CALL get_command_argument(3,filereg)
40IF (filein ==
'' .OR. fileout ==
'' .OR. filereg ==
'')
THEN
41 print
'(A)',
'Convert a shapefile (with polygons) in the dump format required by'
42 print
'(A)',
'the shape2fxtr.pl utilities of fieldextra and directly in the'
43 print
'(A)',
'region file format required by fieldextra.'
44 print
'(A)',
'Usage: shp_fxtr <shp_file> <dump_file> <reg_file>'
50shphandle = shpopen(trim(filein),
'rb')
52IF (shpfileisnull(shphandle) .OR. dbffileisnull(shphandle))
THEN
53 print*,
'Error opening ',trim(filein),
' for reading'
58CALL shpgetinfo(shphandle, nshpr, tshpr, minbound, maxbound, nfield, nrec)
59print*,
'number and type of shapes:',nshpr,tshpr
65 print*,
'Checking shape',i
67 shpobj = shpreadobject(shphandle, i)
69 IF (shpisnull(shpobj))
THEN
70 print*,
'Error in shpreadobject',i
76 print*,
'nvertices:',shpobj%nvertices
77 IF (
ASSOCIATED(shpobj%panpartstart))
THEN
80 IF (
SIZE(shpobj%panpartstart) > 1)
THEN
81 print*,
'Warning, multipart shapes not supported in the conversion'
82 print*,
'skipping shape ',i+1
86 IF (shpobj%nvertices >= 3)
THEN
88 DO j = 1, shpobj%nvertices
89 WRITE(10,
'(F0.5,1X,F0.5,1X,I0)')shpobj%padfx(j),shpobj%padfy(j),i+1
92 WRITE(11,
'(I4,1X,I6,1X,''region_'',I0)')0,shpobj%nvertices,i+1
93 WRITE(11,
'(*(E10.5,1X))')shpobj%padfy(:)
94 WRITE(11,
'(*(E10.5,1X))')shpobj%padfx(:)
100 CALL shpdestroyobject(shpobj)
105CALL shpclose(shphandle)
Fortran 2003 interface to the shapelib http://shapelib.maptools.org/ library.