|
From: Danny B. <dan...@us...> - 2008-08-04 17:44:12
|
Update of /cvsroot/roadmap/roadmap/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv26028 Modified Files: Makefile buildmap_line.c buildmap_osm_binary.c buildmap_osm_main.c buildmap_point.c buildmap_range.c buildmap_shape.c buildmap_square.c buildmap_street.c Added Files: buildmap_osm_text.c buildmap_osm_text.h Log Message: This adds the source for a new option in buildmap_osm, the ability to process the native XML from OpenStreetMap. Index: buildmap_line.c =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/buildmap_line.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** buildmap_line.c 18 Dec 2007 21:22:13 -0000 1.14 --- buildmap_line.c 4 Aug 2008 17:44:07 -0000 1.15 *************** *** 1,4 **** ! /* buildmap_line.c - Build a line table & index for RoadMap. ! * * LICENSE: * --- 1,3 ---- ! /* * LICENSE: * *************** *** 20,25 **** * along with RoadMap; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ! * SYNOPSYS: * * int buildmap_line_add (int tlid, int layer, int from, int to); --- 19,33 ---- * along with RoadMap; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + /** + * @file + * @brief Build a line table & index for RoadMap. * ! * These functions are used to build a table of lines from ! * the Tiger maps. The objective is double: (1) reduce the size of ! * the Tiger data by sharing all duplicated information and ! * (2) produce the index data to serve as the basis for a fast ! * search mechanism for streets in roadmap. * * int buildmap_line_add (int tlid, int layer, int from, int to); *************** *** 34,42 **** * void buildmap_line_get_square_sorted (int line); * - * These functions are used to build a table of lines from - * the Tiger maps. The objective is double: (1) reduce the size of - * the Tiger data by sharing all duplicated information and - * (2) produce the index data to serve as the basis for a fast - * search mechanism for streets in roadmap. */ --- 42,45 ---- *************** *** 161,171 **** ! int buildmap_line_add (int tlid, int layer, int from, int to) { ! int block; int offset; BuildMapLine *this_line; - if (LineById == NULL) buildmap_line_initialize(); --- 164,181 ---- ! /** ! * @brief add a line to buildmap's list ! * @param tlid the line id ! * @param layer the layer of this line ! * @param from point 1 ! * @param to point 2 ! * @return the number of lines we know ! */ ! int buildmap_line_add (int tlid, int layer, int from, int to) ! { int block; int offset; BuildMapLine *this_line; if (LineById == NULL) buildmap_line_initialize(); *************** *** 192,196 **** } if (layer <= 0) { ! buildmap_fatal (0, "invalid layer"); } this_line->tlid = tlid; --- 202,206 ---- } if (layer <= 0) { ! buildmap_fatal (0, "invalid layer %d in line #%d", layer, tlid); } this_line->tlid = tlid; *************** *** 300,303 **** --- 310,319 ---- + /** + * @brief get point ids for a line, from the sorted list + * @param line index from the SortedLine array + * @param from return the from point + * @param to return the to point + */ void buildmap_line_get_points_sorted (int line, int *from, int *to) { *************** *** 483,487 **** } - SortedLine2 = malloc (LineCrossingCount * sizeof(int)); if (SortedLine2 == NULL) { --- 499,502 ---- *************** *** 543,550 **** - buildmap_info ("saving lines..."); - if (!LineCount) return; square_count = buildmap_square_get_count(); --- 558,565 ---- if (!LineCount) return; + buildmap_info ("saving %d lines...", LineCount); + square_count = buildmap_square_get_count(); Index: buildmap_range.c =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/buildmap_range.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** buildmap_range.c 2 Dec 2007 00:32:35 -0000 1.15 --- buildmap_range.c 4 Aug 2008 17:44:07 -0000 1.16 *************** *** 1,4 **** ! /* buildmap_range.c - Build a street address range table & index for RoadMap. ! * * LICENSE: * --- 1,3 ---- ! /* * LICENSE: * *************** *** 20,23 **** --- 19,27 ---- * along with RoadMap; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + /** + * @file + * @brief Build a street address range table & index for RoadMap. * * SYNOPSYS: *************** *** 88,92 **** static void buildmap_range_register (void); ! static void buildmap_range_initialize (void) { --- 92,98 ---- static void buildmap_range_register (void); ! /** ! * @brief ! */ static void buildmap_range_initialize (void) { *************** *** 103,107 **** } ! static BuildMapRange *buildmap_range_new (void) { --- 109,115 ---- } ! /** ! * @brief ! */ static BuildMapRange *buildmap_range_new (void) { *************** *** 129,133 **** } ! void buildmap_range_merge (unsigned int frleft, unsigned int toleft, unsigned int frright, unsigned int toright, --- 137,149 ---- } ! /** ! * @brief ! * @param frleft ! * @param toleft ! * @param frright ! * @param toright ! * @param from ! * @param to ! */ void buildmap_range_merge (unsigned int frleft, unsigned int toleft, unsigned int frright, unsigned int toright, *************** *** 171,175 **** } ! int buildmap_range_add (int line, int street, --- 187,200 ---- } ! /** ! * @brief ! * @param line ! * @param street ! * @param fradd ! * @param toadd ! * @param zip ! * @param city ! * @return ! */ int buildmap_range_add (int line, int street, *************** *** 261,265 **** } ! void buildmap_range_add_no_address (int line, int street) { --- 286,294 ---- } ! /** ! * @brief ! * @param line ! * @param street ! */ void buildmap_range_add_no_address (int line, int street) { *************** *** 327,331 **** } ! void buildmap_range_add_place (RoadMapString place, RoadMapString city) { --- 356,364 ---- } ! /** ! * @brief ! * @param place ! * @param city ! */ void buildmap_range_add_place (RoadMapString place, RoadMapString city) { *************** *** 391,395 **** } ! static int buildmap_range_compare (const void *r1, const void *r2) { --- 424,433 ---- } ! /** ! * @brief ! * @param r1 ! * @param r2 ! * @return ! */ static int buildmap_range_compare (const void *r1, const void *r2) { *************** *** 429,433 **** return i1 - i2; } ! static int buildmap_range_compare_no_addr (const void *r1, const void *r2) { --- 467,476 ---- return i1 - i2; } ! /** ! * @brief ! * @param r1 ! * @param r2 ! * @return ! */ static int buildmap_range_compare_no_addr (const void *r1, const void *r2) { *************** *** 445,448 **** --- 488,494 ---- } + /** + * @brief + */ static void buildmap_range_sort (void) { *************** *** 499,503 **** } ! static void buildmap_range_save (void) { --- 545,551 ---- } ! /** ! * @brief ! */ static void buildmap_range_save (void) { *************** *** 650,654 **** ! buildmap_info ("saving ranges..."); /* Compute the space required for the "byCity" & "byzip" indexes. */ --- 698,702 ---- ! buildmap_info ("saving %d ranges...", RangeCount); /* Compute the space required for the "byCity" & "byzip" indexes. */ *************** *** 936,940 **** } ! static void buildmap_range_summary (void) { --- 984,990 ---- } ! /** ! * @brief ! */ static void buildmap_range_summary (void) { *************** *** 947,951 **** } ! static void buildmap_range_reset (void) { --- 997,1003 ---- } ! /** ! * @brief ! */ static void buildmap_range_reset (void) { *************** *** 996,1000 **** } ! static buildmap_db_module BuildMapRangeModule = { "range", --- 1048,1054 ---- } ! /** ! * @brief ! */ static buildmap_db_module BuildMapRangeModule = { "range", *************** *** 1005,1009 **** }; ! static void buildmap_range_register (void) { buildmap_db_register (&BuildMapRangeModule); --- 1059,1065 ---- }; ! /** ! * @brief ! */ static void buildmap_range_register (void) { buildmap_db_register (&BuildMapRangeModule); Index: Makefile =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/Makefile,v retrieving revision 1.127 retrieving revision 1.128 diff -C2 -d -r1.127 -r1.128 *** Makefile 31 Jul 2008 20:56:30 -0000 1.127 --- Makefile 4 Aug 2008 17:44:07 -0000 1.128 *************** *** 118,121 **** --- 118,123 ---- buildmap_shapefile.c \ buildmap_osm_binary.c \ + buildmap_osm_common.c \ + buildmap_osm_text.c \ buildmap_empty.c \ buildmap_place.c \ *************** *** 192,195 **** --- 194,199 ---- buildmap_opt.h \ buildmap_osm_binary.h \ + buildmap_osm_common.h \ + buildmap_osm_text.h \ buildmap_place.h \ buildmap_point.h \ Index: buildmap_shape.c =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/buildmap_shape.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** buildmap_shape.c 27 Nov 2007 14:41:13 -0000 1.11 --- buildmap_shape.c 4 Aug 2008 17:44:07 -0000 1.12 *************** *** 1,4 **** ! /* buildmap_shape.c - Build a shape table & index for RoadMap. ! * * LICENSE: * --- 1,3 ---- ! /* * LICENSE: * *************** *** 20,23 **** --- 19,27 ---- * along with RoadMap; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + /** + * @file + * @brief Build a shape table & index for RoadMap. * * SYNOPSYS: *************** *** 47,51 **** #include "buildmap_square.h" ! typedef struct { --- 51,57 ---- #include "buildmap_square.h" ! /** ! * @brief ! */ typedef struct { *************** *** 75,79 **** static void buildmap_shape_register (void); ! static void buildmap_shape_initialize (void) { --- 81,87 ---- static void buildmap_shape_register (void); ! /** ! * @brief ! */ static void buildmap_shape_initialize (void) { *************** *** 90,94 **** } ! int buildmap_shape_add (int line, int irec, int uid, int sequence, int longitude, int latitude) { --- 98,111 ---- } ! /** ! * @brief ! * @param line ! * @param irec ! * @param uid ! * @param sequence ! * @param longitude ! * @param latitude ! * @return ! */ int buildmap_shape_add (int line, int irec, int uid, int sequence, int longitude, int latitude) { *************** *** 189,193 **** } ! static int buildmap_shape_compare (const void *r1, const void *r2) { --- 206,215 ---- } ! /** ! * @brief ! * @param r1 ! * @param r2 ! * @return ! */ static int buildmap_shape_compare (const void *r1, const void *r2) { *************** *** 208,212 **** } ! static void buildmap_shape_sort (void) { --- 230,236 ---- } ! /** ! * @brief ! */ static void buildmap_shape_sort (void) { *************** *** 231,235 **** } ! static void buildmap_shape_save (void) { --- 255,261 ---- } ! /** ! * @brief ! */ static void buildmap_shape_save (void) { *************** *** 258,265 **** - buildmap_info ("saving shapes..."); - if (!ShapeCount) return; square_count = buildmap_square_get_count(); --- 284,291 ---- if (!ShapeCount) return; + buildmap_info ("saving %d shapes...", ShapeCount); + square_count = buildmap_square_get_count(); *************** *** 494,498 **** } ! static void buildmap_shape_summary (void) { --- 520,526 ---- } ! /** ! * @brief ! */ static void buildmap_shape_summary (void) { *************** *** 506,510 **** } ! static void buildmap_shape_reset (void) { --- 534,540 ---- } ! /** ! * @brief ! */ static void buildmap_shape_reset (void) { *************** *** 533,537 **** } ! static buildmap_db_module BuildMapShapeModule = { "shape", --- 563,569 ---- } ! /** ! * @brief ! */ static buildmap_db_module BuildMapShapeModule = { "shape", *************** *** 542,546 **** }; ! static void buildmap_shape_register (void) { buildmap_db_register (&BuildMapShapeModule); --- 574,580 ---- }; ! /** ! * @brief ! */ static void buildmap_shape_register (void) { buildmap_db_register (&BuildMapShapeModule); Index: buildmap_osm_binary.c =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/buildmap_osm_binary.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** buildmap_osm_binary.c 21 Jul 2008 18:33:42 -0000 1.7 --- buildmap_osm_binary.c 4 Aug 2008 17:44:07 -0000 1.8 *************** *** 66,173 **** #include "buildmap_layer.h" #include "buildmap_osm_binary.h" extern char *BuildMapResult; - #if 0 - static int KMaxLon = 180000000; - static int KMaxLat = 90000000; - #endif - - typedef struct layer_info { - char *name; - int *layerp; - int flags; - } layer_info_t; - - #define AREA 1 - - typedef struct layer_info_sublist { - char *name; - layer_info_t *list; - int *layerp; - } layer_info_sublist_t; - - /* Road layers. */ - - static int BuildMapLayerFreeway = 0; - static int BuildMapLayerRamp = 0; - static int BuildMapLayerMain = 0; - static int BuildMapLayerStreet = 0; - static int BuildMapLayerTrail = 0; - static int BuildMapLayerRail = 0; - - /* Area layers. */ - - static int BuildMapLayerPark = 0; - static int BuildMapLayerHospital = 0; - static int BuildMapLayerAirport = 0; - static int BuildMapLayerStation = 0; - static int BuildMapLayerMall = 0; - - /* Water layers. */ - - static int BuildMapLayerShoreline = 0; - static int BuildMapLayerRiver = 0; - static int BuildMapLayerCanal = 0; - static int BuildMapLayerLake = 0; - static int BuildMapLayerSea = 0; - - static int BuildMapLayerBoundary = 0; - - #define FREEWAY &BuildMapLayerFreeway - #define RAMP &BuildMapLayerRamp - #define MAIN &BuildMapLayerMain - #define STREET &BuildMapLayerStreet - #define TRAIL &BuildMapLayerTrail - #define RAIL &BuildMapLayerRail - - #define PARK &BuildMapLayerPark - #define HOSPITAL &BuildMapLayerHospital - #define AIRPORT &BuildMapLayerAirport - #define STATION &BuildMapLayerStation - #define MALL &BuildMapLayerMall - - #define SHORELINE &BuildMapLayerShoreline - #define RIVER &BuildMapLayerRiver - #define CANAL &BuildMapLayerCanal - #define LAKE &BuildMapLayerLake - #define SEA &BuildMapLayerSea - #define BOUNDARY &BuildMapLayerBoundary - - static BuildMapDictionary DictionaryPrefix; - static BuildMapDictionary DictionaryStreet; - static BuildMapDictionary DictionaryType; - static BuildMapDictionary DictionarySuffix; - static BuildMapDictionary DictionaryCity; - // static BuildMapDictionary DictionaryFSA; - - /** - * @brief initialize layers - */ - void buildmap_osm_binary_find_layers (void) { - - BuildMapLayerFreeway = buildmap_layer_get ("freeways"); - BuildMapLayerRamp = buildmap_layer_get ("ramps"); - BuildMapLayerMain = buildmap_layer_get ("highways"); - BuildMapLayerStreet = buildmap_layer_get ("streets"); - BuildMapLayerTrail = buildmap_layer_get ("trails"); - BuildMapLayerRail = buildmap_layer_get ("railroads"); - - BuildMapLayerPark = buildmap_layer_get ("parks"); - BuildMapLayerHospital = buildmap_layer_get ("hospitals"); - BuildMapLayerAirport = buildmap_layer_get ("airports"); - BuildMapLayerStation = buildmap_layer_get ("stations"); - BuildMapLayerMall = buildmap_layer_get ("malls"); - - BuildMapLayerShoreline = buildmap_layer_get ("shore"); - BuildMapLayerRiver = buildmap_layer_get ("rivers"); - BuildMapLayerCanal = buildmap_layer_get ("canals"); - BuildMapLayerLake = buildmap_layer_get ("lakes"); - BuildMapLayerSea = buildmap_layer_get ("sea"); - - BuildMapLayerBoundary = buildmap_layer_get ("boundaries"); - } - /** * @brief --- 66,74 ---- #include "buildmap_layer.h" + #include "buildmap_osm_static.h" #include "buildmap_osm_binary.h" extern char *BuildMapResult; /** * @brief *************** *** 198,499 **** #define STRING_REF 9 - static char *stringtype[] = { - "name", - "name_left", - "name_right", - "name_other", - "int_name", - "nat_name", - "reg_name", - "loc_name", - "old_name", - "ref", - "int_ref", - "nat_ref", - "reg_ref", - "loc_ref", - "old_ref", - "ncn_ref", - "rcn_ref", - "lcn_ref", - "icao", - "iata", - "place_name", - "place_numbers", - "postal_code", - "is_in", - "note", - "description", - "image", - "source", - "source_ref", - "created_by", - }; - - static char *datetype[] = { - "date_on", - "date_off", - "start_date", - "end_date", - }; - - #if NEEDED - static char *numeric_type[] = { - "lanes", - "layer", - "ele", - "width", - "est_width", - "maxwidth", - "maxlength", - "maxspeed", - "minspeed", - "day_on", - "day_off", - "hour_on", - "hour_off", - "maxweight", - "maxheight", - }; - #endif - - static layer_info_t highway_to_layer[] = { - { 0, NULL, 0 }, - { "motorway", FREEWAY, 0 }, /* 1 */ - { "motorway_link", FREEWAY, 0 }, /* 2 */ - { "trunk", FREEWAY, 0 }, /* 3 */ - { "trunk_link", FREEWAY, 0 }, /* 4 */ - { "primary", MAIN, 0 }, /* 5 */ - { "primary_link", MAIN, 0 }, /* 6 */ - { "secondary", STREET, 0 }, /* 7 */ - { "tertiary", STREET, 0 }, /* 8 */ - { "unclassified", STREET, 0 }, /* 9 */ - { "minor", STREET, 0 }, /* 10 */ - { "residential", STREET, 0 }, /* 11 */ - { "service", STREET, 0 }, /* 12 */ - { "track", TRAIL, 0 }, /* 13 */ - { "cycleway", TRAIL, 0 }, /* 14 */ - { "bridleway", TRAIL, 0 }, /* 15 */ - { "footway", TRAIL, 0 }, /* 16 */ - { "steps", TRAIL, 0 }, /* 17 */ - { "pedestrian", TRAIL, 0 }, /* =>17 */ - { 0, NULL, 0 }, - }; - - static layer_info_t cycleway_to_layer[] = { - { 0, NULL, 0 }, - { "lane", TRAIL, 0 }, /* 1 */ - { "track", TRAIL, 0 }, /* 2 */ - { "opposite_lane", TRAIL, 0 }, /* 3 */ - { "opposite_track", TRAIL, 0 }, /* 4 */ - { "opposite", NULL, 0 }, /* 5 */ - { 0, NULL, 0 }, - }; - - static layer_info_t waterway_to_layer[] = { - { 0, NULL, 0 }, - { "river", RIVER, 0 }, /* 1 */ - { "canal", RIVER, 0 }, /* 2 */ - { "stream", RIVER, 0 }, /* 3 */ - { "drain", RIVER, 0 }, /* 4 */ - { "dock", RIVER, 0 }, /* 5 */ - { "lock_gate", RIVER, 0 }, /* 6 */ - { "turning_point", RIVER, 0 }, /* 7 */ - { "aquaduct", RIVER, 0 }, /* 8 */ - { "boatyard", RIVER, 0 }, /* 9 */ - { "water_point", RIVER, 0 }, /* 10 */ - { "weir", RIVER, 0 }, /* 11 */ - { "dam", RIVER, 0 }, /* 12 */ - { 0, NULL, 0 }, - }; - - static layer_info_t abutters_to_layer[] = { - { 0, NULL, 0 }, - { "residential", NULL, 0 }, /* 1 */ - { "retail", NULL, 0 }, /* 2 */ - { "industrial", NULL, 0 }, /* 3 */ - { "commercial", NULL, 0 }, /* 4 */ - { "mixed", NULL, 0 }, /* 5 */ - { 0, NULL, 0 }, - }; - - static layer_info_t railway_to_layer[] = { - { 0, NULL, 0 }, - { "rail", RAIL, 0 }, /* 1 */ - { "tram", RAIL, 0 }, /* 2 */ - { "light_rail", RAIL, 0 }, /* 3 */ - { "subway", RAIL, 0 }, /* 4 */ - { "station", NULL, 0 }, /* 5 */ - { "preserved", RAIL, 0 }, /* 6 */ - { "disused", RAIL, 0 }, /* 7 */ - { "abandoned", RAIL, 0 }, /* 8 */ - { "narrow_gauge", RAIL, 0 }, /* 9 */ - { "monorail", RAIL, 0 }, /* 10 */ - { "halt", RAIL, 0 }, /* 11 */ - { "tram_stop", RAIL, 0 }, /* 12 */ - { "viaduct", RAIL, 0 }, /* 13 */ - { "crossing", RAIL, 0 }, /* 14 */ - { "level_crossing", RAIL, 0 }, /* 15 */ - { "subway_entrance", RAIL, 0 }, /* 16 */ - { "turntable", RAIL, 0 }, /* 17 */ - { 0, NULL, 0 }, - }; - - static layer_info_t natural_to_layer[] = { - { 0, NULL, 0 }, - { "coastline", SHORELINE, 0 }, /* 1 */ - { "water", LAKE, AREA }, /* 2 */ - { "wood", NULL, AREA }, /* 3 */ - { "peak", NULL, 0 }, /* 4 */ - { 0, NULL, 0 }, - }; - - static layer_info_t boundary_to_layer[] = { - { 0, NULL, 0 }, - { "administrative", NULL, AREA }, /* 1 */ - { "civil", NULL, AREA }, /* 2 */ - { "political", NULL, AREA }, /* 3 */ - { "national_park", NULL, AREA }, /* 4 */ - { "world_country", NULL, AREA }, /* 5 */ - { 0, NULL, 0 }, - }; - - static layer_info_t amenity_to_layer[] = { - { 0, NULL, 0 }, - { "hospital", HOSPITAL, 0 }, /* 1 */ - { "pub", NULL, 0 }, /* 2 */ - { "parking", NULL, AREA }, /* 3 */ - { "post_office", NULL, 0 }, /* 4 */ - { "fuel", NULL, 0 }, /* 5 */ - { "telephone", NULL, 0 }, /* 6 */ - { "toilets", NULL, 0 }, /* 7 */ - { "post_box", NULL, 0 }, /* 8 */ - { "school", NULL, AREA }, /* 9 */ - { "supermarket", NULL, 0 }, /* 10 */ - { "library", NULL, 0 }, /* 11 */ - { "theatre", NULL, 0 }, /* 12 */ - { "cinema", NULL, 0 }, /* 13 */ - { "police", NULL, 0 }, /* 14 */ - { "fire_station", NULL, 0 }, /* 15 */ - { "restaurant", NULL, 0 }, /* 16 */ - { "fastfood", NULL, 0 }, /* 17 */ - { "bus_station", NULL, 0 }, /* 18 */ - { "place_of_worship", NULL, 0 }, /* 19 */ - { "cafe", NULL, 0 }, /* 20 */ - { "bicycle_parking", NULL, AREA }, /* 21 */ - { "public_building", NULL, AREA }, /* 22 */ - { "grave_yard", NULL, AREA }, /* 23 */ - { "university", NULL, AREA }, /* 24 */ - { "college", NULL, AREA }, /* 25 */ - { "townhall", NULL, AREA }, /* 26 */ - { 0, NULL, 0 }, - }; - - static layer_info_t place_to_layer[] = { - { 0, NULL, 0 }, - { "continent", NULL, AREA }, /* 1 */ - { "country", NULL, AREA }, /* 2 */ - { "state", NULL, AREA }, /* 3 */ - { "region", NULL, AREA }, /* 4 */ - { "county", NULL, AREA }, /* 5 */ - { "city", NULL, AREA }, /* 6 */ - { "town", NULL, AREA }, /* 7 */ - { "village", NULL, AREA }, /* 8 */ - { "hamlet", NULL, AREA }, /* 9 */ - { "suburb", NULL, AREA }, /* 10 */ - { 0, NULL, 0 }, - }; - - static layer_info_t leisure_to_layer[] = { - { 0, NULL, 0 }, - { "park", PARK, AREA }, /* 1 */ - { "common", PARK, AREA }, /* 2 */ - { "garden", PARK, AREA }, /* 3 */ - { "nature_reserve", PARK, AREA }, /* 4 */ - { "fishing", NULL, AREA }, /* 5 */ - { "slipway", NULL, 0 }, /* 6 */ - { "water_park", NULL, AREA }, /* 7 */ - { "pitch", NULL, AREA }, /* 8 */ - { "track", NULL, AREA }, /* 9 */ - { "marina", NULL, AREA }, /* 10 */ - { "stadium", NULL, AREA }, /* 11 */ - { "golf_course", PARK, AREA }, /* 12 */ - { "sports_centre", NULL, AREA }, /* 13 */ - { 0, NULL, 0 }, - }; - - static layer_info_t historic_to_layer[] = { - { 0, NULL, 0 }, - { "castle", NULL, 0 }, /* 1 */ - { "monument", NULL, 0 }, /* 2 */ - { "museum", NULL, 0 }, /* 3 */ - { "archaeological_site",NULL, AREA }, /* 4 */ - { "icon", NULL, 0 }, /* 5 */ - { "ruins", NULL, AREA }, /* 6 */ - { 0, NULL, 0 }, - }; - - #if NEEDED - static char *oneway_type[] = { - 0, - "no", /* 0 */ - "yes", /* 1 */ - "-1" /* 2 */ - }; - #endif - - - static layer_info_sublist_t list_info[] = { - {0, NULL, NULL }, - {"highway", highway_to_layer, NULL }, - {"cycleway", cycleway_to_layer, NULL }, - {"tracktype", NULL, TRAIL }, - {"waterway", waterway_to_layer, RIVER }, - {"railway", railway_to_layer, NULL }, - {"aeroway", NULL, NULL }, - {"aerialway", NULL, NULL }, - {"power", NULL, NULL }, - {"man_made", NULL, NULL }, - {"leisure", leisure_to_layer, NULL }, - {"amenity", amenity_to_layer, NULL }, - {"shop", NULL, NULL }, - {"tourism", NULL, NULL }, - {"historic", historic_to_layer, NULL }, - {"landuse", NULL, NULL }, - {"military", NULL, NULL }, - {"natural", natural_to_layer, NULL }, - {"route", NULL, NULL }, - {"boundary", boundary_to_layer, NULL }, - {"sport", NULL, NULL }, - {"abutters", abutters_to_layer, NULL }, - {"fenced", NULL, NULL }, - {"lit", NULL, NULL }, - {"area", NULL, NULL }, - {"bridge", NULL, MAIN }, - {"cutting", NULL, NULL }, - {"embankment", NULL, NULL }, - {"surface", NULL, NULL }, - {"access", NULL, NULL }, - {"bicycle", NULL, NULL }, - {"foot", NULL, NULL }, - {"goods", NULL, NULL }, - {"hgv", NULL, NULL }, - {"horse", NULL, NULL }, - {"motorcycle", NULL, NULL }, - {"motorcar", NULL, NULL }, - {"psv", NULL, NULL }, - {"motorboat", NULL, NULL }, - {"boat", NULL, NULL }, - {"oneway", NULL, NULL }, - {"noexit", NULL, NULL }, - {"toll", NULL, NULL }, - {"place", place_to_layer, NULL }, - {"lock", NULL, NULL }, - {"attraction", NULL, NULL }, - {"wheelchair", NULL, NULL }, - {"junction", NULL, NULL }, - { 0, NULL, 0 }, - }; - static unsigned char * read_4_byte_int(unsigned char *p, int *r) --- 99,102 ---- --- NEW FILE: buildmap_osm_text.h --- /* * LICENSE: * * Copyright 2007 Paul Fox * Copyright (c) 2008, Danny Backx * * This file is part of RoadMap. * * RoadMap is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * RoadMap is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with RoadMap; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * @file * @brief a module to read OSM text format */ #define LINELEN 512 void buildmap_osm_text_find_layers (void); int buildmap_osm_text_read(FILE * fdata); Index: buildmap_street.c =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/buildmap_street.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** buildmap_street.c 27 Nov 2007 14:41:13 -0000 1.7 --- buildmap_street.c 4 Aug 2008 17:44:07 -0000 1.8 *************** *** 1,4 **** ! /* buildmap_street.c - Build a street table & index for RoadMap. ! * * LICENSE: * --- 1,3 ---- ! /* * LICENSE: * *************** *** 20,23 **** --- 19,27 ---- * along with RoadMap; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + /** + * @file + * @brief Build a street table & index for RoadMap. * * SYNOPSYS: *************** *** 56,60 **** #include "buildmap_line.h" ! struct buildmap_street_struct { --- 60,66 ---- #include "buildmap_line.h" ! /** ! * @brief ! */ struct buildmap_street_struct { *************** *** 66,69 **** --- 72,78 ---- }; + /** + * @brief + */ typedef struct buildmap_street_struct BuildMapStreet; *************** *** 80,84 **** static void buildmap_street_register (void); ! static void buildmap_street_initialize (void) { --- 89,95 ---- static void buildmap_street_register (void); ! /** ! * @brief ! */ static void buildmap_street_initialize (void) { *************** *** 92,95 **** --- 103,116 ---- + /** + * @brief + * @param cfcc + * @param fedirp + * @param fename + * @param fetype + * @param fedirs + * @param line + * @return + */ int buildmap_street_add (char cfcc, *************** *** 181,185 **** } ! static int buildmap_street_compare (const void *r1, const void *r2) { --- 202,211 ---- } ! /** ! * @brief ! * @param r1 ! * @param r2 ! * @return ! */ static int buildmap_street_compare (const void *r1, const void *r2) { *************** *** 198,201 **** --- 224,230 ---- } + /** + * @brief + */ void buildmap_street_sort (void) { *************** *** 231,235 **** } ! void buildmap_street_print_sorted (FILE *file, int street) { --- 260,268 ---- } ! /** ! * @brief ! * @param file ! * @param street ! */ void buildmap_street_print_sorted (FILE *file, int street) { *************** *** 256,259 **** --- 289,297 ---- + /** + * @brief + * @param street + * @return + */ int buildmap_street_get_sorted (int street) { *************** *** 265,274 **** } ! int buildmap_street_count (void) { return StreetCount; } ! static void buildmap_street_save (void) { --- 303,317 ---- } ! /** ! * @brief ! * @return ! */ int buildmap_street_count (void) { return StreetCount; } ! /** ! * @brief ! */ static void buildmap_street_save (void) { *************** *** 284,291 **** - buildmap_info ("saving street..."); - if (!StreetCount) return; root = buildmap_db_add_section (NULL, "street"); if (root == NULL) buildmap_fatal (0, "Can't add a new section"); --- 327,334 ---- if (!StreetCount) return; + buildmap_info ("saving %d streets...", StreetCount); + root = buildmap_db_add_section (NULL, "street"); if (root == NULL) buildmap_fatal (0, "Can't add a new section"); *************** *** 313,317 **** } ! static void buildmap_street_summary (void) { --- 356,362 ---- } ! /** ! * @brief ! */ static void buildmap_street_summary (void) { *************** *** 322,326 **** } ! static void buildmap_street_reset (void) { --- 367,373 ---- } ! /** ! * @brief ! */ static void buildmap_street_reset (void) { *************** *** 345,349 **** } ! static buildmap_db_module BuildMapStreetModule = { "street", --- 392,398 ---- } ! /** ! * @brief ! */ static buildmap_db_module BuildMapStreetModule = { "street", *************** *** 354,358 **** }; ! static void buildmap_street_register (void) { buildmap_db_register (&BuildMapStreetModule); --- 403,409 ---- }; ! /** ! * @brief ! */ static void buildmap_street_register (void) { buildmap_db_register (&BuildMapStreetModule); --- NEW FILE: buildmap_osm_text.c --- /* * LICENSE: * * Copyright (c) 2008, Danny Backx * Based on code Copyright 2007 Stephen Woodbridge that interprets the OSM binary stream. * * This file is part of RoadMap. * * RoadMap is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * RoadMap is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with RoadMap; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * @file * @brief a module to read OSM text format */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdarg.h> #include <ctype.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <sys/mman.h> #include <time.h> #include "roadmap.h" #include "roadmap_types.h" #include "roadmap_math.h" #include "roadmap_path.h" #include "roadmap_file.h" #include "roadmap_osm.h" #include "buildmap.h" #include "buildmap_zip.h" #include "buildmap_city.h" #include "buildmap_square.h" #include "buildmap_point.h" #include "buildmap_line.h" #include "buildmap_street.h" #include "buildmap_range.h" #include "buildmap_area.h" #include "buildmap_shape.h" #include "buildmap_polygon.h" #include "buildmap_layer.h" #include "buildmap_osm_common.h" #include "buildmap_osm_text.h" /** * @brief a couple of variables to keep track of the way we're dealing with */ static int in_way = 0; /**< are we in a way (its id) */ static int nWayNodes = 0; /**< number of nodes known for this way */ static int nWayNodeAlloc = 0; /**< size of the allocation of the array */ static int *WayNodes = 0; /**< the array to keep track of this way's nodes */ static int WayLayer = 0; /**< the layer for this way */ static char *WayStreetName = 0; /**< the street name */ static int WayFlags = 0; /**< properties of this way, from the table flags */ static int WayInvalid = 0; /**< this way contains invalid nodes */ /** * @brief variables referring to the current node */ static int NodeId = 0; /**< which node */ static char *NodePlace = 0; /**< what kind of place is this */ static char *NodeTownName = 0; /**< which town */ static char *NodePostalCode = 0; /**< postal code */ static int NodeLon, /**< coordinates */ NodeLat; /**< coordinates */ /** * @brief some global variables */ static int LineNo; /**< line number in the input file */ static int nPolygons = 0; /**< current polygon id (number of polygons until now) */ /** * @brief allow the user to specify a bounding box */ #if 0 /* Mallorca ? */ int HaveLonMin = 1, HaveLonMax = 1, HaveLatMin = 1, HaveLatMax = 1, LonMin = 2200000, LonMax = 3150000, LatMin = 39100000, LatMax = 39950000; #else int HaveLonMin = 0, HaveLonMax = 0, HaveLatMin = 0, HaveLatMax = 0, LonMin = 0, LonMax = 0, LatMin = 0, LatMax = 0; #endif /** * @brief reset all the info about this way */ static void buildmap_osm_text_reset_way(void) { in_way = 0; nWayNodes = 0; free(WayStreetName); WayStreetName = 0; WayFlags = 0; WayInvalid = 0; } /** * @brief reset all the info about this node */ static void buildmap_osm_text_reset_node(void) { NodeId = 0; free(NodePlace); NodePlace = 0; free(NodeTownName); NodeTownName = 0; free(NodePostalCode); NodePostalCode = 0; } /** * @brief * @param d * @param string * @return */ static RoadMapString str2dict (BuildMapDictionary d, const char *string) { if (string == 0 || !strlen(string)) { return buildmap_dictionary_add (d, "", 0); } return buildmap_dictionary_add (d, (char *) string, strlen(string)); } /** * @brief simplistic way to gather point data */ static int nPointsAlloc = 0; static int nPoints = 0; static struct points { int id; int npoint; } *points = 0; static void buildmap_osm_text_point_add(int id, int npoint) { if (nPoints == nPointsAlloc) { nPointsAlloc += 10000; points = realloc(points, sizeof(struct points) * nPointsAlloc); if (!points) buildmap_fatal(0, "allocate %d points", nPointsAlloc); } points[nPoints].id = id; points[nPoints++].npoint = npoint; } /** * @brief look up a point by id * @param id the external representation * @return the internal index */ static int buildmap_osm_text_point_get(int id) { int i; /* fix me, this needs to be speed up */ for (i=0; i<nPoints; i++) if (points[i].id == id) return points[i].npoint; return -1; } /** * @brief collect node data in pass 1 * @param data * @return an error indicator * * The input line is discarded if a bounding box is specified and the node is outside. * * Example input line : * <node id="123295" timestamp="2005-07-05T03:26:11Z" user="LA2" * lat="50.4443626" lon="3.6855288"/> */ int buildmap_osm_text_node(char *data) { int npoints, nchars, r; double flat, flon; char *p; static char *tag = 0, *value = 0; int NodeLatRead, NodeLonRead; sscanf(data, "node id=%*[\"']%d%*[\"']%n", &NodeId, &nchars); p = data + nchars; /* Initialize/allocate these only once, never free them. */ if (! tag) tag = malloc(512); if (! value) value = malloc(512); NodeLat = NodeLon = 0; NodeLatRead = NodeLonRead = 0; while (NodeLatRead == 0 || NodeLonRead == 0) { for (; *p && isspace(*p); p++) ; r = sscanf(p, "%[a-zA-Z0-9_]=%*[\"']%[^\"']%*[\"']%n", tag, value, &nchars); if (strcmp(tag, "lat") == 0) { sscanf(value, "%lf", &flat); NodeLat = flat * 1000000; NodeLatRead++; } else if (strcmp(tag, "lon") == 0) { sscanf(value, "%lf", &flon); NodeLon = flon * 1000000; NodeLonRead++; } p += nchars; } if ((HaveLonMin && (NodeLon < LonMin)) || (HaveLonMax && (NodeLon > LonMax)) || (HaveLatMin && (NodeLat < LatMin)) || (HaveLatMax && (NodeLat > LatMax))) { /* Outside the specified bounding box, ignore this node */ NodeLat = NodeLon = 0; NodeLatRead = NodeLonRead = 0; return 1; } npoints = buildmap_point_add(NodeLon, NodeLat); buildmap_osm_text_point_add(NodeId, npoints); /* hack */ return 0; } /** * @brief At the end of a node, process its data * @param data point to the line buffer * @return error indication */ int buildmap_osm_text_node_end(char *data) { if (NodePlace && strcmp(NodePlace, "town") == 0) { /* We have a town, process it */ if (NodeTownName && NodePostalCode) { buildmap_verbose("Node %d town %s postal %s", NodeId, NodeTownName, NodePostalCode); } if (NodeTownName) { #if 0 int fips = 32999 * 10000 + NodePostalCode; #else static int fips = 32999 * 10000; fips++; #endif int year = 2008; RoadMapString s = buildmap_dictionary_add (DictionaryCity, (char *) NodeTownName, strlen(NodeTownName)); buildmap_city_add(fips, year, s); } if (NodePostalCode) { int zip = 0; sscanf(NodePostalCode, "%d", &zip); if (zip) buildmap_zip_add(zip, NodeLon, NodeLat); } } buildmap_osm_text_reset_node(); return 0; } /** * @brief this structure keeps shape data for a postprocessing step */ struct shapeinfo { int lineid; int count; int *lons; int *lats; }; static int numshapes = 0; static int nallocshapes = 0; /** * @brief ? */ static struct shapeinfo *shapes; /** * @brief * @param data * @return * * Sample XML : * <way id="75146" timestamp="2006-04-28T15:24:05Z" user="Mercator"> * <nd ref="997466"/> * <nd ref="997470"/> * <nd ref="1536769"/> * <nd ref="997472"/> * <nd ref="1536770"/> * <nd ref="997469"/> * <tag k="highway" v="residential"/> * <tag k="name" v="Rue de Thiribut"/> * <tag k="created_by" v="JOSM"/> * </way> */ static int buildmap_osm_text_way(char *data) { /* Severely cut in pieces. * This only remembers which way we're in... */ sscanf(data, "way id=%*[\"']%d%*[\"']", &in_way); if (in_way == 0) buildmap_fatal(0, "buildmap_osm_text_way(%s) error", data); return 0; } /** * @brief * @param data points into the line of text being processed * @return error indication * * Example line : * <nd ref="997470"/> */ static int buildmap_osm_text_nd(char *data) { int node, ix; float lon, lat; if (! in_way) buildmap_fatal(0, "Wasn't in a way (%s)", data); if (sscanf(data, "nd ref=%*[\"']%d%*[\"']", &node) != 1) return -1; ix = buildmap_osm_text_point_get(node); if (ix < 0) { /* Inconsistent OSM file, this node is not defined */ WayInvalid = 1; return 0; } lon = buildmap_point_get_longitude(ix); lat = buildmap_point_get_latitude(ix); if (nWayNodes == nWayNodeAlloc) { nWayNodeAlloc += 100; WayNodes = (int *)realloc(WayNodes, sizeof(int) * nWayNodeAlloc); if (WayNodes == 0) buildmap_fatal(0, "allocation failed for %d ints", nWayNodeAlloc); } WayNodes[nWayNodes++] = node; return 0; } /** * @brief deal with tag lines outside of ways * @param data points into the line of text being processed * @return error indication */ static int buildmap_osm_text_node_tag(char *data) { static char *tagk = 0; static char *tagv = 0; if (! tagk) tagk = malloc(512); if (! tagv) tagv = malloc(512); sscanf(data, "tag k=%*['\"]%[^\"']%*['\"] v=%*['\"]%[^\"']%*['\"]", tagk, tagv); if (strcmp(tagk, "postal_code") == 0) { /* <tag k="postal_code" v="3020"/> */ if (NodePostalCode) free(NodePostalCode); NodePostalCode = strdup(tagv); } else if (strcmp(tagk, "place") == 0) { /* <tag k="place" v="town"/> */ if (NodePlace) free(NodePlace); NodePlace = strdup(tagv); } else if (strcmp(tagk, "name") == 0) { /* <tag k="name" v="Herent"/> */ if (NodeTownName) free(NodeTownName); NodeTownName = strdup(tagv); } return 0; } /** * @brief deal with tag lines inside a <way> </way> pair * @param data points into the line of text being processed * @return error indication * * Example line : * <tag k="highway" v="residential"/> * <tag k="name" v="Rue de Thiribut"/> * <tag k="created_by" v="JOSM"/> */ static int buildmap_osm_text_tag(char *data) { static char *tag = 0, *value = 0; int i, found; layer_info_t *list; int ret = 0; if (! in_way) { /* Deal with tags outside ways */ return buildmap_osm_text_node_tag(data); } if (! tag) tag = malloc(512); if (! value) value = malloc(512); sscanf(data, "tag k=%*[\"']%[^\"']%*[\"'] v=%*[\"']%[^\"']%*[\"']", tag, value); /* street names */ if (strcmp(tag, "name") == 0) { if (WayStreetName) free(WayStreetName); WayStreetName = strdup(value); return 0; /* FIX ME ?? */ } /* Scan list_info */ found = 0; for (i=1; found == 0 && list_info[i].name != 0; i++) { if (strcmp(tag, list_info[i].name) == 0) { list = list_info[i].list; found = 1; break; } } if (found) { if (list) { for (i=1; list[i].name; i++) { if (strcmp(value, list[i].name) == 0) { WayFlags = list[i].flags; if (list[i].layerp) ret = *(list[i].layerp); } } } else { /* */ } } /* FIX ME When are we supposed to do this */ if (ret) WayLayer = ret; return ret; } /** * @brief We found an end tag for a way, so we must have read all the required data. Process it. * @param data points to the line of text being processed * @return error indication */ static int buildmap_osm_text_way_end(char *data) { int from_point, to_point, line, street; int fromlon, tolon, fromlat, tolat; int j; static int lineid = 1; if (WayInvalid) return 0; if (in_way == 0) buildmap_fatal(0, "Wasn't in a way (%s)", data); RoadMapString rms_dirp = str2dict(DictionaryPrefix, ""); RoadMapString rms_dirs = str2dict(DictionarySuffix, ""); RoadMapString rms_type = str2dict(DictionaryType, ""); RoadMapString rms_name = 0; from_point = buildmap_osm_text_point_get(WayNodes[0]); to_point = buildmap_osm_text_point_get(WayNodes[nWayNodes-1]); fromlon = buildmap_point_get_longitude(from_point); fromlat = buildmap_point_get_latitude(from_point); tolon = buildmap_point_get_longitude(to_point); tolat = buildmap_point_get_latitude(to_point); if ((WayFlags & AREA) && (fromlon == tolon) && (fromlat == tolat)) { static int polyid = 0; static int cenid = 0; int line; static int lineid = 0; /* * Detect an AREA -> create a polygon */ nPolygons++; cenid++; polyid++; rms_name = str2dict(DictionaryStreet, WayStreetName); buildmap_polygon_add_landmark (nPolygons, WayLayer, rms_name); buildmap_polygon_add(nPolygons, cenid, polyid); for (j=1; j<nWayNodes; j++) { int prevpoint = buildmap_osm_text_point_get(WayNodes[j-1]); int point = buildmap_osm_text_point_get(WayNodes[j]); lineid++; line = buildmap_line_add(lineid, WayLayer, prevpoint, point); #if 0 buildmap_verbose("%d <- buildmap_line_add(%d,%d,%d,%d) - nodes %d %d", line, lineid, WayLayer, prevpoint, point, WayNodes[j-1], WayNodes[j]); #endif #if 0 /* This will break on some polygons */ buildmap_polygon_add_line(cenid, polyid, lineid, POLYGON_SIDE_RIGHT); #endif #if 0 int lon1 = buildmap_point_get_longitude(prevpoint); int lat1 = buildmap_point_get_latitude(prevpoint); int lon2 = buildmap_point_get_longitude(point); int lat2 = buildmap_point_get_latitude(point); buildmap_verbose("Poly %d add line %d %d %d" " points prev %d (%d,%d) cur %d (%d,%d)", nPolygons, cenid, polyid, lineid, WayNodes[j-1], lon1, lat1, WayNodes[j], lon2, lat2); #endif } } else { /* * Register the way * * Need to do this several different ways : * - begin and end points form a "line" * - register street name * - adjust the square * - keep memory of the point coordinates so we can postprocess the * so called shapes (otherwise we only have straight lines) */ int *lonsbuf, *latsbuf; /* Map begin and end points to internal point id */ from_point = buildmap_osm_text_point_get(WayNodes[0]); to_point = buildmap_osm_text_point_get(WayNodes[nWayNodes-1]); line = buildmap_line_add(++lineid, WayLayer, from_point, to_point); /* Street name */ if (WayStreetName) rms_name = str2dict(DictionaryStreet, WayStreetName); street = buildmap_street_add(WayLayer, rms_dirp, rms_name, rms_type, rms_dirs, line); buildmap_range_add_no_address(line, street); /* These are never freed, need to be preserved for shape registration. */ lonsbuf = calloc(nWayNodes, sizeof(int)); latsbuf = calloc(nWayNodes, sizeof(int)); for (j=0; j<nWayNodes; j++) { int point = buildmap_osm_text_point_get(WayNodes[j]); int lon = buildmap_point_get_longitude(point); int lat = buildmap_point_get_latitude(point); /* Keep info for the shapes */ lonsbuf[j] = lon; latsbuf[j] = lat; buildmap_square_adjust_limits(lon, lat); } if (numshapes == nallocshapes) { /* Allocate additional space (in big chunks) when needed */ nallocshapes += 1000; shapes = realloc(shapes, nallocshapes * sizeof(struct shapeinfo)); buildmap_check_allocated(shapes); } /* Keep info for the shapes */ shapes[numshapes].lons = lonsbuf; shapes[numshapes].lats = latsbuf; shapes[numshapes].count = nWayNodes; shapes[numshapes].lineid = lineid; numshapes++; } buildmap_osm_text_reset_way(); return 0; } /** * @brief a postprocessing step to load shape info * * this needs to be a separate step because lines need to be sorted */ static int buildmap_osm_text_ways_shapeinfo(void) { int i, j, count, lineid; int *lons, *lats; int line_index; buildmap_info("loading shape info (from %d ways) ...", numshapes); buildmap_line_sort(); for (i = 0; i < numshapes; i++) { count = shapes[i].count; if (count <= 2) continue; lineid = shapes[i].lineid; line_index = buildmap_line_find_sorted(lineid); #if 0 if (line_index != 25) { buildmap_info("Shapes skipped for line %d", line_index); continue; } else { buildmap_info("Shapes generated for line %d", line_index); } #endif if (line_index >= 0) { lons = shapes[i].lons; lats = shapes[i].lats; /* Add the shape points here */ for (j = 1; j < count - 1; j++) { buildmap_shape_add (line_index, i, lineid, j - 1, lons[j], lats[j]); #if 0 if (line_index == 25) buildmap_info("buildmap_shape_add(%d,%d,%d,%d,%d,%d)", line_index, i, lineid, j - 1, lons[j], lats[j]); #endif } } } return 1; } /** * @brief This is the gut of buildmap_osm_text : parse an OSM XML file * @param fdata an open file pointer, this will get read twice * @return error indication * * This is a simplistic approach to parsing the OSM text (XML) files. * It scans the XML twice, to cope with out of order information. * (Note that this simplistic approach may raise eyebrows, but this is * not a big time consumer !) * * Pass 1 deals with node definitions only. * Pass 2 interprets ways and a few tags. * All underlying processing is passed to other functions. */ int buildmap_osm_text_read(FILE * fdata) { int got; static char buf[LINELEN]; int ret = 0; char *p; time_t t0, t1, t2, t3; (void) time(&t0); DictionaryPrefix = buildmap_dictionary_open("prefix"); DictionaryStreet = buildmap_dictionary_open("street"); DictionaryType = buildmap_dictionary_open("type"); DictionarySuffix = buildmap_dictionary_open("suffix"); DictionaryCity = buildmap_dictionary_open("city"); buildmap_osm_common_find_layers (); /* * Pass 1 */ LineNo = 0; while (! feof(fdata)) { buildmap_set_line(++LineNo); got = (int)fgets(buf, LINELEN, fdata); if (got <= 0) { if (feof(fdata)) break; buildmap_fatal(0, "short read (length)"); } /* Figure out the XML */ for (p=buf; *p && isspace(*p); p++) ; if (*p == '\n' || *p == '\r') continue; if (*p != '<') buildmap_fatal(0, "invalid XML"); p++; /* point to character after '<' now */ for (; *p && isspace(*p); p++) ; if (strncasecmp(p, "osm", 3) == 0) { continue; } else if (strncasecmp(p, "?xml", 4) == 0) { continue; } else if (strncasecmp(p, "way", 3) == 0) { // ret += buildmap_osm_text_way(p); continue; } else if (strncasecmp(p, "/way", 4) == 0) { // ret += buildmap_osm_text_way_end(p); continue; } else if (strncasecmp(p, "node", 4) == 0) { ret += buildmap_osm_text_node(p); continue; } else if (strncasecmp(p, "/node", 5) == 0) { ret += buildmap_osm_text_node_end(p); continue; } else if (strncasecmp(p, "nd", 2) == 0) { // ret += buildmap_osm_text_nd(p); continue; } else if (strncasecmp(p, "tag", 3) == 0) { ret += buildmap_osm_text_tag(p); continue; } else if (strncasecmp(p, "relation", 8) == 0) { continue; } else if (strncasecmp(p, "/relation", 9) == 0) { continue; } else if (strncasecmp(p, "member", 6) == 0) { continue; } else if (strncasecmp(p, "/member", 7) == 0) { continue; } else if (strncasecmp(p, "bound", 5) == 0) { continue; } else if (strncasecmp(p, "bounds", 6) == 0) { continue; } else if (strncasecmp(p, "/bounds", 7) == 0) { continue; } else if (strncasecmp(p, "/osm", 4) == 0) { continue; } else { buildmap_fatal(0, "invalid XML token (%s)", p); } } (void) time(&t1); buildmap_info("Pass 1 : %d lines read (%d seconds)", LineNo, t1 - t0); /* * Pass 2 */ LineNo = 0; fseek(fdata, 0L, SEEK_SET); while (! feof(fdata)) { buildmap_set_line(++LineNo); got = (int)fgets(buf, LINELEN, fdata); if (got <= 0) { if (feof(fdata)) break; buildmap_fatal(0, "short read (length)"); } /* Figure out the XML */ for (p=buf; *p && isspace(*p); p++) ; if (*p == '\n' || *p == '\r') continue; if (*p != '<') buildmap_fatal(0, "invalid XML"); p++; /* point to character after '<' now */ for (; *p && isspace(*p); p++) ; if (strncasecmp(p, "osm", 3) == 0) { continue; } else if (strncasecmp(p, "?xml", 4) == 0) { continue; } else if (strncasecmp(p, "way", 3) == 0) { ret += buildmap_osm_text_way(p); continue; } else if (strncasecmp(p, "/way", 4) == 0) { ret += buildmap_osm_text_way_end(p); continue; } else if (strncasecmp(p, "node", 4) == 0) { // ret += buildmap_osm_text_node(p); continue; } else if (strncasecmp(p, "/node", 5) == 0) { // ret += buildmap_osm_text_node_end(p); continue; } else if (strncasecmp(p, "nd", 2) == 0) { ret += buildmap_osm_text_nd(p); continue; } else if (strncasecmp(p, "tag", 3) == 0) { ret += buildmap_osm_text_tag(p); continue; } else if (strncasecmp(p, "relation", 8) == 0) { continue; } else if (strncasecmp(p, "/relation", 9) == 0) { continue; } else if (strncasecmp(p, "member", 6) == 0) { continue; } else if (strncasecmp(p, "/member", 7) == 0) { continue; } else if (strncasecmp(p, "bound", 5) == 0) { continue; } else if (strncasecmp(p, "bounds", 6) == 0) { continue; } else if (strncasecmp(p, "/bounds", 7) == 0) { continue; } else if (strncasecmp(p, "/osm", 4) == 0) { continue; } else { buildmap_fatal(0, "invalid XML token (%s)", p); } } (void) time(&t2); buildmap_info("Pass 2 : %d lines read (%d seconds)", LineNo, t2 - t1); /* * End pass 2 */ buildmap_osm_text_ways_shapeinfo(); (void) time(&t3); buildmap_info("Shape info processed (%d seconds)", t3 - t2); return ret; } Index: buildmap_point.c =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/buildmap_point.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** buildmap_point.c 27 Nov 2007 14:41:13 -0000 1.9 --- buildmap_point.c 4 Aug 2008 17:44:07 -0000 1.10 *************** *** 1,4 **** ! /* buildmap_point.c - Build a table of all points referenced in lines. ! * * LICENSE: * --- 1,3 ---- ! /* * LICENSE: * *************** *** 20,23 **** --- 19,27 ---- * along with RoadMap; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + /** + * @file + * @brief Build a table of all points referenced in lines. * * SYNOPSYS: *************** *** 86,90 **** } ! int buildmap_point_add (int longitude, int latitude) { --- 90,99 ---- } ! /** ! * @brief add a point to buildmap's tables ! * @param longitude the longitude of this point ! * @param latitude the latitude of this point ! * @return the point count ! */ int buildmap_point_add (int longitude, int latitude) { *************** *** 330,338 **** buildmap_db *table_bysquare; - - buildmap_info ("saving points..."); - if (!PointCount) return; square_count = buildmap_square_get_count(); --- 339,346 ---- buildmap_db *table_bysquare; if (!PointCount) return; + buildmap_info ("saving %d points...", PointCount); + square_count = buildmap_square_get_count(); Index: buildmap_osm_main.c =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/buildmap_osm_main.c,v retri... [truncated message content] |