Example #1
0
int
main (int argc, char *argv[])
{
    const void *handle;
    int ret;

    ret = readosm_open ("testdata/test.osm", &handle);
    if (ret != READOSM_OK)
      {
	  fprintf (stderr, "OPEN ERROR: %d\n", ret);
	  return -1;
      }


    ret =
	readosm_parse (handle, (const void *) 0, check_node, check_way,
		       check_relation);
    if (ret != READOSM_OK)
      {
	  fprintf (stderr, ".osm PARSE error: %d\n", ret);
	  return -2;
      }

    ret = readosm_close (handle);
    if (ret != READOSM_OK)
      {
	  fprintf (stderr, "CLOSE ERROR: %d\n", ret);
	  return -3;
      }

    return 0;
}
Example #2
0
int
main (int argc, char *argv[])
{
    const void *osm_handle;
    int ret;
    struct osm_helper helper;

/* initializing the helper struct */
    helper.read_count = 0;
    helper.stop_limit = 0;

    if (argc != 3)
      {
	  fprintf (stderr, "usage: test_osm3 path-to-OSM limit\n");
	  return -1;
      }

/* setting the stop limit */
    helper.stop_limit = atoi (argv[2]);

/*
* STEP #1: opening the OSM file
* this can indifferently be an OSM XML encoded file (.osm)
* or an OSM Protocol Buffer encoded file (.pbf)
* the library will transparently perform any required
* action in both cases.
*/
    ret = readosm_open (argv[1], &osm_handle);
    if (ret != READOSM_OK)
      {
	  fprintf (stderr, "OPEN error: %d\n", ret);
	  goto stop;
      }

/*
* STEP #2: parsing the OSM file
* this task is unbelievably simple
*
* you are simply required to pass the appropriate
* pointers for callback funtions respectively intended
* to process Node-objects, Way-objects and Relation-objects
*
* the library will then parse the whole input file, calling
* the appropriate callback handling function for each OSM object
* found: please see the callback functions implementing code
* to better understand how it works
*
* important notice: this second example is mainly focused on
* using the USER_DATA pointer. in this example we'll pass the 
* address of the osm_statistics struct so to gather some
* general infos.
*/
    ret =
	readosm_parse (osm_handle, &helper, parse_node, parse_way,
		       parse_relation);
    if (ret != READOSM_OK)
      {
	  fprintf (stderr, "PARSE error: %d\n", ret);
	  goto stop;
      }

  stop:
/*
* STEP #3: closing the OSM file
* this will release any internal memory allocation
*/
    readosm_close (osm_handle);
    return 0;
}
Example #3
0
int
main (int argc, char *argv[])
{
    const void *osm_handle;
    int ret;
    struct osm_statistics infos;

/* initializing the statistics struct */
    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;
      }

/*
* STEP #1: opening the OSM file
* this can indifferently be an OSM XML encoded file (.osm)
* or an OSM Protocol Buffer encoded file (.pbf)
* the library will transparently perform any required
* action in both cases.
*/
    ret = readosm_open (argv[1], &osm_handle);
    if (ret != READOSM_OK)
      {
	  fprintf (stderr, "OPEN error: %d\n", ret);
	  goto stop;
      }

/*
* STEP #2: parsing the OSM file
* this task is unbelievebly simple
*
* you are simply required to pass the appropriate
* pointers for callback funtions respectively intended
* to process Node-objects, Way-objects and Relation-objects
*
* the library will then parse the whole input file, calling
* the appropriate callback handling function for each OSM object
* found: please see the callback functions implementing code
* to better understand how it works
*
* important notice: this second example is mainly focused on
* using the USER_DATA pointer. in this example we'll pass the 
* address of the osm_statistics struct so to gather some
* general infos.
*/
    ret =
	readosm_parse (osm_handle, &infos, node_stats, way_stats,
		       relation_stats);
    if (ret != READOSM_OK)
      {
	  fprintf (stderr, "PARSE error: %d\n", ret);
	  goto stop;
      }

/* printing OSM statistics */
    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:
/*
* STEP #3: closing the OSM file
* this will release any internal memory allocation
*/
    readosm_close (osm_handle);
    return 0;
}