-
Notifications
You must be signed in to change notification settings - Fork 0
Appunti
Il file di partenza è stops.txt
che è di base già un file spaziale.
Basta creare un file di testo in formato virtual format, denominarlo ad esempio fermate.vrt e salvarlo nella stessa cartella in cui è stato estratto il file GTFS.
Nota bene: è necessario creare una copia di stops.txt
e cambiargli formato in csv (stops.csv
).
Ecco il virtual file:
<OGRVRTDataSource>
<OGRVRTLayer name="stops">
<SrcDataSource relativeToVRT="1">stops.csv</SrcDataSource>
<GeometryType>wkbPoint</GeometryType>
<LayerSRS>WGS84</LayerSRS>
<GeometryField encoding="PointFromColumns" x="stop_lon" y="stop_lat"/>
</OGRVRTLayer>
</OGRVRTDataSource>
Se trascinato in QGIS verrà visto come file spaziale.
Il file di partenza è shapes.txt
che è di base già un file spaziale.
Con ogr2ogr
si converte in un GeoJSON (o in mille altri formati spaziali) con il comando di sotto.
Nota bene: è necessario creare una copia di shapes.txt
e cambiargli formato in csv (shapes.csv
).
ogr2ogr -f geojson shapes.geojson shapes.csv -dialect SQLite -sql "SELECT shape_id, MakeLine(MakePoint(CAST(shape_pt_lon AS float),CAST(shape_pt_lat AS float))) FROM shapes GROUP BY shape_id"
A partire da un db spatialite in cui sono stati importati tutti i txt
del GTFS, lanciare questa query:
select r.route_id, r.agency_id, r.route_short_name, r.route_long_name, r.route_type, r.route_url, trip_headsign, l.*
from
(select shape_id, MakeLine(pt) AS geometry
from
(select shape_id, CAST(shape_pt_sequence AS Integer) AS seq,
MakePoint(CAST(shape_pt_lon AS float),CAST(shape_pt_lat AS float)) AS pt
from shapes
order by shape_id, seq) AS tpt
group by shape_id) AS l
join
(select distinct route_id, trip_headsign, shape_id from trips) AS t
on t.shape_id == l.shape_id
join
routes AS r on r.route_id == t.route_id;
Nell'esempio le fermate con stop_id
345 e 347.
select GeodesicLength((select MakeLine(GEOMETRY) AS GEOMETRY
from (SELECT * FROM (SELECT "GEOMETRY" FROM "stops" where stop_id IN (345,347))))) as distanza