20 use,
INTRINSIC :: iso_c_binding
24 INTEGER,
PARAMETER :: lencharattr=40, nshp=4, tshp=shpt_polygonz
26 TYPE(shpfileobject) :: shphandle
27 TYPE(shpobject) :: shpobj
29 CHARACTER(len=1024) :: filein, fileout, filereg
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
37 CALL get_command_argument(1,filein)
38 CALL get_command_argument(2,fileout)
39 CALL get_command_argument(3,filereg)
40 IF (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>'
50 shphandle = shpopen(trim(filein),
'rb')
52 IF (shpfileisnull(shphandle) .OR. dbffileisnull(shphandle))
THEN
53 print*,
'Error opening ',trim(filein),
' for reading'
58 CALL shpgetinfo(shphandle, nshpr, tshpr, minbound, maxbound, nfield, nrec)
59 print*,
'number and type of shapes:',nshpr,tshpr
61 OPEN(10, file=fileout)
62 OPEN(11, file=filereg)
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)
105 CALL shpclose(shphandle)
Fortran 2003 interface to the shapelib http://shapelib.maptools.org/ library.