from BeautifulSoup import BeautifulSoup as bs from find_sector import find_polygon, find_sector import shapefile file_name = "stamps.kml" print "reading stamps.kml" soup = bs(open(file_name).read()) placemarks = soup.findAll("placemark") sectors = set() w = shapefile.Writer() w = shapefile.Writer(shapefile.POLYGON) w.field("NAME", "C", "40") for p in placemarks: coord = p.find("point").find("coordinates") lon, lat, h = coord.contents[0].split(",") sector = find_sector(float(lon), float(lat)) if not sector in sectors: sectors.add(sector) poly = find_polygon(float(lon), float(lat)) w.poly(parts=[poly]) w.record(str(sector)) w.save("polygon")
def test_negative(self): lon = -12.234 lat = -0.1 self.assertEqual(find_sector(lon, lat), (-13, -1))
def test_integer(self): lon = -12 lat = -0 self.assertEqual(find_sector(lon, lat), (-12, 0))
def test_simple(self): """testing that lon=37.4 lat=48.1 correspond to sector (37,48) """ lon = 37.4 lat = 48.1 self.assertEqual(find_sector(lon, lat), (37, 48))