User Tools

Site Tools


postgis

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
postgis [2016/10/06 14:55]
mantis
postgis [2020/02/12 12:06] (current)
mantis [Export table to geojson]
Line 11: Line 11:
 ====== Enabling Postgis ====== ====== Enabling Postgis ======
  
- 
-I 
  
 ===== Ubuntu 16.04 (Postgres 9.5) ===== ===== Ubuntu 16.04 (Postgres 9.5) =====
Line 18: Line 16:
 ==== Create a PostGIS-enabled database ==== ==== Create a PostGIS-enabled database ====
  
-and create a database using the template:+
 <code sql> <code sql>
  
Line 101: Line 99:
 ===== Update gis table registry ===== ===== Update gis table registry =====
  
-In table spatial_ref_sys all tables containing PostGIS types are listed.+In table spatial_ref_sysall tables containing PostGIS types are listed.
 To refresh this cache: To refresh this cache:
  
Line 118: Line 116:
 UPDATE mytable SET the_geom = ST_SetSRID(ST_MakePoint(longitude,​latitude),​4326);​ UPDATE mytable SET the_geom = ST_SetSRID(ST_MakePoint(longitude,​latitude),​4326);​
 </​code>​ </​code>​
 +===== Export table to geojson =====
 +
 +Building a FeatureCollection ([[https://​postgis.net/​docs/​ST_AsGeoJSON.html|docs]],​ [[https://​gist.github.com/​brambow/​889aca48831e189a62eec5a70067bf8e|code snippet]]):
 +
 +<code sql>
 + ​SELECT json_build_object(
 +    '​type',​ '​FeatureCollection',​
 +    '​crs', ​ json_build_object(
 +        '​type', ​     '​name', ​
 +        '​properties',​ json_build_object(
 +            '​name',​ '​EPSG:​4326'  ​
 +        )
 +    ), 
 +    '​features',​ json_agg(
 +        json_build_object(
 +              '​type', ​      '​Feature',​
 +    '​id', ​        id,
 +    '​geometry', ​  ​ST_AsGeoJSON(the_geom)::​json,​
 +    '​properties',​ json_build_object(
 +        '​name',​ name,
 +        '​frc',​ frc,
 +        '​fromjunction',​ fromjunction,​
 +        '​tojunction',​ tojunction,
 +          )
 +       )
 +    )
 +)
 + FROM roadmap_table;​
 +</​code>​
 +
 +
 ===== Select all geometries in an area ===== ===== Select all geometries in an area =====
 <code sql> <code sql>
postgis.1475758519.txt.gz ยท Last modified: 2016/10/06 14:55 by mantis