45 use,
INTRINSIC :: iso_c_binding
50 INTEGER,
PARAMETER :: READOSM_UNDEFINED = -1234567890
51 INTEGER,
PARAMETER :: READOSM_MEMBER_NODE = 7361
52 INTEGER,
PARAMETER :: READOSM_MEMBER_WAY = 6731
53 INTEGER,
PARAMETER :: READOSM_MEMBER_RELATION = 3671
54 INTEGER,
PARAMETER :: READOSM_OK = 0
55 INTEGER,
PARAMETER :: READOSM_INVALID_SUFFIX = -1
56 INTEGER,
PARAMETER :: READOSM_FILE_NOT_FOUND = -2
57 INTEGER,
PARAMETER :: READOSM_NULL_HANDLE = -3
58 INTEGER,
PARAMETER :: READOSM_INVALID_HANDLE = -4
59 INTEGER,
PARAMETER :: READOSM_INSUFFICIENT_MEMORY = -5
60 INTEGER,
PARAMETER :: READOSM_CREATE_XML_PARSER_ERROR = -6
61 INTEGER,
PARAMETER :: readosm_read_error = -7
62 INTEGER,
PARAMETER :: readosm_xml_error = -8
63 INTEGER,
PARAMETER :: readosm_invalid_pbf_header = -9
64 INTEGER,
PARAMETER :: readosm_unzip_error = -10
65 INTEGER,
PARAMETER :: readosm_abort = -11
76 CHARACTER(kind=c_char,len=1),
ALLOCATABLE :: key(:)
77 CHARACTER(kind=c_char,len=1),
ALLOCATABLE ::
value(:)
90 TYPE,
BIND(C) :: readosm_node
91 INTEGER(kind=c_long_long) :: id
92 REAL(kind=c_double) :: latitude
93 REAL(kind=c_double) :: longitude
94 INTEGER(kind=c_int) :: version
95 INTEGER(kind=c_long_long) :: changeset
97 INTEGER(kind=c_int) :: uid
98 TYPE(c_ptr) :: timestamp
99 INTEGER(kind=c_int) :: tag_count
105 INTEGER(kind=c_long_long) :: id=0
106 REAL(kind=c_double) :: latitude
107 REAL(kind=c_double) :: longitude
108 INTEGER(kind=c_int) :: version
109 INTEGER(kind=c_long_long) :: changeset
111 INTEGER(kind=c_int) :: uid
130 INTEGER(kind=c_long_long) :: id
131 INTEGER(kind=c_int) :: version;
132 INTEGER(kind=c_long_long) :: changeset
134 INTEGER(kind=c_int) :: uid
135 TYPE(c_ptr) :: timestamp;
136 INTEGER(kind=c_int) :: node_ref_count
137 TYPE(c_ptr) :: node_refs
138 INTEGER(kind=c_int) :: tag_count
144 INTEGER(kind=c_long_long) :: id=0
145 INTEGER(kind=c_int) :: version;
146 INTEGER(kind=c_long_long) :: changeset;
148 INTEGER(kind=c_int) :: uid
150 INTEGER(kind=c_long_long),
ALLOCATABLE :: node_refs(:)
162 INTEGER(kind=c_int) :: member_type
163 INTEGER(kind=c_long_long) :: id
169 INTEGER(kind=c_int) :: member_type=readosm_undefined
170 INTEGER(kind=c_long_long) :: id
171 CHARACTER(kind=c_char,len=1),
ALLOCATABLE :: role(:)
187 INTEGER(kind=c_long_long) :: id
188 INTEGER(kind=c_int) :: version;
189 INTEGER(kind=c_long_long) :: changeset;
191 INTEGER(kind=c_int) :: uid
192 TYPE(c_ptr) :: timestamp;
193 INTEGER(kind=c_int) :: member_count
194 TYPE(c_ptr) :: members
195 INTEGER(kind=c_int) :: tag_count;
201 INTEGER(kind=c_long_long) :: id
202 INTEGER(kind=c_int) :: version;
203 INTEGER(kind=c_long_long) :: changeset;
205 INTEGER(kind=c_int) :: uid
212 #undef ARRAYOF_ORIGEQ
214 #undef ARRAYOF_ORIGTYPE
216 #define ARRAYOF_ORIGTYPE TYPE(readosm_node_f)
217 #define ARRAYOF_TYPE arrayof_readosm_node_f
218 #include "arrayof_pre.F90"
220 #undef ARRAYOF_ORIGTYPE
222 #define ARRAYOF_ORIGTYPE TYPE(readosm_way_f)
223 #define ARRAYOF_TYPE arrayof_readosm_way_f
224 #include "arrayof_pre.F90"
226 #undef ARRAYOF_ORIGTYPE
228 #define ARRAYOF_ORIGTYPE TYPE(readosm_relation_f)
229 #define ARRAYOF_TYPE arrayof_readosm_relation_f
230 #include "arrayof_pre.F90"
253 CHARACTER(kind=c_char),
INTENT(in) :: path(*)
254 TYPE(c_ptr),
INTENT(out) :: osm_handle
268 TYPE(c_ptr),
VALUE :: osm_handle
269 INTEGER(kind=c_int) :: readosm_close
286 FUNCTION readosm_parse(osm_handle, user_data, node_fnct, way_fnct, &
287 relation_fnct) bind(C,name='readosm_parse')
289 TYPE(c_ptr),
VALUE :: osm_handle
290 TYPE(c_ptr),
VALUE :: user_data
291 TYPE(c_funptr),
VALUE :: node_fnct
292 TYPE(c_funptr),
VALUE :: way_fnct
293 TYPE(c_funptr),
VALUE :: relation_fnct
294 INTEGER(kind=c_int) :: readosm_parse
297 MODULE PROCEDURE readosm_parse_f
301 INTERFACE readosm_object_f
302 MODULE PROCEDURE readosm_object_f_node, readosm_object_f_way, &
303 readosm_object_f_relation
304 END INTERFACE readosm_object_f
310 PRIVATE readosm_object_f_node, readosm_object_f_way, &
311 readosm_object_f_relation
322 FUNCTION readosm_parse_f(osm_handle, user_data, node_fnct, way_fnct, &
324 TYPE(c_ptr),
VALUE :: osm_handle
325 TYPE(c_ptr),
VALUE :: user_data
326 INTERFACE !< callback
function intended to consume node objects (may be NULL if processing NODEs is not an interesting option)
327 FUNCTION node_fnct(user_data, node)
BIND(C)
329 TYPE(c_ptr),
VALUE :: user_data
330 TYPE(readosm_node) :: node
331 INTEGER(kind=c_int) :: node_fnct
332 END FUNCTION node_fnct
337 FUNCTION way_fnct(user_data, way)
BIND(C)
339 TYPE(c_ptr),
VALUE :: user_data
341 INTEGER(kind=c_int) :: way_fnct
342 END FUNCTION way_fnct
347 FUNCTION relation_fnct(user_data, relation)
BIND(C)
349 TYPE(c_ptr),
VALUE :: user_data
351 INTEGER(kind=c_int) :: relation_fnct
352 END FUNCTION relation_fnct
355 OPTIONAL :: node_fnct
357 OPTIONAL :: relation_fnct
358 INTEGER(kind=c_int) :: readosm_parse_f
360 TYPE(c_funptr) :: nf, wf, rf
362 IF (
present(node_fnct))
THEN
363 nf = c_funloc(node_fnct)
367 IF (
present(way_fnct))
THEN
368 wf = c_funloc(way_fnct)
372 IF (
present(relation_fnct))
THEN
373 rf = c_funloc(relation_fnct)
378 readosm_parse_f =
readosm_parse(osm_handle, user_data, nf, wf, rf)
380 END FUNCTION readosm_parse_f
386 SUBROUTINE readosm_object_f_tags(tags, tag_count, f_type)
388 INTEGER(kind=c_int) :: tag_count;
395 IF (tag_count > 0 .AND. c_associated(tags))
THEN
396 CALL c_f_pointer(tags, tmptags, (/tag_count/))
397 ALLOCATE(f_type(tag_count))
399 f_type(i)%key = tmptags(i)%key
400 f_type(i)%value = tmptags(i)%value
406 END SUBROUTINE readosm_object_f_tags
412 SUBROUTINE readosm_object_f_members(members, member_count, f_type)
413 TYPE(c_ptr) :: members
414 INTEGER(kind=c_int) :: member_count;
421 IF (member_count > 0 .AND. c_associated(members))
THEN
422 CALL c_f_pointer(members, tmpmembers, (/member_count/))
423 ALLOCATE(f_type(member_count))
424 DO i = 1, member_count
425 f_type(i)%member_type = tmpmembers(i)%member_type
426 f_type(i)%id = tmpmembers(i)%id
427 f_type(i)%role = tmpmembers(i)%role
433 END SUBROUTINE readosm_object_f_members
436 FUNCTION readosm_object_f_node(c_type)
RESULT(f_type)
441 f_type%id = c_type%id
442 f_type%latitude = c_type%latitude
443 f_type%longitude = c_type%longitude
444 f_type%version = c_type%version
445 f_type%changeset = c_type%changeset
447 f_type%uid = c_type%uid
449 CALL readosm_object_f_tags(c_type%tags, c_type%tag_count, f_type%tags)
452 END FUNCTION readosm_object_f_node
455 FUNCTION readosm_object_f_way(c_type)
RESULT(f_type)
460 INTEGER(kind=c_long_long),
POINTER :: node_refs(:)
462 f_type%id = c_type%id
463 f_type%version = c_type%version
464 f_type%changeset = c_type%changeset
466 f_type%uid = c_type%uid
468 IF (c_type%node_ref_count > 0 .AND. c_associated(c_type%node_refs))
THEN
469 CALL c_f_pointer(c_type%node_refs, node_refs, (/c_type%node_ref_count/))
470 f_type%node_refs = node_refs
472 ALLOCATE(f_type%node_refs(0))
474 CALL readosm_object_f_tags(c_type%tags, c_type%tag_count, f_type%tags)
477 END FUNCTION readosm_object_f_way
480 FUNCTION readosm_object_f_relation(c_type)
RESULT(f_type)
485 f_type%id = c_type%id
486 f_type%version = c_type%version
487 f_type%changeset = c_type%changeset
489 f_type%uid = c_type%uid
491 CALL readosm_object_f_members(c_type%members, c_type%member_count, f_type%members)
492 CALL readosm_object_f_tags(c_type%tags, c_type%tag_count, f_type%tags)
495 END FUNCTION readosm_object_f_relation
499 #undef ARRAYOF_ORIGEQ
501 #undef ARRAYOF_ORIGTYPE
503 #define ARRAYOF_ORIGTYPE TYPE(readosm_node_f)
504 #define ARRAYOF_TYPE arrayof_readosm_node_f
505 #include "arrayof_post.F90"
507 #undef ARRAYOF_ORIGTYPE
509 #define ARRAYOF_ORIGTYPE TYPE(readosm_way_f)
510 #define ARRAYOF_TYPE arrayof_readosm_way_f
511 #include "arrayof_post.F90"
513 #undef ARRAYOF_ORIGTYPE
515 #define ARRAYOF_ORIGTYPE TYPE(readosm_relation_f)
516 #define ARRAYOF_TYPE arrayof_readosm_relation_f
517 #include "arrayof_post.F90"
529 FUNCTION readosm_parse_full_f(osm_handle, fulldata)
530 TYPE(c_ptr),
VALUE :: osm_handle
531 TYPE(readosm_full_f),
INTENT(inout),
TARGET :: fulldata
532 INTEGER :: readosm_parse_full_f
535 readosm_parse_full_f =
readosm_parse(osm_handle, c_loc(fulldata), &
536 readosm_full_node, readosm_full_way, readosm_full_relation)
542 END FUNCTION readosm_parse_full_f
548 FUNCTION readosm_full_node(user_data, node)
BIND(C)
549 TYPE(c_ptr),
VALUE :: user_data
550 TYPE(readosm_node) :: node
551 INTEGER(kind=c_int) :: readosm_full_node
553 TYPE(readosm_full_f),
POINTER :: fulldata
557 CALL c_f_pointer(user_data, fulldata)
558 CALL insert(fulldata%nodes, readosm_object_f(node))
560 readosm_full_node = readosm_ok
562 END FUNCTION readosm_full_node
568 FUNCTION readosm_full_way(user_data, way)
BIND(C)
569 TYPE(c_ptr),
VALUE :: user_data
571 INTEGER(kind=c_int) :: readosm_full_way
577 CALL c_f_pointer(user_data, fulldata)
578 CALL insert(fulldata%ways, readosm_object_f(way))
580 readosm_full_way = readosm_ok
582 END FUNCTION readosm_full_way
588 FUNCTION readosm_full_relation(user_data, relation)
BIND(C)
589 TYPE(c_ptr),
VALUE :: user_data
591 INTEGER(kind=c_int) :: readosm_full_relation
597 CALL c_f_pointer(user_data, fulldata)
598 CALL insert(fulldata%relations, readosm_object_f(relation))
600 readosm_full_relation = readosm_ok
602 END FUNCTION readosm_full_relation
Method for inserting elements of the array at a desired position.
Method for packing the array object reducing at a minimum the memory occupation, without destroying i...
Close the .osm or .pbf file and release any allocated resource.
Open the .osm or .pbf file, preparing for future functions.
Parse the corresponding file calling the selected callbacks for every entity encountered.
Utility module for supporting Fortran 2003 C language interface module.
Fortran 2003 interface to the readosm https://www.gaia-gis.it/fossil/readosm/index library.
Derived type defining a dynamically extensible array of TYPE(readosm_node_f) elements.
Derived type defining a dynamically extensible array of TYPE(readosm_relation_f) elements.
Derived type defining a dynamically extensible array of TYPE(readosm_way_f) elements.
Derived type for performing a prepackaged full parsing of an osm file.
A more Fortran-friendly object describing a RELATION-MEMEBER structure.
Object describing a RELATION-MEMBER structure.
A more Fortran-friendly object describing a NODE structure.
Object describing a NODE structure.
A more Fortran-friendly object describing a RELATION structure.
Object describing a RELATION structure.
A more Fortran-friendly object describing a TAG structure.
Object describing a TAG structure.
A more Fortran-friendly object describing a WAY structure.
Object describing a WAY structure.