開発中の
Fortranのプログラムでシェープファイルを読み込めるようにしたかったので,モジュールを作った.
FortranGISという,シェープファイルを読み書きできる
Fortranのライブラリーがあるが,せっかくなので自分で作ってみたいと思って新しく作った.
モジュールとサンプルプログラム
+
shapefile.20201019.tar.gz
Variables
type shp_
type shp_entity_
type shp_part_
type dbf_
type dbf_field_
type dbf_record_
type dbf_value_
Procedures
subroutine SHPOpen
subroutine SHPClose
subroutine SHPGetInfo
subroutine SHPGetEntityInfo
subroutine SHPGetEntityData
subroutine SHPGetData
subroutine SHPGetAll
subroutine SHPClean
subroutine DBFOpen
subroutine DBFClose
subroutine DBFGetInfo
subroutine DBFGetRecord
subroutine DBFGetAll
subroutine DBFClean
Usually, only the following procedures are important:
subroutine SHPOpen( f )
Open the shp file
f.
subroutine SHPClose( )
Close the shp file opened with
SHPOpen.
subroutine SHPGetAll( shp )
Get all information and data of shp file opened with
SHPOpen.
subroutine SHPClean( shp )
Initialize and deallocate all the components of
shp.
subroutine DBFOpen( f )
Open the dbf file
f.
subroutine DBFClose( )
Close the dbf file opened with
DBFOpen.
subroutine DBFGetAll( dbf )
Get all information and data of dbf file opened with
DBFOpen.
subroutine DBFClean( dbf )
Initialize and deallocate all the components of
dbf.
Other procedures are used to get the specific information or data.
type(shp_)
Name |
Type |
Initial value |
nEntities |
int4 |
0 |
entity(:) |
*type(shp_entity_) |
|
SHPType |
int4 |
0 |
SHPTypeName |
char(16) |
/c_lightskyblue{(empty)} |
minBound(4) |
dble |
0.d0 |
maxBound(4) |
dble |
0.d0 |
type(shp_entity_)
Name |
Type |
Initial value |
id |
int4 |
0 |
nVertices |
int4 |
0 |
nParts |
int4 |
0 |
part(:) |
*type(shp_part_) |
|
xmin |
dble |
0.d0 |
xmax |
dble |
0.d0 |
ymin |
dble |
0.d0 |
ymax |
dble |
0.d0 |
zmin |
dble |
0.d0 |
zmax |
dble |
0.d0 |
mmin |
dble |
0.d0 |
mmax |
dble |
0.d0 |
measureIsUsed |
log4 |
.false. |
type(shp_part_)
Name |
Type |
Initial value |
id |
int4 |
0 |
nVertices |
int4 |
0 |
x(:) |
*dble |
|
y(:) |
*dble |
|
z(:) |
*dble |
|
m(:) |
*dble |
|
type(dbf_)
Name |
Type |
Initial value |
nFields |
int4 |
0 |
nRecords |
int4 |
0 |
field(:) |
*type(dbf_field_) |
|
record(:) |
*type(dbf_record_) |
|
type(dbf_field_)
Name |
Type |
Initial value |
typeChar |
char(1) |
/c_lightskyblue{(empty)} |
typeName |
char(7) |
/c_lightskyblue{(empty)} |
title |
char(64) |
/c_lightskyblue{(empty)} |
width |
int4 |
0 |
decimals |
int4 |
0 |
type(dbf_record_)
Name |
Type |
Initial value |
value(:) |
*type(dbf_value_) |
|
type(dbf_value_)
Name |
Type |
Initial value |
s |
*char(:) |
|
i |
int4 |
0 |
d |
dble |
0.d0 |
subroutine SHPOpen( f )
Open a file of shapefile format.
Argument |
Type |
Intent |
Description |
f |
char(*) |
in |
File name of the shapefile to open. |
subroutine SHPClose( )
Close the file opened with SHPOpen.
Argument |
Type |
Intent |
Description |
subroutine SHPGetInfo
An interface of:
SHPGetInfo_structure
SHPGetInfo_components
subroutine SHPGetInfo_structure( shp )
Get information of shapefile data:
shp%nEntities (the number of entities)
shp%SHPType (shape type)
shp%SHPTypeName (shape type name)
shp%minBound(:) (lower bounds of x, y, z and m)
shp%maxBound(:) (upper bounds of x, y, z and m)
Argument |
Type |
Intent |
Description |
shp |
type(shp_) |
inout |
|
subroutine SHPGetInfo_components( nEntities, SHPType, SHPTypeName, minBound, maxBound )
Same to SHPGetInfo_structure, but data are specified separately.
Argument |
Type |
Intent |
Description |
nEntities |
int4 |
out |
|
SHPType |
int4 |
out |
|
SHPTypeName |
char(*) |
out |
|
minBound(4) |
dble |
out |
|
maxBound(4) |
dble |
out |
|
subroutine SHPGetEntityInfo
An interface of:
SHPGetEntityInfo_structure
SHPGetEntityInfo_components
subroutine SHPGetEntityInfo_structure( iEntity, entity )
Get information of the iEntity-th entity, namely shp%entity(iEntity):
entity%nVertices (the number of vertices)
entity%nParts (the number of parts)
entity%measureIsUsed (if measure is used)
entity%xmin, entity%xmax (lower, upper bounds of x coordinates)
entity%ymin, entity%ymax ( " of y coordinates)
entity%zmin, entity%zmax ( " of z coordinates)
entity%mmin, entity%mmax ( " of m coordinates)
iEntity and
entity%iEntity must be equal. If vn{entity%iEntity} is 0,
iEntity is substituted to
entity%iEntity.
Argument |
Type |
Intent |
Description |
iEntity |
int4 |
in |
|
entity |
type(shp_entity_) |
out |
|
subroutine SHPGetEntityInfo_components( iEntity, nVertices, nParts, measureIsUsed, xmin, xmax, ymin, ymax, zmin, zmax, mmin, mmax )
Same to SHPGetEntityInfo_structure, but data are specified separately.
Argument |
Type |
Intent |
Description |
iEntity |
int4 |
in |
|
nVertices |
int4 |
out |
|
nParts |
int4 |
out |
|
measureIsUsed |
log4 |
out |
|
xmin |
dble |
out |
|
xmax |
dble |
out |
|
ymin |
dble |
out |
|
ymax |
dble |
out |
|
zmin |
dble |
out |
|
zmax |
dble |
out |
|
mmin |
dble |
out |
|
mmax |
dble |
out |
|
subroutine SHPGetEntityData( iEntity, entity )
Call
SHPGetEntityInfo.
Get data of the iEntity-th entity, namely shp%entity(iEntity):
for i = 1 ~ entity%nParts,
entity%part(i)%nVertices
entity%part(i)%x(:)
entity%part(i)%y(:)
entity%part(i)%z(:)
entity%part(i)%m(:) if entity%measureIsUsed is true
%part,
%part%x,
%part%y,
%part%z and
%part%m are allocated in this procedure.
Argument |
Type |
Intent |
Description |
iEntity |
int4 |
in |
|
entity |
type(shp_entity_) |
inout |
|
subroutine SHPGetData( shp )
Call
SHPGetInfo and call
SHPGetEntityData for all the entities.
Argument |
Type |
Intent |
Description |
shp |
type(shp_) |
inout |
|
subroutine SHPGetAll( shp )
Get all information and data of opened file with
SHPOpen.
Argument |
Type |
Intent |
Description |
shp |
type(shp_) |
inout |
|
subroutine SHPClean( shp )
Initialize and deallocate all the components of
shp.
Argument |
Type |
Intent |
Description |
shp |
type(shp_) |
inout |
|
subroutine DBFOpen( f )
Open the dbf file.
Argument |
Type |
Intent |
Description |
f |
char(*) |
in |
|
subroutine DBFClose( )
Close the dbf file opend with
DBFOpen.
Argument |
Type |
Intent |
Description |
subroutine DBFGetInfo
An interface of:
DBFGetInfo_structure
DBFGetInfo_components
subroutine DBFGetInfo_structure( dbf )
Get the number of records and field information:
dbf%nFields (the number of fields)
dbf%nRecords (the number of records)
for i = 1 ~ dbf%nFields,
dbf%field(i)%typeChar (a character corresponds to type name)
dbf%field(i)%typeName (type name of the field values)
dbf%field(i)%title (field title)
dbf%field(i)%width (width of the values)
dbf%field(i)%decimals (decimals of the values)
Argument |
Type |
Intent |
Description |
dbf |
type(dbf_) |
out |
|
subroutine DBFGetInfo_components( nFields, nRecords, typeChar, typeName, title, width, decimals )
Same to
DBFGetInfo_structure, but data are specifiled separately.
Argument |
Type |
Intent |
Description |
nFields |
int4 |
out |
|
nRecords |
int4 |
out |
|
typeChar(:) |
char(*) |
pointer |
|
typeName(:) |
char(*) |
pointer |
|
title(:) |
char(*) |
pointer |
|
width(:) |
int4 |
pointer |
|
decimals(:) |
int4 |
pointer |
|
subroutine DBFGetRecord( iRecord, field, record )
Get the values of all fields of the iRecord-th record.
Case that field(i)%typeChar is 'C' (char): record%value(i)%s
Case that field(i)%typeChar is 'N' (int4): record%value(i)%i
Case that field(i)%typeChar is 'D' (dble): record%value(i)%d
Argument |
Type |
Intent |
Description |
iRecord |
int4 |
in |
|
field(:) |
type(dbf_field_) |
in |
|
record |
type(dbf_record_) |
out |
|
subroutine DBFGetAll( dbf )
Get all information and data of dbf file opened with
DBFOpen.
Argument |
Type |
Intent |
Description |
dbf |
type(dbf_) |
inout |
|
subroutine DBFClean( dbf )
Initialize and deallocate all the components of
dbf.
Argument |
Type |
Intent |
Description |
dbf |
type(dbf_) |
inout |
|
Sample program
Output: