-
Notifications
You must be signed in to change notification settings - Fork 9
/
postgis_setup_notes.txt
36 lines (23 loc) · 1.13 KB
/
postgis_setup_notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
--------------------------------------------------
POSTGIS SETUP NOTES
Works with SQLAlchemy and PostgreSQL
--------------------------------------------------
1) install in vagrant
sudo apt-get update (http://technobytz.com/install-postgis-postgresql-9-3-ubuntu.html)
sudo apt-get install postgis (https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postgis-on-ubuntu-14-04)
2) pip install geoalchemy2
3) setup model.py with postgis column in sqlalchemy
example: latlng = db.Column(Geometry(geometry_type='POINT'), nullable=False)
from sqlalchemy import func
from geoalchemy2 import Geometry
4) createdb
5) psql [database]
CREATE EXTENSION postgis;
6) create/seed your database tables
seeding data must contain formatting like this:
'POINT(%s %s)' % (latitude, longitude)
7) query using:
for approximations of nearby distances using spherical distance, search units nearby by meters; example below searches within 1000m
db.session.query(UnitDetails).filter(func.ST_Distance_Sphere("POINT(37.776164 -122.423355)",UnitDetails.latlng) < 1000).all()
--------------------------------------------------
3219 meters ~ 2 miles