Mapping United States is a mapping tool that utilizes the census shape files.
Project description
Mapping United States
This repo contains a few helper methods to make working with the US Census shape files a bit easier.
- Caching layer to prevent make sure limit the amount of network activity.
- Converts the layers over to Geopandas for you (where applicable) which makes graphing much easier.
- A few helper functions for merging counties/states to create beautiful maps easily.
All of this should equate to an easier time making maps, and gives you more time for perfecting the design.
Installing
pip install mapping-united-states
Basic Usage
This will generate a county in Inyo County, California. The default settings should look decent on almost all maps you generate, but we'll look at customizing everything in a moment.
from mapping_united_states import mapping, CensusData
census_data = CensusData()
def map_county():
# Mapping based on counties
mapping.map_area(
'./Sub-California.png',
[
'06027' # You can provide the county FIPS, State FIPS, or the 2 letter state abbreviation
],
mapping.MappingOptions(),
census_data
)
if __name__ == "__main__":
map_county()
The code above will generate a file in the local directory called Sub-California.png. Assuming everything works as intended, you'll see an image similar to below.
Customizing
Here's a simple example where we join a few counties in CA and NV together and change a few of the display settings.
from mapping_united_states import CensusData, mapping
from mapping_united_states.mapping import MappingOptions
census_data = CensusData()
# Adjusting the mapping colors while mapping part of Nevada and Cali
options = MappingOptions()
options.border.line_color = '#FF0000'
options.border.fill_color = '#00FF00'
options.primary_roads.line_color = '#0000FF'
options.primary_roads.line_thickness = 10
options.secondary_roads.is_visible = False
options.neighborhood_roads.is_visible = False
# This defaults to 9,000,000 and represents how large the body of water needs to be before mapping
# Not having this option made some states feel a bit too busy for my liking... but Nevada it doesn't matter too much.
options.water.min_water_area = None
mapping.map_area(
'Sub-California-Nevada.png',
[
'06027',
'06071',
'32003',
'32023',
'32017',
'32009'
],
options,
census_data
)
The code above will generate a file in the local directory called Sub-California-Nevada.png. Since we overrode a lot of
functionality and colors, this one will look a bit like a crayon drawing, but you can use these simple settings to get more creative.
Technical Docs
CensusData Class
The CensusData is just a simple wrapper using the requests library to retrieve the shapes file from the Census Bureau's FTP. The first time,
it will download the files from the FTP, but afterwards it'll just use the cache to provide the files.
There's a few basic settings you can specify in the constructor to configure how the caching works and which year of census data it uses.
CensusData(
census_year: int = 2022,
cache_directory: Optional[str] = './caching/',
delay_between_requests_in_seconds: Optional[int] = 3
)
- census_year - This is based on the Census's FTP. The library was built off of 2022 (which is the default value), but
does work with other years (assuming the directory structure doesn't change).
- https://www2.census.gov/geo/tiger/
- Look for directories prefixed with `TIGER`, and those are the ones that this process is using for almost everything.
- cache_directory - This is where the files will be saved locally and will be used each time you build a map moving forward. DEFAULT is './caching/'
- delay_between_requests_in_seconds - For some of the map building, it's nesscary to hit the FTP with multiple requests in quick succession. This just prevents us from hitting the FTP too hard. Delay is in seconds and defaults to 3.
Other Notes
Check out the example_usage.py for a few more simple examples.
Support us by checking out the blog. We share additional tips to make the most of this library.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mapping-united-states-0.0.2.tar.gz.
File metadata
- Download URL: mapping-united-states-0.0.2.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3458fac31ba77e62745f8b3f4c0e1f458a482d46fd457fba44f6fdb83fe41958
|
|
| MD5 |
bb7c85cf66e301d05859668180acb00c
|
|
| BLAKE2b-256 |
2017d4ed9582893e198ac8c135df02f1064bb52d9702d11570f0f05ec98ec96e
|
File details
Details for the file mapping_united_states-0.0.2-py3-none-any.whl.
File metadata
- Download URL: mapping_united_states-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9739cb233e4cf23a5b538948148d14fadd678773c1b43a660637dafe925523b2
|
|
| MD5 |
556e781fc22bf54c7da1612f5b814723
|
|
| BLAKE2b-256 |
3ef00493cf52d2aefd9c7d24e3f02eaacbd9700c2e57bd72b9000a0395c7542b
|