Skip to content

Creating custom map polygons from Service Areas defined by Serviceable Zipcodes & GeoJSON

Notifications You must be signed in to change notification settings

halocline/cb-market-polygons

Repository files navigation

Generates Map Polygons from Zipcodes & GeoJSON

This application generates custom map polygons for a service area or market based on the Zipcodes composing the market.

polygon

Why Care?

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

Scope

The app has a minimal UI to allow an end user to:

  1. Generate an up to date market polygon based on the current market definition.
  2. Render the generated market polygon as a layer in a Google map.

Details

  1. Data:
  • Market definitions defined and live in database
  • GeoJSON polygon definitions live in separate database
  1. 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
  1. 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

Getting Started

Install Dependencies

#!bash
$ cd [path to your project directory]
$ npm update
$ npm install

Create Local Datastore for GeoJSON Zipcode Shapefiles

1) Zipcode shapefiles are found on data.gov:

2) Make 'data' directory to hold shapefile & download shapefiles

#!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

3) Unzip and convert shapefiles to JSON

!!! 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

4) Modify GeoJSON file

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

5) Run script to load zipcode polygons into document Database

#!bash
$ cd ..
## NOTE: Ensure mongo is running prior
$ node add_zipcode_polygons_to_db_v1.2.js

Starting the Server

#!bash
$ cd [path to your project directory]
$ npm update
$ npm install
$ node index.js

About

Creating custom map polygons from Service Areas defined by Serviceable Zipcodes & GeoJSON

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published