static void find_all_nodes(Nodes *nodes,callback_t callback) { ll_bin_t latminbin=latlong_to_bin(radians_to_latlong(LatMin))-nodes->file.latzero; ll_bin_t latmaxbin=latlong_to_bin(radians_to_latlong(LatMax))-nodes->file.latzero; ll_bin_t lonminbin=latlong_to_bin(radians_to_latlong(LonMin))-nodes->file.lonzero; ll_bin_t lonmaxbin=latlong_to_bin(radians_to_latlong(LonMax))-nodes->file.lonzero; ll_bin_t latb,lonb; index_t i,index1,index2; /* Loop through all of the nodes. */ for(latb=latminbin;latb<=latmaxbin;latb++) for(lonb=lonminbin;lonb<=lonmaxbin;lonb++) { ll_bin2_t llbin=lonb*nodes->file.latbins+latb; if(llbin<0 || llbin>(nodes->file.latbins*nodes->file.lonbins)) continue; index1=LookupNodeOffset(nodes,llbin); index2=LookupNodeOffset(nodes,llbin+1); for(i=index1;i<index2;i++) { Node *node=LookupNode(nodes,i,1); double lat=latlong_to_radians(bin_to_latlong(nodes->file.latzero+latb)+off_to_latlong(node->latoffset)); double lon=latlong_to_radians(bin_to_latlong(nodes->file.lonzero+lonb)+off_to_latlong(node->lonoffset)); if(lat>LatMin && lat<LatMax && lon>LonMin && lon<LonMax) (*callback)(i,lat,lon); } } }
void AppendNode(NodesX *nodesx,node_t id,double latitude,double longitude,transports_t allow,uint16_t flags) { NodeX nodex; nodex.id=id; nodex.latitude =radians_to_latlong(latitude); nodex.longitude=radians_to_latlong(longitude); nodex.allow=allow; nodex.flags=flags; WriteFile(nodesx->fd,&nodex,sizeof(NodeX)); nodesx->number++; assert(nodesx->number<NODE_FAKE); /* NODE_FAKE marks the high-water mark for real nodes. */ }
void RemoveNonHighwayNodes(NodesX *nodesx,SegmentsX *segmentsx) { NodeX nodex; index_t total=0,highway=0,nothighway=0; ll_bin_t lat_min_bin,lat_max_bin,lon_min_bin,lon_max_bin; latlong_t lat_min,lat_max,lon_min,lon_max; int fd; /* Print the start message */ printf_first("Checking Nodes: Nodes=0"); /* While we are here we can work out the range of data */ lat_min=radians_to_latlong( 2); lat_max=radians_to_latlong(-2); lon_min=radians_to_latlong( 4); lon_max=radians_to_latlong(-4); /* Re-open the file read-only and a new file writeable */ nodesx->fd=ReOpenFile(nodesx->filename); DeleteFile(nodesx->filename); fd=OpenFileNew(nodesx->filename); /* Modify the on-disk image */ while(!ReadFile(nodesx->fd,&nodex,sizeof(NodeX))) { if(!IsBitSet(segmentsx->usednode,total)) nothighway++; else { nodex.id=highway; WriteFile(fd,&nodex,sizeof(NodeX)); nodesx->idata[highway]=nodesx->idata[total]; highway++; if(nodex.latitude<lat_min) lat_min=nodex.latitude; if(nodex.latitude>lat_max) lat_max=nodex.latitude; if(nodex.longitude<lon_min) lon_min=nodex.longitude; if(nodex.longitude>lon_max) lon_max=nodex.longitude; } total++; if(!(total%10000)) printf_middle("Checking Nodes: Nodes=%"Pindex_t" Highway=%"Pindex_t" not-Highway=%"Pindex_t,total,highway,nothighway); } nodesx->number=highway; /* Close the files */ nodesx->fd=CloseFile(nodesx->fd); CloseFile(fd); /* Work out the number of bins */ lat_min_bin=latlong_to_bin(lat_min); lon_min_bin=latlong_to_bin(lon_min); lat_max_bin=latlong_to_bin(lat_max); lon_max_bin=latlong_to_bin(lon_max); nodesx->latzero=lat_min_bin; nodesx->lonzero=lon_min_bin; nodesx->latbins=(lat_max_bin-lat_min_bin)+1; nodesx->lonbins=(lon_max_bin-lon_min_bin)+1; /* Free the now-unneeded index */ free(segmentsx->usednode); segmentsx->usednode=NULL; /* Allocate and set the super-node markers */ nodesx->super=(uint8_t*)malloc((1+nodesx->number/8)*sizeof(uint8_t)); assert(nodesx->super); /* Check calloc() worked */ memset(nodesx->super,~0,(1+nodesx->number/8)); /* Print the final message */ printf_last("Checked Nodes: Nodes=%"Pindex_t" Highway=%"Pindex_t" not-Highway=%"Pindex_t,total,highway,nothighway); }