Pare down city fields; add more cities
This commit is contained in:
		
							parent
							
								
									64d655879a
								
							
						
					
					
						commit
						69f28a60d5
					
				
					 3 changed files with 6638 additions and 353 deletions
				
			
		
							
								
								
									
										6931
									
								
								doc/cities.tsv
									
										
									
									
									
								
							
							
						
						
									
										6931
									
								
								doc/cities.tsv
									
										
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -2,30 +2,22 @@ import csv | |||
| import shapely | ||||
| 
 | ||||
| """ | ||||
| Implements a parser and wrapper class for the top 150 populous US cities | ||||
| available on Wikipedia: | ||||
| 
 | ||||
|     https://en.wikipedia.org/wiki/List_of_United_States_cities_by_population | ||||
| 
 | ||||
| The input TSV file is created by copying and pasting the tabular data | ||||
| from a web browser into a text file. | ||||
| Implements a parser and wrapper class for a TSV list of cities. | ||||
| """ | ||||
| 
 | ||||
| class City(): | ||||
|     name:         str | ||||
|     state:        str | ||||
|     pop_estimate: int | ||||
|     pop_census:   int | ||||
|     location:     shapely.Point | ||||
|     name:       str | ||||
|     state:      str | ||||
|     population: int | ||||
|     location:   shapely.Point | ||||
| 
 | ||||
|     @staticmethod | ||||
|     def from_tsv_row(row: list): | ||||
|         city = City() | ||||
|         city.name         = row[0] | ||||
|         city.state        = row[1] | ||||
|         city.pop_estimate = int(row[2]) | ||||
|         city.pop_census   = int(row[3]) | ||||
|         city.location     = shapely.Point(float(row[10]), float(row[9])) | ||||
|         city.name       = row[0] | ||||
|         city.state      = row[1] | ||||
|         city.population = int(row[2]) | ||||
|         city.location   = shapely.Point(float(row[4]), float(row[3])) | ||||
| 
 | ||||
|         return city | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,7 +1,10 @@ | |||
| import math | ||||
| import cairo | ||||
| import shapely | ||||
| import gi | ||||
| 
 | ||||
| from xmet.city import City | ||||
| 
 | ||||
| gi.require_version('Rsvg', '2.0') | ||||
| 
 | ||||
| from gi.repository import Rsvg | ||||
|  | @ -74,3 +77,34 @@ class EquirectMap(): | |||
|                 first = False | ||||
|             else: | ||||
|                 cr.line_to(x, y) | ||||
| 
 | ||||
|     def draw_city(self, cr: cairo.Context, city: City): | ||||
|         cr.save() | ||||
| 
 | ||||
|         x, y = self.map_to_screen(city.location) | ||||
| 
 | ||||
|         if city.population >= 1000000: | ||||
|             radius = 4 | ||||
|             pass | ||||
|         elif city.population >= 500000: | ||||
|             radius = 3 | ||||
|             pass | ||||
|         elif city.population >= 100000: | ||||
|             radius = 2 | ||||
|             pass | ||||
|         else: | ||||
|             radius = 1 | ||||
|             pass | ||||
| 
 | ||||
|         if radius > 2: | ||||
|             extents = cr.text_extents(city.name) | ||||
| 
 | ||||
|             cr.set_source_rgb(0.2, 0.2, 0.2) | ||||
|             cr.arc(x, y, radius, 0, 2*math.pi) | ||||
|             cr.fill() | ||||
| 
 | ||||
|             cr.set_font_size(14) | ||||
|             cr.move_to(x + 8, y + extents.height / 2) | ||||
|             cr.show_text(city.name) | ||||
| 
 | ||||
|         cr.restore() | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue