Skip to content

Commit 3370e1d

Browse files
committed
Updated README for installations with and without virtualenv
1 parent 6ba35df commit 3370e1d

File tree

4 files changed

+81
-19
lines changed

4 files changed

+81
-19
lines changed

README

+12-8
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,23 @@ The integers mean:
5959

6060
== INSTALL ==
6161
You need:
62-
* Boost
62+
* Boost (only for unordered_map that will be included in C++1X)
6363
* expat (XML parser)
6464
* python
6565
* swig
6666

67+
# Just run the following command
68+
sudo python setup.py install
69+
# Run it
70+
osm4routing --help
71+
72+
# Alternative:
73+
# If you don't have the rights to install it system-wide, or don't want to, use virtualenv:
6774
# Create a virtual environment and activate it
6875
python virtualenv.py env
6976
source env/bin/activate
70-
71-
# Get python dependencies and build the application
72-
python setup.py develop
73-
74-
# Run it
75-
python parse.py --help
77+
python setup.py install
78+
osm4routing --help
7679

7780

7881
== USAGE ==
@@ -82,12 +85,13 @@ For bigger regions you might find what you want at http://download.geofabrik.de/
8285
Osmosis can help you to have a smaller region from a big dump http://wiki.openstreetmap.org/wiki/Osmosis
8386

8487
To know the options, run:
85-
python parse.py --help
88+
osm4routing --help
8689

8790
== PERFORMANCE ==
8891
OSM data can get very big and can be very consuming, don't try to parse the whole world ;)
8992
On my laptop from 2006 (core2duo 1.66Ghz, 2Gb Ram, slow hard drive),
9093
it takes 20 minutes to parse 8Gb uncompressed (0.5Gb as bzip2) and represents France in June 2010
94+
On a iMac from 2010 (i5
9195

9296
== Postgis output ==
9397
Only if you want to use the spatial abilities of postgis, please read those extra informations

parse.py osm4routing.py

+64-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1-
from osm4routing import *
1+
from osm4routing_xml import *
22
from progressbar import ProgressBar
33
import os
44
import bz2, gzip
55
import sys
66
from optparse import OptionParser
7-
7+
from sqlalchemy import Table, Column, MetaData, Integer, String, Float, SmallInteger, create_engine
8+
from sqlalchemy.orm import mapper, sessionmaker
9+
10+
class Node(object):
11+
def __init__(self, id, lon, lat):
12+
self.id = id
13+
self.lon = lon
14+
self.lat = lat
15+
16+
17+
class Edge(object):
18+
def __init__(self, id, source, target, length, car, car_rev, bike, bike_rev, foot, the_geom):
19+
self.id = id
20+
self.source = source
21+
self.target = target
22+
self.length = length
23+
self.car = car
24+
self.car_rev = car_rev
25+
self.bike = bike
26+
self.bike_rev = bike
27+
self.foot = foot
28+
self.the_geom = the_geom
829

930
def parse(file, outformat="csv", edges_name="edges", nodes_name="nodes", conn = ""):
1031

@@ -39,19 +60,53 @@ def parse(file, outformat="csv", edges_name="edges", nodes_name="nodes", conn =
3960

4061
print " Read {0} nodes and {1} ways\n".format(p.get_osm_nodes(), p.get_osm_ways())
4162

63+
if outformat != "csv":
64+
metadata = MetaData()
65+
nodes_table = Table(nodes_name, metadata,
66+
Column('id', Integer, primary_key = True),
67+
Column('lon', Float),
68+
Column('lat', Float))
69+
70+
edges_table = Table(edges_name, metadata,
71+
Column('id', Integer, primary_key=True),
72+
Column('source', Integer, index=True),
73+
Column('target', Integer, index=True),
74+
Column('length', Float),
75+
Column('car', SmallInteger),
76+
Column('car_rev', SmallInteger),
77+
Column('bike', SmallInteger),
78+
Column('bike_rev', SmallInteger),
79+
Column('foot', SmallInteger),
80+
Column('the_geom', String))
81+
82+
engine = create_engine(conn)
83+
metadata.drop_all(engine)
84+
metadata.create_all(engine)
85+
mapper(Node, nodes_table)
86+
mapper(Edge, nodes_table)
87+
Session = sessionmaker(bind=engine)
88+
session = Session()
89+
90+
4291
print "Step 2: saving the nodes"
4392
nodes = p.get_nodes()
4493
if outformat == "csv":
4594
n = open(nodes_name + '.csv', 'w')
4695
n.write('"node_id","longitude","latitude"\n')
96+
4797
pbar = ProgressBar(maxval=len(nodes))
4898
count = 0
4999
for node in nodes:
50100
if outformat == "csv":
51101
n.write("{0},{1},{2}\n".format(node.id, node.lon, node.lat))
102+
else:
103+
session.add(Node(node.id, node.lon, node.lat))
52104
count += 1
53105
pbar.update(count)
54-
n.close()
106+
if outformat == "csv":
107+
n.close()
108+
else:
109+
session.commit()
55110
pbar.finish()
56111

57112
print " Wrote {0} nodes\n".format(count)
@@ -66,9 +121,14 @@ def parse(file, outformat="csv", edges_name="edges", nodes_name="nodes", conn =
66121
for edge in edges:
67122
if outformat == "csv":
68123
e.write('{0},{1},{2},{3},{4},{5},{6},{7},{8},LINESTRING("{9}")\n'.format(edge.edge_id, edge.source, edge.target, edge.length, edge.car, edge.car_d, edge.bike, edge.bike_d, edge.foot, edge.geom))
124+
else:
125+
session.add(Edge(edge.edge_id, edge.source, edge.target, edge.length, edge.car, edge.car_d, edge.bike, edge.bike_d, edge.foot, edge.geom))
69126
count += 1
70127
pbar.update(count)
71-
e.close()
128+
if outformat == "csv":
129+
e.close()
130+
else:
131+
session.commit()
72132
pbar.finish()
73133
print " Wrote {0} edges\n".format(count)
74134

parse.i

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%module osm4routing
1+
%module osm4routing_xml
22
%include "std_vector.i"
33
%include "std_string.i"
44
%{

setup.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@
88
author_email = '[email protected]',
99
url = 'http://github.com/Tristramg/osm4routing/',
1010
install_requires = ['progressbar', 'sqlalchemy', 'setuptools-git'],
11-
py_modules = ['parse', 'osm4routing'],
11+
py_modules = ['osm4routing', 'osm4routing_xml'],
1212

1313
ext_modules = [
14-
Extension("_osm4routing",
14+
Extension("_osm4routing_xml",
1515
sources=["parse.cc", "parameters.cc", "parse.i"],
1616
swig_opts=['-c++'],
17+
include_dirs=['.'],
1718
libraries=['expat'])
1819
],
1920
entry_points = {
20-
'console_scripts': ['osm4routing = parse:main'],
21-
'setuptools.installation': ['eggsecutable = parse:main',
22-
]
23-
21+
'console_scripts': ['osm4routing = osm4routing:main'],
2422
}
2523

2624
)

0 commit comments

Comments
 (0)