The code samples in this documentation were validated and run on the following software versions and with these packages. Note that only direct package imports are listed below (package dependencies are not included). If you are having issues running any of the code samples in this documentation, double check your package versions against those listed here. For help installing these packages, please see the Installing Packages section below.
To install the packages used in this documentation in Python, you can download the Python requirements and use either pip or conda. The instructions below for conda create a new environment, while the instructions for pip simply install the packages globally. To create a virtual environment in pip, see these instructions on creating a virtual environment (instructions vary by operating system).
Note
The code in these document does not rely on Jupyter or Jupyter Notebooks. If you would like to run these samples in a Jupyter Notebook or an Python Interactive session, you will also need to install the necessary package(s). For more information, see installing Jupyter.
To install the packages used in this documentation in R, you can download the R requirements. You can install the packages required through the instructions below.
Note
The style of package installation below does not install specific versions. If you want to install specific versions of R packages, you can first download the R package remotes and use the function install-version to install specific versions of the R packages.
Detailed information on the LODES file structure can be found in the LODES Technical Documentation. Selected schema tables are provided below for ease (and for attachment of labels, if desired).
The code to generate the image in Case Study: Finding all the Jobs Within 5 KM of a Point is provided below in Python. In this code, the geographic crosswalk is used to to find the blocks within a 5 kilometer buffer of the specified point. Then, the buffer, original point, and blocks are plotted on the same image. Note that the packagecontextilyis not included in the dependencies for this project, so it will need to be installed to generate this image.
importgeopandasasgpdfromshapely.geometryimportPointimportmatplotlib.pyplotaspltimportcontextilyasctx# Input coordinates (latitude, longitude)center_lat=40.736679center_lon=-74.175975# Create GeoDataFrame of the target pointcenter_point=gpd.GeoDataFrame(geometry=[Point(center_lon,center_lat)],crs="EPSG:4326")# Project to meters (Web Mercator) for buffering and basemapcenter_point_proj=center_point.to_crs(epsg=3857)# Create 5 km buffer (5000 meters)buffer=center_point_proj.buffer(5000).iloc[0]crosswalk=read_crosswalk("nj",cols=["cty","blklondd","blklatdd"])# Convert to GeoDataFramecrosswalk=gpd.GeoDataFrame(crosswalk,geometry=gpd.points_from_xy(crosswalk.blklondd,crosswalk.blklatdd),crs="EPSG:4326",)# Project blocks to same CRS as buffer (meters)blocks_proj=crosswalk.to_crs(epsg=3857)# Select blocks within bufferblocks_within=blocks_proj[blocks_proj.geometry.within(buffer)]fig,ax=plt.subplots(figsize=(10,10))# Plot buffer outlinegpd.GeoSeries(buffer).plot(ax=ax,edgecolor="red",facecolor="none",linewidth=2)# Plot blocks within the 5 km radiusblocks_within.plot(ax=ax,color="blue",markersize=3)# Plot center pointcenter_point_proj.plot(ax=ax,color="red",markersize=50,marker="*")# Add basemapctx.add_basemap(ax,source=ctx.providers.OpenStreetMap.Mapnik)