Quickstart: Patterns and Best Practices¶
Importing the Library¶
Importing the Census Geocoder is very straightforward. You can either import its components precisely (see API Reference) or simply import the entire module:
# Import the entire module.
import census_geocoder as geocoder
result = geocoder.location.from_address('4600 Silver Hill Rd, Washington, DC 20233')
result = geocoder.geography.from_address('4600 Silver Hill Rd, Washington, DC 20233')
# Import precise components.
from census_geocoder import Location, Geography
result = Location.from_address('4600 Silver Hill Rd, Washington, DC 20233')
result = Geography.from_address('4600 Silver Hill Rd, Washington, DC 20233')
Getting Location Data¶
Retrieving data about canonical locations is very straightforward. You have four different ways to get this information, depending on what information you have about the location you want to geocode:
import census_geocoder as geocoder
result = geocoder.location.from_address('4600 Silver Hill Rd, Washington, DC 20233')
See also
import census_geocoder as geocoder
result = geocoder.location.from_address(street = '4600 Silver Hill Rd',
city = 'Washington',
state = 'DC',
zip_code = '20233')
See also
import census_geocoder as geocoder
result = geocoder.location.from_coordinates(longitude = -76.92744,
latitude = 38.845985)
See also
import census_geocoder as geocoder
result = geocoder.location.from_batch(file_ = '/my-csv-file.csv')
Caution
The batch file indicated can have a maximum of 10,000 records.
Warning
While the Census Geocoder API supports CSV, TXT, XLSX, and DAT formats the Census Geocoder library only supports CSV and TXT formats so as to avoid dependency-bloat (read: Why rely on other libraries to read XLSX format data?).
See also
Getting Geographical Area Data¶
Retrieving data about the geographic areas that contain a given location/place is just
as straightforward as getting location data. In fact, the
syntax is almost identical. Just swap out the word 'location'
for 'geography'
and you’re done!
Here’s how to do it:
import census_geocoder as geocoder
result = geocoder.geography.from_address('4600 Silver Hill Rd, Washington, DC 20233')
See also
import census_geocoder as geocoder
result = geocoder.geography.from_address(street = '4600 Silver Hill Rd',
city = 'Washington',
state = 'DC',
zip_code = '20233')
See also
import census_geocoder as geocoder
result = geocoder.geography.from_coordinates(longitude = -76.92744,
latitude = 38.845985)
See also
import census_geocoder as geocoder
result = geocoder.geography.from_batch(file_ = '/my-csv-file.csv')
Caution
The batch file indicated can have a maximum of 10,000 records.
Warning
While the Census Geocoder API supports CSV, TXT, XLSX, and DAT formats the Census Geocoder library only supports CSV and TXT formats so as to avoid dependency-bloat (read: Why rely on other libraries to read XLSX format data?).
See also