From 5a1842aad1f46a3706b2a241b4c84f401d38fef1 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sat, 2 Apr 2011 03:45:50 +0000 Subject: [PATCH] remove tabs --- plugins/input/gdal/SConscript | 8 +- plugins/input/geos/SConscript | 8 +- plugins/input/kismet/SConscript | 8 +- plugins/input/occi/SConscript | 14 +- plugins/input/occi/occi_featureset.cpp | 2 +- plugins/input/ogr/SConscript | 12 +- plugins/input/ogr/ogr_datasource.cpp | 6 +- plugins/input/osm/Makefile.example | 4 +- plugins/input/osm/SConscript | 16 +- plugins/input/osm/basiccurl.cpp | 56 +-- plugins/input/osm/basiccurl.h | 4 +- plugins/input/osm/dataset_deliverer.cpp | 76 ++--- plugins/input/osm/demo/GoogleProjection.h | 106 +++--- plugins/input/osm/demo/MapSource.cpp | 40 +-- plugins/input/osm/libMakefile | 2 +- plugins/input/osm/osm.cpp | 322 +++++++++--------- plugins/input/osm/osm.h | 2 +- plugins/input/osm/osm_datasource.cpp | 2 +- plugins/input/osm/osm_datasource.hpp | 10 +- plugins/input/osm/osm_featureset.hpp | 4 +- plugins/input/osm/osmparser.cpp | 222 ++++++------ plugins/input/osm/osmparser.h | 2 +- plugins/input/osm/osmtagtypes.h | 24 +- plugins/input/osm/render.cpp | 66 ++-- plugins/input/osm/test.cpp | 34 +- plugins/input/osm/test.xml | 74 ++-- plugins/input/osm/test2.xml | 56 +-- plugins/input/osm/test3.xml | 56 +-- plugins/input/postgis/SConscript | 4 +- plugins/input/postgis/postgisfs.cpp | 98 +++--- plugins/input/raster/SConscript | 10 +- plugins/input/rasterlite/SConscript | 8 +- .../rasterlite/rasterlite_datasource.cpp | 6 +- .../rasterlite/rasterlite_featureset.cpp | 2 +- plugins/input/shape/SConscript | 6 +- plugins/input/shape/dbf_test.cpp | 2 +- plugins/input/shape/shape_io.cpp | 8 +- plugins/input/sqlite/SConscript | 8 +- plugins/input/sqlite/sqlite_types.hpp | 2 +- plugins/input/templates/helloworld/build.py | 8 +- 40 files changed, 702 insertions(+), 696 deletions(-) diff --git a/plugins/input/gdal/SConscript b/plugins/input/gdal/SConscript index ce6f11abe..dd910463a 100644 --- a/plugins/input/gdal/SConscript +++ b/plugins/input/gdal/SConscript @@ -27,10 +27,10 @@ install_prefix = env['DESTDIR'] + '/' + prefix plugin_env = env.Clone() gdal_src = Split( - """ - gdal_datasource.cpp - gdal_featureset.cpp - """ + """ + gdal_datasource.cpp + gdal_featureset.cpp + """ ) libraries = [env['PLUGINS']['gdal']['lib']] diff --git a/plugins/input/geos/SConscript b/plugins/input/geos/SConscript index a5b89c1c1..8619633da 100644 --- a/plugins/input/geos/SConscript +++ b/plugins/input/geos/SConscript @@ -28,10 +28,10 @@ install_prefix = env['DESTDIR'] + '/' + prefix plugin_env = env.Clone() geos_src = Split( - """ - geos_datasource.cpp - geos_featureset.cpp - """ + """ + geos_datasource.cpp + geos_featureset.cpp + """ ) libraries = [env['PLUGINS']['geos']['lib']] diff --git a/plugins/input/kismet/SConscript b/plugins/input/kismet/SConscript index c24afc42a..400e46825 100644 --- a/plugins/input/kismet/SConscript +++ b/plugins/input/kismet/SConscript @@ -27,10 +27,10 @@ install_prefix = env['DESTDIR'] + '/' + prefix plugin_env = env.Clone() kismet_src = Split( - """ - kismet_datasource.cpp - kismet_featureset.cpp - """ + """ + kismet_datasource.cpp + kismet_featureset.cpp + """ ) libraries = [] diff --git a/plugins/input/occi/SConscript b/plugins/input/occi/SConscript index bc064aa3c..13df7cb04 100644 --- a/plugins/input/occi/SConscript +++ b/plugins/input/occi/SConscript @@ -27,13 +27,13 @@ install_prefix = env['DESTDIR'] + '/' + prefix plugin_env = env.Clone() occi_src = Split( - """ - occi_types.cpp - occi_datasource.cpp - occi_featureset.cpp - spatial_classesm.cpp - spatial_classeso.cpp - """ + """ + occi_types.cpp + occi_datasource.cpp + occi_featureset.cpp + spatial_classesm.cpp + spatial_classeso.cpp + """ ) libraries = [ 'occi', 'ociei' ] diff --git a/plugins/input/occi/occi_featureset.cpp b/plugins/input/occi/occi_featureset.cpp index 101ddd7de..feb057556 100644 --- a/plugins/input/occi/occi_featureset.cpp +++ b/plugins/input/occi/occi_featureset.cpp @@ -189,7 +189,7 @@ feature_ptr occi_featureset::next() std::clog << "OCCI Plugin: unknown datatype (type_oid=" << type_oid << ")" << std::endl; #endif break; - } + } } ++count_; diff --git a/plugins/input/ogr/SConscript b/plugins/input/ogr/SConscript index ebbfede73..39ba4887a 100644 --- a/plugins/input/ogr/SConscript +++ b/plugins/input/ogr/SConscript @@ -28,12 +28,12 @@ install_prefix = env['DESTDIR'] + '/' + prefix plugin_env = env.Clone() ogr_src = Split( - """ - ogr_converter.cpp - ogr_datasource.cpp - ogr_featureset.cpp - ogr_index_featureset.cpp - """ + """ + ogr_converter.cpp + ogr_datasource.cpp + ogr_featureset.cpp + ogr_index_featureset.cpp + """ ) libraries = [env['PLUGINS']['ogr']['lib']] diff --git a/plugins/input/ogr/ogr_datasource.cpp b/plugins/input/ogr/ogr_datasource.cpp index f99a2f9d8..1063976fa 100644 --- a/plugins/input/ogr/ogr_datasource.cpp +++ b/plugins/input/ogr/ogr_datasource.cpp @@ -300,7 +300,7 @@ featureset_ptr ogr_datasource::features(query const& q) const { s <<",\""<<*pos<<"\""; ++pos; - } + } s << " from " << layerName_ ; // execute existing SQL @@ -353,8 +353,8 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const else { OGRPoint point; - point.setX (pt.x); - point.setY (pt.y); + point.setX (pt.x); + point.setY (pt.y); return featureset_ptr(new ogr_featureset (*dataset_, *layer_, diff --git a/plugins/input/osm/Makefile.example b/plugins/input/osm/Makefile.example index 8268e6792..b89658478 100644 --- a/plugins/input/osm/Makefile.example +++ b/plugins/input/osm/Makefile.example @@ -3,7 +3,7 @@ LDFLAGS = `xml2-config --libs` -L/usr/local/lib LDFLAGS5 = `xml2-config --libs` -L/usr/local/lib -lmapnik OBJ = test.o osm.o osmparser.o test: $(OBJ) - g++ -o test $(OBJ) $(LDFLAGS) + g++ -o test $(OBJ) $(LDFLAGS) render: render.o - g++ -o render render.o $(LDFLAGS5) + g++ -o render render.o $(LDFLAGS5) diff --git a/plugins/input/osm/SConscript b/plugins/input/osm/SConscript index 5b88cd8bb..82f606820 100644 --- a/plugins/input/osm/SConscript +++ b/plugins/input/osm/SConscript @@ -27,14 +27,14 @@ install_prefix = env['DESTDIR'] + '/' + prefix plugin_env = env.Clone() osm_src = Split( - """ - osmparser.cpp - osm.cpp - osm_datasource.cpp - osm_featureset.cpp - dataset_deliverer.cpp - basiccurl.cpp - """ + """ + osmparser.cpp + osm.cpp + osm_datasource.cpp + osm_featureset.cpp + dataset_deliverer.cpp + basiccurl.cpp + """ ) libraries = [ 'xml2' ] diff --git a/plugins/input/osm/basiccurl.cpp b/plugins/input/osm/basiccurl.cpp index bb582b086..74d6c9880 100755 --- a/plugins/input/osm/basiccurl.cpp +++ b/plugins/input/osm/basiccurl.cpp @@ -2,44 +2,44 @@ CURL_LOAD_DATA *grab_http_response(const char *url) { - CURL_LOAD_DATA *data; + CURL_LOAD_DATA *data; - CURL *curl = curl_easy_init(); + CURL *curl = curl_easy_init(); - if(curl) - { - data = do_grab(curl,url); - curl_easy_cleanup(curl); - return data; - } - return NULL; + if(curl) + { + data = do_grab(curl,url); + curl_easy_cleanup(curl); + return data; + } + return NULL; } CURL_LOAD_DATA *do_grab(CURL *curl,const char *url) { - CURLcode res; - CURL_LOAD_DATA *data = (CURL_LOAD_DATA *)malloc(sizeof(CURL_LOAD_DATA)); - data->data = NULL; - data->nbytes = 0; - - curl_easy_setopt(curl,CURLOPT_URL,url); - curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,response_callback); - curl_easy_setopt(curl,CURLOPT_WRITEDATA,data); + CURLcode res; + CURL_LOAD_DATA *data = (CURL_LOAD_DATA *)malloc(sizeof(CURL_LOAD_DATA)); + data->data = NULL; + data->nbytes = 0; + + curl_easy_setopt(curl,CURLOPT_URL,url); + curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,response_callback); + curl_easy_setopt(curl,CURLOPT_WRITEDATA,data); - res=curl_easy_perform(curl); + res=curl_easy_perform(curl); - return data; + return data; } size_t response_callback(void *ptr,size_t size,size_t nmemb, void *d) { - size_t rsize=size*nmemb; - CURL_LOAD_DATA *data=(CURL_LOAD_DATA *)d; -// fprintf(stderr,"rsize is %d\n", rsize); - data->data=(char *)realloc(data->data,(data->nbytes+rsize) - *sizeof(char)); - memcpy(&(data->data[data->nbytes]),ptr,rsize); - data->nbytes += rsize; -// fprintf(stderr,"data->nbytes is %d\n", data->nbytes); - return rsize; + size_t rsize=size*nmemb; + CURL_LOAD_DATA *data=(CURL_LOAD_DATA *)d; +// fprintf(stderr,"rsize is %d\n", rsize); + data->data=(char *)realloc(data->data,(data->nbytes+rsize) + *sizeof(char)); + memcpy(&(data->data[data->nbytes]),ptr,rsize); + data->nbytes += rsize; +// fprintf(stderr,"data->nbytes is %d\n", data->nbytes); + return rsize; } diff --git a/plugins/input/osm/basiccurl.h b/plugins/input/osm/basiccurl.h index 5e600cf49..8981c773a 100755 --- a/plugins/input/osm/basiccurl.h +++ b/plugins/input/osm/basiccurl.h @@ -7,8 +7,8 @@ typedef struct { - char *data; - int nbytes; + char *data; + int nbytes; } CURL_LOAD_DATA; CURL_LOAD_DATA *grab_http_response(const char *url); diff --git a/plugins/input/osm/dataset_deliverer.cpp b/plugins/input/osm/dataset_deliverer.cpp index 07e0b9a56..1e2b11d8c 100644 --- a/plugins/input/osm/dataset_deliverer.cpp +++ b/plugins/input/osm/dataset_deliverer.cpp @@ -7,50 +7,50 @@ std::string dataset_deliverer::last_bbox = ""; std::string dataset_deliverer::last_filename = ""; osm_dataset* dataset_deliverer::load_from_file(const string& file, - const string& parser) + const string& parser) { - // Only actually load from file if we haven't done so already - if(dataset == NULL) - { - dataset = new osm_dataset; - if(dataset->load(file.c_str(),parser)==false) - return NULL; - atexit(dataset_deliverer::release); - last_filename = file; - } - else if(file != last_filename) - { - dataset = new osm_dataset; - if(dataset->load(file.c_str(),parser)==false) - return NULL; - last_filename = file; - } - return dataset; + // Only actually load from file if we haven't done so already + if(dataset == NULL) + { + dataset = new osm_dataset; + if(dataset->load(file.c_str(),parser)==false) + return NULL; + atexit(dataset_deliverer::release); + last_filename = file; + } + else if(file != last_filename) + { + dataset = new osm_dataset; + if(dataset->load(file.c_str(),parser)==false) + return NULL; + last_filename = file; + } + return dataset; } osm_dataset* dataset_deliverer::load_from_url - (const string& url,const string& bbox,const string& parser) + (const string& url,const string& bbox,const string& parser) { - - if(dataset==NULL) - { - dataset = new osm_dataset; - if(dataset->load_from_url(url.c_str(),bbox,parser)==false) - return NULL; - atexit(dataset_deliverer::release); - last_bbox = bbox; - } - else if (bbox != last_bbox) - { + + if(dataset==NULL) + { + dataset = new osm_dataset; + if(dataset->load_from_url(url.c_str(),bbox,parser)==false) + return NULL; + atexit(dataset_deliverer::release); + last_bbox = bbox; + } + else if (bbox != last_bbox) + { #ifdef MAPNIK_DEBUG - cerr<<"BBOXES ARE DIFFERENT: " << last_bbox<<","<clear(); - if(dataset->load_from_url(url.c_str(),bbox,parser)==false) - return NULL; - last_bbox = bbox; - } - return dataset; + // Reload the dataset + dataset->clear(); + if(dataset->load_from_url(url.c_str(),bbox,parser)==false) + return NULL; + last_bbox = bbox; + } + return dataset; } diff --git a/plugins/input/osm/demo/GoogleProjection.h b/plugins/input/osm/demo/GoogleProjection.h index 801c9b6e1..e292ea28d 100644 --- a/plugins/input/osm/demo/GoogleProjection.h +++ b/plugins/input/osm/demo/GoogleProjection.h @@ -10,16 +10,16 @@ using std::vector; struct ScreenPos { - int x,y; - ScreenPos() { x=y=0; } - ScreenPos(int x,int y) { this->x=x; this->y=y; } + int x,y; + ScreenPos() { x=y=0; } + ScreenPos(int x,int y) { this->x=x; this->y=y; } }; struct EarthPoint { - double x,y; - EarthPoint() { x=y=0.0; } - EarthPoint(double x,double y) { this->x=x; this->y=y; } + double x,y; + EarthPoint() { x=y=0.0; } + EarthPoint(double x,double y) { this->x=x; this->y=y; } }; class GoogleProjection @@ -29,69 +29,69 @@ class GoogleProjection vector Bc,Cc,zc,Ac; int levels; - double minmax (double a,double b, double c) - { - a = max(a,b); - a = min(a,c); - return a; - } + double minmax (double a,double b, double c) + { + a = max(a,b); + a = min(a,c); + return a; + } public: GoogleProjection(int levels=18) { - this->levels=levels; + this->levels=levels; double c = 256; - double e; + double e; for (int d=0; dnbytes+1]; - memcpy(blx,resp->data,resp->nbytes); - blx[resp->nbytes] = '\0'; + if(resp!=NULL) + { + char *blx = new char[resp->nbytes+1]; + memcpy(blx,resp->data,resp->nbytes); + blx[resp->nbytes] = '\0'; #ifdef MAPNIK_DEBUG - cerr<< " CURL RESPONSE: " << blx << endl; + cerr<< " CURL RESPONSE: " << blx << endl; #endif - delete[] blx; - bool success= osmparser::parse(this,resp->data,resp->nbytes); - return success; - } - } - return false; + delete[] blx; + bool success= osmparser::parse(this,resp->data,resp->nbytes); + return success; + } + } + return false; } osm_dataset::~osm_dataset() { - clear(); + clear(); } void osm_dataset::clear() { #ifdef MAPNIK_DEBUG - cerr<<"osm_dataset::clear()"<to_string(); - } - for(unsigned int count=0; countto_string(); - } - return result; + for(unsigned int count=0; countto_string(); + } + for(unsigned int count=0; countto_string(); + } + return result; } bounds osm_dataset::get_bounds() { - bounds b (-180,-90,180,90); - for(unsigned int count=0; countlon > b.w) - b.w=nodes[count]->lon; - if(nodes[count]->lon < b.e) - b.e=nodes[count]->lon; - if(nodes[count]->lat > b.s) - b.s=nodes[count]->lat; - if(nodes[count]->lat < b.n) - b.n=nodes[count]->lat; - } - return b; + bounds b (-180,-90,180,90); + for(unsigned int count=0; countlon > b.w) + b.w=nodes[count]->lon; + if(nodes[count]->lon < b.e) + b.e=nodes[count]->lon; + if(nodes[count]->lat > b.s) + b.s=nodes[count]->lat; + if(nodes[count]->lat < b.n) + b.n=nodes[count]->lat; + } + return b; } osm_node *osm_dataset::next_node() { - if(node_i!=nodes.end()) - { - return *(node_i++); - } - return NULL; - + if(node_i!=nodes.end()) + { + return *(node_i++); + } + return NULL; + } osm_way *osm_dataset::next_way() { - if(way_i!=ways.end()) - { - return *(way_i++); - } - return NULL; + if(way_i!=ways.end()) + { + return *(way_i++); + } + return NULL; } - + osm_item *osm_dataset::next_item() { - osm_item *item=NULL; - if(next_item_mode==Node) - { - item = next_node(); - if(item==NULL) - { - next_item_mode=Way; - rewind_ways(); - item = next_way(); - } - } - else - { - item = next_way(); - } - return item; + osm_item *item=NULL; + if(next_item_mode==Node) + { + item = next_node(); + if(item==NULL) + { + next_item_mode=Way; + rewind_ways(); + item = next_way(); + } + } + else + { + item = next_way(); + } + return item; } - + std::set osm_dataset::get_keys() { - std::set keys; - for(unsigned int count=0; count::iterator i= - nodes[count]->keyvals.begin(); i!=nodes[count]->keyvals.end(); i++) - { - keys.insert(i->first); - } - } - for(unsigned int count=0; count::iterator i= - ways[count]->keyvals.begin(); i!=ways[count]->keyvals.end(); i++) - { - keys.insert(i->first); - } - } - return keys; + std::set keys; + for(unsigned int count=0; count::iterator i= + nodes[count]->keyvals.begin(); i!=nodes[count]->keyvals.end(); i++) + { + keys.insert(i->first); + } + } + for(unsigned int count=0; count::iterator i= + ways[count]->keyvals.begin(); i!=ways[count]->keyvals.end(); i++) + { + keys.insert(i->first); + } + } + return keys; } - - + + std::string osm_item::to_string() { - std::ostringstream strm; - strm << "id=" << id << std::endl << "Keyvals: " << std::endl; - for(std::map::iterator i=keyvals.begin(); - i!=keyvals.end(); i++) - { - strm << "Key " << i->first << " Value " << i->second << std::endl; - } - return strm.str(); + std::ostringstream strm; + strm << "id=" << id << std::endl << "Keyvals: " << std::endl; + for(std::map::iterator i=keyvals.begin(); + i!=keyvals.end(); i++) + { + strm << "Key " << i->first << " Value " << i->second << std::endl; + } + return strm.str(); } std::string osm_node::to_string() { - std::ostringstream strm; - strm << "Node: "<< osm_item::to_string() << - " Lat=" << lat <<" lon=" <id << " "; - } - } - strm << std::endl; - return strm.str(); + for(unsigned int count=0; countid << " "; + } + } + strm << std::endl; + return strm.str(); } bounds osm_way::get_bounds() { - bounds b (-180,-90,180,90); - for(unsigned int count=0; countlon > b.w) - b.w=nodes[count]->lon; - if(nodes[count]->lon < b.e) - b.e=nodes[count]->lon; - if(nodes[count]->lat > b.s) - b.s=nodes[count]->lat; - if(nodes[count]->lat < b.n) - b.n=nodes[count]->lat; - } - return b; + bounds b (-180,-90,180,90); + for(unsigned int count=0; countlon > b.w) + b.w=nodes[count]->lon; + if(nodes[count]->lon < b.e) + b.e=nodes[count]->lon; + if(nodes[count]->lat > b.s) + b.s=nodes[count]->lat; + if(nodes[count]->lat < b.n) + b.n=nodes[count]->lat; + } + return b; } bool osm_way::is_polygon() { - for(unsigned int count=0; count("natural","heath")); ptypes.push_back(std::pair("natural","marsh")); ptypes.push_back(std::pair("military", - "danger_area")); + "danger_area")); ptypes.push_back(std::pair ("landuse","forest")); ptypes.push_back(std::pair diff --git a/plugins/input/osm/osm_datasource.cpp b/plugins/input/osm/osm_datasource.cpp index 82d779b32..5c18373f8 100644 --- a/plugins/input/osm/osm_datasource.cpp +++ b/plugins/input/osm/osm_datasource.cpp @@ -71,7 +71,7 @@ void osm_datasource::bind() const { // otherwise if we supplied a url and a bounding box, load from the url #ifdef MAPNIK_DEBUG - cerr<<"loading_from_url: url="<lat=atof((char*)xlat); - node->lon=atof((char*)xlon); - node->id = atol((char*)xid); - cur_item = node; - tmp_node_store[node->id] = node; - xmlFree(xid); - xmlFree(xlon); - xmlFree(xlat); - } - else if (xmlStrEqual(name,BAD_CAST "way")) - { - curID=0; - in_way = true; - osm_way *way=new osm_way; - xid=xmlTextReaderGetAttribute(reader,BAD_CAST "id"); - assert(xid); - way->id = atol((char*)xid); - cur_item = way; - // Prevent ways with no name being assigned a name of "0" - cur_item->keyvals["name"] = ""; + if(xmlStrEqual(name,BAD_CAST "node")) + { + curID = 0; + in_node = true; + osm_node *node=new osm_node; + xlat=xmlTextReaderGetAttribute(reader,BAD_CAST "lat"); + xlon=xmlTextReaderGetAttribute(reader,BAD_CAST "lon"); + xid=xmlTextReaderGetAttribute(reader,BAD_CAST "id"); + assert(xlat); + assert(xlon); + assert(xid); + node->lat=atof((char*)xlat); + node->lon=atof((char*)xlon); + node->id = atol((char*)xid); + cur_item = node; + tmp_node_store[node->id] = node; + xmlFree(xid); + xmlFree(xlon); + xmlFree(xlat); + } + else if (xmlStrEqual(name,BAD_CAST "way")) + { + curID=0; + in_way = true; + osm_way *way=new osm_way; + xid=xmlTextReaderGetAttribute(reader,BAD_CAST "id"); + assert(xid); + way->id = atol((char*)xid); + cur_item = way; + // Prevent ways with no name being assigned a name of "0" + cur_item->keyvals["name"] = ""; - // HACK: allows comparison with "" in the XML file. Otherwise it - // doesn't work. Only do for the most crucial tags for Freemap's - // purposes. TODO investigate why this is - cur_item->keyvals["width"] = ""; - cur_item->keyvals["horse"] = ""; - cur_item->keyvals["foot"] = ""; - cur_item->keyvals["bicycle"] = ""; - xmlFree(xid); - } - else if (xmlStrEqual(name,BAD_CAST "nd")) - { - xid=xmlTextReaderGetAttribute(reader,BAD_CAST "ref"); - assert(xid); - long ndid = atol((char*)xid); - if(tmp_node_store.find(ndid)!=tmp_node_store.end()) - { - (static_cast(cur_item))->nodes.push_back - (tmp_node_store[ndid]); - } - xmlFree(xid); - } - else if (xmlStrEqual(name,BAD_CAST "tag")) - { - std::string key="", value=""; - xk = xmlTextReaderGetAttribute(reader,BAD_CAST "k"); - xv = xmlTextReaderGetAttribute(reader,BAD_CAST "v"); - assert(xk); - assert(xv); - cur_item->keyvals[(char*)xk] = (char*)xv; - xmlFree(xk); - xmlFree(xv); - } + // HACK: allows comparison with "" in the XML file. Otherwise it + // doesn't work. Only do for the most crucial tags for Freemap's + // purposes. TODO investigate why this is + cur_item->keyvals["width"] = ""; + cur_item->keyvals["horse"] = ""; + cur_item->keyvals["foot"] = ""; + cur_item->keyvals["bicycle"] = ""; + xmlFree(xid); + } + else if (xmlStrEqual(name,BAD_CAST "nd")) + { + xid=xmlTextReaderGetAttribute(reader,BAD_CAST "ref"); + assert(xid); + long ndid = atol((char*)xid); + if(tmp_node_store.find(ndid)!=tmp_node_store.end()) + { + (static_cast(cur_item))->nodes.push_back + (tmp_node_store[ndid]); + } + xmlFree(xid); + } + else if (xmlStrEqual(name,BAD_CAST "tag")) + { + std::string key="", value=""; + xk = xmlTextReaderGetAttribute(reader,BAD_CAST "k"); + xv = xmlTextReaderGetAttribute(reader,BAD_CAST "v"); + assert(xk); + assert(xv); + cur_item->keyvals[(char*)xk] = (char*)xv; + xmlFree(xk); + xmlFree(xv); + } } void osmparser::endElement(const xmlChar* name) { - if(xmlStrEqual(name,BAD_CAST "node")) - { - in_node = false; - components->add_node(static_cast(cur_item)); - } - else if(xmlStrEqual(name,BAD_CAST "way")) - { - in_way = false; - components->add_way(static_cast(cur_item)); - } + if(xmlStrEqual(name,BAD_CAST "node")) + { + in_node = false; + components->add_node(static_cast(cur_item)); + } + else if(xmlStrEqual(name,BAD_CAST "way")) + { + in_way = false; + components->add_way(static_cast(cur_item)); + } } bool osmparser::parse(osm_dataset *ds, const char* filename) { - components=ds; - xmlTextReaderPtr reader = xmlNewTextReaderFilename(filename); - int ret=do_parse(reader); - xmlFreeTextReader(reader); - return (ret==0) ? true:false; + components=ds; + xmlTextReaderPtr reader = xmlNewTextReaderFilename(filename); + int ret=do_parse(reader); + xmlFreeTextReader(reader); + return (ret==0) ? true:false; } bool osmparser::parse(osm_dataset *ds,char* data, int nbytes) { - // from cocoasamurai.blogspot.com/2008/10/getting-some-xml-love-with- - // libxml2.html, converted from Objective-C to straight C + // from cocoasamurai.blogspot.com/2008/10/getting-some-xml-love-with- + // libxml2.html, converted from Objective-C to straight C - components=ds; - xmlTextReaderPtr reader = xmlReaderForMemory(data,nbytes,NULL,NULL,0); - int ret=do_parse(reader); - xmlFreeTextReader(reader); - return (ret==0) ? true:false; + components=ds; + xmlTextReaderPtr reader = xmlReaderForMemory(data,nbytes,NULL,NULL,0); + int ret=do_parse(reader); + xmlFreeTextReader(reader); + return (ret==0) ? true:false; } - + int osmparser::do_parse(xmlTextReaderPtr reader) { - int ret=-1; - if(reader!=NULL) - { - ret = xmlTextReaderRead(reader); - while(ret==1) - { - processNode(reader); - ret=xmlTextReaderRead(reader); - } - } - return ret; + int ret=-1; + if(reader!=NULL) + { + ret = xmlTextReaderRead(reader); + while(ret==1) + { + processNode(reader); + ret=xmlTextReaderRead(reader); + } + } + return ret; } diff --git a/plugins/input/osm/osmparser.h b/plugins/input/osm/osmparser.h index 1ac25f3a1..5ffa0477f 100644 --- a/plugins/input/osm/osmparser.h +++ b/plugins/input/osm/osmparser.h @@ -17,7 +17,7 @@ private: static std::string error; static std::map tmp_node_store; - static int do_parse(xmlTextReaderPtr); + static int do_parse(xmlTextReaderPtr); public: static void processNode(xmlTextReaderPtr reader); diff --git a/plugins/input/osm/osmtagtypes.h b/plugins/input/osm/osmtagtypes.h index 1d48f2bcd..d486946a8 100644 --- a/plugins/input/osm/osmtagtypes.h +++ b/plugins/input/osm/osmtagtypes.h @@ -9,20 +9,20 @@ class osm_tag_types { private: - std::map types; + std::map types; public: - void add_type(std::string tag, mapnik::eAttributeType type) - { - types[tag]=type; - } + void add_type(std::string tag, mapnik::eAttributeType type) + { + types[tag]=type; + } - mapnik::eAttributeType get_type(std::string tag) - { - std::map::iterator i = - types.find(tag); - return (i==types.end()) ? mapnik::String: i->second; - } + mapnik::eAttributeType get_type(std::string tag) + { + std::map::iterator i = + types.find(tag); + return (i==types.end()) ? mapnik::String: i->second; + } }; - + #endif // OSMTAGTYPES_H diff --git a/plugins/input/osm/render.cpp b/plugins/input/osm/render.cpp index e09521ec8..b55e8dd53 100644 --- a/plugins/input/osm/render.cpp +++ b/plugins/input/osm/render.cpp @@ -17,43 +17,43 @@ using namespace std; int main(int argc,char *argv[]) { - if(argc < 6) - { - std::cerr<<"Usage: render XMLfile w s e n [OSMfile]" << std::endl; - exit(0); - } + if(argc < 6) + { + std::cerr<<"Usage: render XMLfile w s e n [OSMfile]" << std::endl; + exit(0); + } - datasource_cache::instance()->register_datasources - ("/usr/local/lib/mapnik/input"); - freetype_engine::register_font - ("/usr/local/lib/mapnik/fonts/DejaVuSans.ttf"); + datasource_cache::instance()->register_datasources + ("/usr/local/lib/mapnik/input"); + freetype_engine::register_font + ("/usr/local/lib/mapnik/fonts/DejaVuSans.ttf"); - Map m (800,800); - load_map(m,argv[1]); - - if(argc>6) - { - parameters p; - p["type"] = "osm"; - p["file"] = argv[6]; - for(int count=0; countparams(); - m.getLayer(count).set_datasource(datasource_cache::instance()-> - create(p)); - } - } + Map m (800,800); + load_map(m,argv[1]); + + if(argc>6) + { + parameters p; + p["type"] = "osm"; + p["file"] = argv[6]; + for(int count=0; countparams(); + m.getLayer(count).set_datasource(datasource_cache::instance()-> + create(p)); + } + } - box2d bbox (atof(argv[2]),atof(argv[3]), - atof(argv[4]),atof(argv[5])); - - m.zoom_to_box(bbox); + box2d bbox (atof(argv[2]),atof(argv[3]), + atof(argv[4]),atof(argv[5])); + + m.zoom_to_box(bbox); - image_32 buf (m.width(), m.height()); - agg_renderer r(m,buf); - r.apply(); + image_32 buf (m.width(), m.height()); + agg_renderer r(m,buf); + r.apply(); - save_to_file(buf.data(),"blah.png","png"); + save_to_file(buf.data(),"blah.png","png"); - return 0; + return 0; } diff --git a/plugins/input/osm/test.cpp b/plugins/input/osm/test.cpp index d8ec5fe93..ddee14274 100644 --- a/plugins/input/osm/test.cpp +++ b/plugins/input/osm/test.cpp @@ -5,21 +5,21 @@ using std::endl; int main(int argc,char* argv[]) { - if(argc>=2) - { - osm_dataset dataset(argv[1]); - bounds b = dataset.get_bounds(); - osm_item *item; - dataset.rewind(); - while((item=dataset.next_item())!=NULL) - { - std::cerr << item->to_string() << endl; - } - } - else - { - std::cerr<<"Usage: test OSMfile"<=2) + { + osm_dataset dataset(argv[1]); + bounds b = dataset.get_bounds(); + osm_item *item; + dataset.rewind(); + while((item=dataset.next_item())!=NULL) + { + std::cerr << item->to_string() << endl; + } + } + else + { + std::cerr<<"Usage: test OSMfile"< - - #f2efe9 - - + + #f2efe9 + + + + - - + - + - + diff --git a/plugins/input/osm/test2.xml b/plugins/input/osm/test2.xml index 578dfb387..1d25f8710 100644 --- a/plugins/input/osm/test2.xml +++ b/plugins/input/osm/test2.xml @@ -5,22 +5,22 @@ [amenity]='pub' + width="16" height="16" /> [man_made]='mast' + width="16" height="16" /> [amenity]='parking' + width="16" height="16"/> [residence]='farm' + width="16" height="16"/> @@ -46,7 +46,7 @@ [leisure] = 'park' or [leisure] = 'common' or - [leisure] = 'golf_course' + [leisure] = 'golf_course' #d8e8d0 @@ -98,12 +98,12 @@ [natural] = 'peak' - - [natural] = 'wood' or [natural] = 'water' or [natural] = 'heath' - or [leisure] = 'golf_course' - - + + [natural] = 'wood' or [natural] = 'water' or [natural] = 'heath' + or [leisure] = 'golf_course' + + + + - - + - + - + @@ -46,7 +46,7 @@ [leisure] = 'park' or [leisure] = 'common' or - [leisure] = 'golf_course' + [leisure] = 'golf_course' #d8e8d0 @@ -98,12 +98,12 @@ [natural] = 'peak' - - [natural] = 'wood' or [natural] = 'water' or [natural] = 'heath' - or [leisure] = 'golf_course' - - + + [natural] = 'wood' or [natural] = 'water' or [natural] = 'heath' + or [leisure] = 'golf_course' + + + + - - + - + - +