13 CHARACTER(len=1024) :: filein, fileout
16 INTEGER,
ALLOCATABLE :: shapesize(:)
17 INTEGER :: i, j, dot, nshape, id
18 DOUBLE PRECISION,
ALLOCATABLE :: shp(:,:)
20 CALL getarg(1, filein)
21 dot = index(filein,
'.', back=.true.)
23 fileout = trim(filein)//
'_out' 24 ELSE IF (dot == 1)
THEN 27 fileout = filein(:dot-1)
33 DO WHILE(read_ungenerate_shape(10) >= 0)
38 print*,
'Error, bad number of shapes ',nshape,
' in file ',trim(filein)
41 print*,
'Found ',nshape,
' shapes' 42 ALLOCATE(shapesize(nshape))
47 shapesize(i) = read_ungenerate_shape(10)
48 IF (shapesize(i) < 0)
THEN 49 print*,
'Error, bad size of shape ',i,shapesize(i),
' in file ',trim(filein)
53 print*,
'Counted shapes' 54 ALLOCATE(shp(maxval(shapesize),2))
56 shapefile = shpcreate(fileout, shpt_arc)
57 IF (shpfileisnull(shapefile) .OR. dbffileisnull(shapefile))
THEN 58 print*,
'Error, opening output shapefile ',trim(fileout)
61 j = dbfaddfield(shapefile,
'ID', ftinteger, 9, 0)
65 j = read_ungenerate_shape(10, shapeid=id, values=shp)
66 shapes = shpcreatesimpleobject(shpt_arc, shapesize(i), shp(1,1), shp(1,2))
67 j = shpwriteobject(shapefile, -1, shapes)
69 CALL shpdestroyobject(shapes)
73 CALL shpclose(shapefile)
80 FUNCTION read_ungenerate_shape(unit, shapeid, values) RESULT(read_status)
81 INTEGER,
INTENT(in) :: unit
82 INTEGER,
INTENT(out),
OPTIONAL :: shapeid
83 DOUBLE PRECISION,
INTENT(out),
OPTIONAL :: values(:,:)
84 INTEGER :: read_status
86 CHARACTER(len=1024) :: line
87 INTEGER :: npts, nptsmax, lshapeid
88 DOUBLE PRECISION :: x(2)
91 IF (
PRESENT(values))
THEN 92 IF (
SIZE(values,2) >= 2)
THEN 93 nptsmax =
SIZE(values,1)
97 READ(unit,
'(A)',end=120,err=120)line
98 IF (line ==
'END')
THEN 103 READ(line,
'(I10.0)',end=120,err=120) lshapeid
104 IF (
PRESENT(shapeid)) shapeid = lshapeid
105 IF (lshapeid < 0)
GOTO 120
109 READ(unit,
'(A)',end=120,err=120)line
110 IF (line ==
'END')
THEN 114 READ(line,*,end=120,err=120)x
116 IF (nptsmax >= npts) values(npts,1:2) = x(:)
125 END FUNCTION read_ungenerate_shape
Interface to FUNCTIONs for setting 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.