def add_obj(obj, ui, josm, server): print "Add object in JOSM:", obj if type(obj) is not GpxWaypoint: ui.error(_("Only waypoints can be sent to JOSM")) return # Create an OSM XML file containing the desired point. fh = StringIO.StringIO() osm = OsmWriter(fh, "GPX Trip Planner") tags = sym_to_tags.get(obj.sym, {}) osm.new_node(obj.lat, obj.lon, tags) osm.save() osm_text = fh.getvalue() # Ask our internal HTTP server to dispense the text of the # OSM XML file when JOSM asks for it. The HTTP server gives us # the URL to pass to JOSM. temp_url = server.add_temp(osm_text) # Create a bounding box to describe a small area around the new point. bbox = BoundingBox() bbox.add_point(Point(obj.lat + 0.001, obj.lon - 0.001)) bbox.add_point(Point(obj.lat - 0.001, obj.lon + 0.001)) josm.cmd_zoom(bbox) josm.send_cmd("import", {'url': temp_url})
def on_button_release(self, gdkevent): if self.hover_point is not None: self.projected_points.append(self.hover_point) self.points.append(self.layer.containing_map.unproject_points(*(self.hover_point))) bbox = BoundingBox() bbox.add_points(self.points) self.fire_done(MapVectorBoundingBox(bbox))
def get_bbox(self): p1 = self.unproject_point(0, 0) p2 = self.unproject_point(self.width, self.height) bbox = BoundingBox() bbox.add_point(p1) bbox.add_point(p2) return bbox
def do_viewport(self): map_bbox = self.containing_map.get_bbox() self.visible_objs = [] for shape in self.sf.shapes(): if shape.shapeType == 3: # polyline shape_bbox = BoundingBox(shape.bbox) if shape_bbox.overlaps(map_bbox): points = map(lambda p: Point(p[1], p[0]), shape.points) self.visible_objs.append(self.containing_map.project_points(points))
def on_button_release(self, gdkevent): if self.hover_point is not None: self.projected_points.append(self.hover_point) self.points.append( self.layer.containing_map.unproject_points( *(self.hover_point))) bbox = BoundingBox() bbox.add_points(self.points) self.fire_done(MapVectorBoundingBox(bbox))
def place_polygon(place, bbox): polygonpoints = place.get('polygonpoints') if polygonpoints is not None: return Polygon(map(lambda i: Point(float(i[1]), float(i[0])), json.loads(polygonpoints)[:-1])) # Sometime around January 2011 Nominatim stopped returning polygons for some objects. # If there is no polygon, make one out of the bounding box. else: p = BoundingBox(bbox) p.scale(1.05) return p.as_polygon()
class PointWrapper(object): def __init__(self, *args): self.points = [Point(*args)] self.bbox = None def get_bbox(self): if self.bbox is None: self.bbox = BoundingBox() self.bbox.add_points(self.points) return self.bbox def as_geojson(self): return self.points[0].as_geojson()
def make_visible(self, lat, lon): self.feedback.debug(1, "make_visible(%f, %f)" % (lat, lon)) bbox = BoundingBox(self.get_bbox()) bbox.scale(0.9) point = Point(lat, lon) if not bbox.contains_point(point): bbox.add_point(point) self.zoom_to_extent(bbox)
def make_visible_polygon(self, points): self.feedback.debug(1, "make_visible_polygon(%s)" % str(points)) bbox = BoundingBox(init=self.get_bbox()) bbox.scale(0.9) count = 0 for point in points: if not bbox.contains_point(point): bbox.add_point(point) count += 1 if count: self.zoom_to_extent(bbox)
def render_tiles(self, zoom_start, zoom_stop): bbox = BoundingBox() for layer in self.layers_ordered: bbox.add_bbox(layer.get_bbox()) x_start, y_start = map(int, project_to_tilespace(bbox.max_lat, bbox.min_lon, zoom_start)) x_stop, y_stop = map(int, project_to_tilespace(bbox.min_lat, bbox.max_lon, zoom_start)) total = tile_count(x_stop-x_start+1, y_stop-y_start+1, zoom_stop-zoom_start+1) count = 0 for zoom in range(zoom_start, zoom_stop+1): x_start, y_start = map(int, project_to_tilespace(bbox.max_lat, bbox.min_lon, zoom)) x_stop, y_stop = map(int, project_to_tilespace(bbox.min_lat, bbox.max_lon, zoom)) for x in range(x_start-1, x_stop+2): for y in range(y_start-1, y_stop+2): #print "render_tile(%d, %d, %d)" % (x, y, zoom) if (count % 73) == 0: # 73 speeds things while letting all of the digits change self.feedback.progress(count, total, _("Rending tile {count} of {total}").format(count=count, total=total)) tile_data = self.render_tile(x, y, zoom) if tile_data is not None: self.writer.add_tile(zoom, x, y, tile_data) #else: # print " blank tile" count += 1
Point(42.125, -72.8)]))) vector.add_obj( MapVectorPolygon(Polygon([ Point(42.0, -72.0), Point(42.0, -71.0), Point(41.0, -72.0), Point(42.0, -72.0) ], [[ Point(41.9, -71.9), Point(41.9, -71.2), Point(41.2, -71.9), Point(41.9, -71.9) ]]), style={'fill-color': (1.0, 1.0, 1.0, 0.5)})) bbox = BoundingBox() bbox.add_point(Point(42.125, -72.70)) bbox.add_point(Point(42.10, -72.65)) vector.add_obj(MapVectorBoundingBox(bbox)) # Add some On Screen Display layers map_widget.add_osd_layer(MapLayerScale()) map_widget.add_osd_layer(MapLayerAttribution()) # Initial center and zoom level map_widget.set_center_and_zoom(42.125, -72.75, 12) # Run GTK+ main loop gtk.main()
map_widget.add_layer("vector-doodles", vector) vector.add_obj(MapVectorMarker(Point(42.125, -72.73), {"label":"a house"})) vector.add_obj(MapVectorLineString(Polygon([Point(42.120, -72.80), Point(42.10, -72.73), Point(42.115, -72.745)]))) vector.add_obj(MapVectorPolygon(Polygon([Point(42.125, -72.75), Point(42.2, -72.75), Point(42.125, -72.8)]))) vector.add_obj(MapVectorPolygon(Polygon( [Point(42.0, -72.0), Point(42.0, -71.0), Point(41.0, -72.0), Point(42.0, -72.0)], [[ Point(41.9, -71.9), Point(41.9, -71.2), Point(41.2, -71.9), Point(41.9, -71.9)]] ), style={'fill-color':(1.0,1.0,1.0,0.5)})) bbox = BoundingBox() bbox.add_point(Point(42.125, -72.70)) bbox.add_point(Point(42.10, -72.65)) vector.add_obj(MapVectorBoundingBox(bbox)) # Add some On Screen Display layers map_widget.add_osd_layer(MapLayerScale()) map_widget.add_osd_layer(MapLayerAttribution()) # Initial center and zoom level map_widget.set_center_and_zoom(42.125, -72.75, 12) # Run GTK+ main loop gtk.main()
def place_bbox(place): min_lat, max_lat, min_lon, max_lon = map(lambda i: float(i), (place.get('boundingbox')).split(',')) return BoundingBox((min_lon, min_lat, max_lon, max_lat))
def get_bbox(self): if self.bbox is None: self.bbox = BoundingBox() self.bbox.add_points(self.points) return self.bbox
def get_bbox(self): bbox = BoundingBox() for marker_group in self.markers.values(): for marker in marker_group: bbox.add_point(Point(marker.lat, marker.lon)) return bbox