Files
sql/postgis/postgis.sql

55 lines
1.4 KiB
MySQL
Raw Normal View History

2025-09-05 07:48:52 +02:00
create table point (
2025-09-06 08:11:37 +02:00
id serial primary key,
nom text not null,
2025-09-06 08:04:01 +02:00
altitude double precision,
2025-09-06 08:11:37 +02:00
geom geometry(point, 4326) not null
2025-09-05 07:48:52 +02:00
);
create index idx_point_geom on point using gist (geom);
create table route (
id serial primary key,
2025-09-06 08:04:01 +02:00
depart int,
arrivee int,
geom geometry(linestring, 4326) not null,
longueur double precision
2025-09-05 07:48:52 +02:00
);
create index idx_route_geom on route using gist (geom);
2025-09-06 08:04:01 +02:00
create or replace function maj_longueur()
returns trigger as $$
begin
2025-09-06 16:17:55 +02:00
new.longueur := st_length(new.geom) * 1000;
2025-09-06 08:04:01 +02:00
return new;
end;
$$ language plpgsql;
2025-09-05 07:48:52 +02:00
2025-09-06 08:04:01 +02:00
create trigger trigger_longueur
before insert or update on route
for each row
execute function maj_longueur();
2025-09-05 07:48:52 +02:00
2025-09-06 08:04:01 +02:00
-- ************************************************************
create table route_cout (
route_id int references route(id),
tag text,
cout float,
cout_inverse float,
primary key (route_id, tag)
2025-09-05 07:48:52 +02:00
);
create table zone (
2025-09-06 08:11:37 +02:00
id serial primary key,
2025-09-06 08:04:01 +02:00
nom text,
2025-09-06 08:11:37 +02:00
geom geometry(polygon, 4326) -- on choisit srid 4326 (wgs84)
2025-09-05 07:48:52 +02:00
);
2025-09-06 08:04:01 +02:00
-- ************************************************************
2025-09-05 07:48:52 +02:00
2025-09-06 08:04:01 +02:00
\COPY point FROM '/tmp/point.csv' (FORMAT CSV, header, ENCODING 'UTF8');
2025-09-06 16:17:55 +02:00
\COPY route(id, depart, arrivee, geom) FROM '/tmp/route.csv' (FORMAT CSV, header, ENCODING 'UTF8');
\COPY route_cout FROM '/tmp/route_cout.csv' (FORMAT CSV, header, ENCODING 'UTF8');
2025-09-06 08:04:01 +02:00
\COPY zone FROM '/tmp/zone.csv' (FORMAT CSV, header, ENCODING 'UTF8');