def cip(polygon, iso_code): con = mdb.connect(uim.host, uim.user, uim.password, uim.db) with con: cur = con.cursor() sql_string = "SELECT polygons FROM country_polygons WHERE ISO2='%s'" % iso_code cur.execute(sql_string) country_polygon = list(cur.fetchall()[0])[0] F = 0 T = 0 # The contry polygon may be made up of several polygons separated by ':'. for poly in country_polygon.split(':'): for node in poly.split(' '): x = float(node.split(',')[0]) y = float(node.split(',')[1]) test = pip(polygon, x, y) if test == True: T = 1 elif test == False: F = 1 # Country in polygon if T == 1 and F == 0: return True # Country not in polygon if T == 0 and F == 1: return False # Part of the country in the polygon if T == 1 and F == 1: return None
def remove_redundant(additional_species_list, species_list, raw_species_list, polygon): for record in additional_species_list: # Add all species_id's in "additional_species_list" to "raw_species_list" raw_species_list.append(record[0]) for record in additional_species_list: print record # Devel. print int(raw_species_list.count(record[0])) # Devel. print int(uid.occurrence_nr) # Devel. # Test if if int(raw_species_list.count(record[0])) >= int(uid.occurrence_nr) and record not in species_list: # Test if the occurrence record has longitude data if record[1] != None: print pip(polygon, record[1], record[2]) # Devel. print record[1] # Devel. print record[2] # Devel. if pip(polygon, record[1], record[2]) == True: print "### Match ###" # Devel. species_list.append(record) return species_list
def geo_test(polygon, record): # Test if the occurrence record has longitude data if record[1] != None: if pip(polygon, record[1], record[2]) == True: # print "### Match ###" # Devel. return True # container.append(record) else: # print 'No' # Devel. return False else: return False