コード例 #1
0
ファイル: tagim.py プロジェクト: hobson/tagim
def location2latlon(location_string):
    import geopy
    lat = lon = alt = 0.0
    mo = POINT_PATTERN.match(location_string)
    try:
        p = geopy.point.Point(location_string)
        lat = p.latitude
        lon = p.longitude
        # TODO: need to trigger these warnings or messages only when "verbose" or "debug" global option is set
        print "geopy module point.Point() read the gps string, but is it valid?"
        print '(' + str(lat) + ',' + str(lon) + ') ' + ' == ' + '"' + location_string + '" ?'
    except ValueError:
        if mo: # and (mo.group('latitude_degrees' ) or mo.group('longitude_degrees' )):
            lat = (float(zero_if_none(mo.group('latitude_degrees')))
                 + float(zero_if_none(mo.group('latitude_arcminutes'))) / 60.0
                 + float(zero_if_none(mo.group('latitude_arcseconds'))) / 3600.0)
            lon = (float(zero_if_none(mo.group('longitude_degrees')))
                 + float(zero_if_none(mo.group('longitude_arcminutes'))) / 60.0
                 + float(zero_if_none(mo.group('longitude_arcseconds'))) / 3600.0)
            # TODO: altitude
            print "geopy.point.Point() unable to read gps string, but tg.tagim got ..."
            print '('+str(lat)+','+str(lon)+') '+' from the string '+'"'+location_string+'" ?'
            print mo.groupdict()
        else:
            return (None, None, None)
    return (lat, lon, alt)
コード例 #2
0
ファイル: preprocess.py プロジェクト: totalgood/tagim
def quantify(s,lookfor=['units'],ignore=['']): # look_for=['gps','range','units','list']
	"""UNFINISHED: Extract quantitative data from a string.
	
	value1 = first numerical value found in string (usually in a pair for a range)
	units  = string for the units of measure
	value2 = second numerical value found in a string list of numerical values
	
	TODO: treat look_for as a prioritization list, with all non-ignored searches at the bottom of the list
	"""
	if isinstance(lookfor,str):
		look_for = look_for.lower()
	else:
		look_for = map(str.lower,look_for)
	if ('gps' in look_for) or ('gps' in ignore):
		from tg.regex_patterns import POINT_PATTERN, DATETIME_PATTERN
		import geopy
		value1 = value2 = 0
		try:
			p = geopy.point.Point(s)
			value1 = p.latitude
			value2 = p.longitude
		except ValueError:
			mo = POINT_PATTERN.findall(s) # or .match(s)
			if mo: # and (mo.group('latitude_degrees' ) or mo.group('longitude_degrees' )):
				value1 = (float(zero_if_none(mo.group('latitude_degrees' )))
					 + float(zero_if_none(mo.group('latitude_arcminutes' )))/60.0
					 + float(zero_if_none(mo.group('latitude_arcseconds' )))/3600.0)
				value2 = (float(zero_if_none(mo.group('longitude_degrees'))) 
					 + float(zero_if_none(mo.group('longitude_arcminutes')))/60.0 
					 + float(zero_if_none(mo.group('longitude_arcseconds')))/3600.0)
	elif ('units' in lookfor)
		from tg.regex_patterns import VALUE_WITH_UNITS