Find Census Tract from Point Coordinates¶
M. Fawcett February 18, 2024
This notebook explores finding which Delaware Census Tract a street address longitude/latitude coordinate falls within.
Uses Python Shapely and Geopandas packages.
Addresses and their associated longitude and latitude coordinates for Delaware were found here:
https://www.transportation.gov/gis/national-address-database
There is code in this notebook that shows how the Delaware addresses were extracted from the national address CSV file and placed into a separate new CSV file called NAD_r15_Delaware.csv.
# Import packages needed for this analysis
import requests # to make http requests for data using census web API
import pandas as pd # to make dataframes
import numpy as np # to do numerical stuff
import matplotlib.pyplot as plt
import geopandas as gpd # Extension of pandas for creating *geospatial* dataframes
import json # for interactive maps using Bokeh
import bokeh # for interactive maps using json
import csv
# See: https://www.matecdev.com/posts/point-in-polygon.html
from shapely.geometry import Point, Polygon
### Import this custom config file containing MY google maps api key needed by Bokeh to show maps.
### (do not share this key!)
import config
# Set option to make Pandas dataframe output more readable
pd.set_option('display.max_columns', None)
### Set some global variables
# Working directory path - This is my path on a Mac
mydir = "~/Documents/Data Science/Points Inside Census Tract"
### Test set up by getting Delaware census tract populations for 2017
# Base URL
# Components of the base URL go into variables.
HOST = "https://api.census.gov/data"
year = "2017"
dataset = "acs/acs5" # The data product
# Code to join the base url components
base_url = "/".join([HOST, year, dataset])
# Form the predicates dictionary
predicates = {} # initialize empty dictionary
get_vars = ["NAME", "B01003_001E"] # Get Name of the tract and the population. The "E" indicates estimate.
# The "B" indicates it is a base table. Base tables are the most detailed.
predicates["get"] = ",".join(get_vars)
predicates["for"] = "tract:*" # Census tracts are the desired geography. "*" means all tracts.
predicates["in"] = "state:10" # Delaware only
# The table code does not need to be supplied. Variable codes are unique within data products.
# Specifying the data product (ACS 5 year), year and variable code is sufficient.
# Make the request. Results get loaded into the variable "response_population".
response_population = requests.get(base_url, params = predicates)
# Display the result
print(response_population.text)
# When the results are displayed there are going to be five values for each tract. This appears contrary
# to the get_vars list only specifying two variables. The results will have a Name, population (B01003_001E),
# state code, county code and tract code. This is just the way it works. You will need to examine the results
# and then decide which columns to use, or rename, when moving the data into a dataframe.
[["NAME","B01003_001E","state","county","tract"], ["Census Tract 4, New Castle County, Delaware","2940","10","003","000400"], ["Census Tract 13, New Castle County, Delaware","3503","10","003","001300"], ["Census Tract 26, New Castle County, Delaware","3968","10","003","002600"], ["Census Tract 102, New Castle County, Delaware","2144","10","003","010200"], ["Census Tract 103, New Castle County, Delaware","3306","10","003","010300"], ["Census Tract 108, New Castle County, Delaware","4906","10","003","010800"], ["Census Tract 6.02, New Castle County, Delaware","3247","10","003","000602"], ["Census Tract 16, New Castle County, Delaware","2112","10","003","001600"], ["Census Tract 23, New Castle County, Delaware","2814","10","003","002300"], ["Census Tract 120, New Castle County, Delaware","4716","10","003","012000"], ["Census Tract 122, New Castle County, Delaware","4481","10","003","012200"], ["Census Tract 129, New Castle County, Delaware","4593","10","003","012900"], ["Census Tract 132, New Castle County, Delaware","2744","10","003","013200"], ["Census Tract 136.04, New Castle County, Delaware","4458","10","003","013604"], ["Census Tract 142, New Castle County, Delaware","2152","10","003","014200"], ["Census Tract 147.02, New Castle County, Delaware","1785","10","003","014702"], ["Census Tract 147.05, New Castle County, Delaware","5482","10","003","014705"], ["Census Tract 12, New Castle County, Delaware","1618","10","003","001200"], ["Census Tract 114, New Castle County, Delaware","3426","10","003","011400"], ["Census Tract 126, New Castle County, Delaware","2855","10","003","012600"], ["Census Tract 127, New Castle County, Delaware","4027","10","003","012700"], ["Census Tract 136.08, New Castle County, Delaware","2112","10","003","013608"], ["Census Tract 136.11, New Castle County, Delaware","5478","10","003","013611"], ["Census Tract 11, New Castle County, Delaware","3234","10","003","001100"], ["Census Tract 27, New Castle County, Delaware","2433","10","003","002700"], ["Census Tract 104, New Castle County, Delaware","4650","10","003","010400"], ["Census Tract 112.04, New Castle County, Delaware","3434","10","003","011204"], ["Census Tract 119, New Castle County, Delaware","3434","10","003","011900"], ["Census Tract 125, New Castle County, Delaware","5269","10","003","012500"], ["Census Tract 131, New Castle County, Delaware","2468","10","003","013100"], ["Census Tract 133, New Castle County, Delaware","1917","10","003","013300"], ["Census Tract 138, New Castle County, Delaware","5401","10","003","013800"], ["Census Tract 140, New Castle County, Delaware","5192","10","003","014000"], ["Census Tract 141, New Castle County, Delaware","4269","10","003","014100"], ["Census Tract 144.03, New Castle County, Delaware","5809","10","003","014403"], ["Census Tract 148.03, New Castle County, Delaware","4129","10","003","014803"], ["Census Tract 150, New Castle County, Delaware","5824","10","003","015000"], ["Census Tract 159, New Castle County, Delaware","3893","10","003","015900"], ["Census Tract 164.01, New Castle County, Delaware","6641","10","003","016401"], ["Census Tract 136.12, New Castle County, Delaware","6306","10","003","013612"], ["Census Tract 145.02, New Castle County, Delaware","6165","10","003","014502"], ["Census Tract 147.03, New Castle County, Delaware","4585","10","003","014703"], ["Census Tract 151, New Castle County, Delaware","3474","10","003","015100"], ["Census Tract 160, New Castle County, Delaware","2850","10","003","016000"], ["Census Tract 510.05, Sussex County, Delaware","4912","10","005","051005"], ["Census Tract 510.06, Sussex County, Delaware","3046","10","005","051006"], ["Census Tract 510.07, Sussex County, Delaware","5019","10","005","051007"], ["Census Tract 511.01, Sussex County, Delaware","742","10","005","051101"], ["Census Tract 511.02, Sussex County, Delaware","946","10","005","051102"], ["Census Tract 511.03, Sussex County, Delaware","959","10","005","051103"], ["Census Tract 512.01, Sussex County, Delaware","1500","10","005","051201"], ["Census Tract 512.02, Sussex County, Delaware","903","10","005","051202"], ["Census Tract 512.03, Sussex County, Delaware","727","10","005","051203"], ["Census Tract 512.04, Sussex County, Delaware","577","10","005","051204"], ["Census Tract 512.05, Sussex County, Delaware","748","10","005","051205"], ["Census Tract 513.05, Sussex County, Delaware","2652","10","005","051305"], ["Census Tract 513.06, Sussex County, Delaware","2854","10","005","051306"], ["Census Tract 9900, Sussex County, Delaware","0","10","005","990000"], ["Census Tract 109, New Castle County, Delaware","2630","10","003","010900"], ["Census Tract 124, New Castle County, Delaware","4617","10","003","012400"], ["Census Tract 111, New Castle County, Delaware","2900","10","003","011100"], ["Census Tract 112.02, New Castle County, Delaware","4106","10","003","011202"], ["Census Tract 118, New Castle County, Delaware","3991","10","003","011800"], ["Census Tract 134, New Castle County, Delaware","2585","10","003","013400"], ["Census Tract 136.13, New Castle County, Delaware","5814","10","003","013613"], ["Census Tract 144.02, New Castle County, Delaware","3771","10","003","014402"], ["Census Tract 145.01, New Castle County, Delaware","2130","10","003","014501"], ["Census Tract 148.05, New Castle County, Delaware","10261","10","003","014805"], ["Census Tract 161, New Castle County, Delaware","1850","10","003","016100"], ["Census Tract 163.02, New Castle County, Delaware","7470","10","003","016302"], ["Census Tract 168.01, New Castle County, Delaware","5720","10","003","016801"], ["Census Tract 22, New Castle County, Delaware","2527","10","003","002200"], ["Census Tract 110, New Castle County, Delaware","3286","10","003","011000"], ["Census Tract 116, New Castle County, Delaware","3505","10","003","011600"], ["Census Tract 130, New Castle County, Delaware","1850","10","003","013000"], ["Census Tract 166.04, New Castle County, Delaware","12424","10","003","016604"], ["Census Tract 147.06, New Castle County, Delaware","2930","10","003","014706"], ["Census Tract 148.07, New Castle County, Delaware","8885","10","003","014807"], ["Census Tract 154, New Castle County, Delaware","3105","10","003","015400"], ["Census Tract 2, New Castle County, Delaware","6576","10","003","000200"], ["Census Tract 9, New Castle County, Delaware","2256","10","003","000900"], ["Census Tract 101.01, New Castle County, Delaware","4126","10","003","010101"], ["Census Tract 112.05, New Castle County, Delaware","1969","10","003","011205"], ["Census Tract 135.01, New Castle County, Delaware","6791","10","003","013501"], ["Census Tract 143, New Castle County, Delaware","6725","10","003","014300"], ["Census Tract 139.01, New Castle County, Delaware","3241","10","003","013901"], ["Census Tract 24, New Castle County, Delaware","4835","10","003","002400"], ["Census Tract 152, New Castle County, Delaware","5798","10","003","015200"], ["Census Tract 15, New Castle County, Delaware","2116","10","003","001500"], ["Census Tract 112.03, New Castle County, Delaware","4790","10","003","011203"], ["Census Tract 14, New Castle County, Delaware","2367","10","003","001400"], ["Census Tract 121, New Castle County, Delaware","2732","10","003","012100"], ["Census Tract 136.07, New Castle County, Delaware","5751","10","003","013607"], ["Census Tract 156, New Castle County, Delaware","2947","10","003","015600"], ["Census Tract 112.06, New Castle County, Delaware","4362","10","003","011206"], ["Census Tract 5, New Castle County, Delaware","3375","10","003","000500"], ["Census Tract 135.03, New Castle County, Delaware","7525","10","003","013503"], ["Census Tract 501.01, Sussex County, Delaware","3861","10","005","050101"], ["Census Tract 504.01, Sussex County, Delaware","3781","10","005","050401"], ["Census Tract 506.01, Sussex County, Delaware","5410","10","005","050601"], ["Census Tract 503.01, Sussex County, Delaware","8341","10","005","050301"], ["Census Tract 505.01, Sussex County, Delaware","3965","10","005","050501"], ["Census Tract 513.03, Sussex County, Delaware","5069","10","005","051303"], ["Census Tract 504.03, Sussex County, Delaware","3639","10","005","050403"], ["Census Tract 508.03, Sussex County, Delaware","8073","10","005","050803"], ["Census Tract 515, Sussex County, Delaware","4918","10","005","051500"], ["Census Tract 517.02, Sussex County, Delaware","5237","10","005","051702"], ["Census Tract 519, Sussex County, Delaware","4260","10","005","051900"], ["Census Tract 506.02, Sussex County, Delaware","6488","10","005","050602"], ["Census Tract 518.01, Sussex County, Delaware","4565","10","005","051801"], ["Census Tract 503.02, Sussex County, Delaware","5277","10","005","050302"], ["Census Tract 507.01, Sussex County, Delaware","4271","10","005","050701"], ["Census Tract 513.01, Sussex County, Delaware","6565","10","005","051301"], ["Census Tract 513.02, Sussex County, Delaware","3708","10","005","051302"], ["Census Tract 517.01, Sussex County, Delaware","3872","10","005","051701"], ["Census Tract 518.02, Sussex County, Delaware","4716","10","005","051802"], ["Census Tract 501.03, Sussex County, Delaware","4589","10","005","050103"], ["Census Tract 502, Sussex County, Delaware","3894","10","005","050200"], ["Census Tract 510.03, Sussex County, Delaware","5740","10","005","051003"], ["Census Tract 508.02, Sussex County, Delaware","5798","10","005","050802"], ["Census Tract 514, Sussex County, Delaware","3874","10","005","051400"], ["Census Tract 508.01, Sussex County, Delaware","3750","10","005","050801"], ["Census Tract 428, Kent County, Delaware","6877","10","001","042800"], ["Census Tract 422.02, Kent County, Delaware","9532","10","001","042202"], ["Census Tract 431, Kent County, Delaware","2867","10","001","043100"], ["Census Tract 402.01, Kent County, Delaware","5311","10","001","040201"], ["Census Tract 416, Kent County, Delaware","2060","10","001","041600"], ["Census Tract 421, Kent County, Delaware","3766","10","001","042100"], ["Census Tract 430, Kent County, Delaware","5332","10","001","043000"], ["Census Tract 417.02, Kent County, Delaware","4405","10","001","041702"], ["Census Tract 402.02, Kent County, Delaware","15267","10","001","040202"], ["Census Tract 402.03, Kent County, Delaware","6055","10","001","040203"], ["Census Tract 409, Kent County, Delaware","3016","10","001","040900"], ["Census Tract 413, Kent County, Delaware","2273","10","001","041300"], ["Census Tract 417.01, Kent County, Delaware","6097","10","001","041701"], ["Census Tract 420, Kent County, Delaware","3039","10","001","042000"], ["Census Tract 429, Kent County, Delaware","4810","10","001","042900"], ["Census Tract 407, Kent County, Delaware","4649","10","001","040700"], ["Census Tract 414, Kent County, Delaware","3622","10","001","041400"], ["Census Tract 415, Kent County, Delaware","4317","10","001","041500"], ["Census Tract 418.01, Kent County, Delaware","10075","10","001","041801"], ["Census Tract 418.02, Kent County, Delaware","5313","10","001","041802"], ["Census Tract 401, Kent County, Delaware","6849","10","001","040100"], ["Census Tract 411, Kent County, Delaware","3604","10","001","041100"], ["Census Tract 412, Kent County, Delaware","4719","10","001","041200"], ["Census Tract 419, Kent County, Delaware","5485","10","001","041900"], ["Census Tract 422.01, Kent County, Delaware","11915","10","001","042201"], ["Census Tract 425, Kent County, Delaware","3837","10","001","042500"], ["Census Tract 410, Kent County, Delaware","6445","10","001","041000"], ["Census Tract 144.04, New Castle County, Delaware","3894","10","003","014404"], ["Census Tract 149.03, New Castle County, Delaware","7561","10","003","014903"], ["Census Tract 3, New Castle County, Delaware","2794","10","003","000300"], ["Census Tract 6.01, New Castle County, Delaware","3080","10","003","000601"], ["Census Tract 21, New Castle County, Delaware","1968","10","003","002100"], ["Census Tract 25, New Castle County, Delaware","3061","10","003","002500"], ["Census Tract 112.01, New Castle County, Delaware","2428","10","003","011201"], ["Census Tract 113, New Castle County, Delaware","2147","10","003","011300"], ["Census Tract 115, New Castle County, Delaware","3015","10","003","011500"], ["Census Tract 117, New Castle County, Delaware","3992","10","003","011700"], ["Census Tract 123, New Castle County, Delaware","2646","10","003","012300"], ["Census Tract 148.08, New Castle County, Delaware","6461","10","003","014808"], ["Census Tract 136.10, New Castle County, Delaware","6250","10","003","013610"], ["Census Tract 137, New Castle County, Delaware","4228","10","003","013700"], ["Census Tract 149.04, New Castle County, Delaware","5045","10","003","014904"], ["Census Tract 162, New Castle County, Delaware","2485","10","003","016200"], ["Census Tract 163.01, New Castle County, Delaware","5418","10","003","016301"], ["Census Tract 166.01, New Castle County, Delaware","12533","10","003","016601"], ["Census Tract 166.02, New Castle County, Delaware","8455","10","003","016602"], ["Census Tract 169.01, New Castle County, Delaware","2117","10","003","016901"], ["Census Tract 405.01, Kent County, Delaware","4490","10","001","040501"], ["Census Tract 405.02, Kent County, Delaware","2252","10","001","040502"], ["Census Tract 432.02, Kent County, Delaware","4219","10","001","043202"], ["Census Tract 433, Kent County, Delaware","6085","10","001","043300"], ["Census Tract 434, Kent County, Delaware","4562","10","001","043400"], ["Census Tract 9900, Kent County, Delaware","0","10","001","990000"], ["Census Tract 19.02, New Castle County, Delaware","1885","10","003","001902"], ["Census Tract 28, New Castle County, Delaware","1527","10","003","002800"], ["Census Tract 29, New Castle County, Delaware","3587","10","003","002900"], ["Census Tract 30.02, New Castle County, Delaware","3453","10","003","003002"], ["Census Tract 101.04, New Castle County, Delaware","3752","10","003","010104"], ["Census Tract 105.02, New Castle County, Delaware","6121","10","003","010502"], ["Census Tract 107.02, New Castle County, Delaware","5439","10","003","010702"], ["Census Tract 135.05, New Castle County, Delaware","2924","10","003","013505"], ["Census Tract 135.06, New Castle County, Delaware","4466","10","003","013506"], ["Census Tract 136.14, New Castle County, Delaware","3105","10","003","013614"], ["Census Tract 136.15, New Castle County, Delaware","3916","10","003","013615"], ["Census Tract 139.03, New Castle County, Delaware","5356","10","003","013903"], ["Census Tract 139.04, New Castle County, Delaware","8290","10","003","013904"], ["Census Tract 148.09, New Castle County, Delaware","8127","10","003","014809"], ["Census Tract 148.10, New Castle County, Delaware","7820","10","003","014810"], ["Census Tract 149.06, New Castle County, Delaware","4842","10","003","014906"], ["Census Tract 149.07, New Castle County, Delaware","4889","10","003","014907"], ["Census Tract 149.08, New Castle County, Delaware","2088","10","003","014908"], ["Census Tract 149.09, New Castle County, Delaware","6386","10","003","014909"], ["Census Tract 155.02, New Castle County, Delaware","2580","10","003","015502"], ["Census Tract 158.02, New Castle County, Delaware","2354","10","003","015802"], ["Census Tract 163.05, New Castle County, Delaware","8230","10","003","016305"], ["Census Tract 164.04, New Castle County, Delaware","3412","10","003","016404"], ["Census Tract 166.08, New Castle County, Delaware","4738","10","003","016608"], ["Census Tract 168.04, New Castle County, Delaware","7334","10","003","016804"], ["Census Tract 169.04, New Castle County, Delaware","3954","10","003","016904"], ["Census Tract 9801, New Castle County, Delaware","0","10","003","980100"], ["Census Tract 9901, New Castle County, Delaware","0","10","003","990100"], ["Census Tract 501.04, Sussex County, Delaware","4520","10","005","050104"], ["Census Tract 501.05, Sussex County, Delaware","6006","10","005","050105"], ["Census Tract 504.05, Sussex County, Delaware","3983","10","005","050405"], ["Census Tract 504.06, Sussex County, Delaware","5081","10","005","050406"], ["Census Tract 504.07, Sussex County, Delaware","5310","10","005","050407"], ["Census Tract 504.08, Sussex County, Delaware","4488","10","005","050408"], ["Census Tract 505.03, Sussex County, Delaware","5587","10","005","050503"], ["Census Tract 505.04, Sussex County, Delaware","6177","10","005","050504"], ["Census Tract 507.03, Sussex County, Delaware","2021","10","005","050703"], ["Census Tract 509.01, Sussex County, Delaware","2404","10","005","050901"], ["Census Tract 507.04, Sussex County, Delaware","4357","10","005","050704"], ["Census Tract 507.05, Sussex County, Delaware","4994","10","005","050705"], ["Census Tract 507.06, Sussex County, Delaware","1769","10","005","050706"], ["Census Tract 509.02, Sussex County, Delaware","4814","10","005","050902"], ["Census Tract 510.04, Sussex County, Delaware","4794","10","005","051004"]]
### I downloaded the TIGER/Line shape zip file containing Delaware census tract boundaries from US Census.
# See https://catalog.data.gov/dataset/tiger-line-shapefile-2017-state-delaware-current-census-tract-state-based
# Look for download link to tl_2017_10_tract.zip
# "tl" = Tiger line file
# "10" = Delaware
# "tract" = Census tract boundaries
# The zip file was extracted into the working directory for this project
### Create a geospatial dataframe out of the .shp file
# Load the tracts shapefile into a geopandas dataframe
gdf_tract = gpd.read_file("/Users/mitchellfawcett/Documents/Data Science/Points Inside Census Tract/tl_2017_10_tract.shp")
# Note - you'll get an error if the other files in the shape file set are not in the same folder as the .shp file. These act
# as a complete set and all files are necessary to get the shapes.
# Examine the geo dataframe.
print(gdf_tract.head())
STATEFP COUNTYFP TRACTCE GEOID NAME NAMELSAD MTFCC \ 0 10 001 040502 10001040502 405.02 Census Tract 405.02 G5020 1 10 001 043202 10001043202 432.02 Census Tract 432.02 G5020 2 10 001 040501 10001040501 405.01 Census Tract 405.01 G5020 3 10 001 990000 10001990000 9900 Census Tract 9900 G5020 4 10 001 043400 10001043400 434 Census Tract 434 G5020 FUNCSTAT ALAND AWATER INTPTLAT INTPTLON \ 0 S 29380975 461377 +39.2124212 -075.5318919 1 S 295721374 46419973 +39.1456066 -075.4324489 2 S 10394105 0 +39.1995840 -075.5439015 3 S 0 495919229 +39.1258693 -075.3111928 4 S 66115677 653023 +38.9723618 -075.4729061 geometry 0 POLYGON ((-75.58160 39.24208, -75.58145 39.242... 1 POLYGON ((-75.54956 39.35384, -75.54939 39.353... 2 POLYGON ((-75.58810 39.24403, -75.58806 39.244... 3 POLYGON ((-75.51194 39.36595, -75.51178 39.366... 4 POLYGON ((-75.52892 39.01019, -75.52871 39.010...
### Only keep tracts that have non-zero land. Zero land area tracts represent the Delaware River.
gdf_tract = gdf_tract[gdf_tract['ALAND'] != 0]
### Plot the tract shape file using bokeh.
# Load bokeh libraries
from bokeh.io import output_notebook, show, output_file
from bokeh.plotting import figure
from bokeh.models import GeoJSONDataSource, LinearColorMapper, ColorBar
from bokeh.palettes import brewer
### Bokeh requires json format data to plot
#Read data to json.
gdf_tract_json = json.loads(gdf_tract.to_json())
#Convert to String like object.
gdf_tract_json_data = json.dumps(gdf_tract_json)
### Create the bokeh figure to visualize Delaware Census Tracts
#Input GeoJSON source that contains features to be plotted.
geosource = GeoJSONDataSource(geojson = gdf_tract_json_data)
# Create the figure object.
p = figure(title = 'Delaware Census Tracts', height = 600 , width = 300, toolbar_location = None)
p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None
# Add patch renderer to figure.
p.patches('xs','ys',
source = geosource,
line_color = 'black',
line_width = 0.25,
fill_color = None,
fill_alpha = 1)
# Display Delaware census tracts figure inline in Jupyter Notebook.
output_notebook()
show(p)
# Cite https://www.matecdev.com/posts/point-in-polygon.html
# Do a quick test of Point in Polygon.
# Create Point objects
p1 = Point(24.82, 60.24)
p2 = Point(24.895, 60.05)
# Create a square
coords = [(24.89, 60.06), (24.75, 60.06), (24.75, 60.30), (24.89, 60.30)]
poly = Polygon(coords)
# PIP test with 'within'
p1.within(poly) # True
p2.within(poly) # False
# PIP test with 'contains'
poly.contains(p1) # True
poly.contains(p2) # False </code></pre>
False
p1.within(poly) # True
True
poly.contains(p2) # False
False
# Use Delaware shape file
# Put the shapefile into a geopandas geo dataframe
de_tracts_gdf = gpd.GeoDataFrame.from_file(mydir + "/tl_2017_10_tract.shp")
de_tracts_gdf.head()
# The "geometry" column has the point paths of census tract boundaries
STATEFP | COUNTYFP | TRACTCE | GEOID | NAME | NAMELSAD | MTFCC | FUNCSTAT | ALAND | AWATER | INTPTLAT | INTPTLON | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 10 | 001 | 040502 | 10001040502 | 405.02 | Census Tract 405.02 | G5020 | S | 29380975 | 461377 | +39.2124212 | -075.5318919 | POLYGON ((-75.58160 39.24208, -75.58145 39.242... |
1 | 10 | 001 | 043202 | 10001043202 | 432.02 | Census Tract 432.02 | G5020 | S | 295721374 | 46419973 | +39.1456066 | -075.4324489 | POLYGON ((-75.54956 39.35384, -75.54939 39.353... |
2 | 10 | 001 | 040501 | 10001040501 | 405.01 | Census Tract 405.01 | G5020 | S | 10394105 | 0 | +39.1995840 | -075.5439015 | POLYGON ((-75.58810 39.24403, -75.58806 39.244... |
3 | 10 | 001 | 990000 | 10001990000 | 9900 | Census Tract 9900 | G5020 | S | 0 | 495919229 | +39.1258693 | -075.3111928 | POLYGON ((-75.51194 39.36595, -75.51178 39.366... |
4 | 10 | 001 | 043400 | 10001043400 | 434 | Census Tract 434 | G5020 | S | 66115677 | 653023 | +38.9723618 | -075.4729061 | POLYGON ((-75.52892 39.01019, -75.52871 39.010... |
# display the census tract boundaries
base = de_tracts_gdf.boundary.plot(linewidth=1, edgecolor="black", figsize=(15,15))
# Generate some random points for another test demo
# https://www.matecdev.com/posts/point-in-polygon.html
N=1000
lat = np.random.uniform(38.4,40.0,N) # some random latitudes near Delaware
lon = np.random.uniform(-75.8,-75.0,N) # some random longitudes near Delaware
# Create geodataframe from numpy arrays
df = pd.DataFrame({'lon':lon, 'lat':lat})
df['coords'] = list(zip(df['lon'],df['lat'])) # Zip() combines two or more lists, or other Iterable objects, into one entity
df['coords'] = df['coords'].apply(Point)
points = gpd.GeoDataFrame(df, geometry='coords', crs=de_tracts_gdf.crs)
points.head()
lon | lat | coords | |
---|---|---|---|
0 | -75.633827 | 39.112459 | POINT (-75.63383 39.11246) |
1 | -75.231496 | 39.269592 | POINT (-75.23150 39.26959) |
2 | -75.076523 | 39.071421 | POINT (-75.07652 39.07142) |
3 | -75.269321 | 39.153624 | POINT (-75.26932 39.15362) |
4 | -75.452774 | 39.730990 | POINT (-75.45277 39.73099) |
# Perform spatial join to match points and polygons
pointInPolys = gpd.tools.sjoin(points, de_tracts_gdf, predicate="within", how='left')
# Plot map with points
base = de_tracts_gdf.boundary.plot(linewidth=1, edgecolor="black", figsize=(15,15))
points.plot(ax=base, linewidth=1, color="blue", markersize=1)
plt.show()
# Examine the generated points data frame showing what Census Tract they are in
pointInPolys.head(100)
lon | lat | coords | index_right | STATEFP | COUNTYFP | TRACTCE | GEOID | NAME | NAMELSAD | MTFCC | FUNCSTAT | ALAND | AWATER | INTPTLAT | INTPTLON | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | -75.688211 | 38.992596 | POINT (-75.68821 38.99260) | 193.0 | 10 | 001 | 042800 | 10001042800 | 428 | Census Tract 428 | G5020 | S | 147899008.0 | 542235.0 | +38.9957512 | -075.6283501 |
1 | -75.660924 | 39.496872 | POINT (-75.66092 39.49687) | 38.0 | 10 | 003 | 016602 | 10003016602 | 166.02 | Census Tract 166.02 | G5020 | S | 51293992.0 | 899748.0 | +39.5185461 | -075.6880137 |
2 | -75.352929 | 38.968923 | POINT (-75.35293 38.96892) | 1.0 | 10 | 001 | 043202 | 10001043202 | 432.02 | Census Tract 432.02 | G5020 | S | 295721374.0 | 46419973.0 | +39.1456066 | -075.4324489 |
3 | -75.285362 | 38.995251 | POINT (-75.28536 38.99525) | 3.0 | 10 | 001 | 990000 | 10001990000 | 9900 | Census Tract 9900 | G5020 | S | 0.0 | 495919229.0 | +39.1258693 | -075.3111928 |
4 | -75.200084 | 38.832075 | POINT (-75.20008 38.83207) | 217.0 | 10 | 005 | 990000 | 10005990000 | 9900 | Census Tract 9900 | G5020 | S | 0.0 | 534627888.0 | +38.8648060 | -075.2250098 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
95 | -75.427061 | 39.189003 | POINT (-75.42706 39.18900) | 1.0 | 10 | 001 | 043202 | 10001043202 | 432.02 | Census Tract 432.02 | G5020 | S | 295721374.0 | 46419973.0 | +39.1456066 | -075.4324489 |
96 | -75.131307 | 38.753294 | POINT (-75.13131 38.75329) | 24.0 | 10 | 005 | 051003 | 10005051003 | 510.03 | Census Tract 510.03 | G5020 | S | 20037219.0 | 39992.0 | +38.7380987 | -075.1102568 |
97 | -75.372738 | 39.467211 | POINT (-75.37274 39.46721) | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
98 | -75.031915 | 39.602897 | POINT (-75.03191 39.60290) | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
99 | -75.334355 | 39.728025 | POINT (-75.33435 39.72802) | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
100 rows × 16 columns
# Example use: get points in Census Tract '429'
pnt_429 = points[pointInPolys.NAME=='429']
# Plot map again with Census Tract 429 points in Red, all others in Blue
base = de_tracts_gdf.boundary.plot(linewidth=1, edgecolor="black", figsize=(15,15))
points.plot(ax=base, linewidth=1, color="blue", markersize=1)
pnt_429.plot(ax=base, linewidth=1, color="red", markersize=8)
plt.show()
Use the National Address Database to build a dataframe of Delaware street addresses¶
This assumes an ASCII text file of addresses was downloaded from https://www.transportation.gov/mission/open/gis/national-address-database/national-address-database-nad-disclaimer
A copy of the file was stored locally at "~/Documents/National Address Database 2024 r15/TXT/NAD.txt"
There are earlier versions of the NAD stored on this computrer, but they have different schemas.
# Look at the first 100 rows of the addresses
firstn_df = pd.read_csv("~/Documents/National Address Database 2024 r15/TXT/NAD.txt", nrows = 100)
firstn_df
OID | AddNum_Pre | Add_Number | AddNum_Suf | AddNo_Full | St_PreMod | St_PreDir | St_PreTyp | St_PreSep | St_Name | St_PosTyp | St_PosDir | St_PosMod | StNam_Full | Building | Floor | Unit | Room | Seat | Addtl_Loc | SubAddress | LandmkName | County | Inc_Muni | Post_City | Census_Plc | Uninc_Comm | Nbrhd_Comm | NatAmArea | NatAmSub | Urbnztn_PR | PlaceOther | PlaceNmTyp | State | Zip_Code | Plus_4 | UUID | AddAuth | AddrRefSys | Longitude | Latitude | NatGrid | Elevation | Placement | AddrPoint | Related_ID | RelateType | ParcelSrc | Parcel_ID | AddrClass | Lifecycle | Effective | Expire | DateUpdate | AnomStatus | LocatnDesc | Addr_Type | DeliverTyp | NAD_Source | DataSet_ID | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | -1 | NaN | 26800 | NaN | 26800 | NaN | NaN | NaN | NaN | EKLUTNA VILLAGE | Road | NaN | NaN | EKLUTNA VILLAGE Road | NaN | NaN | TRLR 26800 | NaN | NaN | NaN | TRLR 26800 | NaN | Anchorage Municipality | Unincorporated | Chugiak | NaN | Northern Communities | NaN | Eklutna ANVSA | NaN | NaN | NaN | NaN | AK | 99567 | NaN | {F7DE0555-9BE8-44A9-89A7-C9FA22B17866} | Municipality of Anchorage, Alaska | NaN | -149.375648 | 61.465525 | 06VUP7341516947 | NaN | Unknown | -149.37564802268 61.4655246739195 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 4/26/2022 0:00:00 | NaN | NaN | Unknown | NaN | Municipality of Anchorage, Alaska | NaN |
1 | -1 | NaN | 26960 | NaN | 26960 | NaN | NaN | NaN | NaN | ADAK | Circle | NaN | NaN | ADAK Circle | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Anchorage Municipality | Unincorporated | Eagle River | NaN | Northern Communities | NaN | Eklutna ANVSA | NaN | NaN | NaN | NaN | AK | 99577 | NaN | {602F8773-0D6B-42C5-90B6-64FD2B8EFD6E} | Municipality of Anchorage, Alaska | NaN | -149.360392 | 61.463624 | 06VUN6488599795 | NaN | Unknown | -149.360391525476 61.4636243831014 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 4/26/2022 0:00:00 | NaN | NaN | Unknown | NaN | Municipality of Anchorage, Alaska | NaN |
2 | -1 | NaN | 26636 | NaN | 26636 | NaN | NaN | NaN | NaN | EKLUTNA VILLAGE | Road | NaN | NaN | EKLUTNA VILLAGE Road | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Anchorage Municipality | Unincorporated | Chugiak | NaN | Northern Communities | NaN | Eklutna ANVSA | NaN | NaN | NaN | NaN | AK | 99567 | NaN | {612F3150-A5E0-4F6A-8757-0CA74C1AB958} | Municipality of Anchorage, Alaska | NaN | -149.361471 | 61.460711 | 06VUP7415116384 | NaN | Unknown | -149.36147119804 61.460711123149 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 4/26/2022 0:00:00 | NaN | NaN | Unknown | NaN | Municipality of Anchorage, Alaska | NaN |
3 | -1 | NaN | 26585 | NaN | 26585 | NaN | NaN | NaN | NaN | EKLUTNA VILLAGE | Road | NaN | NaN | EKLUTNA VILLAGE Road | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Anchorage Municipality | Unincorporated | Chugiak | NaN | Northern Communities | NaN | Eklutna ANVSA | NaN | NaN | NaN | NaN | AK | 99567 | NaN | {3B590E65-520D-45C3-B3B5-8DDB966EDDEF} | Municipality of Anchorage, Alaska | NaN | -149.360808 | 61.460619 | 06VUP7418616372 | NaN | Unknown | -149.360808398565 61.460619411486 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 4/26/2022 0:00:00 | NaN | NaN | Unknown | NaN | Municipality of Anchorage, Alaska | NaN |
4 | -1 | NaN | 26612 | NaN | 26612 | NaN | NaN | NaN | NaN | EKLUTNA VILLAGE | Road | NaN | NaN | EKLUTNA VILLAGE Road | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Anchorage Municipality | Unincorporated | Chugiak | NaN | Northern Communities | NaN | Eklutna ANVSA | NaN | NaN | NaN | NaN | AK | 99567 | NaN | {8903A38A-A49D-4985-849D-4433BDF0CCDF} | Municipality of Anchorage, Alaska | NaN | -149.361635 | 61.460386 | 06VUP7414116348 | NaN | Unknown | -149.361634630336 61.4603857255667 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 4/26/2022 0:00:00 | NaN | NaN | Unknown | NaN | Municipality of Anchorage, Alaska | NaN |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
95 | -1 | NaN | 24707 | NaN | 24707 | NaN | NaN | NaN | NaN | THUNDERBIRD | Drive | NaN | NaN | THUNDERBIRD Drive | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Anchorage Municipality | Unincorporated | Chugiak | NaN | Northern Communities | NaN | NaN | NaN | NaN | NaN | NaN | AK | 99567 | NaN | {87288261-1F12-4638-ABA1-92E6CBAD86F1} | Municipality of Anchorage, Alaska | NaN | -149.368321 | 61.443466 | 06VUP7371614477 | NaN | Unknown | -149.368321425206 61.4434660266244 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 4/26/2022 0:00:00 | NaN | NaN | Unknown | NaN | Municipality of Anchorage, Alaska | NaN |
96 | -1 | NaN | 24643 | NaN | 24643 | NaN | NaN | NaN | NaN | TEAL | Loop | NaN | NaN | TEAL Loop | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Anchorage Municipality | Unincorporated | Chugiak | NaN | Northern Communities | NaN | NaN | NaN | NaN | NaN | NaN | AK | 99567 | NaN | {B501946B-63FB-4A88-89EC-977D4E725C8C} | Municipality of Anchorage, Alaska | NaN | -149.364682 | 61.443099 | 06VUP7390914429 | NaN | Unknown | -149.364681587321 61.443098685482 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 4/26/2022 0:00:00 | NaN | NaN | Unknown | NaN | Municipality of Anchorage, Alaska | NaN |
97 | -1 | NaN | 27627 | NaN | 27627 | NaN | NaN | NaN | NaN | MALLARD | Court | NaN | NaN | MALLARD Court | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Anchorage Municipality | Unincorporated | Chugiak | NaN | Northern Communities | NaN | NaN | NaN | NaN | NaN | NaN | AK | 99567 | NaN | {90B13D6E-8C24-46E5-A940-005968E2AA49} | Municipality of Anchorage, Alaska | NaN | -149.366674 | 61.443128 | 06VUP7380214436 | NaN | Unknown | -149.366674350658 61.4431283177893 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 4/26/2022 0:00:00 | NaN | NaN | Unknown | NaN | Municipality of Anchorage, Alaska | NaN |
98 | -1 | NaN | 27617 | NaN | 27617 | NaN | NaN | NaN | NaN | MALLARD | Court | NaN | NaN | MALLARD Court | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Anchorage Municipality | Unincorporated | Chugiak | NaN | Northern Communities | NaN | NaN | NaN | NaN | NaN | NaN | AK | 99567 | NaN | {94AEEFF9-F937-4A19-8A72-C13CF9AF8CF1} | Municipality of Anchorage, Alaska | NaN | -149.366948 | 61.443146 | 06VUP7378814438 | NaN | Unknown | -149.366948055647 61.4431457965646 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 4/26/2022 0:00:00 | NaN | NaN | Unknown | NaN | Municipality of Anchorage, Alaska | NaN |
99 | -1 | NaN | 24636 | NaN | 24636 | NaN | NaN | NaN | NaN | TEAL | Loop | NaN | NaN | TEAL Loop | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Anchorage Municipality | Unincorporated | Chugiak | NaN | Northern Communities | NaN | NaN | NaN | NaN | NaN | NaN | AK | 99567 | NaN | {1AD66292-4601-4C45-896B-721B8A3BB9A4} | Municipality of Anchorage, Alaska | NaN | -149.365157 | 61.443107 | 06VUP7388314431 | NaN | Unknown | -149.36515668202 61.4431066667334 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 4/26/2022 0:00:00 | NaN | NaN | Unknown | NaN | Municipality of Anchorage, Alaska | NaN |
100 rows × 60 columns
print(firstn_df.info())
<class 'pandas.core.frame.DataFrame'> RangeIndex: 100 entries, 0 to 99 Data columns (total 60 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 OID 100 non-null int64 1 AddNum_Pre 0 non-null float64 2 Add_Number 100 non-null int64 3 AddNum_Suf 0 non-null float64 4 AddNo_Full 100 non-null int64 5 St_PreMod 0 non-null float64 6 St_PreDir 0 non-null float64 7 St_PreTyp 0 non-null float64 8 St_PreSep 0 non-null float64 9 St_Name 100 non-null object 10 St_PosTyp 100 non-null object 11 St_PosDir 0 non-null float64 12 St_PosMod 0 non-null float64 13 StNam_Full 100 non-null object 14 Building 0 non-null float64 15 Floor 0 non-null float64 16 Unit 2 non-null object 17 Room 0 non-null float64 18 Seat 0 non-null float64 19 Addtl_Loc 0 non-null float64 20 SubAddress 2 non-null object 21 LandmkName 0 non-null float64 22 County 100 non-null object 23 Inc_Muni 100 non-null object 24 Post_City 100 non-null object 25 Census_Plc 0 non-null float64 26 Uninc_Comm 100 non-null object 27 Nbrhd_Comm 0 non-null float64 28 NatAmArea 24 non-null object 29 NatAmSub 0 non-null float64 30 Urbnztn_PR 0 non-null float64 31 PlaceOther 0 non-null float64 32 PlaceNmTyp 0 non-null float64 33 State 100 non-null object 34 Zip_Code 100 non-null int64 35 Plus_4 0 non-null float64 36 UUID 100 non-null object 37 AddAuth 100 non-null object 38 AddrRefSys 0 non-null float64 39 Longitude 100 non-null float64 40 Latitude 100 non-null float64 41 NatGrid 100 non-null object 42 Elevation 0 non-null float64 43 Placement 100 non-null object 44 AddrPoint 100 non-null object 45 Related_ID 0 non-null float64 46 RelateType 0 non-null float64 47 ParcelSrc 0 non-null float64 48 Parcel_ID 0 non-null float64 49 AddrClass 100 non-null object 50 Lifecycle 0 non-null float64 51 Effective 0 non-null float64 52 Expire 0 non-null float64 53 DateUpdate 100 non-null object 54 AnomStatus 0 non-null float64 55 LocatnDesc 0 non-null float64 56 Addr_Type 100 non-null object 57 DeliverTyp 0 non-null float64 58 NAD_Source 100 non-null object 59 DataSet_ID 0 non-null float64 dtypes: float64(36), int64(4), object(20) memory usage: 47.0+ KB None
# Load the Delaware address CSV file into a dataframe & examine
delaware_df = pd.read_csv("~/Documents/National Address Database 2024 r15/TXT/NAD_r15_Delaware.csv")
delaware_df.head()
/var/folders/9v/165788x50k7_g0vrrn1__z1h0000gn/T/ipykernel_8757/186015339.py:2: DtypeWarning: Columns (3,4,7,11,12,14,15,16,17,19,20,25,26,27,28,37) have mixed types. Specify dtype option on import or set low_memory=False. delaware_df = pd.read_csv("~/Documents/National Address Database 2024 r15/TXT/NAD_r15_Delaware.csv")
OID | AddNum_Pre | Add_Number | AddNum_Suf | AddNo_Full | St_PreMod | St_PreDir | St_PreTyp | St_PreSep | St_Name | St_PosTyp | St_PosDir | St_PosMod | StNam_Full | Building | Floor | Unit | Room | Seat | Addtl_Loc | SubAddress | LandmkName | County | Inc_Muni | Post_City | Census_Plc | Uninc_Comm | Nbrhd_Comm | NatAmArea | NatAmSub | Urbnztn_PR | PlaceOther | PlaceNmTyp | State | Zip_Code | Plus_4 | UUID | AddAuth | AddrRefSys | Longitude | Latitude | NatGrid | Elevation | Placement | AddrPoint | Related_ID | RelateType | ParcelSrc | Parcel_ID | AddrClass | Lifecycle | Effective | Expire | DateUpdate | AnomStatus | LocatnDesc | Addr_Type | DeliverTyp | NAD_Source | DataSet_ID | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | -1 | NaN | 216 | NaN | 216 | NaN | NaN | NaN | NaN | KING | Street | NaN | NaN | KING Street | NaN | NaN | APT B | NaN | NaN | NaN | APT B | NaN | Kent | Unincorporated | Smyrna | NaN | NaN | Smyrna | NaN | NaN | NaN | NaN | NaN | DE | 19977.0 | NaN | {090F51C5-7577-412C-B1E7-E18905DF905F} | NaN | NaN | -75.589069 | 39.309325 | 18SVJ4921451269 | NaN | Unknown | -75.5890689551341 39.3093249142128 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 7/1/2022 0:00:00 | NaN | NaN | Unknown | NaN | Kent County, Delaware | NaN |
1 | -1 | NaN | 978 | NaN | 978 | NaN | NaN | NaN | NaN | CAVEAT | Road | NaN | NaN | CAVEAT Road | NaN | NaN | APT B | NaN | NaN | NaN | APT B | NaN | Kent | Unincorporated | Magnolia | NaN | NaN | Magnolia | NaN | NaN | NaN | NaN | NaN | DE | 19962.0 | NaN | {BAD7810A-EFA0-4591-8C1E-F203665DAF3B} | NaN | NaN | -75.568466 | 39.250083 | 18SVJ5946322577 | NaN | Unknown | -75.5684660865876 39.2500827735636 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 7/1/2022 0:00:00 | NaN | NaN | Unknown | NaN | Kent County, Delaware | NaN |
2 | -1 | NaN | 14 | NaN | 14 | NaN | NaN | NaN | NaN | BURNSIDE | Drive | NaN | NaN | BURNSIDE Drive | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Kent | Unincorporated | Smyrna | NaN | NaN | Wicksfield | NaN | NaN | NaN | NaN | NaN | DE | 19977.0 | NaN | {9E4CD656-EEB1-4DA6-A62C-2036F209F158} | NaN | NaN | -75.616076 | 39.275783 | 18SVJ4686047562 | NaN | Unknown | -75.6160764495596 39.2757829759585 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 11/13/2012 0:00:00 | NaN | NaN | Unknown | NaN | Kent County, Delaware | NaN |
3 | -1 | NaN | 347 | NaN | 347 | NaN | NaN | NaN | NaN | WILLOWWOOD | Drive | NaN | NaN | WILLOWWOOD Drive | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Kent | Unincorporated | Smyrna | NaN | NaN | Willowwood | NaN | NaN | NaN | NaN | NaN | DE | 19977.0 | NaN | {C63BC5D6-FC2F-47CC-8CAB-81F09AF50CF1} | NaN | NaN | -75.596984 | 39.260780 | 18SVJ4849645886 | NaN | Unknown | -75.5969835035535 39.2607799993354 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 5/2/2012 0:00:00 | NaN | NaN | Unknown | NaN | Kent County, Delaware | NaN |
4 | -1 | NaN | 22 | NaN | 22 | NaN | NaN | NaN | NaN | MALCOLMS MILL | Drive | NaN | NaN | MALCOLMS MILL Drive | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Kent | Unincorporated | Smyrna | NaN | NaN | Smyrna | NaN | NaN | NaN | NaN | NaN | DE | 19977.0 | NaN | {95EF8E9D-A53F-4099-B57A-5CC45D5F3AD7} | NaN | NaN | -75.616818 | 39.240314 | 18SVJ4676943626 | NaN | Unknown | -75.6168176827436 39.2403144684381 | NaN | NaN | NaN | NaN | Numbered Thoroughfare Address | NaN | NaN | NaN | 5/8/2012 0:00:00 | NaN | NaN | Unknown | NaN | Kent County, Delaware | NaN |
delaware_df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 534407 entries, 0 to 534406 Data columns (total 60 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 OID 534407 non-null int64 1 AddNum_Pre 0 non-null float64 2 Add_Number 534407 non-null int64 3 AddNum_Suf 335 non-null object 4 AddNo_Full 534407 non-null object 5 St_PreMod 0 non-null float64 6 St_PreDir 67506 non-null object 7 St_PreTyp 4 non-null object 8 St_PreSep 0 non-null float64 9 St_Name 534407 non-null object 10 St_PosTyp 531475 non-null object 11 St_PosDir 3000 non-null object 12 St_PosMod 4 non-null object 13 StNam_Full 534407 non-null object 14 Building 741 non-null object 15 Floor 12 non-null object 16 Unit 59872 non-null object 17 Room 53 non-null object 18 Seat 0 non-null float64 19 Addtl_Loc 96 non-null object 20 SubAddress 60774 non-null object 21 LandmkName 0 non-null float64 22 County 534407 non-null object 23 Inc_Muni 534407 non-null object 24 Post_City 534407 non-null object 25 Census_Plc 67533 non-null object 26 Uninc_Comm 266780 non-null object 27 Nbrhd_Comm 267515 non-null object 28 NatAmArea 9363 non-null object 29 NatAmSub 0 non-null float64 30 Urbnztn_PR 0 non-null float64 31 PlaceOther 0 non-null float64 32 PlaceNmTyp 0 non-null float64 33 State 534407 non-null object 34 Zip_Code 534162 non-null float64 35 Plus_4 0 non-null float64 36 UUID 534406 non-null object 37 AddAuth 186840 non-null object 38 AddrRefSys 0 non-null float64 39 Longitude 534407 non-null float64 40 Latitude 534407 non-null float64 41 NatGrid 534406 non-null object 42 Elevation 0 non-null float64 43 Placement 534406 non-null object 44 AddrPoint 534407 non-null object 45 Related_ID 0 non-null float64 46 RelateType 0 non-null float64 47 ParcelSrc 0 non-null float64 48 Parcel_ID 0 non-null float64 49 AddrClass 534407 non-null object 50 Lifecycle 0 non-null float64 51 Effective 0 non-null float64 52 Expire 0 non-null float64 53 DateUpdate 534407 non-null object 54 AnomStatus 0 non-null float64 55 LocatnDesc 0 non-null float64 56 Addr_Type 534406 non-null object 57 DeliverTyp 0 non-null float64 58 NAD_Source 534407 non-null object 59 DataSet_ID 0 non-null float64 dtypes: float64(26), int64(2), object(32) memory usage: 244.6+ MB
# Select the columns necessary for the point-in-census-tract analysis.
# I want just the address columns and longitude and latitude columns.
# Also keeping the UUID column to use for easier joins to form the final dataset.
de_address_df = delaware_df[['AddNo_Full', 'St_Name', 'St_PosTyp', 'St_PosDir', 'St_PosMod', 'County', 'Post_City', \
'State', 'Zip_Code', 'Longitude', 'Latitude', 'AddrPoint', 'UUID']].copy()
# Examnine results
de_address_df.head()
AddNo_Full | St_Name | St_PosTyp | St_PosDir | St_PosMod | County | Post_City | State | Zip_Code | Longitude | Latitude | AddrPoint | UUID | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 216 | KING | Street | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.589069 | 39.309325 | -75.5890689551341 39.3093249142128 | {090F51C5-7577-412C-B1E7-E18905DF905F} |
1 | 978 | CAVEAT | Road | NaN | NaN | Kent | Magnolia | DE | 19962.0 | -75.568466 | 39.250083 | -75.5684660865876 39.2500827735636 | {BAD7810A-EFA0-4591-8C1E-F203665DAF3B} |
2 | 14 | BURNSIDE | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.616076 | 39.275783 | -75.6160764495596 39.2757829759585 | {9E4CD656-EEB1-4DA6-A62C-2036F209F158} |
3 | 347 | WILLOWWOOD | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.596984 | 39.260780 | -75.5969835035535 39.2607799993354 | {C63BC5D6-FC2F-47CC-8CAB-81F09AF50CF1} |
4 | 22 | MALCOLMS MILL | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.616818 | 39.240314 | -75.6168176827436 39.2403144684381 | {95EF8E9D-A53F-4099-B57A-5CC45D5F3AD7} |
len(de_address_df)
534407
# Get some coordinate points from the delaware address data to test this process
point_sample_df = de_address_df.sample(n=1000)
# Zip() combines two or more lists, or other Iterable objects, into one entity, here called 'coords'
point_sample_df['coords'] = list(zip(point_sample_df['Longitude'],point_sample_df['Latitude']))
# Convert the 'coords' entity into a geometry Point object needed to use with the 'within' polygon function.
point_sample_df['coords'] = point_sample_df['coords'].apply(Point)
# Examine the dataframe with the newly added 'coords' Point column (right-most column)
point_sample_df.head()
AddNo_Full | St_Name | St_PosTyp | St_PosDir | St_PosMod | County | Post_City | State | Zip_Code | Longitude | Latitude | AddrPoint | UUID | coords | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
363168 | 29556 | MAPLE | Road | NaN | NaN | Sussex | LEWES | DE | 19958.0 | -75.234757 | 38.737225 | -75.2347568123153 38.7372245335924 | {D8CEF7A8-7E04-4D8D-98DB-6F0D4D15188A} | POINT (-75.2347568123153 38.7372245335924) |
505387 | 18888 | BETHPAGE | Drive | NaN | NaN | Sussex | LEWES | DE | 19958.0 | -75.144634 | 38.732908 | -75.1446337160359 38.7329081540269 | {09EBB22B-5974-4202-982A-F84F2FFDA5F7} | POINT (-75.1446337160359 38.73290815402689) |
259712 | 303 | WALDEN | Road | NaN | NaN | New Castle | WILMINGTON | DE | 19803.0 | -75.552691 | 39.797975 | -75.5526910174496 39.797974732606 | {981FC722-E078-4512-9546-394E91B3525B} | POINT (-75.5526910174496 39.797974732606) |
423799 | 1004 | CAPTAIN HOOK | Trail | NaN | NaN | Sussex | SELBYVILLE | DE | 19975.0 | -75.081028 | 38.465249 | -75.0810278397987 38.4652492117774 | {D5234580-9844-48D9-B56D-3E724CA7A465} | POINT (-75.08102783979869 38.4652492117774) |
342634 | 18 | RIVERS END EAST | Drive | NaN | NaN | New Castle | CLAYMONT | DE | 19703.0 | -75.465175 | 39.793302 | -75.4651749368478 39.79330240308 | {CF4467DE-79F4-4D4D-91E9-74BAA53C5D56} | POINT (-75.4651749368478 39.79330240308) |
# Create the geodataframe object needed for matching points to polygons in the final step
de_points_gdf = gpd.GeoDataFrame(point_sample_df, geometry='coords', crs=de_tracts_gdf.crs)
de_points_gdf.info() # Note, this must be a 'geodataframe' object for point-polygon matching to work.
<class 'geopandas.geodataframe.GeoDataFrame'> Index: 1000 entries, 363168 to 223009 Data columns (total 14 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 AddNo_Full 1000 non-null object 1 St_Name 1000 non-null object 2 St_PosTyp 990 non-null object 3 St_PosDir 3 non-null object 4 St_PosMod 0 non-null object 5 County 1000 non-null object 6 Post_City 1000 non-null object 7 State 1000 non-null object 8 Zip_Code 1000 non-null float64 9 Longitude 1000 non-null float64 10 Latitude 1000 non-null float64 11 AddrPoint 1000 non-null object 12 UUID 1000 non-null object 13 coords 1000 non-null geometry dtypes: float64(3), geometry(1), object(10) memory usage: 117.2+ KB
# Final step - Perform spatial join to match points and polygons.
# Put results into a geodataframe
pointInTracts_gdf = gpd.tools.sjoin(de_points_gdf, de_tracts_gdf, predicate="within", how='left')
# Examine the results. 'NAME' column has the census tract that each address point was found.
pointInTracts_gdf.head()
AddNo_Full | St_Name | St_PosTyp | St_PosDir | St_PosMod | County | Post_City | State | Zip_Code | Longitude | Latitude | AddrPoint | UUID | coords | index_right | STATEFP | COUNTYFP | TRACTCE | GEOID | NAME | NAMELSAD | MTFCC | FUNCSTAT | ALAND | AWATER | INTPTLAT | INTPTLON | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
363168 | 29556 | MAPLE | Road | NaN | NaN | Sussex | LEWES | DE | 19958.0 | -75.234757 | 38.737225 | -75.2347568123153 38.7372245335924 | {D8CEF7A8-7E04-4D8D-98DB-6F0D4D15188A} | POINT (-75.23476 38.73722) | 20 | 10 | 005 | 050803 | 10005050803 | 508.03 | Census Tract 508.03 | G5020 | S | 45222333 | 831841 | +38.7601194 | -075.2551308 |
505387 | 18888 | BETHPAGE | Drive | NaN | NaN | Sussex | LEWES | DE | 19958.0 | -75.144634 | 38.732908 | -75.1446337160359 38.7329081540269 | {09EBB22B-5974-4202-982A-F84F2FFDA5F7} | POINT (-75.14463 38.73291) | 164 | 10 | 005 | 051004 | 10005051004 | 510.04 | Census Tract 510.04 | G5020 | S | 20319511 | 336020 | +38.7287224 | -075.1684692 |
259712 | 303 | WALDEN | Road | NaN | NaN | New Castle | WILMINGTON | DE | 19803.0 | -75.552691 | 39.797975 | -75.5526910174496 39.797974732606 | {981FC722-E078-4512-9546-394E91B3525B} | POINT (-75.55269 39.79797) | 97 | 10 | 003 | 011700 | 10003011700 | 117 | Census Tract 117 | G5020 | S | 19458464 | 0 | +39.8023473 | -075.5597904 |
423799 | 1004 | CAPTAIN HOOK | Trail | NaN | NaN | Sussex | SELBYVILLE | DE | 19975.0 | -75.081028 | 38.465249 | -75.0810278397987 38.4652492117774 | {D5234580-9844-48D9-B56D-3E724CA7A465} | POINT (-75.08103 38.46525) | 116 | 10 | 005 | 051306 | 10005051306 | 513.06 | Census Tract 513.06 | G5020 | S | 11824830 | 2881388 | +38.4787667 | -075.1012742 |
342634 | 18 | RIVERS END EAST | Drive | NaN | NaN | New Castle | CLAYMONT | DE | 19703.0 | -75.465175 | 39.793302 | -75.4651749368478 39.79330240308 | {CF4467DE-79F4-4D4D-91E9-74BAA53C5D56} | POINT (-75.46517 39.79330) | 136 | 10 | 003 | 010104 | 10003010104 | 101.04 | Census Tract 101.04 | G5020 | S | 3629092 | 2863836 | +39.7961063 | -075.4534792 |
# Plot the results of random sample of address points
# Plot map with points
base = de_tracts_gdf.boundary.plot(linewidth=1, edgecolor="black", figsize=(15,15))
de_points_gdf.plot(ax=base, linewidth=1, color="blue", markersize=1)
plt.show()
# Plot again, this time with one census tract points in red
# Example use: get points in Census Tract '141'
pnt_141 = de_points_gdf[pointInTracts_gdf.NAME=='141']
pnt_141
AddNo_Full | St_Name | St_PosTyp | St_PosDir | St_PosMod | County | Post_City | State | Zip_Code | Longitude | Latitude | AddrPoint | UUID | coords | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
299838 | 41 | AUGUSTA | Drive | NaN | NaN | New Castle | NEWARK | DE | 19713.0 | -75.707925 | 39.678196 | -75.7079253368914 39.6781956215546 | {8F0F744D-2C60-42FB-BFD4-59372F60A045} | POINT (-75.70793 39.67820) |
129240 | 511 | BANYAN | Road | NaN | NaN | New Castle | NEWARK | DE | 19713.0 | -75.717448 | 39.677296 | -75.7174478435114 39.6772958879247 | {C1F6A7FC-42D6-4F95-8C77-18FB16A5016D} | POINT (-75.71745 39.67730) |
297341 | 8 | CAROLE | Road | NaN | NaN | New Castle | NEWARK | DE | 19713.0 | -75.710418 | 39.679249 | -75.7104183066428 39.6792487781724 | {4F5AEEAF-126A-462C-A4FF-32983372EBDC} | POINT (-75.71042 39.67925) |
196225 | 17 | MALVERN | Road | NaN | NaN | New Castle | NEWARK | DE | 19713.0 | -75.702286 | 39.676410 | -75.7022857071547 39.6764101711002 | {83357730-D9E0-4652-8586-C9E466E35195} | POINT (-75.70229 39.67641) |
233945 | 8 | GREENBRIDGE | Drive | NaN | NaN | New Castle | NEWARK | DE | 19713.0 | -75.723115 | 39.674842 | -75.7231149917752 39.6748423692452 | {2859990B-B2CA-41A1-98EE-CB8A4BAFF4CD} | POINT (-75.72311 39.67484) |
# Plot map again with Census Tract 141 points in Red, all others in Blue
base = de_tracts_gdf.boundary.plot(linewidth=1, edgecolor="black", figsize=(15,15))
de_points_gdf.plot(ax=base, linewidth=1, color="blue", markersize=1)
pnt_141.plot(ax=base, linewidth=1, color="red", markersize=8)
plt.show()
# The above matched point-in-polygons for 1000 sample addresses. Repeat the matching for all Delaware addresses.
# Get some coordinate points from the delaware address data
# point_sample_df = de_address_df.sample(n=1000)
# Zip() combines two or more lists, or other Iterable objects, into one entity, here called 'coords'
de_address_df['coords'] = list(zip(de_address_df['Longitude'],de_address_df['Latitude']))
# Convert the 'coords' entity into a geometry Point object needed to use with the 'within' polygon function.
de_address_df['coords'] = de_address_df['coords'].apply(Point)
# Examine the dataframe with the newly added 'coords' Point column (right-most column)
de_address_df.head()
AddNo_Full | St_Name | St_PosTyp | St_PosDir | St_PosMod | County | Post_City | State | Zip_Code | Longitude | Latitude | AddrPoint | UUID | coords | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 216 | KING | Street | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.589069 | 39.309325 | -75.5890689551341 39.3093249142128 | {090F51C5-7577-412C-B1E7-E18905DF905F} | POINT (-75.5890689551341 39.3093249142128) |
1 | 978 | CAVEAT | Road | NaN | NaN | Kent | Magnolia | DE | 19962.0 | -75.568466 | 39.250083 | -75.5684660865876 39.2500827735636 | {BAD7810A-EFA0-4591-8C1E-F203665DAF3B} | POINT (-75.56846608658761 39.2500827735636) |
2 | 14 | BURNSIDE | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.616076 | 39.275783 | -75.6160764495596 39.2757829759585 | {9E4CD656-EEB1-4DA6-A62C-2036F209F158} | POINT (-75.6160764495596 39.2757829759585) |
3 | 347 | WILLOWWOOD | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.596984 | 39.260780 | -75.5969835035535 39.2607799993354 | {C63BC5D6-FC2F-47CC-8CAB-81F09AF50CF1} | POINT (-75.5969835035535 39.2607799993354) |
4 | 22 | MALCOLMS MILL | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.616818 | 39.240314 | -75.6168176827436 39.2403144684381 | {95EF8E9D-A53F-4099-B57A-5CC45D5F3AD7} | POINT (-75.6168176827436 39.24031446843809) |
print("There are", len(de_address_df), "rows of addresses and coordinate points")
There are 534407 rows of addresses and coordinate points
# Create the geodataframe object needed for matching points to polygons in the final step
de_all_points_gdf = gpd.GeoDataFrame(de_address_df, geometry='coords', crs=de_tracts_gdf.crs)
# Final step - Perform spatial join to match points and polygons.
# Put results into a geodataframe
all_DE_pointInTracts_gdf = gpd.tools.sjoin(de_all_points_gdf, de_tracts_gdf, predicate="within", how='left')
# Examine the results. 'NAME' column has the census tract that each address point was found.
all_DE_pointInTracts_gdf.head()
AddNo_Full | St_Name | St_PosTyp | St_PosDir | St_PosMod | County | Post_City | State | Zip_Code | Longitude | Latitude | AddrPoint | UUID | coords | index_right | STATEFP | COUNTYFP | TRACTCE | GEOID | NAME | NAMELSAD | MTFCC | FUNCSTAT | ALAND | AWATER | INTPTLAT | INTPTLON | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 216 | KING | Street | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.589069 | 39.309325 | -75.5890689551341 39.3093249142128 | {090F51C5-7577-412C-B1E7-E18905DF905F} | POINT (-75.58907 39.30932) | 195.0 | 10 | 001 | 040203 | 10001040203 | 402.03 | Census Tract 402.03 | G5020 | S | 59368816.0 | 1534599.0 | +39.2858685 | -075.5508360 |
1 | 978 | CAVEAT | Road | NaN | NaN | Kent | Magnolia | DE | 19962.0 | -75.568466 | 39.250083 | -75.5684660865876 39.2500827735636 | {BAD7810A-EFA0-4591-8C1E-F203665DAF3B} | POINT (-75.56847 39.25008) | 195.0 | 10 | 001 | 040203 | 10001040203 | 402.03 | Census Tract 402.03 | G5020 | S | 59368816.0 | 1534599.0 | +39.2858685 | -075.5508360 |
2 | 14 | BURNSIDE | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.616076 | 39.275783 | -75.6160764495596 39.2757829759585 | {9E4CD656-EEB1-4DA6-A62C-2036F209F158} | POINT (-75.61608 39.27578) | 208.0 | 10 | 001 | 040202 | 10001040202 | 402.02 | Census Tract 402.02 | G5020 | S | 31959485.0 | 669328.0 | +39.2597299 | -075.6117335 |
3 | 347 | WILLOWWOOD | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.596984 | 39.260780 | -75.5969835035535 39.2607799993354 | {C63BC5D6-FC2F-47CC-8CAB-81F09AF50CF1} | POINT (-75.59698 39.26078) | 208.0 | 10 | 001 | 040202 | 10001040202 | 402.02 | Census Tract 402.02 | G5020 | S | 31959485.0 | 669328.0 | +39.2597299 | -075.6117335 |
4 | 22 | MALCOLMS MILL | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.616818 | 39.240314 | -75.6168176827436 39.2403144684381 | {95EF8E9D-A53F-4099-B57A-5CC45D5F3AD7} | POINT (-75.61682 39.24031) | 208.0 | 10 | 001 | 040202 | 10001040202 | 402.02 | Census Tract 402.02 | G5020 | S | 31959485.0 | 669328.0 | +39.2597299 | -075.6117335 |
# Save results to a CSV file
all_DE_pointInTracts_gdf.to_csv('DelawarePointsInCensusTract.csv')
# Read back a few rows of the CSV to see how it looks
pd.read_csv('DelawarePointsInCensusTract.csv', nrows = 100)
Unnamed: 0 | AddNo_Full | St_Name | St_PosTyp | St_PosDir | St_PosMod | County | Post_City | State | Zip_Code | Longitude | Latitude | AddrPoint | UUID | coords | index_right | STATEFP | COUNTYFP | TRACTCE | GEOID | NAME | NAMELSAD | MTFCC | FUNCSTAT | ALAND | AWATER | INTPTLAT | INTPTLON | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 216 | KING | Street | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.589069 | 39.309325 | -75.5890689551341 39.3093249142128 | {090F51C5-7577-412C-B1E7-E18905DF905F} | POINT (-75.5890689551341 39.3093249142128) | 195.0 | 10 | 1 | 40203 | 10001040203 | 402.03 | Census Tract 402.03 | G5020 | S | 59368816.0 | 1534599.0 | 39.285868 | -75.550836 |
1 | 1 | 978 | CAVEAT | Road | NaN | NaN | Kent | Magnolia | DE | 19962.0 | -75.568466 | 39.250083 | -75.5684660865876 39.2500827735636 | {BAD7810A-EFA0-4591-8C1E-F203665DAF3B} | POINT (-75.56846608658761 39.2500827735636) | 195.0 | 10 | 1 | 40203 | 10001040203 | 402.03 | Census Tract 402.03 | G5020 | S | 59368816.0 | 1534599.0 | 39.285868 | -75.550836 |
2 | 2 | 14 | BURNSIDE | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.616076 | 39.275783 | -75.6160764495596 39.2757829759585 | {9E4CD656-EEB1-4DA6-A62C-2036F209F158} | POINT (-75.6160764495596 39.2757829759585) | 208.0 | 10 | 1 | 40202 | 10001040202 | 402.02 | Census Tract 402.02 | G5020 | S | 31959485.0 | 669328.0 | 39.259730 | -75.611733 |
3 | 3 | 347 | WILLOWWOOD | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.596984 | 39.260780 | -75.5969835035535 39.2607799993354 | {C63BC5D6-FC2F-47CC-8CAB-81F09AF50CF1} | POINT (-75.5969835035535 39.2607799993354) | 208.0 | 10 | 1 | 40202 | 10001040202 | 402.02 | Census Tract 402.02 | G5020 | S | 31959485.0 | 669328.0 | 39.259730 | -75.611733 |
4 | 4 | 22 | MALCOLMS MILL | Drive | NaN | NaN | Kent | Smyrna | DE | 19977.0 | -75.616818 | 39.240314 | -75.6168176827436 39.2403144684381 | {95EF8E9D-A53F-4099-B57A-5CC45D5F3AD7} | POINT (-75.6168176827436 39.24031446843809) | 208.0 | 10 | 1 | 40202 | 10001040202 | 402.02 | Census Tract 402.02 | G5020 | S | 31959485.0 | 669328.0 | 39.259730 | -75.611733 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
95 | 95 | 3089 | KITTS HUMMOCK | Road | NaN | NaN | Kent | Dover | DE | 19901.0 | -75.401731 | 39.102705 | -75.4017313264713 39.1027047760118 | {6F9DDB72-F731-4C9D-AE92-344D61247B09} | POINT (-75.40173132647129 39.1027047760118) | 1.0 | 10 | 1 | 43202 | 10001043202 | 432.02 | Census Tract 432.02 | G5020 | S | 295721374.0 | 46419973.0 | 39.145607 | -75.432449 |
96 | 96 | 3083 | KITTS HUMMOCK | Road | NaN | NaN | Kent | Dover | DE | 19901.0 | -75.401741 | 39.102821 | -75.401740998113 39.1028206745749 | {4F9A62B6-83FA-4B7D-99E0-AFFA724439EC} | POINT (-75.40174099811301 39.10282067457489) | 1.0 | 10 | 1 | 43202 | 10001043202 | 432.02 | Census Tract 432.02 | G5020 | S | 295721374.0 | 46419973.0 | 39.145607 | -75.432449 |
97 | 97 | 3073 | KITTS HUMMOCK | Road | NaN | NaN | Kent | Dover | DE | 19901.0 | -75.402067 | 39.102718 | -75.4020668866337 39.1027181743677 | {E7BD28BE-99CE-4255-AED3-8774B12970A3} | POINT (-75.40206688663369 39.10271817436769) | 1.0 | 10 | 1 | 43202 | 10001043202 | 432.02 | Census Tract 432.02 | G5020 | S | 295721374.0 | 46419973.0 | 39.145607 | -75.432449 |
98 | 98 | 1970 | LITTLE CREEK | Road | NaN | NaN | Kent | Dover | DE | 19901.0 | -75.476258 | 39.154503 | -75.4762582016554 39.1545030351478 | {C8A50559-E5F9-4F4B-8D9F-78E69CEA5CA2} | POINT (-75.4762582016554 39.1545030351478) | 172.0 | 10 | 1 | 41000 | 10001041000 | 410.00 | Census Tract 410 | G5020 | S | 26732724.0 | 21809.0 | 39.158842 | -75.471365 |
99 | 99 | 359 | BAY | Drive | NaN | NaN | Kent | Dover | DE | 19901.0 | -75.400671 | 39.097586 | -75.4006705151962 39.0975855043087 | {89D9155F-D97A-4859-8FD8-E0AB6A51BCE8} | POINT (-75.4006705151962 39.0975855043087) | 1.0 | 10 | 1 | 43202 | 10001043202 | 432.02 | Census Tract 432.02 | G5020 | S | 295721374.0 | 46419973.0 | 39.145607 | -75.432449 |
100 rows × 28 columns
# Create a sample CSV file for iReach to test
all_DE_pointInTracts_gdf.sample(n=1000).to_csv('SampleDelawarePointsInCensusTract.csv')