kopia lustrzana https://github.com/hholzgra/ocitysmap
Rename OCitySMap Python module from ocitysmap2 to ocitysmap
Renamed ocitysmap2-render as render.py since we don't need/want "ocitysmap2" in the name anymore. Rename conf template as ocitysmap.conf.dist for the same reason. Updated INSTALL instructions accordingly. Signed-off-by: Maxime Petazzoni <maxime.petazzoni@bulix.org>stable
rodzic
e415b30707
commit
1aa5c5b068
|
@ -1,7 +1,6 @@
|
|||
*~
|
||||
*.mo
|
||||
/ocitysmap.conf.mine
|
||||
/support/planet-update-daily.sh
|
||||
/ocitysmap.conf
|
||||
/support/shoreline-update.sh
|
||||
/stylesheet/maposmatic-printable/inc/datasource-settings.xml.inc
|
||||
/stylesheet/maposmatic-printable/inc/fontset-settings.xml.inc
|
||||
|
|
24
INSTALL
24
INSTALL
|
@ -238,8 +238,8 @@ are using. They have been tested on several x86_64 hosts.
|
|||
d. Configuration
|
||||
|
||||
python ./generate_xml.py --dbname maposmatic --host 'localhost' \
|
||||
--user maposmatic --port 5432 \
|
||||
--password 'ereiamjh'
|
||||
--user maposmatic --port 5432 \
|
||||
--password 'ereiamjh'
|
||||
|
||||
11. Installation of OCitySMap
|
||||
|
||||
|
@ -264,7 +264,7 @@ are using. They have been tested on several x86_64 hosts.
|
|||
d. Configuration file
|
||||
|
||||
Create a ~/.ocitysmap.conf configuration file, modeled after the
|
||||
provided ocitysmap2.conf-template file.
|
||||
provided ocitysmap2.conf.dist file.
|
||||
|
||||
12. Run OCitySMap
|
||||
|
||||
|
@ -290,10 +290,10 @@ Appendix A: Installation of maposmatic-printable stylesheet
|
|||
cd stylesheet/maposmatic-printable/
|
||||
|
||||
python ./generate_xml.py --dbname maposmatic --host 'localhost' \
|
||||
--user maposmatic --port 5432 \
|
||||
--password 'ereiamjh' \
|
||||
--world_boundaries mapnik2-osm/world_boundaries \
|
||||
--symbols mapnik2-osm/symbols
|
||||
--user maposmatic --port 5432 \
|
||||
--password 'ereiamjh' \
|
||||
--world_boundaries mapnik2-osm/world_boundaries \
|
||||
--symbols mapnik2-osm/symbols
|
||||
|
||||
Appendix B: installation of the MapQuest stylesheet
|
||||
-------------------------------------------------
|
||||
|
@ -351,11 +351,11 @@ replace "Arial" by "DejaVu".
|
|||
Create the .inc files from the templates:
|
||||
|
||||
python /path/to/mapnik2-osm/generate_xml.py --inc mapquest_inc \
|
||||
--symbols mapquest_symbols \
|
||||
--dbname maposmatic \
|
||||
--host 'localhost' \
|
||||
--user maposmatic --port 5432 \
|
||||
--password 'ereiamjh'
|
||||
--symbols mapquest_symbols \
|
||||
--dbname maposmatic \
|
||||
--host 'localhost' \
|
||||
--user maposmatic --port 5432 \
|
||||
--password 'ereiamjh'
|
||||
|
||||
The final step is to integrate this new stylesheet in ocitysmap. To do
|
||||
so, edit your ~/.ocitysmap.conf file, and add a new stylesheet
|
||||
|
|
6
i18n.py
6
i18n.py
|
@ -32,9 +32,9 @@ def make_pot():
|
|||
print "Make locale/ocitysmap.pot"
|
||||
subprocess.check_call(['xgettext', '-o', 'ocitysmap.pot', '-p', 'locale',
|
||||
'-L', 'Python',
|
||||
'ocitysmap2/indexlib/indexer.py',
|
||||
'ocitysmap2/layoutlib/multi_page_renderer.py',
|
||||
'ocitysmap2/layoutlib/single_page_renderers.py'])
|
||||
'ocitysmap/indexlib/indexer.py',
|
||||
'ocitysmap/layoutlib/multi_page_renderer.py',
|
||||
'ocitysmap/layoutlib/single_page_renderers.py'])
|
||||
return
|
||||
|
||||
def make_po(languages):
|
||||
|
|
|
@ -38,27 +38,27 @@ How to use OCitySMap?
|
|||
|
||||
The API of OCitySMap is very simple. First, you need to instanciate the main
|
||||
OCitySMap class with the path to your OCitySMap configuration file (see
|
||||
ocitysmap.conf-template):
|
||||
ocitysmap.conf.dist):
|
||||
|
||||
|
||||
ocitysmap = ocitysmap2.OCitySMap('/path/to/your/config')
|
||||
renderer = ocitysmap.OCitySMap('/path/to/your/config')
|
||||
|
||||
The next step is to create a RenderingConfiguration, the object that
|
||||
encapsulates all the information to parametize the rendering, including the
|
||||
Mapnik stylesheet. You can retrieve the list of supported stylesheets (directly
|
||||
as Stylesheet objects) with:
|
||||
|
||||
styles = ocitysmap.get_all_style_configurations()
|
||||
styles = renderer.get_all_style_configurations()
|
||||
|
||||
Fill in your RenderingConfiguration with the map title, the OSM ID or bounding
|
||||
box, the chosen map language, the Stylesheet object and the paper size (in
|
||||
millimeters) and simply pass it to OCitySMap's render method:
|
||||
|
||||
ocitysmap.render(rendering_configuration, layout_name,
|
||||
output_formats, prefix)
|
||||
renderer.render(rendering_configuration, layout_name,
|
||||
output_formats, prefix)
|
||||
|
||||
The layout name is the renderer's key name. You can get the list of all
|
||||
supported renderers with ocitysmap.get_all_renderers(). The output_formats is a
|
||||
supported renderers with renderer.get_all_renderers(). The output_formats is a
|
||||
list of output formats. For now, the following formats are supported:
|
||||
|
||||
* PNG at 72dpi
|
||||
|
@ -83,17 +83,14 @@ import os
|
|||
import psycopg2
|
||||
import re
|
||||
import tempfile
|
||||
|
||||
import shapely
|
||||
import shapely.wkt
|
||||
import shapely.geometry
|
||||
|
||||
import coords
|
||||
import i18n
|
||||
|
||||
from indexlib.indexer import StreetIndex
|
||||
from indexlib.commons import IndexDoesNotFitError, IndexEmptyError
|
||||
|
||||
from layoutlib import PAPER_SIZES, renderers
|
||||
import layoutlib.commons
|
||||
|
||||
|
@ -167,6 +164,9 @@ class Stylesheet:
|
|||
|
||||
s.name = parser.get(section_name, 'name')
|
||||
s.path = parser.get(section_name, 'path')
|
||||
if not os.path.exists(s.path):
|
||||
raise ValueError, \
|
||||
'Could not find stylesheet file for stylesheet %s!' % s.name
|
||||
assign_if_present('description')
|
||||
|
||||
assign_if_present('grid_line_color')
|
||||
|
@ -217,7 +217,7 @@ class OCitySMap:
|
|||
config_files = [config_files]
|
||||
|
||||
config_files = map(os.path.expanduser, config_files)
|
||||
LOG.info('Reading OCitySMap configuration from %s...' %
|
||||
LOG.debug('Reading OCitySMap configuration from %s...' %
|
||||
', '.join(config_files))
|
||||
|
||||
self._parser = ConfigParser.RawConfigParser()
|
||||
|
@ -229,8 +229,7 @@ class OCitySMap:
|
|||
|
||||
# Read stylesheet configuration
|
||||
self.STYLESHEET_REGISTRY = Stylesheet.create_all_from_config(self._parser)
|
||||
LOG.debug('Found %d Mapnik stylesheets.'
|
||||
% len(self.STYLESHEET_REGISTRY))
|
||||
LOG.debug('Found %d Mapnik stylesheets.' % len(self.STYLESHEET_REGISTRY))
|
||||
|
||||
@property
|
||||
def _db(self):
|
|
@ -26,7 +26,8 @@
|
|||
import cairo
|
||||
import pango
|
||||
import pangocairo
|
||||
import ocitysmap2.layoutlib.commons as commons
|
||||
|
||||
import ocitysmap.layoutlib.commons as commons
|
||||
|
||||
def draw_text(ctx, pc, layout, fascent, fheight,
|
||||
baseline_x, baseline_y, text, pango_alignment):
|
|
@ -23,30 +23,29 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import string
|
||||
import random
|
||||
import psycopg2
|
||||
import cairo
|
||||
import logging
|
||||
import os
|
||||
import psycopg2
|
||||
import random
|
||||
import string
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
from ocitysmap2 import i18n, coords
|
||||
from ocitysmap2.maplib.grid import Grid
|
||||
|
||||
from ocitysmap import i18n, coords
|
||||
from ocitysmap.maplib.grid import Grid
|
||||
from indexer import StreetIndex
|
||||
from renderer import StreetIndexRenderer
|
||||
from commons import IndexCategory, IndexItem
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
random.seed(42)
|
||||
|
||||
lang = "fr_FR.UTF-8"
|
||||
#lang = "ar_MA.UTF-8"
|
||||
#lang = "zh_CN.utf8"
|
||||
i18n = i18n.install_translation(lang,
|
||||
os.path.join(os.path.dirname(__file__),
|
||||
"..", "..", "locale"))
|
||||
os.path.join(os.path.dirname(__file__),
|
||||
"..", "..", "locale"))
|
||||
|
||||
bbox = coords.BoundingBox(48.8162, 2.3417, 48.8063, 2.3699) # France
|
||||
#bbox = coords.BoundingBox(34.0322, -6.8648, 34.0073, -6.8133) # Moroco
|
|
@ -22,12 +22,14 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import pango
|
||||
import sys
|
||||
|
||||
import os, sys
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
import draw_utils
|
||||
|
||||
|
||||
class IndexEmptyError(Exception):
|
||||
"""This exception is raised when no data is to be rendered in the index."""
|
||||
pass
|
||||
|
@ -206,7 +208,7 @@ class IndexItem:
|
|||
Update the location_str field from the given Grid object.
|
||||
|
||||
Args:
|
||||
grid (ocitysmap2.Grid): the Grid object from which we
|
||||
grid (ocitysmap.Grid): the Grid object from which we
|
||||
compute the location strings
|
||||
|
||||
Returns:
|
|
@ -23,15 +23,13 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import logging
|
||||
import locale
|
||||
import psycopg2
|
||||
import csv
|
||||
import datetime
|
||||
from itertools import groupby
|
||||
|
||||
import commons
|
||||
from ocitysmap2 import coords
|
||||
import locale
|
||||
import logging
|
||||
import os
|
||||
import psycopg2
|
||||
|
||||
import psycopg2.extensions
|
||||
# compatibility with django: see http://code.djangoproject.com/ticket/5996
|
||||
|
@ -39,6 +37,8 @@ psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
|
|||
# SQL string escaping routine
|
||||
_sql_escape_unicode = lambda s: psycopg2.extensions.adapt(s.encode('utf-8'))
|
||||
|
||||
import commons
|
||||
import ocitysmap
|
||||
|
||||
l = logging.getLogger('ocitysmap')
|
||||
|
||||
|
@ -76,7 +76,7 @@ class StreetIndex:
|
|||
mapping them onto the given grid.
|
||||
|
||||
Args:
|
||||
grid (ocitysmap2.Grid): the Grid object from which we
|
||||
grid (ocitysmap.Grid): the Grid object from which we
|
||||
compute the location strings
|
||||
|
||||
Returns:
|
||||
|
@ -232,8 +232,8 @@ class StreetIndex:
|
|||
l.exception("Error parsing %s for %s" % (repr(linestring),
|
||||
repr(street_name)))
|
||||
raise
|
||||
endpoint1 = coords.Point(s_endpoint1[1], s_endpoint1[0])
|
||||
endpoint2 = coords.Point(s_endpoint2[1], s_endpoint2[0])
|
||||
endpoint1 = ocitysmap.coords.Point(s_endpoint1[1], s_endpoint1[0])
|
||||
endpoint2 = ocitysmap.coords.Point(s_endpoint2[1], s_endpoint2[0])
|
||||
current_category.items.append(commons.IndexItem(street_name,
|
||||
endpoint1,
|
||||
endpoint2,
|
||||
|
@ -368,8 +368,8 @@ order by amenity_name""" \
|
|||
repr(amenity_name)))
|
||||
continue
|
||||
## raise
|
||||
endpoint1 = coords.Point(s_endpoint1[1], s_endpoint1[0])
|
||||
endpoint2 = coords.Point(s_endpoint2[1], s_endpoint2[0])
|
||||
endpoint1 = ocitysmap.coords.Point(s_endpoint1[1], s_endpoint1[0])
|
||||
endpoint2 = ocitysmap.coords.Point(s_endpoint2[1], s_endpoint2[0])
|
||||
current_category.items.append(commons.IndexItem(amenity_name,
|
||||
endpoint1,
|
||||
endpoint2,
|
||||
|
@ -443,8 +443,8 @@ order by village_name""" \
|
|||
repr(village_name)))
|
||||
continue
|
||||
## raise
|
||||
endpoint1 = coords.Point(s_endpoint1[1], s_endpoint1[0])
|
||||
endpoint2 = coords.Point(s_endpoint2[1], s_endpoint2[0])
|
||||
endpoint1 = ocitysmap.coords.Point(s_endpoint1[1], s_endpoint1[0])
|
||||
endpoint2 = ocitysmap.coords.Point(s_endpoint2[1], s_endpoint2[0])
|
||||
current_category.items.append(commons.IndexItem(village_name,
|
||||
endpoint1,
|
||||
endpoint2,
|
||||
|
@ -456,9 +456,7 @@ order by village_name""" \
|
|||
return [category for category in result if category.items]
|
||||
|
||||
if __name__ == "__main__":
|
||||
import os
|
||||
import psycopg2
|
||||
from ocitysmap2 import i18n
|
||||
from ocitysmap import i18n
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
@ -472,7 +470,7 @@ if __name__ == "__main__":
|
|||
"..", "..", "locale"))
|
||||
|
||||
# Chevreuse
|
||||
chevreuse_bbox = coords.BoundingBox(48.7097, 2.0333, 48.7048, 2.0462)
|
||||
chevreuse_bbox = ocitysmap.coords.BoundingBox(48.7097, 2.0333, 48.7048, 2.0462)
|
||||
limits_wkt = chevreuse_bbox.as_wkt()
|
||||
|
||||
# Paris envelope:
|
|
@ -18,12 +18,13 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import cairo
|
||||
import ocitysmap2.layoutlib.commons as UTILS
|
||||
import math
|
||||
import pango
|
||||
import pangocairo
|
||||
import math
|
||||
|
||||
import draw_utils
|
||||
from ocitysmap2.layoutlib.abstract_renderer import Renderer
|
||||
import ocitysmap.layoutlib.commons as UTILS
|
||||
from ocitysmap.layoutlib.abstract_renderer import Renderer
|
||||
|
||||
# FIXME: refactoring
|
||||
# We use the same 10mm as GRAYED_MARGIN_MM in the map multi-page renderer
|
||||
|
@ -223,6 +224,7 @@ class MultiPageStreetIndexRenderer:
|
|||
if __name__ == '__main__':
|
||||
import random
|
||||
import string
|
||||
|
||||
import commons
|
||||
import coords
|
||||
|
|
@ -29,7 +29,7 @@ import pango
|
|||
import pangocairo
|
||||
|
||||
import commons
|
||||
import ocitysmap2.layoutlib.commons as UTILS
|
||||
import ocitysmap.layoutlib.commons as UTILS
|
||||
|
||||
LOG = logging.getLogger('ocitysmap')
|
||||
|
||||
|
@ -495,7 +495,6 @@ if __name__ == '__main__':
|
|||
import random
|
||||
import string
|
||||
|
||||
from ocitysmap2 import coords
|
||||
import commons
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
@ -505,7 +504,7 @@ if __name__ == '__main__':
|
|||
|
||||
random.seed(42)
|
||||
|
||||
bbox = coords.BoundingBox(48.8162, 2.3417, 48.8063, 2.3699)
|
||||
bbox = ocitysmap.coords.BoundingBox(48.8162, 2.3417, 48.8063, 2.3699)
|
||||
|
||||
surface = cairo.PDFSurface('/tmp/myindex_render.pdf', width, height)
|
||||
|
|
@ -23,28 +23,27 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
import cairo
|
||||
import logging
|
||||
import mapnik
|
||||
assert mapnik.mapnik_version >= 200100, \
|
||||
"Mapnik module version %s is too old, see ocitysmap's INSTALL " \
|
||||
"for more details." % mapnik.mapnik_version_string()
|
||||
import math
|
||||
import pango
|
||||
import os
|
||||
import re
|
||||
|
||||
from ocitysmap2.maplib.map_canvas import MapCanvas
|
||||
from ocitysmap2.maplib.grid import Grid
|
||||
import commons
|
||||
from ocitysmap2 import maplib
|
||||
from ocitysmap2 import draw_utils
|
||||
import shapely.wkt
|
||||
import sys
|
||||
|
||||
import logging
|
||||
import commons
|
||||
from ocitysmap.maplib.map_canvas import MapCanvas
|
||||
from ocitysmap.maplib.grid import Grid
|
||||
from ocitysmap import draw_utils, maplib
|
||||
|
||||
LOG = logging.getLogger('ocitysmap')
|
||||
|
||||
|
||||
class Renderer:
|
||||
"""
|
||||
The job of an OCitySMap layout renderer is to lay out the resulting map and
|
||||
|
@ -102,7 +101,7 @@ class Renderer:
|
|||
os.path.dirname(__file__), '..', '..', 'images', 'osm-logo.png'))
|
||||
if not os.path.exists(logo_path):
|
||||
logo_path = os.path.join(
|
||||
sys.exec_prefix, 'share', 'images', 'ocitysmap2',
|
||||
sys.exec_prefix, 'share', 'images', 'ocitysmap',
|
||||
'osm-logo.png')
|
||||
|
||||
try:
|
|
@ -19,42 +19,38 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import logging
|
||||
import tempfile
|
||||
import math
|
||||
import sys
|
||||
import cairo
|
||||
import datetime
|
||||
from itertools import groupby
|
||||
import locale
|
||||
import logging
|
||||
import mapnik
|
||||
assert mapnik.mapnik_version >= 200100, \
|
||||
"Mapnik module version %s is too old, see ocitysmap's INSTALL " \
|
||||
"for more details." % mapnik.mapnik_version_string()
|
||||
import coords
|
||||
import locale
|
||||
import math
|
||||
import os
|
||||
import pangocairo
|
||||
import pango
|
||||
import datetime
|
||||
|
||||
from itertools import groupby
|
||||
import shapely.wkt
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import ocitysmap
|
||||
import coords
|
||||
import commons
|
||||
from abstract_renderer import Renderer
|
||||
|
||||
from ocitysmap2.maplib.map_canvas import MapCanvas
|
||||
from ocitysmap2.maplib.grid import Grid
|
||||
from ocitysmap2.maplib.overview_grid import OverviewGrid
|
||||
from indexlib.commons import IndexCategory
|
||||
from indexlib.indexer import StreetIndex
|
||||
from indexlib.multi_page_renderer import MultiPageStreetIndexRenderer
|
||||
|
||||
import ocitysmap2
|
||||
import commons
|
||||
import shapely.wkt
|
||||
from ocitysmap2 import maplib
|
||||
from ocitysmap2 import draw_utils
|
||||
|
||||
from indexlib.commons import IndexCategory
|
||||
from ocitysmap import draw_utils, maplib
|
||||
from ocitysmap.maplib.map_canvas import MapCanvas
|
||||
from ocitysmap.maplib.grid import Grid
|
||||
from ocitysmap.maplib.overview_grid import OverviewGrid
|
||||
|
||||
LOG = logging.getLogger('ocitysmap')
|
||||
|
||||
|
||||
class MultiPageRenderer(Renderer):
|
||||
"""
|
||||
This Renderer creates a multi-pages map, with all the classic overlayed
|
||||
|
@ -736,7 +732,7 @@ class MultiPageRenderer(Renderer):
|
|||
index_position=None, hsplit=1, vsplit=1):
|
||||
valid_sizes = []
|
||||
acceptable_formats = [ 'A5', 'A4', 'US letter' ]
|
||||
for sz in ocitysmap2.layoutlib.PAPER_SIZES:
|
||||
for sz in ocitysmap.layoutlib.PAPER_SIZES:
|
||||
# Skip unsupported paper formats
|
||||
if sz[0] not in acceptable_formats:
|
||||
continue
|
|
@ -22,24 +22,22 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import math
|
||||
import datetime
|
||||
import cairo
|
||||
import datetime
|
||||
import locale
|
||||
import logging
|
||||
import mapnik
|
||||
assert mapnik.mapnik_version >= 200100, \
|
||||
"Mapnik module version %s is too old, see ocitysmap's INSTALL " \
|
||||
"for more details." % mapnik.mapnik_version_string()
|
||||
import math
|
||||
import pango
|
||||
import pangocairo
|
||||
|
||||
import commons
|
||||
import ocitysmap2
|
||||
import ocitysmap
|
||||
from abstract_renderer import Renderer
|
||||
from ocitysmap2.indexlib.renderer import StreetIndexRenderer
|
||||
|
||||
import logging
|
||||
|
||||
from ocitysmap.indexlib.renderer import StreetIndexRenderer
|
||||
from indexlib.indexer import StreetIndex
|
||||
from indexlib.commons import IndexDoesNotFitError, IndexEmptyError
|
||||
import draw_utils
|
||||
|
@ -510,7 +508,7 @@ class SinglePageRenderer(Renderer):
|
|||
# Test both portrait and landscape orientations when checking for paper
|
||||
# sizes.
|
||||
valid_sizes = []
|
||||
for name, w, h in ocitysmap2.layoutlib.PAPER_SIZES:
|
||||
for name, w, h in ocitysmap.layoutlib.PAPER_SIZES:
|
||||
portrait_ok = paper_width_mm <= w and paper_height_mm <= h
|
||||
landscape_ok = paper_width_mm <= h and paper_height_mm <= w
|
||||
|
||||
|
@ -638,7 +636,7 @@ class SinglePageRendererIndexBottom(SinglePageRenderer):
|
|||
if __name__ == '__main__':
|
||||
import renderers
|
||||
import coords
|
||||
from ocitysmap2 import i18n
|
||||
from ocitysmap import i18n
|
||||
|
||||
# Hack to fake gettext
|
||||
try:
|
|
@ -160,8 +160,8 @@ class Grid:
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from ocitysmap2 import coords
|
||||
import ocitysmap
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
grid = Grid(coords.BoundingBox(44.4883, -1.0901, 44.4778, -1.0637))
|
||||
grid = Grid(ocitysmap.coords.BoundingBox(44.4883, -1.0901, 44.4778, -1.0637))
|
||||
shape = grid.generate_shape_file('/tmp/mygrid.shp')
|
|
@ -34,12 +34,12 @@ assert mapnik.mapnik_version >= 200100, \
|
|||
"Mapnik module version %s is too old, see ocitysmap's INSTALL " \
|
||||
"for more details." % mapnik.mapnik_version_string()
|
||||
|
||||
import math
|
||||
import os
|
||||
|
||||
from ocitysmap2 import coords
|
||||
import ocitysmap
|
||||
from layoutlib.commons import convert_pt_to_dots
|
||||
import shapes
|
||||
import math
|
||||
|
||||
l = logging.getLogger('ocitysmap')
|
||||
|
||||
|
@ -199,7 +199,7 @@ class MapCanvas:
|
|||
bounding box."""
|
||||
c0 = self._proj.inverse(mapnik.Coord(envelope.minx, envelope.miny))
|
||||
c1 = self._proj.inverse(mapnik.Coord(envelope.maxx, envelope.maxy))
|
||||
return coords.BoundingBox(c0.y, c0.x, c1.y, c1.x)
|
||||
return ocitysmap.coords.BoundingBox(c0.y, c0.x, c1.y, c1.x)
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
@ -208,7 +208,7 @@ if __name__ == '__main__':
|
|||
def __init__(self):
|
||||
self.path = '/home/sam/src/python/maposmatic/mapnik-osm/osm.xml'
|
||||
|
||||
bbox = coords.BoundingBox(48.7148, 2.0155, 48.6950, 2.0670)
|
||||
bbox = ocitysmap.coords.BoundingBox(48.7148, 2.0155, 48.6950, 2.0670)
|
||||
canvas = MapCanvas(StylesheetMock(), bbox, 297.0/210)
|
||||
new_bbox = canvas.get_actual_bounding_box()
|
||||
|
|
@ -22,14 +22,15 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
__version__ = '0.1'
|
||||
__version__ = '0.22'
|
||||
|
||||
import logging
|
||||
import optparse
|
||||
import sys, os
|
||||
import os
|
||||
import sys
|
||||
|
||||
import ocitysmap2
|
||||
import ocitysmap2.layoutlib.renderers
|
||||
import ocitysmap
|
||||
import ocitysmap.layoutlib.renderers
|
||||
from coords import BoundingBox
|
||||
|
||||
def main():
|
||||
|
@ -38,13 +39,13 @@ def main():
|
|||
# Paper sizes, sorted in increasing widths
|
||||
KNOWN_PAPER_SIZE_NAMES = \
|
||||
map(lambda p: p[0],
|
||||
sorted(ocitysmap2.layoutlib.PAPER_SIZES,
|
||||
sorted(ocitysmap.layoutlib.PAPER_SIZES,
|
||||
key=lambda p: p[1]))
|
||||
|
||||
# Known renderer names
|
||||
KNOWN_RENDERERS_NAMES = \
|
||||
map(lambda r: "%s (%s)" % (r.name, r.description),
|
||||
ocitysmap2.layoutlib.renderers.get_renderers())
|
||||
ocitysmap.layoutlib.renderers.get_renderers())
|
||||
|
||||
# Known paper orientations
|
||||
KNOWN_PAPER_ORIENTATIONS = ['portrait', 'landscape']
|
||||
|
@ -53,46 +54,49 @@ def main():
|
|||
parser = optparse.OptionParser(usage=usage,
|
||||
version='%%prog %s' % __version__)
|
||||
parser.add_option('-C', '--config', dest='config_file', metavar='FILE',
|
||||
help='Specify the location of the config file.')
|
||||
help='specify the location of the config file.')
|
||||
parser.add_option('-p', '--prefix', dest='output_prefix', metavar='PREFIX',
|
||||
help='Specify the prefix of generated files. '
|
||||
help='set a prefix to the generated file names. '
|
||||
'Defaults to "citymap".',
|
||||
default='citymap')
|
||||
parser.add_option('-f', '--format', dest='output_formats', metavar='FMT',
|
||||
help='Specify the output formats. Supported file '
|
||||
help='specify the output formats. Supported file '
|
||||
'formats: svg, svgz, pdf, ps, ps.gz, png, and csv. '
|
||||
'Defaults to PDF. May be specified multiple times.',
|
||||
action='append')
|
||||
parser.add_option('-t', '--title', dest='output_title', metavar='TITLE',
|
||||
help='Specify the title displayed in the output files.',
|
||||
help='specify the title displayed in the output files.',
|
||||
default="My Map")
|
||||
parser.add_option('--osmid', dest='osmid', metavar='OSMID',
|
||||
help='OSM id representing the polygon of the city '
|
||||
help='OSM ID representing the polygon of the city '
|
||||
'to render.', type="int"),
|
||||
parser.add_option('-b', '--bounding-box', dest='bbox', nargs=2,
|
||||
metavar='LAT1,LON1 LAT2,LON2',
|
||||
help='Bounding box (EPSG: 4326).')
|
||||
help='bounding box (EPSG: 4326).')
|
||||
parser.add_option('-L', '--language', dest='language',
|
||||
metavar='LANGUAGE_CODE',
|
||||
help='Language to use when generating the index'
|
||||
' (default=fr_FR.UTF-8).',
|
||||
help='language to use when generating the index '
|
||||
'(default=fr_FR.UTF-8). The map language is '
|
||||
'driven by the system\' locale setting.',
|
||||
default='fr_FR.UTF-8')
|
||||
parser.add_option('-s', '--stylesheet', dest='stylesheet',
|
||||
metavar='NAME',
|
||||
help="Name of the stylesheet to use. Defaults to the "
|
||||
"first specified in the config file.")
|
||||
help='specify which stylesheet to use. Defaults to the '
|
||||
'first specified in the configuration file.')
|
||||
parser.add_option('-l', '--layout', dest='layout',
|
||||
metavar='NAME',
|
||||
default=KNOWN_RENDERERS_NAMES[0].split()[0],
|
||||
help= ("Name of the layout to use, among %s. Default: %s."
|
||||
% (', '.join(KNOWN_RENDERERS_NAMES),
|
||||
KNOWN_RENDERERS_NAMES[0].split()[0])))
|
||||
help=('specify which layout to use. Available layouts '
|
||||
'are: %s. Defaults to %s.' %
|
||||
(', '.join(KNOWN_RENDERERS_NAMES),
|
||||
KNOWN_RENDERERS_NAMES[0].split()[0])))
|
||||
parser.add_option('--paper-format', metavar='FMT',
|
||||
help='Either "default", or one of %s.'\
|
||||
% ', '.join(KNOWN_PAPER_SIZE_NAMES),
|
||||
help='set the output paper format. Either "default", '
|
||||
'or one of %s.' % ', '.join(KNOWN_PAPER_SIZE_NAMES),
|
||||
default='default')
|
||||
parser.add_option('--orientation', metavar='ORIENTATION',
|
||||
help='Either "portrait" or "landscape".',
|
||||
help='set the output paper orientation. Either '
|
||||
'"portrait" or "landscape". Defaults to portrait.',
|
||||
default='portrait')
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
@ -115,9 +119,8 @@ def main():
|
|||
"or --osmid are exclusive")
|
||||
|
||||
# Parse config file and instanciate main object
|
||||
mapper = ocitysmap2.OCitySMap([options.config_file
|
||||
or os.path.join(os.environ["HOME"],
|
||||
'.ocitysmap.conf')])
|
||||
mapper = ocitysmap.OCitySMap(
|
||||
[options.config_file or os.path.join(os.environ["HOME"], '.ocitysmap.conf')])
|
||||
|
||||
# Parse bounding box arguments when given
|
||||
bbox = None
|
||||
|
@ -150,21 +153,20 @@ def main():
|
|||
stylesheet = mapper.get_stylesheet_by_name(options.stylesheet)
|
||||
except LookupError, ex:
|
||||
parser.error("%s. Available stylesheets: %s."
|
||||
% (ex, ', '.join(map(lambda s: "%s (%s)"
|
||||
% (s.name, s.description),
|
||||
mapper.STYLESHEET_REGISTRY))))
|
||||
% (ex, ', '.join(map(lambda s: s.name,
|
||||
mapper.STYLESHEET_REGISTRY))))
|
||||
|
||||
# Parse rendering layout
|
||||
if options.layout is None:
|
||||
cls_renderer = ocitysmap2.layoutlib.renderers.get_renderers()[0]
|
||||
cls_renderer = ocitysmap.layoutlib.renderers.get_renderers()[0]
|
||||
else:
|
||||
try:
|
||||
cls_renderer = ocitysmap2.layoutlib.renderers.get_renderer_class_by_name(options.layout)
|
||||
cls_renderer = ocitysmap.layoutlib.renderers.get_renderer_class_by_name(options.layout)
|
||||
except LookupError, ex:
|
||||
parser.error("%s\nAvailable layouts: %s."
|
||||
% (ex, ', '.join(map(lambda lo: "%s (%s)"
|
||||
% (lo.name, lo.description),
|
||||
ocitysmap2.layoutlib.renderers.get_renderers()))))
|
||||
ocitysmap.layoutlib.renderers.get_renderers()))))
|
||||
|
||||
# Output file formats
|
||||
if not options.output_formats:
|
||||
|
@ -218,7 +220,7 @@ def main():
|
|||
parser.error("Requested paper orientation %s not compatible with this rendering at this paper size." % options.orientation)
|
||||
|
||||
# Prepare the rendering config
|
||||
rc = ocitysmap2.RenderingConfiguration()
|
||||
rc = ocitysmap.RenderingConfiguration()
|
||||
rc.title = options.output_title
|
||||
rc.osmid = options.osmid or None # Force to None if absent
|
||||
rc.bounding_box = bbox
|
16
setup.py
16
setup.py
|
@ -39,11 +39,13 @@ designed to be printed.
|
|||
license="GPL",
|
||||
maintainer="The Hackfest2009 team",
|
||||
maintainer_email="staff@maposmatic.org",
|
||||
packages = ['ocitysmap2',
|
||||
'ocitysmap2.maplib',
|
||||
'ocitysmap2.indexlib',
|
||||
'ocitysmap2.layoutlib' ],
|
||||
scripts = ['ocitysmap2-render' ],
|
||||
data_files = [ ('share/images/ocitysmap2',
|
||||
['images/osm-logo.png', 'images/osm-logo.svg']) ]
|
||||
packages = ['ocitysmap',
|
||||
'ocitysmap.maplib',
|
||||
'ocitysmap.indexlib',
|
||||
'ocitysmap.layoutlib' ],
|
||||
scripts = ['render.py' ],
|
||||
data_files = [
|
||||
('share/images/ocitysmap', ['images/osm-logo.png',
|
||||
'images/osm-logo.svg'])
|
||||
]
|
||||
)
|
||||
|
|
|
@ -21,47 +21,47 @@ TESTS=(
|
|||
TESTID=0
|
||||
|
||||
for tst in ${TESTS[@]} ; do
|
||||
type=$(echo $tst | cut -f1 -d':')
|
||||
title=$(echo $tst | cut -f2 -d':')
|
||||
ref=$(echo $tst | cut -f3 -d':')
|
||||
renderer=$(echo $tst | cut -f4 -d':')
|
||||
paper_format=$(echo $tst | cut -f5 -d':')
|
||||
paper_orientation=$(echo $tst | cut -f6 -d':')
|
||||
type=$(echo $tst | cut -f1 -d':')
|
||||
title=$(echo $tst | cut -f2 -d':')
|
||||
ref=$(echo $tst | cut -f3 -d':')
|
||||
renderer=$(echo $tst | cut -f4 -d':')
|
||||
paper_format=$(echo $tst | cut -f5 -d':')
|
||||
paper_orientation=$(echo $tst | cut -f6 -d':')
|
||||
|
||||
if [ $type == "osmid" ] ; then
|
||||
area_opt="--osmid=$ref"
|
||||
else
|
||||
bbox_part1=$(echo $ref|cut -f1 -d'-')
|
||||
bbox_part2=$(echo $ref|cut -f2 -d'-')
|
||||
area_opt="-b ${bbox_part1} ${bbox_part2}"
|
||||
fi
|
||||
if [ $type == "osmid" ] ; then
|
||||
area_opt="--osmid=$ref"
|
||||
else
|
||||
bbox_part1=$(echo $ref|cut -f1 -d'-')
|
||||
bbox_part2=$(echo $ref|cut -f2 -d'-')
|
||||
area_opt="-b ${bbox_part1} ${bbox_part2}"
|
||||
fi
|
||||
|
||||
if [ $renderer == "multi_page" ] ; then
|
||||
output_formats="-f pdf"
|
||||
else
|
||||
output_formats="-f png -f pdf -f svgz"
|
||||
fi
|
||||
if [ $renderer == "multi_page" ] ; then
|
||||
output_formats="-f pdf"
|
||||
else
|
||||
output_formats="-f png -f pdf -f svgz"
|
||||
fi
|
||||
|
||||
printf "\e[31m>>> Starting test with\n area='%s'\n renderer='%s'\n formats='%s'\n paper='%s'\n orientation='%s'\n title='%s'\n\n\e[m" \
|
||||
"$area_opt" \
|
||||
"$renderer" \
|
||||
"$output_formats" \
|
||||
"$paper_format" \
|
||||
"$paper_orientation" \
|
||||
"$title"
|
||||
printf "\e[31m>>> Starting test with\n area='%s'\n renderer='%s'\n formats='%s'\n paper='%s'\n orientation='%s'\n title='%s'\n\n\e[m" \
|
||||
"$area_opt" \
|
||||
"$renderer" \
|
||||
"$output_formats" \
|
||||
"$paper_format" \
|
||||
"$paper_orientation" \
|
||||
"$title"
|
||||
|
||||
./ocitysmap2-render \
|
||||
$output_formats \
|
||||
-l $renderer \
|
||||
$area_opt \
|
||||
-p test_$TESTID \
|
||||
-t "$title" \
|
||||
--paper-format=$paper_format \
|
||||
--orientation=$paper_orientation
|
||||
./render.py \
|
||||
$output_formats \
|
||||
-l $renderer \
|
||||
$area_opt \
|
||||
-p test_$TESTID \
|
||||
-t "$title" \
|
||||
--paper-format=$paper_format \
|
||||
--orientation=$paper_orientation
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "==== ERROR, ABORTING"
|
||||
exit 1
|
||||
fi
|
||||
TESTID=$((TESTID+1))
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "==== ERROR, ABORTING"
|
||||
exit 1
|
||||
fi
|
||||
TESTID=$((TESTID+1))
|
||||
done
|
||||
|
|
Ładowanie…
Reference in New Issue