kopia lustrzana https://github.com/hholzgra/ocitysmap
fixed: vert/horiz grid lines should now be displayed in all cases
rodzic
49e7a3ea34
commit
4573ed55d9
|
|
@ -53,9 +53,9 @@ class BoundingBox:
|
|||
def get_pixel_size_for_zoom_factor(self, zoom = 17):
|
||||
"""Return the size in pixels (tuple width,height) needed to
|
||||
render the bounding box at the given zoom factor"""
|
||||
delta_lat = abs(self._lat1 - self._lat2)
|
||||
delta_lat = abs(self._lat1 - self._lat2)
|
||||
delta_long = abs(self._long1 - self._long2)
|
||||
# 2^zoom tiles (1 tile = 256 pix) for the whole earth
|
||||
pix_x = delta_long * (2 ** (zoom + 8)) / 360
|
||||
pix_y = delta_lat * (2 ** (zoom + 8)) / 180
|
||||
return (int(math.ceil(pix_x)),
|
||||
int(math.ceil(pix_y)))
|
||||
pix_y = delta_lat * (2 ** (zoom + 8)) / 180 # 237 ?????
|
||||
return (int(math.ceil(pix_x)), int(math.ceil(pix_y)))
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ class GridDescriptor:
|
|||
l.debug("vertical labels: %s" % self.vertical_labels)
|
||||
l.debug("horizontal labels: %s" % self.horizontal_labels)
|
||||
|
||||
def generate_shape_file(self, filename):
|
||||
g = map_canvas.GridFile(filename)
|
||||
def generate_shape_file(self, filename, bbox):
|
||||
g = map_canvas.GridFile(bbox, filename)
|
||||
for v in self.vertical_lines:
|
||||
g.add_vert_line(v)
|
||||
for h in self.horizontal_lines:
|
||||
|
|
|
|||
|
|
@ -23,11 +23,13 @@ class GridFile:
|
|||
any attempt to add grid lines will fail (exception).
|
||||
The coordinates are not related to any projection
|
||||
"""
|
||||
def __init__(self, out_filename, layer_name = "Grid"):
|
||||
def __init__(self, envelope, out_filename, layer_name = "Grid"):
|
||||
"""
|
||||
@param envelope (BoundingBox) envelope of the grid lines
|
||||
@param out_filename (string) path to the output shape file we generate
|
||||
@param layer_name (string) layer name in the shape file
|
||||
"""
|
||||
self._envelope = envelope
|
||||
self._filepath = out_filename
|
||||
driver = ogr.GetDriverByName('ESRI Shapefile')
|
||||
if os.path.exists(out_filename):
|
||||
|
|
@ -42,8 +44,8 @@ class GridFile:
|
|||
Add a new latitude line at the given latitude
|
||||
"""
|
||||
line = ogr.Geometry(type = ogr.wkbLineString)
|
||||
line.AddPoint_2D(-180, y)
|
||||
line.AddPoint_2D(180, y)
|
||||
line.AddPoint_2D(self._envelope.get_top_left()[1], y)
|
||||
line.AddPoint_2D(self._envelope.get_bottom_right()[1], y)
|
||||
f = ogr.Feature(feature_def = self._layer.GetLayerDefn())
|
||||
f.SetGeometryDirectly(line)
|
||||
self._layer.CreateFeature(f)
|
||||
|
|
@ -54,8 +56,8 @@ class GridFile:
|
|||
Add a new longitude line at the given longitude
|
||||
"""
|
||||
line = ogr.Geometry(type = ogr.wkbLineString)
|
||||
line.AddPoint_2D(x, -80)
|
||||
line.AddPoint_2D(x, 80)
|
||||
line.AddPoint_2D(x, self._envelope.get_top_left()[0])
|
||||
line.AddPoint_2D(x, self._envelope.get_bottom_right()[0])
|
||||
f = ogr.Feature(feature_def = self._layer.GetLayerDefn())
|
||||
f.SetGeometryDirectly(line)
|
||||
self._layer.CreateFeature(f)
|
||||
|
|
@ -206,7 +208,8 @@ class MapCanvas:
|
|||
% (self._envelope, self._map.height, self._map.width))
|
||||
bbox = _project_envelope(self._proj, self._envelope)
|
||||
self._map.zoom_to_box(bbox)
|
||||
l.debug("rendered to bbox %sx%s." % (self._map.height, self._map.width))
|
||||
l.debug("rendered to bbox %s as %sx%s." \
|
||||
% (bbox, self._map.height, self._map.width))
|
||||
self._dirty = False
|
||||
return self._map
|
||||
|
||||
|
|
|
|||
|
|
@ -181,10 +181,9 @@ class OCitySMap:
|
|||
def render_into_files(self, osm_map_file, out_filenames, zoom_factor):
|
||||
GRID_COLOR = '#8BB381'
|
||||
l.debug('rendering from %s to %s...' % (osm_map_file, out_filenames))
|
||||
g = self.griddesc.generate_shape_file('x.shp')
|
||||
|
||||
bbox = self.boundingbox.create_expanded(self.griddesc.height_square_angle/2.,
|
||||
self.griddesc.width_square_angle/2.)
|
||||
g = self.griddesc.generate_shape_file('x.shp', bbox)
|
||||
city = map_canvas.MapCanvas(osm_map_file, bbox, zoom_factor)
|
||||
city.add_shapefile(g.get_filepath(), GRID_COLOR)
|
||||
l.debug('adding labels...')
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue