def load_community_districts(self): ds = DataSource(str(COMMUNITY_DISTRICT_SHAPEFILE)) layer = ds[0] for feature in layer: boro_cd = str(feature['boro_cd']) name = CommunityDistrict.boro_cd_to_name(boro_cd) instance = get_or_construct(CommunityDistrict, boro_cd=boro_cd) geom = feature.geom geom.transform(4326) instance.geom = to_multipolygon(geom.geos) instance.name = name print(f"Saving {instance.name}.") instance.save()
def create_cd(boro_cd="164", name="Central Park", geom=POLY_1): cd = CommunityDistrict(boro_cd=boro_cd, name=name, geom=to_multipolygon(geom)) cd.save() return cd
def test_boro_cd_to_name_shows_community_districts(self): assert CommunityDistrict.boro_cd_to_name('36') == 'Brooklyn CD 6'
def test_str_works(self): cd = CommunityDistrict(name='Boop') assert str(cd) == 'Boop'
def test_boro_cd_to_name_shows_joint_interest_areas(self): assert CommunityDistrict.boro_cd_to_name( '164') == 'Manhattan JIA 64 (Central Park)'