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;
}