See an example at whatsmydistrict.org.
- Ruby 1.9.3
- postgresql --
brew install postgres
- postgis --
brew install postgis
Clone this repository. The rest of the commands should happen in the directory containing this project.
- Download & Install Virtualbox
- Download & Install Vagrant
vagrant plugin install vagrant-berkshelf
vagrant plugin install vagrant-omnibus
vagrant up
vagrant ssh
cd WhatsMyDistrict
sudo bundle install
psql -U postgres
create database districts;
\q
psql -U postgres -d districts < sql/wmd.sql
foreman start
- Open browser to http://localhost:4567
- Hack
-
bundle
-
puma
to start the server at localhost:9292. -
For a new postgresql install in OS X:
mkdir -p ~/Library/LaunchAgents cp /usr/local/Cellar/postgresql/9.2.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist initdb /usr/local/var/postgres -E utf8 pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
See also Postgres.app.
-
Create the database:
createdb -p 5432 -h localhost districts
-
Add necessary postgis functions to the database:
psql -p 5432 -h localhost -d districts -f /usr/local/share/postgis/postgis.sql
andpsql -p 5432 -h localhost -d districts -f /usr/local/share/postgis/spatial_ref_sys.sql
-- thanks to PostGres - PostGIS on OS X Lion.
sudo apt-get install postgresql-9.1 postgresql-9.1-postgis postgis libpq
bundle install
- Create the database:
$ sudo -u postgres psql
# \password
sorandomwow
sorandomwow
# create database districts;
# \q
- Add PostGIS extensions:
sudo -u postgres psql -U postgres -d districts -f `pg_config --sharedir`/contrib/postgis-*/postgis.sql`
sudo -u postgres psql -U postgres -d districts -f `pg_config --sharedir`/contrib/postgis-*/spatial_ref_sys.sql
psql -U postgres -d districts < sql/wmd.sql
cp dotenv.sample .env
foreman start
- Open browser to http://localhost:4567.
- Hack.
Remember to either set relevant values in .env
file or to set ENV values.
-
Download the new shape file from data.lexingtonky.gov -- for example, under Community, Board of Elections - Voting Precincts.
-
Run
shp2pgsql -c -D -s 4269 -I shapefile.shp tablename > filename.sql
. For example:$ shp2pgsql -c -D -s 4269 -I VotingPrecinct.shp voting > VotingPrecinct.sql Shapefile type: Polygon Postgis type: MULTIPOLYGON[2]
Another example:
~/Downloads/PostOffice
% shp2pgsql -c -D -s 4269 -I PostOffice.shp post_office > PostOffice.sql
Shapefile type: Point
Postgis type: POINT[2]
- In psql, drop the table you will be updating.
- Run
psql -d database -f file.sql
, for examplepsql -p 5432 -h localhost -d districts -f VotingPrecinct.sql
.