def migrate(self): projects = self.portal_catalog(portal_type = 'Project') for brain in projects: project = brain.getObject() geo = IGeoManager(project) style = IGeoCustomFeatureStyle(project) print project.Title() print geo.isGeoreferenceable() lat = project.getLatitude() lon = project.getLongitude() leadagency = project.getLeadagency() la ='' if leadagency: la = leadagency.Title().strip() if lat and lon and geo.isGeoreferenceable(): print lat, lon geo.setCoordinates('Point', (lon, lat)) style.geostyles.data['use_custom_styles']=True if la == 'Food and Agricultural Organization (FAO)': style.geostyles.data['marker_image'] = 'string:${portal_url}/marker-icon-fao.png' elif la == 'United Nations Development Programme (UNDP)': style.geostyles.data['marker_image'] = 'string:${portal_url}/marker-icon-undp.png' elif la == 'International Bank for Reconstruction and Development (WB)': style.geostyles.data['marker_image'] = 'string:${portal_url}/marker-icon-wb.png' elif la == 'United Nations Environment Programme (UNEP)': style.geostyles.data['marker_image'] = 'string:${portal_url}/marker-icon-unep.png' elif la == 'United Nations Office for Project Services (UNOPS)': style.geostyles.data['marker_image'] = 'string:${portal_url}/marker-icon-unops.png' elif la == 'Inter-American Development Bank (IADB)': style.geostyles.data['marker_image'] = 'string:${portal_url}/marker-icon-iabd.png' elif la == 'International Fund for Agriculture and Development (IFAD)': style.geostyles.data['marker_image'] = 'string:${portal_url}/marker-icon-ifad.png' style.geostyles.update(style.geostyles) return 'finished setting coordinates'
def set_geoannotation(context, icon): try: geo = IGeoManager(context) style = IGeoCustomFeatureStyle(context) image = Image.open(context.getFile().getIterator()) exif_data = get_exif_data(image) lat, lon = get_lat_lon(exif_data) timestamp = get_timestamp(exif_data) except: return None if lat and lon and geo.isGeoreferenceable(): geo.setCoordinates('Point', (lon, lat)) if icon: style.geostyles.data['use_custom_styles']=True style.geostyles.data['marker_image'] = icon style.geostyles.data['marker_image_size'] = 1.0 style.geostyles.update(style.geostyles) logger.info('annotated %s with lat %f, lon %f' % (context.getId(), lat, lon)) success = True else: success = False logger.info('Image has no EXIF GPS information') timestamp = exif_data.get('DateTimeOriginal') if timestamp: context.setCreationDate(timestamp) return success
def get_venues(self): """This function retrieves all related Venue objects for given Info and for each Venue gets the coordinates. Return a list of venues which have coordinates set. Each element of this list is a dictionary that contains three keys: location, title, description """ venues = [] refs = self.context.venue if not refs: return venues for ref in refs: ob = ref.to_object geo = IGeoManager(ob, None) if geo and geo.isGeoreferenceable(): geometry, coordinates = geo.getCoordinates() if not coordinates or len(coordinates) != 2: continue else: longitude, latitude = coordinates if geometry == 'Point' and longitude and latitude: venues.append({ 'title': ob.Title(), 'description': DESC_TEMPLATE % ob.Description(), 'location': "%r,%r,0.000000" % (longitude, latitude), }) return venues
def get_venues(self): """This function retrieves all related Venue objects for given Info and for each Venue gets the coordinates. Return a list of venues which have coordinates set. Each element of this list is a dictionary that contains three keys: location, title, description """ venues = [] refs = self.context.venue if not refs: return venues for ref in refs: ob = ref.to_object geo = IGeoManager(ob, None) if geo and geo.isGeoreferenceable(): geometry, coordinates = geo.getCoordinates() if not coordinates or len(coordinates) != 2: continue else: longitude, latitude = coordinates if geometry == 'Point' and longitude and latitude: venues.append({ 'title': ob.Title(), 'description': DESC_TEMPLATE % ob.Description(), 'location': "%r,%r,0.000000" % (longitude, latitude), }) return venues
def is_georeferenced(context): try: geo = IGeoManager(context) if geo.isGeoreferenceable(): if geo.getCoordinates()[0]: return True except TypeError: # catch TypeError: ('Could not adapt', <ATFile ...>, <Interfa...oManager>) pass return False
def layers(self): #add basemaps layers = super(LegalFWMapLayers, self).layers() geo = IGeoManager(self.context) if self.context.getField('country').get(self.context): layers.append(LegalFWCountryMapLayer(self.context)) if self.context.getField('basin').get(self.context): layers.append(LegalFWBasinMapLayer(self.context)) if geo.isGeoreferenceable(): if geo.getCoordinates(): layers.append(LegalFWMapLayer(self.context)) return layers
def make_place(self, brain): ob = brain.getObject() url = brain.getURL() + '/@@adr_view.html' view = cgi.escape(AdrView(ob, self.request)()).encode( 'ascii', 'xmlcharrefreplace') params = {'outputType': 'json', #'documentURL': url, 'documentContent': view, 'documentType': 'text/html', 'appid': 'pySuZD7V34FHjlmmw72YPBBf4R55MwkhtNCo_c3fR1aQY4wNKsU6YevDnyPSwJ53uu3SlwvPifbaWjUCfMu_umRPPGk-', } try: params = urllib.urlencode(params) except: logger.error(brain.Title + ': error encoding org') return brain.Title + ': Error setting coordinates' #try: response = urllib2.urlopen(self.url, params) #except urllib2.HTTPError, e: # Check for for Forbidden HTTP status, which means invalid API key. # if e.code == 403: # return ['Invalid API key.'] # return ['error %i' % e.code] output = json.loads(response.read()) try: logger.info(brain.Title + ': ' + str(output['document']['extents']['center'])) geo = IGeoManager(ob) print geo.isGeoreferenceable() lat = float(output['document']['extents']['center']['latitude']) lon = float(output['document']['extents']['center']['longitude']) geo.setCoordinates('Point', (lon, lat)) return brain.Title + str(output['document']['extents']['center']) except: logger.error(brain.Title + ': ' + str(output)) return brain.Title + ': Error setting coordinates'
def _get_markers(self, brain): """Return dict of marker details. Handle Info objects in special way. """ markers = [] if brain.portal_type == 'tbfac.Info': # get related Venues obj = brain.getObject() if obj is None: return [] refs = obj.venue if not refs: return [] for ref in refs: venue = ref.to_object geo = IGeoManager(venue, None) if geo and geo.isGeoreferenceable(): geometry, coordinates = geo.getCoordinates() if not coordinates or len(coordinates) != 2: continue else: longitude, latitude = coordinates if geometry == 'Point' and longitude and latitude: markers.append({ 'uid': IUUID(venue), 'search_uid': brain.UID, 'url': brain.getURL(), 'title': brain.Title, 'tags': brain.Subject or [], 'start': brain.start or '', 'end': brain.end or '', 'geometry': { 'style': None, 'type': 'Point', 'coordinates': (longitude, latitude) }, 'latitude': latitude, 'longitude': longitude, }) else: markers = super(UshahidiMapView, self)._get_markers(brain) return markers
def _get_markers(self, brain): """Return dict of marker details. Handle Info objects in special way. """ markers = [] if brain.portal_type == 'tbfac.Info': # get related Venues obj = brain.getObject() if obj is None: return [] refs = obj.venue if not refs: return [] for ref in refs: venue = ref.to_object geo = IGeoManager(venue, None) if geo and geo.isGeoreferenceable(): geometry, coordinates = geo.getCoordinates() if not coordinates or len(coordinates) != 2: continue else: longitude, latitude = coordinates if geometry == 'Point' and longitude and latitude: markers.append({ 'uid': IUUID(venue), 'search_uid': brain.UID, 'url': brain.getURL(), 'title': brain.Title, 'tags': brain.Subject or [], 'start': brain.start or '', 'end': brain.end or '', 'geometry': { 'style': None, 'type': 'Point', 'coordinates': (longitude, latitude)}, 'latitude': latitude, 'longitude': longitude, }) else: markers = super(UshahidiMapView, self)._get_markers(brain) return markers
def index_object(self, documentId, obj, threshold=None): """index an object, normalizing the indexed value to its bounds o Objects which have 'None' as indexed value are *omitted*, by design. 'documentId' is the integer ID of the document. 'obj' is the object to be indexed. """ returnStatus = 0 try: geoitem=IGeoManager(obj) except: return 0 if geoitem.wkt: geometry = wkt.loads(geoitem.wkt) else: geometry = None if geoitem.isGeoreferenceable() and geoitem.getCoordinates()[1]: newValue = geoitem.wkt if newValue is callable: newValue = newValue() oldValue = self.backward.get(documentId, _marker ) if newValue is _marker: if oldValue is not _marker: self.rtree.delete(documentId, wkt.loads(oldValue).bounds) try: del self.backward[documentId] except ConflictError: raise except: pass else: if oldValue is not _marker and newValue!=oldValue: self.rtree.delete(documentId, wkt.loads(oldValue).bounds) if geometry: self.rtree.add(documentId, geometry.bounds) self.backward[documentId] = newValue returnStatus = 1 return returnStatus
def is_geo_referenced(self): geo = IGeoManager(self.context) if geo.isGeoreferenceable(): return True else: return False