def mm(self, points): bbox = self.calculate_bbox_for_points(points) if self.method == 'bbox': bbox = self.adjust_bbox(bbox, .5) self.bbox = bbox dims = ModestMaps.Core.Point(self.width, self.height) sw = ModestMaps.Geo.Location(bbox[0], bbox[1]) ne = ModestMaps.Geo.Location(bbox[2], bbox[3]) provider = ModestMaps.builtinProviders[ 'MICROSOFT_AERIAL' ]() if self.method == 'bbox': mm_obj = ModestMaps.mapByExtentZoom(provider, sw, ne, self.zoom) else: mm_obj = ModestMaps.mapByExtent(provider, sw, ne, dims) self.mm_provider = provider self.mm_obj = mm_obj self.mm_markers = modestMMarkers.modestMMarkers(self.mm_obj) return True
def infer_zoom(width, height, north, west, south, east): """ """ mmap = mm.mapByExtent(mm.OpenStreetMap.Provider(), mm.Geo.Location(north, west), mm.Geo.Location(south, east), mm.Core.Point(width, height)) zoom = int(mmap.coordinate.zoom) return zoom
def __init__(self, width, height, bbox, with_bg=False): check_envelope(bbox) self.width = width self.height = height self.ll = (bbox[0], bbox[2]) self.ur = (bbox[1], bbox[3]) self.legends = [] self.img_format = 'JPG' MapConf = Pool().get('map.conf') conf = MapConf.search([]) if with_bg: if len(conf) == 0: self.provider = 'OPENSTREETMAP' provider = ModestMaps.builtinProviders['OPENSTREETMAP']() elif conf[0].map_provider == 'OPENSTREETMAP_CUSTOM': self.provider = 'OPENSTREETMAP' provider = OSMCustomProvider(conf[0].osm_url) else: self.provider = conf[0].map_provider if self.provider is None: self.provider = 'OPENSTREETMAP' provider = ModestMaps.builtinProviders[self.provider]() dimensions = ModestMaps.Core.Point(self.width, self.height) locationLL = ModestMaps.Geo.Location(self.ll[1], self.ll[0]) locationUR = ModestMaps.Geo.Location(self.ur[1], self.ur[0]) self.map = ModestMaps.mapByExtent(provider, locationLL, locationUR, dimensions) else: self.map = None if len(conf) != 0: self.img_format = conf[0].img_format self.has_bg = False self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) self.ctx = cairo.Context(self.surface) # Clear the image self.ctx.set_source_rgb(1.0, 1.0, 1.0) self.ctx.rectangle(0, 0, self.width, self.height) self.ctx.fill()
def draw_map_extentified (self) : if self.ctx.has_key('adjust') : self.ctx['bbox'] = self.__adjust_bbox(self.ctx['bbox'], self.ctx['adjust']) # provider = self.load_provider(self.ctx['provider']) sw = ModestMaps.Geo.Location(self.ctx['bbox'][0], self.ctx['bbox'][1]) ne = ModestMaps.Geo.Location(self.ctx['bbox'][2], self.ctx['bbox'][3]) dims = ModestMaps.Core.Point(self.ctx['width'], self.ctx['height']); self.ctx['map'] = ModestMaps.mapByExtent(provider, sw, ne, dims) coord, offset = ModestMaps.calculateMapExtent(provider, self.ctx['width'], self.ctx['height'], ModestMaps.Geo.Location(self.ctx['bbox'][0], self.ctx['bbox'][1]), ModestMaps.Geo.Location(self.ctx['bbox'][2], self.ctx['bbox'][3])) self.ctx['zoom'] = coord.zoom return self.ctx['map'].draw()
def draw_map_extentified(self): if self.ctx.has_key('adjust'): self.ctx['bbox'] = self.__adjust_bbox(self.ctx['bbox'], self.ctx['adjust']) # provider = self.load_provider(self.ctx['provider']) sw = ModestMaps.Geo.Location(self.ctx['bbox'][0], self.ctx['bbox'][1]) ne = ModestMaps.Geo.Location(self.ctx['bbox'][2], self.ctx['bbox'][3]) dims = ModestMaps.Core.Point(self.ctx['width'], self.ctx['height']) self.ctx['map'] = ModestMaps.mapByExtent(provider, sw, ne, dims) coord, offset = ModestMaps.calculateMapExtent( provider, self.ctx['width'], self.ctx['height'], ModestMaps.Geo.Location(self.ctx['bbox'][0], self.ctx['bbox'][1]), ModestMaps.Geo.Location(self.ctx['bbox'][2], self.ctx['bbox'][3])) self.ctx['zoom'] = coord.zoom return self.ctx['map'].draw()
center = ModestMaps.Geo.Location(lat, lon) zoom = options.zoom map = ModestMaps.mapByCenterZoom(provider, center, zoom, dimensions) elif options.extent and options.dimensions: latA, lonA = options.extent[0], options.extent[1] latB, lonB = options.extent[2], options.extent[3] width, height = options.dimensions[0], options.dimensions[1] dimensions = ModestMaps.Core.Point(width, height) locationA = ModestMaps.Geo.Location(latA, lonA) locationB = ModestMaps.Geo.Location(latB, lonB) map = ModestMaps.mapByExtent(provider, locationA, locationB, dimensions) elif options.extent and options.zoom: latA, lonA = options.extent[0], options.extent[1] latB, lonB = options.extent[2], options.extent[3] locationA = ModestMaps.Geo.Location(latA, lonA) locationB = ModestMaps.Geo.Location(latB, lonB) zoom = options.zoom map = ModestMaps.mapByExtentZoom(provider, locationA, locationB, zoom) else: raise BadComposure("Error: not really sure what's going on.")
dimensions = ModestMaps.Core.Point(width, height) center = ModestMaps.Geo.Location(lat, lon) zoom = options.zoom map = ModestMaps.mapByCenterZoom(provider, center, zoom, dimensions) elif options.extent and options.dimensions: latA, lonA = options.extent[0], options.extent[1] latB, lonB = options.extent[2], options.extent[3] width, height = options.dimensions[0], options.dimensions[1] dimensions = ModestMaps.Core.Point(width, height) locationA = ModestMaps.Geo.Location(latA, lonA) locationB = ModestMaps.Geo.Location(latB, lonB) map = ModestMaps.mapByExtent(provider, locationA, locationB, dimensions) elif options.extent and options.zoom: latA, lonA = options.extent[0], options.extent[1] latB, lonB = options.extent[2], options.extent[3] locationA = ModestMaps.Geo.Location(latA, lonA) locationB = ModestMaps.Geo.Location(latB, lonB) zoom = options.zoom map = ModestMaps.mapByExtentZoom(provider, locationA, locationB, zoom) else: raise BadComposure("Error: not really sure what's going on.") except BadComposure, e:
#!/usr/bin/python import ModestMaps provider = ModestMaps.WMS.Provider('http://gmu.azavea.com/geoserver/wms',{ 'LAYERS':'pmp:demo_va_county_poptot', 'WIDTH': 256, 'HEIGHT': 256, 'SRS':'EPSG:3785' }) ll = ModestMaps.Geo.Location(36.483530296000694, -83.781734299520878) ur = ModestMaps.Geo.Location(39.504037835739027, -75.124508209709902) dims = ModestMaps.Core.Point(512,226) image = ModestMaps.mapByExtent(provider, ll, ur, dims).draw() image.save('regular.png') sld_body = """<?xml version="1.0" encoding="ISO-8859-1"?> <sld:StyledLayerDescriptor version="1.0.0" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"> <sld:NamedLayer> <sld:Name>pmp:demo_va_county_poptot</sld:Name> <sld:UserStyle> <sld:Name>Default Styler</sld:Name> <sld:Title>Population</sld:Title> <sld:Abstract>A grayscale style showing the population numbers in a given geounit.</sld:Abstract> <sld:FeatureTypeStyle> <sld:Name>name</sld:Name> <sld:Rule> <sld:Title>< 48,350</sld:Title>
#!/usr/bin/python import ModestMaps provider = ModestMaps.WMS.Provider( 'http://gmu.azavea.com/geoserver/wms', { 'LAYERS': 'pmp:demo_va_county_poptot', 'WIDTH': 256, 'HEIGHT': 256, 'SRS': 'EPSG:3785' }) ll = ModestMaps.Geo.Location(36.483530296000694, -83.781734299520878) ur = ModestMaps.Geo.Location(39.504037835739027, -75.124508209709902) dims = ModestMaps.Core.Point(512, 226) image = ModestMaps.mapByExtent(provider, ll, ur, dims).draw() image.save('regular.png') sld_body = """<?xml version="1.0" encoding="ISO-8859-1"?> <sld:StyledLayerDescriptor version="1.0.0" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"> <sld:NamedLayer> <sld:Name>pmp:demo_va_county_poptot</sld:Name> <sld:UserStyle> <sld:Name>Default Styler</sld:Name> <sld:Title>Population</sld:Title> <sld:Abstract>A grayscale style showing the population numbers in a given geounit.</sld:Abstract> <sld:FeatureTypeStyle> <sld:Name>name</sld:Name> <sld:Rule>
def draw (self, **kwargs) : polys = [] donuts = [] children = [] # Fetch the current shapefile req = Flickr.API.Request(method='flickr.places.getInfo', woe_id=kwargs['woeid'], sign=False) res = self.api.execute_request(req) (polys, allpoints) = self.munge_place(ET.parse(res)) # Fetch donut hole shapes if opts.donuts : req = Flickr.API.Request(method='flickr.places.getShapeHistory', woe_id=kwargs['woeid'], sign=False) res = self.api.execute_request(req) et = ET.parse(res) for shp in et.findall(".//shape") : if shp.attrib['is_donuthole'] == '1' : (donuts, ignore) = self.munge_place(shp) break # Fetch children if opts.children : req = Flickr.API.Request(method='flickr.places.getChildrenWithPhotosPublic', woe_id=kwargs['woeid'], sign=False) res = self.api.execute_request(req) et = ET.parse(res) for pl in et.findall(".//place") : woeid = pl.attrib['woeid'] subreq = Flickr.API.Request(method='flickr.places.getInfo', woe_id=woeid) subres = self.api.execute_request(subreq) (child_polys, child_points) = self.munge_place(ET.parse(subres)) if len(child_polys) > 0 : children.append(child_polys) # Draw the map bbox = self.calculate_bbox_for_points(allpoints) dims = ModestMaps.Core.Point(int(kwargs['width']), int(kwargs['height'])) sw = ModestMaps.Geo.Location(bbox[0], bbox[1]) ne = ModestMaps.Geo.Location(bbox[2], bbox[3]) provider = ModestMaps.builtinProviders[kwargs['provider']]() mm_obj = ModestMaps.mapByExtent(provider, sw, ne, dims) mm_img = mm_obj.draw() # Draw the shapes markers = modestMMarkers.modestMMarkers(mm_obj) # The bounding box? if kwargs['bbox'] : mm_img = markers.draw_bounding_box(mm_img, allpoints, colour=(1, 0, .005), opacity_fill=.1) # The current shape of WOE ID mm_img = markers.draw_polylines(mm_img, polys) # Donut holes if len(donuts) : mm_img = markers.draw_polylines(mm_img, donuts, colour=(.005, 0, 1)) # Child WOE IDs if len(children) : for ch in children : mm_img = markers.draw_polylines(mm_img, ch, colour=(255,255,255), no_fill=True) # sssshhhh..... # mm_img = markers.draw_points(mm_img, allpoints, colour=(.005, 0, 1)) # Happy self.mm_img = mm_img