test_osm3.c shows how to intentionally abort the parser.
test_osm3.c shows how to intentionally abort the parser.Here is a typical usage example, parsing an OSM XML file (.osm):
#include <stdio.h>
#include <stdlib.h>
struct osm_helper
{
int read_count;
int stop_limit;
};
static int
eval_abort (struct osm_helper *helper)
{
if (helper->read_count > helper->stop_limit)
return 1;
return 0;
}
static int
parse_node (
const void *user_data,
const readosm_node * node)
{
struct osm_helper *helper = (struct osm_helper *) user_data;
if (node != NULL)
node = NULL;
helper->read_count++;
if (eval_abort (helper))
printf ("Node#%d\n", helper->read_count);
}
static int
parse_way (
const void *user_data,
const readosm_way * way)
{
struct osm_helper *helper = (struct osm_helper *) user_data;
if (way != NULL)
way = NULL;
helper->read_count++;
if (eval_abort (helper))
printf ("Way#%d\n", helper->read_count);
}
static int
{
struct osm_helper *helper = (struct osm_helper *) user_data;
if (relation != NULL)
relation = NULL;
helper->read_count++;
if (eval_abort (helper))
printf ("Relation#%d\n", helper->read_count);
}
int
main (int argc, char *argv[])
{
const void *osm_handle;
int ret;
struct osm_helper helper;
helper.read_count = 0;
helper.stop_limit = 0;
if (argc != 3)
{
fprintf (stderr, "usage: test_osm3 path-to-OSM limit\n");
return -1;
}
helper.stop_limit = atoi (argv[2]);
{
fprintf (stderr, "OPEN error: %d\n", ret);
goto stop;
}
ret =
parse_relation);
{
fprintf (stderr, "PARSE error: %d\n", ret);
goto stop;
}
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.
READOSM_DECLARE int readosm_close(const void *osm_handle)
Close the .osm or .pbf file and release any allocated resource.
#define READOSM_OK
No error, success.
Definition readosm.h:88
#define READOSM_ABORT
user-required parser abort
Definition readosm.h:101
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 NODE object, and wrapping a complex XML fragment like the following:
Definition readosm.h:133
a struct representing a RELATION object, and wrapping a complex XML fragment like the following:
Definition readosm.h:220
a struct representing a WAY object, and wrapping a complex XML fragment like the following:
Definition readosm.h:166