This application generates custom map polygons for a service area or market based on the Zipcodes composing the market.
Use Case: Service area businesses typically define operating regions, pricing, availability, and more based off of zipcodes which they service. The ability to display service area boundaries in a map is useful for:
- Visual interface for Users to see if they fall within a service area
- Visual interface for Customer Support to service customers
- Geospatial analysis
The app has a minimal UI to allow an end user to:
- Generate an up to date market polygon based on the current market definition.
- Render the generated market polygon as a layer in a Google map.
- Data:
- Market definitions defined and live in database
- GeoJSON polygon definitions live in separate database
- Creating market polygons:
- Get zipcodes for market of interest
- Query database for each polygon Zipcode matching market Zipcodes
- Melts independent Zipcode polygons into a single polygon representing the aggregate market
- Display market polygons:
- Utilize Google Maps API to initialize map instance on DOM
- Add polygon, center point, and zoom level to map data
- Render map
#!bash
$ cd [path to your project directory]
$ npm update
$ npm install
- https://catalog.data.gov/dataset/tiger-line-shapefile-2014-2010-nation-u-s-2010-census-5-digit-zip-code-tabulation-area-zcta5-na/resource/5515a599-3457-40b7-a915-fc4a5ee47549
- (file is: http://www2.census.gov/geo/tiger/TIGER2014/ZCTA5/tl_2014_us_zcta510.zip)
- Most recent as of Feb 27, 2019: https://www2.census.gov/geo/tiger/TIGER2018/ZCTA510/tl_2018_us_zcta510.zip
#!bash
$ cd [path to your project directory]
$ mkdir scripts/data
$ cd scripts/data
$ curl -O https://www2.census.gov/geo/tiger/TIGER2018/ZCTA510/tl_2018_us_zcta510.zip
!!! The next few commands will take awhile... !!!
gdal is Geospatial Data Abstraction Library and has a lot to it.
Converting the .shp to .geojson is also time consuming.
#!bash
$ unzip tl_2014_us_zcta510.zip -d ./
$ brew install gdal ## Mac or for Linux $ apt-get install gdal-bin
$ ogr2ogr -f GeoJSON -t_srs crs:84 geojson_zips.geojson tl_2014_us_zcta510.shp
Isolating the "features" property which is an array of zipcode polygons in this case.
#!bash
$ brew install jq
$ jq '.features' geojson_zips.geojson > zips.geojson
#!bash
$ cd ..
## NOTE: Ensure mongo is running prior
$ node add_zipcode_polygons_to_db_v1.2.js
#!bash
$ cd [path to your project directory]
$ npm update
$ npm install
$ node index.js