test_osm1.c is a simple demonstration tool for OSM file formats.
test_osm1.c is a simple demonstration tool for OSM file formats.This sample code provides an example of:
Please note: the output produced by test_osm1 is usually verbose, so redirecting the standard output to a disk file is strongly recommended.
#include <stdio.h>
static int
print_node (
const void *user_data,
const readosm_node * node)
{
char buf[128];
int i;
if (user_data != NULL)
user_data = NULL;
#if defined(_WIN32) || defined(__MINGW32__)
sprintf (buf,
"%I64d", node->
id);
#else
sprintf (buf,
"%lld", node->
id);
#endif
printf ("\t<node id=\"%s\"", buf);
printf (
" lat=\"%1.7f\"", node->
latitude);
printf (
" version=\"%d\"", node->
version);
{
#if defined(_WIN32) || defined(__MINGW32__)
#else
#endif
printf (" changeset=\"%s\"", buf);
}
printf (
" user=\"%s\"", node->
user);
printf (
" uid=\"%d\"", node->
uid);
printf (
" timestamp=\"%s\"", node->
timestamp);
printf (" />\n");
else
{
printf (">\n");
{
printf (
"\t\t<tag k=\"%s\" v=\"%s\" />\n", tag->
key,
}
printf ("\t</node>\n");
}
}
static int
print_way (
const void *user_data,
const readosm_way * way)
{
char buf[128];
int i;
if (user_data != NULL)
user_data = NULL;
#if defined(_WIN32) || defined(__MINGW32__)
sprintf (buf,
"%I64d", way->
id);
#else
sprintf (buf,
"%lld", way->
id);
#endif
printf ("\t<way id=\"%s\"", buf);
printf (
" version=\"%d\"", way->
version);
{
#if defined(_WIN32) || defined(__MINGW32__)
#else
#endif
printf (" changeset=\"%s\"", buf);
}
printf (
" user=\"%s\"", way->
user);
printf (
" uid=\"%d\"", way->
uid);
printf (
" timestamp=\"%s\"", way->
timestamp);
printf (" />\n");
else
{
printf (">\n");
{
#if defined(_WIN32) || defined(__MINGW32__)
sprintf (buf,
"%I64d", *(way->
node_refs + i));
#else
sprintf (buf,
"%lld", *(way->
node_refs + i));
#endif
printf ("\t\t<nd ref=\"%s\" />\n", buf);
}
{
printf (
"\t\t<tag k=\"%s\" v=\"%s\" />\n", tag->
key,
}
printf ("\t</way>\n");
}
}
static int
{
char buf[128];
int i;
if (user_data != NULL)
user_data = NULL;
#if defined(_WIN32) || defined(__MINGW32__)
sprintf (buf,
"%I64d", relation->
id);
#else
sprintf (buf,
"%lld", relation->
id);
#endif
printf ("\t<relation id=\"%s\"", buf);
printf (
" version=\"%d\"", relation->
version);
{
#if defined(_WIN32) || defined(__MINGW32__)
#else
#endif
printf (" changeset=\"%s\"", buf);
}
if (relation->
user != NULL)
printf (
" user=\"%s\"", relation->
user);
printf (
" uid=\"%d\"", relation->
uid);
printf (
" timestamp=\"%s\"", relation->
timestamp);
printf (" />\n");
else
{
printf (">\n");
{
#if defined(_WIN32) || defined(__MINGW32__)
sprintf (buf,
"%I64d", member->
id);
#else
sprintf (buf,
"%lld", member->
id);
#endif
{
printf ("\t\t<member type=\"node\" ref=\"%s\"", buf);
break;
printf ("\t\t<member type=\"way\" ref=\"%s\"", buf);
break;
printf ("\t\t<member type=\"relation\" ref=\"%s\"", buf);
break;
default:
printf ("\t\t<member ref=\"%s\"", buf);
break;
};
if (member->
role != NULL)
printf (
" role=\"%s\" />\n", member->
role);
else
printf (" />\n");
}
{
tag = relation->
tags + i;
printf (
"\t\t<tag k=\"%s\" v=\"%s\" />\n", tag->
key,
}
printf ("\t</relation>\n");
}
}
int
main (int argc, char *argv[])
{
const void *osm_handle;
int ret;
if (argc != 2)
{
fprintf (stderr, "usage: test_osm1 path-to-OSM-file\n");
return -1;
}
{
fprintf (stderr, "OPEN error: %d\n", ret);
goto stop;
}
ret =
readosm_parse (osm_handle, (
const void *) 0, print_node, print_way,
print_relation);
{
fprintf (stderr, "PARSE error: %d\n", ret);
goto stop;
}
fprintf (stderr, "Ok, OSM input file successfully parsed\n");
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 char * role
intended role for this reference
Definition readosm.h:197
const int member_type
can be one of: READOSM_MEMBER_NODE, READOSM_MEMBER_WAY or READOSM_MEMBER_RELATION
Definition readosm.h:195
const long long id
ID-value identifying the referenced object.
Definition readosm.h:196
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 readosm_tag * tags
array of TAG objects (may be NULL)
Definition readosm.h:143
const double latitude
geographic latitude
Definition readosm.h:135
const int uid
corresponding numeric UserID
Definition readosm.h:140
const int version
object version
Definition readosm.h:137
const long long id
NODE-ID (expected to be a unique value)
Definition readosm.h:134
const int tag_count
number of associated TAGs (may be zero)
Definition readosm.h:142
const long long changeset
ChangeSet ID.
Definition readosm.h:138
const char * timestamp
when this NODE was defined
Definition readosm.h:141
const char * user
name of the User defining this NODE
Definition readosm.h:139
a struct representing a RELATION object, and wrapping a complex XML fragment like the following:
Definition readosm.h:220
const readosm_tag * tags
array of TAG objects (may be NULL)
Definition readosm.h:230
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 long long id
RELATION-ID (expected to be a unique value)
Definition readosm.h:221
const long long changeset
ChangeSet ID.
Definition readosm.h:223
const int version
object version
Definition readosm.h:222
const int member_count
number of associated MEMBERs (may be zero)
Definition readosm.h:227
const char * timestamp
when this RELATION was defined
Definition readosm.h:226
const char * user
name of the User defining this RELATION
Definition readosm.h:224
const int uid
corresponding numeric UserID
Definition readosm.h:225
a struct representing a key:value pair, and wrapping an XML fragment like the following:
Definition readosm.h:110
const char * key
the KEY
Definition readosm.h:112
const char * value
the VALUE
Definition readosm.h:113
a struct representing a WAY object, and wrapping a complex XML fragment like the following:
Definition readosm.h:166
const long long * node_refs
array of NODE-IDs (may be NULL)
Definition readosm.h:174
const int version
object version
Definition readosm.h:168
const char * user
name of the User defining this WAY
Definition readosm.h:170
const int uid
corresponding numeric UserID
Definition readosm.h:171
const long long changeset
ChangeSet ID.
Definition readosm.h:169
const long long id
WAY-ID (expected to be a unique value)
Definition readosm.h:167
const char * timestamp
when this WAY was defined
Definition readosm.h:172
const int node_ref_count
number of referenced NODE-IDs (may be zero)
Definition readosm.h:173
const readosm_tag * tags
array of TAG objects (may be NULL)
Definition readosm.h:176
const int tag_count
number of associated TAGs (may be zero)
Definition readosm.h:175