test_osm2.c is another simple demonstration tool for OSM file formats.
test_osm2.c is another simple demonstration tool for OSM file formats.This sample code provides an example of:
#include <stdio.h>
struct osm_statistics
{
int node_count;
int node_tag_count;
int way_count;
int way_ndref_count;
int way_tag_count;
int relation_count;
int relation_member_node_count;
int relation_member_way_count;
int relation_member_relation_count;
int relation_tag_count;
double min_longitude;
double max_longitude;
double min_latitude;
double max_latitude;
};
static int
node_stats (
const void *user_data,
const readosm_node * node)
{
struct osm_statistics *stats = (struct osm_statistics *) user_data;
stats->node_count++;
{
if (node->
latitude > stats->max_latitude)
if (node->
latitude < stats->min_latitude)
}
{
}
}
static int
way_stats (
const void *user_data,
const readosm_way * way)
{
struct osm_statistics *stats = (struct osm_statistics *) user_data;
stats->way_count++;
}
static int
{
int i;
struct osm_statistics *stats = (struct osm_statistics *) user_data;
stats->relation_count++;
{
{
stats->relation_member_node_count++;
break;
stats->relation_member_way_count++;
break;
stats->relation_member_relation_count++;
break;
};
}
stats->relation_tag_count += relation->
tag_count;
}
int
main (int argc, char *argv[])
{
const void *osm_handle;
int ret;
struct osm_statistics infos;
infos.node_count = 0;
infos.node_tag_count = 0;
infos.way_count = 0;
infos.way_ndref_count = 0;
infos.way_tag_count = 0;
infos.relation_count = 0;
infos.relation_member_node_count = 0;
infos.relation_member_way_count = 0;
infos.relation_member_relation_count = 0;
infos.relation_tag_count = 0;
infos.min_longitude = 180.0;
infos.max_longitude = -180.0;
infos.min_latitude = 90.0;
infos.max_latitude = -90.0;
if (argc != 2)
{
fprintf (stderr, "usage: test_osm2 path-to-OSM-file\n");
return -1;
}
{
fprintf (stderr, "OPEN error: %d\n", ret);
goto stop;
}
ret =
relation_stats);
{
fprintf (stderr, "PARSE error: %d\n", ret);
goto stop;
}
printf ("Longitude range: %1.7f / %1.7f\n", infos.min_longitude,
infos.max_longitude);
printf ("Latitude range: %1.7f / %1.7f\n\n", infos.min_latitude,
infos.max_latitude);
printf ("Nodes : %d\n", infos.node_count);
printf (" tags: %d\n\n", infos.node_tag_count);
printf ("Ways : %d\n", infos.way_count);
printf (" ndref: %d\n", infos.way_ndref_count);
printf (" tags: %d\n\n", infos.way_tag_count);
printf ("Relations : %d\n", infos.relation_count);
printf (" member.nodes : %d\n", infos.relation_member_node_count);
printf (" member.ways : %d\n", infos.relation_member_way_count);
printf (" member.relations: %d\n", infos.relation_member_relation_count);
printf (" tags: %d\n", infos.relation_tag_count);
stop:
return 0;
}
Function declarations and constants for ReadOSM library.
READOSM_DECLARE int readosm_parse(const void *osm_handle, const void *user_data, readosm_node_callback node_fnct, readosm_way_callback way_fnct, readosm_relation_callback relation_fnct)
Close the .osm or .pbf file and release any allocated resource.
#define READOSM_MEMBER_WAY
MemberType: WAY.
Definition readosm.h:83
#define READOSM_MEMBER_NODE
MemberType: NODE.
Definition readosm.h:81
READOSM_DECLARE int readosm_close(const void *osm_handle)
Close the .osm or .pbf file and release any allocated resource.
#define READOSM_MEMBER_RELATION
MemberType: RELATION.
Definition readosm.h:85
#define READOSM_UNDEFINED
information is not available
Definition readosm.h:79
#define READOSM_OK
No error, success.
Definition readosm.h:88
READOSM_DECLARE int readosm_open(const char *path, const void **osm_handle)
Open the .osm or .pbf file, preparing for future functions.
a struct representing a RELATION-MEMBER, and wrapping an XML fragment like the following:
Definition readosm.h:193
const int member_type
can be one of: READOSM_MEMBER_NODE, READOSM_MEMBER_WAY or READOSM_MEMBER_RELATION
Definition readosm.h:195
a struct representing a NODE object, and wrapping a complex XML fragment like the following:
Definition readosm.h:133
const double longitude
geographic longitude
Definition readosm.h:136
const double latitude
geographic latitude
Definition readosm.h:135
const int tag_count
number of associated TAGs (may be zero)
Definition readosm.h:142
a struct representing a RELATION object, and wrapping a complex XML fragment like the following:
Definition readosm.h:220
const readosm_member * members
array of MEMBER objects (may be NULL)
Definition readosm.h:228
const int tag_count
number of associated TAGs (may be zero)
Definition readosm.h:229
const int member_count
number of associated MEMBERs (may be zero)
Definition readosm.h:227
a struct representing a WAY object, and wrapping a complex XML fragment like the following:
Definition readosm.h:166
const int node_ref_count
number of referenced NODE-IDs (may be zero)
Definition readosm.h:173
const int tag_count
number of associated TAGs (may be zero)
Definition readosm.h:175