Permalink
Browse files

Completed first release of the draw lines tool.

  • Loading branch information...
1 parent 3002dec commit 6c719346f6196b58bba1e42ee4d60c9796f580e9 Roland Olbricht committed Mar 3, 2011
Showing with 151 additions and 28 deletions.
  1. +4 −1 Makefile
  2. +35 −0 html/public_transport.html
  3. +35 −0 konzept.txt
  4. +0 −1 utils/diagrams/read_input.cc
  5. +70 −24 utils/diagrams/topographic.cc
  6. +7 −2 utils/draw-line.sh
View
@@ -76,7 +76,7 @@ union_$(suffix)
objects = expat_justparse_interface.o cgi-helper.o user_interface.o script_queries.o node_strings_file_io.o way_strings_file_io.o relation_strings_file_io.o script_tools.o vigilance_control.o $(stmts)
executable_objects = script-interpreter.o add_rule.o dump_rules.o get_rule.o load_rules.o update_rule.o import_osm.o apply_osc.o
executables = cgi-bin/interpreter cgi-bin/add_rule cgi-bin/get_rule cgi-bin/update_rule bin/dump_rules bin/load_rules
-shortcuts = cgi-bin/download cgi-bin/poi cgi-bin/elems bin/nodes-csv-lat-lon-name cgi-bin/nodes-csv bin/memberlist cgi-bin/nodes-csv-gzip cgi-bin/sketch-route cgi-bin/sketch-line bin/sketch-route-svg cgi-bin/sketch-options bin/uncgi bin/escape_xml bin/bbox-brim-query cgi-bin/rels-extended
+shortcuts = cgi-bin/download cgi-bin/poi cgi-bin/elems bin/nodes-csv-lat-lon-name cgi-bin/nodes-csv bin/memberlist cgi-bin/nodes-csv-gzip cgi-bin/sketch-route cgi-bin/sketch-line bin/sketch-route-svg bin/draw-route-svg cgi-bin/sketch-options bin/uncgi bin/escape_xml bin/bbox-brim-query cgi-bin/rels-extended
tool_headers = expat_justparse_interface.h script_datatypes.h script_queries.h script_tools.h user_interface.h
backend_generic_h = backend/raw_file_db.h backend/file_types.h script_datatypes.h
@@ -247,6 +247,9 @@ cgi-bin/%: utils/%.sh
cp $< $@
chmod 755 $@
+bin/draw-route-svg: utils/diagrams/topographic.cc utils/diagrams/read_input.cc utils/diagrams/read_input.h src/expat/expat_justparse_interface.cc src/expat/expat_justparse_interface.h
+ g++ -lexpat -o $@ -O3 -Wall $^
+
bin/%: utils/%.c expat_justparse_interface.h expat_justparse_interface.o
g++ -lexpat -o $@ -O3 -Wall $^
@@ -106,5 +106,40 @@
<li><emph>Mo-Fr 09:00-12:00; Mo-Tu 15:00-18:00; Th-Fr 15:00-18:00</emph>. This service is not operational on wednesday afternoons.</li>
</ul>
+<h1>Public Transport Line Map</h1>
+
+<h2>Access By network and line number</h2>
+
+<form action="api/draw-line" method="get" accept-charset="UTF-8">
+ <strong>Network</strong>: <input name="network" type="text" size="40"/><br/>
+ The value of the tag <em>network</em> of the relation(s) to consider. A working example is <em>VRR</em>
+ for the German <em>Verkehrsverbund Rhein-Ruhr</em>.<br/>
+ <strong>Line number</strong>: <input name="ref" type="text" size="40"/><br/>
+ The value of the tag <em>ref</em> of the relation(s) to consider. A working example is <em>625</em>.<br/>
+ <strong>Scale</strong>: <input name="scale" type="text" value="10.0" size="40"/><br/>
+ The scale in meter per pixel. Bigger values mean smaller maps. A useful scale for bus services is <em>10.0</em>. For train services, <em>25.0</em> or bigger may suit better.<br/>
+ <strong>Pivot meridian</strong>: <input name="pivot-lon" type="text" size="10"/><br/>
+ The used projection is Sinusoidal, and this is the central meridian for this projection. If you leave the field empty, the algorithm will detect a suitable value on its own.<br/>
+ <strong>Font size of stop names</strong>: <input name="font-size" value="12.0" type="text" size="10"/><br/>
+ The font size in pixels for the stopname in the generated SVG.<br/>
+ <input type="submit"/>
+</form>
+
+<p>You can access this service directly with an URL of the form<br/>
+http://78.46.81.38/api/draw-line?network=<em>network</em>&amp;ref=<em>ref</em>
+<p>
+
+<h3>By id(s)</h3>
+
+<p>You can access this service directly with an URL of the form<br/>
+http://78.46.81.38/api/sketch-route?<em>relation-id</em><br/>
+or<br/>
+http://78.46.81.38/api/sketch-route?<em>relation-id</em>&amp;<em>relation-id</em><br/>
+<em>Relation-id</em> means here the id(s) of the relations (one or two) to consider.
+</p>
+
+<p>A working example is<br/>
+<a href="http://78.46.81.38/api/sketch-route?34631&amp;361959">http://78.46.81.38/api/sketch-route?34631&amp;361959</a></p>
+
</body>
</html>
View
@@ -476,3 +476,38 @@ Transactions::Dispatcher
vector< int > reading_idx_pids;
bool pending_commit;
};
+
+---
+
+query:
+- Read all elem-ids from one-block-clauses.
+- Intersect them if applicable.
+- If there are less than THRESHOLD, locate them. (cache?)
+- Could be faster if the index is stored along with the node_id. To reduce the data amount, we could attach a shortened index to the key. Does this pay off? We need at least 24 bit of index to make meaningful predictions. This will be 150000 to 750000 indices, thus useful only for tags with more than 1.2 mio. to 5 mio. occurences. If you query for such a tag alone, you will exceed the element limit anyway.
+- Small area/bbox works like a query with few results and known locations, but intersecting isn't possible.
+
+- if known, indices are provided. World assumed otherwise.
+
+- prelocated searches are performed via local_tags, one located clause suffices.
+
+area-query/bbox-query:
+- see above
+
+recurse:
+- Indices can be translated one by one. This isn't helpful if the initial index of a way or relation takes much space.
+- Element numbers could be calculated from the idx files, assuming an uniform distribution. Once again, this profits from more precise way indices.
+
+union/intersect:
+- Indices are unified/intersected.
+- Element numbers go to proportionals of the shared indices, based on the averages of all sets. The union has at most the sum of all counts, the intersection at most the minimum of all counts.
+
+print:
+- only output.
+
+All times need to be mesured with different samples.
+
+Tasks:
+@database:
+- extend values in tags_global
+- reworked way and relation indices
+- changes for transactionality: different idx management
@@ -123,7 +123,6 @@ void start(const char *el, const char **attr)
}
else if (!strcmp(el, "member"))
{
- uint32 ref(0);
pending_members[current_elem].push_back(RelMember());
RelMember& rel_member(pending_members[current_elem].back());
for (unsigned int i(0); attr[i]; i += 2)
@@ -1,5 +1,6 @@
#include <algorithm>
#include <cmath>
+#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
@@ -152,7 +153,8 @@ Features extract_features(const OSMData& osm_data)
if (node)
{
if ((node->tags["highway"] == "bus_stop") ||
- (node->tags["railway"] == "station"))
+ (node->tags["railway"] == "station") ||
+ (node->tags["railway"] == "tram_stop"))
{
pair< map< string, uint32 >::iterator, bool >
itp(name_to_node.insert
@@ -263,50 +265,76 @@ namespace
return Bbox(north, south, east, west);
}
- double vpos(double lat, double north, double m_per_pixel)
+ // Transforms (lat,lon) coordinates into coordinates on the map
+ class Coord_Transform
{
- return (north - lat)*(1000000.0/9.0)/m_per_pixel;
- }
-
- double hpos(double lat, double lon, double west, double m_per_pixel)
- {
- return (lon - west)*(1000000.0/9.0)/m_per_pixel*cos(lat/90.0*acos(0));
- }
+ public:
+ Coord_Transform
+ (double north, double south, double west, double east,
+ double m_per_pixel, double pivot_lon)
+ : north_(north), south_(south), west_(west), east_(east),
+ m_per_pixel_(m_per_pixel), pivot_lon_(pivot_lon)
+ {
+ pivot_hpos_ =
+ (pivot_lon - west)*(1000000.0/9.0)/m_per_pixel
+ *cos((south + north)*(1/2.0/90.0*acos(0)));
+ }
+
+ double vpos(double lat)
+ {
+ return (north_ - lat)*(1000000.0/9.0)/m_per_pixel_;
+ }
+
+ double hpos(double lat, double lon)
+ {
+ return (lon - pivot_lon_)*(1000000.0/9.0)/m_per_pixel_
+ *cos(lat*(1/90.0*acos(0))) + pivot_hpos_;
+ }
+
+ private:
+ double north_, south_, west_, east_;
+ double m_per_pixel_, pivot_lon_, pivot_hpos_;
+ };
}
void sketch_features
(const OSMData& osm_data,
const Features& features,
- double pivot_lon, double m_per_pixel)
+ double pivot_lon, double m_per_pixel, double stop_font_size)
{
::Bbox bbox(::calc_bbox(osm_data));
//expand the bounding box to avoid elements scratching the frame
bbox.north += 0.001*m_per_pixel;
bbox.south -= 0.001*m_per_pixel;
- bbox.east += 0.002*m_per_pixel;
- bbox.west -= 0.002*m_per_pixel;
+ bbox.east += 0.003*m_per_pixel;
+ bbox.west -= 0.003*m_per_pixel;
+ ::Coord_Transform coord_transform
+ (bbox.north, bbox.south, bbox.west, bbox.east,
+ m_per_pixel, pivot_lon);
cout<<"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<svg xmlns=\"http://www.w3.org/2000/svg\"\n"
" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
" xmlns:ev=\"http://www.w3.org/2001/xml-events\"\n"
" version=\"1.1\" baseProfile=\"full\"\n"
- " width=\""<<hpos(bbox.south, bbox.east, bbox.west, m_per_pixel)<<"px\" "
- "height=\""<<vpos(bbox.south, bbox.north, m_per_pixel)<<"px\">\n"
+ " width=\""
+ <<coord_transform.hpos((bbox.south + bbox.north)/2.0, bbox.east)<<"px\" "
+ "height=\""<<coord_transform.vpos(bbox.south)<<"px\">\n"
"\n";
for (vector< StopFeature >::const_iterator it(features.stops.begin());
it != features.stops.end(); ++it)
{
cout<<"<circle cx=\""
- <<hpos(it->lat, it->lon, bbox.west, m_per_pixel)
+ <<coord_transform.hpos(it->lat, it->lon)
<<"\" cy=\""
- <<vpos(it->lat, bbox.north, m_per_pixel)
+ <<coord_transform.vpos(it->lat)
<<"\" r=\"6\" fill=\""<<it->color<<"\"/>\n";
- cout<<"<text x=\""<<hpos(it->lat, it->lon, bbox.west, m_per_pixel) + 6
- <<"\" y=\""<<vpos(it->lat, bbox.north, m_per_pixel) - 6
- <<"\" font-size=\"12px\">"<<it->name<<"</text>\n";
+ cout<<"<text x=\""
+ <<coord_transform.hpos(it->lat, it->lon) + 6
+ <<"\" y=\""<<coord_transform.vpos(it->lat) - 6
+ <<"\" font-size=\""<<stop_font_size<<"px\">"<<it->name<<"</text>\n";
}
cout<<'\n';
@@ -321,14 +349,14 @@ void sketch_features
vector< pair< double, double > >::const_iterator it3(it2->lat_lon.begin());
if (it3 != it2->lat_lon.end())
{
- cout<<hpos(it3->first, it3->second, bbox.west, m_per_pixel)<<' '
- <<vpos(it3->first, bbox.north, m_per_pixel);
+ cout<<coord_transform.hpos(it3->first, it3->second)<<' '
+ <<coord_transform.vpos(it3->first);
++it3;
}
for (; it3 != it2->lat_lon.end(); ++it3)
{
- cout<<", "<<hpos(it3->first, it3->second, bbox.west, m_per_pixel)<<' '
- <<vpos(it3->first, bbox.north, m_per_pixel);
+ cout<<", "<<coord_transform.hpos(it3->first, it3->second)
+ <<' '<<coord_transform.vpos(it3->first);
}
cout<<"\"/>\n";
}
@@ -340,12 +368,30 @@ void sketch_features
int main(int argc, char *argv[])
{
+ int argi(1);
+ double pivot_lon(-200.0), stop_font_size(12.0), scale(10.0);
+ while (argi < argc)
+ {
+ if (!strncmp("--pivot-lon=", argv[argi], 12))
+ pivot_lon = atof(((string)(argv[argi])).substr(12).c_str());
+ else if (!strncmp("--stop-font-size=", argv[argi], 17))
+ stop_font_size = atof(((string)(argv[argi])).substr(17).c_str());
+ else if (!strncmp("--scale=", argv[argi], 8))
+ scale = atoi(((string)(argv[argi])).substr(8).c_str());
+ ++argi;
+ }
+
// read the XML input
const OSMData& current_data(read_osm());
Features features(extract_features(current_data));
- sketch_features(current_data, features, middle_lon(current_data), 10.0);
+ // choose pivot_lon automatically
+ if (pivot_lon == -200.0)
+ pivot_lon = middle_lon(current_data);
+
+ sketch_features(current_data, features, pivot_lon, scale,
+ stop_font_size);
//sketch_unscaled_osm_data(current_data);
View
@@ -21,8 +21,12 @@ while [[ -n $BUF ]]; do
REF=$VALUE
REF_=`echo $VALUE | ../bin/uncgi`
};
- elif [[ $KEY == "pivot" && -n $VALUE ]]; then
- SKETCH_PARAMS="$SKETCH_PARAMS --pivot=$VALUE"
+ elif [[ $KEY == "pivot-lon" && -n $VALUE ]]; then
+ SKETCH_PARAMS="$SKETCH_PARAMS --pivot-lon=$VALUE"
+ elif [[ $KEY == "scale" && -n $VALUE ]]; then
+ SKETCH_PARAMS="$SKETCH_PARAMS --scale=$VALUE"
+ elif [[ $KEY == "font-size" && -n $VALUE ]]; then
+ SKETCH_PARAMS="$SKETCH_PARAMS --stop-font-size=$VALUE"
elif [[ $KEY == "debug" && -n $VALUE ]]; then
DEBUG=$VALUE
fi
@@ -79,6 +83,7 @@ else
echo
cat <$BASEDIR/answer.1
echo
+ echo "../bin/draw-route-svg $SKETCH_PARAMS"
};
fi;

0 comments on commit 6c71934

Please sign in to comment.