1065 |
|
|
1066 |
#include <sys/time.h> |
#include <sys/time.h> |
1067 |
|
|
1068 |
osm_t *osm_parse(char *filename) { |
osm_t *osm_parse(char *path, char *filename) { |
1069 |
|
|
1070 |
struct timeval start; |
struct timeval start; |
1071 |
gettimeofday(&start, NULL); |
gettimeofday(&start, NULL); |
1073 |
LIBXML_TEST_VERSION; |
LIBXML_TEST_VERSION; |
1074 |
|
|
1075 |
// use stream parser |
// use stream parser |
1076 |
osm_t *osm = process_file(filename); |
osm_t *osm = NULL; |
1077 |
|
if(filename[0] == '/') |
1078 |
|
osm = process_file(filename); |
1079 |
|
else { |
1080 |
|
char *full = g_strjoin(NULL, path, filename, NULL); |
1081 |
|
osm = process_file(full); |
1082 |
|
g_free(full); |
1083 |
|
} |
1084 |
|
|
1085 |
xmlCleanupParser(); |
xmlCleanupParser(); |
1086 |
|
|
1087 |
struct timeval end; |
struct timeval end; |
1223 |
|
|
1224 |
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); |
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); |
1225 |
xmlNodePtr root_node = xmlNewNode(NULL, BAD_CAST "osm"); |
xmlNodePtr root_node = xmlNewNode(NULL, BAD_CAST "osm"); |
|
#ifndef API06 |
|
|
xmlNewProp(root_node, BAD_CAST "version", BAD_CAST "0.5"); |
|
|
xmlNewProp(root_node, BAD_CAST "generator", BAD_CAST PACKAGE " v" VERSION); |
|
|
#endif |
|
1226 |
xmlDocSetRootElement(doc, root_node); |
xmlDocSetRootElement(doc, root_node); |
1227 |
|
|
1228 |
switch(type) { |
switch(type) { |
1236 |
snprintf(str, sizeof(str), "%u", (unsigned)node->id); |
snprintf(str, sizeof(str), "%u", (unsigned)node->id); |
1237 |
xmlNewProp(node_node, BAD_CAST "id", BAD_CAST str); |
xmlNewProp(node_node, BAD_CAST "id", BAD_CAST str); |
1238 |
} |
} |
|
#ifdef API06 |
|
1239 |
snprintf(str, sizeof(str), "%u", (unsigned)node->version); |
snprintf(str, sizeof(str), "%u", (unsigned)node->version); |
1240 |
xmlNewProp(node_node, BAD_CAST "version", BAD_CAST str); |
xmlNewProp(node_node, BAD_CAST "version", BAD_CAST str); |
1241 |
snprintf(str, sizeof(str), "%u", (unsigned)changeset); |
snprintf(str, sizeof(str), "%u", (unsigned)changeset); |
1242 |
xmlNewProp(node_node, BAD_CAST "changeset", BAD_CAST str); |
xmlNewProp(node_node, BAD_CAST "changeset", BAD_CAST str); |
|
#endif |
|
1243 |
g_ascii_formatd(str, sizeof(str), LL_FORMAT, node->pos.lat); |
g_ascii_formatd(str, sizeof(str), LL_FORMAT, node->pos.lat); |
1244 |
xmlNewProp(node_node, BAD_CAST "lat", BAD_CAST str); |
xmlNewProp(node_node, BAD_CAST "lat", BAD_CAST str); |
1245 |
g_ascii_formatd(str, sizeof(str), LL_FORMAT, node->pos.lon); |
g_ascii_formatd(str, sizeof(str), LL_FORMAT, node->pos.lon); |
1254 |
xmlNodePtr way_node = xmlNewChild(root_node, NULL, BAD_CAST "way", NULL); |
xmlNodePtr way_node = xmlNewChild(root_node, NULL, BAD_CAST "way", NULL); |
1255 |
snprintf(str, sizeof(str), "%u", (unsigned)way->id); |
snprintf(str, sizeof(str), "%u", (unsigned)way->id); |
1256 |
xmlNewProp(way_node, BAD_CAST "id", BAD_CAST str); |
xmlNewProp(way_node, BAD_CAST "id", BAD_CAST str); |
|
#ifdef API06 |
|
1257 |
snprintf(str, sizeof(str), "%u", (unsigned)way->version); |
snprintf(str, sizeof(str), "%u", (unsigned)way->version); |
1258 |
xmlNewProp(way_node, BAD_CAST "version", BAD_CAST str); |
xmlNewProp(way_node, BAD_CAST "version", BAD_CAST str); |
1259 |
snprintf(str, sizeof(str), "%u", (unsigned)changeset); |
snprintf(str, sizeof(str), "%u", (unsigned)changeset); |
1260 |
xmlNewProp(way_node, BAD_CAST "changeset", BAD_CAST str); |
xmlNewProp(way_node, BAD_CAST "changeset", BAD_CAST str); |
|
#endif |
|
1261 |
|
|
1262 |
node_chain_t *node_chain = way->node_chain; |
node_chain_t *node_chain = way->node_chain; |
1263 |
while(node_chain) { |
while(node_chain) { |
1279 |
BAD_CAST "relation", NULL); |
BAD_CAST "relation", NULL); |
1280 |
snprintf(str, sizeof(str), "%u", (unsigned)relation->id); |
snprintf(str, sizeof(str), "%u", (unsigned)relation->id); |
1281 |
xmlNewProp(rel_node, BAD_CAST "id", BAD_CAST str); |
xmlNewProp(rel_node, BAD_CAST "id", BAD_CAST str); |
|
#ifdef API06 |
|
1282 |
snprintf(str, sizeof(str), "%u", (unsigned)relation->version); |
snprintf(str, sizeof(str), "%u", (unsigned)relation->version); |
1283 |
xmlNewProp(rel_node, BAD_CAST "version", BAD_CAST str); |
xmlNewProp(rel_node, BAD_CAST "version", BAD_CAST str); |
1284 |
snprintf(str, sizeof(str), "%u", (unsigned)changeset); |
snprintf(str, sizeof(str), "%u", (unsigned)changeset); |
1285 |
xmlNewProp(rel_node, BAD_CAST "changeset", BAD_CAST str); |
xmlNewProp(rel_node, BAD_CAST "changeset", BAD_CAST str); |
|
#endif |
|
1286 |
|
|
1287 |
member_t *member = relation->member; |
member_t *member = relation->member; |
1288 |
while(member) { |
while(member) { |
1529 |
node->visible = TRUE; |
node->visible = TRUE; |
1530 |
node->time = time(NULL); |
node->time = time(NULL); |
1531 |
|
|
|
#ifndef API06 |
|
|
/* add created_by tag */ |
|
|
node->tag = g_new0(tag_t, 1); |
|
|
node->tag->key = g_strdup("created_by"); |
|
|
node->tag->value = g_strdup(PACKAGE " v" VERSION); |
|
|
#endif |
|
|
|
|
1532 |
/* convert screen position back to ll */ |
/* convert screen position back to ll */ |
1533 |
lpos2pos(osm->bounds, &node->lpos, &node->pos); |
lpos2pos(osm->bounds, &node->lpos, &node->pos); |
1534 |
|
|
1569 |
way->flags = OSM_FLAG_NEW; |
way->flags = OSM_FLAG_NEW; |
1570 |
way->time = time(NULL); |
way->time = time(NULL); |
1571 |
|
|
|
#ifndef API06 |
|
|
/* add created_by tag */ |
|
|
way->tag = g_new0(tag_t, 1); |
|
|
way->tag->key = g_strdup("created_by"); |
|
|
way->tag->value = g_strdup(PACKAGE " v" VERSION); |
|
|
#endif |
|
|
|
|
1572 |
return way; |
return way; |
1573 |
} |
} |
1574 |
|
|
1746 |
return rel_chain; |
return rel_chain; |
1747 |
} |
} |
1748 |
|
|
1749 |
|
/* return all relations a relation is in */ |
1750 |
|
relation_chain_t *osm_relation_to_relation(osm_t *osm, relation_t *rel) { |
1751 |
|
relation_chain_t *rel_chain = NULL, **cur_rel_chain = &rel_chain; |
1752 |
|
|
1753 |
|
relation_t *relation = osm->relation; |
1754 |
|
while(relation) { |
1755 |
|
gboolean is_member = FALSE; |
1756 |
|
|
1757 |
|
member_t *member = relation->member; |
1758 |
|
while(member) { |
1759 |
|
switch(member->object.type) { |
1760 |
|
case RELATION: { |
1761 |
|
/* relations can be check directly */ |
1762 |
|
if(member->object.relation == rel) |
1763 |
|
is_member = TRUE; |
1764 |
|
} break; |
1765 |
|
|
1766 |
|
default: |
1767 |
|
break; |
1768 |
|
} |
1769 |
|
member = member->next; |
1770 |
|
} |
1771 |
|
|
1772 |
|
/* way is a member of this relation, so move it to the member chain */ |
1773 |
|
if(is_member) { |
1774 |
|
*cur_rel_chain = g_new0(relation_chain_t, 1); |
1775 |
|
(*cur_rel_chain)->relation = relation; |
1776 |
|
cur_rel_chain = &((*cur_rel_chain)->next); |
1777 |
|
} |
1778 |
|
|
1779 |
|
relation = relation->next; |
1780 |
|
} |
1781 |
|
|
1782 |
|
return rel_chain; |
1783 |
|
} |
1784 |
|
|
1785 |
|
/* return all relations an object is in */ |
1786 |
|
relation_chain_t *osm_object_to_relation(osm_t *osm, object_t *object) { |
1787 |
|
relation_chain_t *rel_chain = NULL; |
1788 |
|
|
1789 |
|
switch(object->type) { |
1790 |
|
case NODE: |
1791 |
|
rel_chain = osm_node_to_relation(osm, object->node); |
1792 |
|
break; |
1793 |
|
|
1794 |
|
case WAY: |
1795 |
|
rel_chain = osm_way_to_relation(osm, object->way); |
1796 |
|
break; |
1797 |
|
|
1798 |
|
case RELATION: |
1799 |
|
rel_chain = osm_relation_to_relation(osm, object->relation); |
1800 |
|
break; |
1801 |
|
|
1802 |
|
default: |
1803 |
|
break; |
1804 |
|
} |
1805 |
|
|
1806 |
|
return rel_chain; |
1807 |
|
} |
1808 |
|
|
1809 |
|
void osm_relation_chain_free(relation_chain_t *rchain) { |
1810 |
|
while(rchain) { |
1811 |
|
relation_chain_t *next = rchain->next; |
1812 |
|
g_free(rchain); |
1813 |
|
rchain = next; |
1814 |
|
} |
1815 |
|
} |
1816 |
|
|
1817 |
/* return all ways a node is in */ |
/* return all ways a node is in */ |
1818 |
way_chain_t *osm_node_to_way(osm_t *osm, node_t *node) { |
way_chain_t *osm_node_to_way(osm_t *osm, node_t *node) { |
1819 |
way_chain_t *chain = NULL, **cur_chain = &chain; |
way_chain_t *chain = NULL, **cur_chain = &chain; |
1909 |
relation->flags = OSM_FLAG_NEW; |
relation->flags = OSM_FLAG_NEW; |
1910 |
relation->time = time(NULL); |
relation->time = time(NULL); |
1911 |
|
|
|
#ifndef API06 |
|
|
/* add created_by tag */ |
|
|
relation->tag = g_new0(tag_t, 1); |
|
|
relation->tag->key = g_strdup("created_by"); |
|
|
relation->tag->value = g_strdup(PACKAGE " v" VERSION); |
|
|
#endif |
|
|
|
|
1912 |
return relation; |
return relation; |
1913 |
} |
} |
1914 |
|
|