@@ -0,0 +1,1612 @@
+import os%0Aimport psycopg2%0A%0A'''%0Agenerate milestones for single line in geojson file, using PostGIS. %0Ainput: %09source.json%0Aoutput:%09route.gpx with route for garmin%0A%09View public.milestones in PostGIS database with points %0A%0A'''%0A%0Adef process():%0A%09dbname='residential'%0A%09user='user'%0A%09host='localhost'%0A%09password='user'%0A%09try:%0A%09%09conn = psycopg2.connect(%22dbname='%22 + dbname + %22' user='%22%0A                                + user + %22' host='%22 + host%0A                                + %22' password='%22 + password + %22'%22)%0A%09except:%0A%09%09print 'I am unable to connect to the database'%0A%09%09return 0%0A%09cur = conn.cursor()%0A%09sql ='''%0A%09DROP TABLE IF EXISTS pkline;%0A%0A%09%0A%09'''%0A%0A%09cur.execute(sql)%0A%09conn.commit()%0A%0A%0A%09os.system('''%0A%09ogr2ogr -overwrite -f %22PostgreSQL%22 PG:%22host=localhost user=user dbname=residential password=user%22  -nln pkline source.json -s_srs EPSG:4326 -t_srs EPSG:32637%0A%09''')%0A%0A%09os.system('''%0A%09rm route.gpx -f%0A%09''')%0A%09os.system('''%0A%09ogr2ogr -overwrite -f %22GPX%22 route.gpx   source.json -s_srs EPSG:4326 -select name -dsco FORCE_GPX_ROUTE=YES%0A%09''')%0A%0A%09cur = conn.cursor()%0A%09sql ='''%0A%09CREATE OR REPLACE VIEW milestones AS%0A%09(%0A%09-- calculate lenght of line%0A%09WITH line_length as (SELECT round((ST_Length(wkb_geometry)/1000)::numeric,3) AS line_length FROM pkline )%0A%09-- calculate record id%0A%09SELECT wkb_geometry, (row_number() OVER ()) AS id FROM %0A%09(SELECT %0A%09st_line_interpolate_point%0A%09%09(wkb_geometry, %0A%09%09generate_series%0A%09%09%09(0,%0A%09%09%09(line_length.line_length*100)::integer,%0A%09%09%091*100)%0A%09%09/(line_length.line_length*100)::real) %0A%09%09AS wkb_geometry%0A%09 FROM line_length, pkline) AS points_calculation%0A%09);%0A%0A%09%0A%09'''%0A%0A%0A%09%0A%0A%0A%0A%0Aif __name__ == '__main__':%0A%09process()%0A

Create milestones_generation.py