diff --git a/data/point.csv b/data/point.csv new file mode 100644 index 0000000..aacefe4 --- /dev/null +++ b/data/point.csv @@ -0,0 +1,68 @@ +id,nom,altitude,st_astext +1,Boulangerie,5,POINT(-4.015703101491354 48.74486669121691) +2,Salle des fêtes,5,POINT(-4.015239140663459 48.74492186050464) +3,Crêperie,5,POINT(-4.014856569536992 48.7443672236213) +4,Le port,5,POINT(-4.014622630636358 48.74422250405495) +5,Marie,5,POINT(-4.012923318316306 48.744464903795695) +6,La Poste,5,POINT(-4.012978426113158 48.74533129595439) +7,École primaire,5,POINT(-4.013836730543368 48.74532080203461) +8,Pharmacie,5,POINT(-4.015872431573694 48.744366311013145) +9,Bibliothèque,5,POINT(-4.016980255105276 48.744098914937105) +10,Librairie,5,POINT(-4.016665326243746 48.743593603906454) +11,Poissonerie,5,POINT(-4.016075499189723 48.74310777723044) +12,Sémaphore,5,POINT(-4.012662534462987 48.746366309239995) +13,Boucherie,5,POINT(-4.011495268160466 48.74529523306027) +14,Bergerie,5,POINT(-4.011312939560446 48.74748052979569) +15,Pré Bufflon,5,POINT(-4.009257379103126 48.74722639293891) +16,Coiffeur,5,POINT(-4.016956564846333 48.745789441786364) +17,Dentiste,5,POINT(-4.01820013254909 48.74479792341952) +18,Barbier,5,POINT(-4.017587939063573 48.743928486493644) +19,Épicerie,5,POINT(-4.017747955389328 48.743796358377686) +20,Bijouterie,5,POINT(-4.018062422255594 48.7437899354743) +21,Écurie,5,POINT(-4.021474470423531 48.743798899001895) +22,Gendarmerie,5,POINT(-4.017604084487115 48.74301074961062) +23,Église,5,POINT(-4.009740236952372 48.7443705675445) +24,Collège,5,POINT(-4.010006715847536 48.744224245372685) +25,Hôtel,5,POINT(-4.007081519366921 48.741375261285945) +26,Cabinet médical,5,POINT(-4.006265083289092 48.74170845222292) +27,Pompier,5,POINT(-4.006068894377577 48.74217891432291) +28,Cimetière,5,POINT(-4.006845744265865 48.74322789648684) +29,Auberge de jeunesse,5,POINT(-4.003382101837223 48.74299767351865) +30,Déchetterie,5,POINT(-4.003359497656666 48.74446857837965) +31,Manoir,5,POINT(-4.02409175802312 48.742996715873396) +32,Vélociste,5,POINT(-4.01912934818259 48.74268049223412) +33,Gare maritime,5,POINT(-4.018192176747797 48.74216778273092) +34,"",5,POINT(-4.018379963875775 48.74486077568912) +35,"",5,POINT(-4.018471838120006 48.74490975460548) +36,"",5,POINT(-4.019749464187122 48.7446192424776) +37,"",5,POINT(-4.016742028469542 48.7463977395358) +38,Camping,5,POINT(-4.026763459160912 48.74370038197837) +39,Stade,5,POINT(-4.031846430822729 48.74394055031432) +40,Fort du Chenal,5,POINT(-4.035045050633306 48.74215424186477) +41,Menhir,5,POINT(-4.028345710607815 48.748196934160724) +42,Marre aux canards,5,POINT(-4.020154074930217 48.74906065795587) +43,"",5,POINT(-4.014797919605925 48.747024535624156) +44,"",5,POINT(-4.016395477507864 48.74542363596422) +45,"",5,POINT(-4.009682374592884 48.74407907017208) +46,"",5,POINT(-4.004546871176246 48.74271289799514) +47,"",5,POINT(-4.001954457639246 48.74307169008736) +48,Jardin botanique,5,POINT(-3.990176578853866 48.74059175123833) +49,"",5,POINT(-4.000950904056741 48.741135124247315) +50,"",5,POINT(-4.010346362352669 48.750789110078216) +51,Lande,5,POINT(-4.007517963846762 48.7467451382293) +52,"",5,POINT(-4.005964352989594 48.74779732620556) +53,"",5,POINT(-3.991737053544233 48.740862659029595) +54,"",5,POINT(-4.002010874949346 48.742058865441216) +55,"",5,POINT(-4.01402240501942 48.74579808339848) +56,"",5,POINT(-4.017522629972719 48.74286683161378) +57,"",5,POINT(-4.019068477779029 48.74357188947294) +58,"",5,POINT(-4.039760109514953 48.74577305806608) +59,"",5,POINT(-4.019470065786261 48.74048898114416) +60,"",5,POINT(-4.020288865038362 48.74713526405362) +61,"",5,POINT(-4.019383739200152 48.75166818981731) +62,"",5,POINT(-4.019243199277812 48.747977789700094) +63,"",5,POINT(-4.019383739200152 48.75166818981731) +64,"",5,POINT(-4.027461793463843 48.74699628476703) +65,"",5,POINT(-4.022868438960439 48.74610257019231) +66,"",5,POINT(-4.030275663090021 48.747734038145396) +67,"",5,POINT(-4.024974678681478 48.74905338475223) diff --git a/data/zone.csv b/data/zone.csv new file mode 100644 index 0000000..dce67c1 --- /dev/null +++ b/data/zone.csv @@ -0,0 +1,4 @@ +id,name,geom +1,Ouest,"POLYGON((-4.040063351830218 48.74527596273623,-4.040183352157932 48.746086990110854,-4.038314154122992 48.746889115438336,-4.037513069250877 48.747906426705455,-4.036247085143734 48.748084195580645,-4.035517903792343 48.74758836709975,-4.034058608032577 48.746790427029545,-4.032772080266011 48.74710004638985,-4.032008718538774 48.74747567812633,-4.031850647896184 48.747923159378665,-4.032156833500774 48.74899320175574,-4.032054292373235 48.74922608498922,-4.031666914780309 48.749233597333614,-4.031142815683997 48.749045788386674,-4.03088076613584 48.74878285468168,-4.030049412069343 48.748683350572634,-4.029354042681365 48.74888051593271,-4.028910998400772 48.7494013374016,-4.028457589641049 48.74938631330268,-4.026912657533427 48.75020229220042,-4.026468238400779 48.74919297470383,-4.02523374081009 48.74919297470383,-4.020394510254588 48.740238464088826,-4.021144837569628 48.739436263774664,-4.022256740162941 48.738947406438065,-4.023977541795449 48.739628313570414,-4.025380656972725 48.73975052669476,-4.025857186655574 48.74032667027862,-4.025866979243504 48.74143763666284,-4.02671325838234 48.74213486863882,-4.028612126227357 48.74217400007769,-4.029383541289396 48.742702271520606,-4.03012480508506 48.74181692648819,-4.030391852837649 48.742000168836405,-4.030510244998417 48.74208800178819,-4.030596642342909 48.742199044699696,-4.030770477122116 48.74231913839474,-4.030820144201889 48.742504737177214,-4.031051923907498 48.74257570123645,-4.030977423287838 48.7426739589992,-4.031076757447384 48.74277767531816,-4.032004513804501 48.743069645356606,-4.032831494914659 48.74322373353422,-4.03397398375217 48.74287614025014,-4.034184721247667 48.74247717589915,-4.034152125225761 48.742143843763394,-4.033999519056478 48.74200450145771,-4.034099300013317 48.74174903956062,-4.03396769950894 48.74136087588372,-4.034531956029629 48.74114619996145,-4.035248127767424 48.741346564184106,-4.035718045741134 48.74237943963195,-4.037597589654442 48.743804031979984,-4.037579870908306 48.744106215768575,-4.038241057387516 48.744845286337636,-4.040063351830218 48.74527596273623))" +2,Centre,"POLYGON((-4.02523374081009 48.74919297470383,-4.024716119857816 48.7508750854278,-4.023220568949025 48.75194879250916,-4.023220568949025 48.753197769836284,-4.021893253883405 48.75278317548799,-4.02106032874744 48.75335115087621,-4.019851331314684 48.75345801690918,-4.019996825878966 48.7524527695531,-4.018700681758014 48.751795407188034,-4.014518301722906 48.75231853725851,-4.012641865385059 48.75323012304652,-4.011222927214064 48.75249659340496,-4.006666897046123 48.7528720020309,-4.009234652034756 48.74313664396521,-4.011347556456463 48.7442679950781,-4.013474562193409 48.74439948793502,-4.01477070631436 48.74411458631018,-4.015604659602713 48.74349483436875,-4.01402450268663 48.741541037517905,-4.014326361007127 48.74136749047571,-4.016436329474995 48.74286326394115,-4.018177053460988 48.74218495358343,-4.016937446986115 48.740984843601765,-4.018678170972106 48.73959337586721,-4.020366145746403 48.74016736097527,-4.020394510254588 48.740238464088826,-4.02523374081009 48.74919297470383))" +3,Est,"POLYGON((-4.006666897046123 48.7528720020309,-4.005870355067274 48.75026102618178,-4.003629135498721 48.748652881336724,-4.003761789902432 48.748081148250314,-4.002233004529002 48.74755521329037,-3.999937714914126 48.7464361648583,-3.99797899305511 48.74527609818918,-3.995092725552696 48.74493656593118,-3.994005074879722 48.745523370840516,-3.99176414816747 48.74527609818918,-3.991005795751217 48.745762437542936,-3.990115899746057 48.74515390188169,-3.990600941905078 48.74446523423448,-3.991631210308911 48.744136501877115,-3.991851437957331 48.74306933218229,-3.991032989945395 48.74181339859825,-3.989504204571964 48.74130931484149,-3.989869783683002 48.74019154586896,-3.988783465668242 48.7393151550319,-3.989903018147642 48.73865731268846,-3.990933286551476 48.73854772281224,-3.991066224410035 48.737714831944906,-3.992262665137067 48.73712303267929,-3.993896752679784 48.73699956468981,-3.993159995682341 48.73826278801588,-3.994090560692255 48.73922717619345,-3.993492340328739 48.74019154586896,-3.994135372740324 48.74093375678278,-3.994688781055771 48.74130931484149,-3.996151097499921 48.74135314841233,-3.997081662509836 48.741791482018286,-3.998089648029249 48.74147327911715,-3.998278103236868 48.740936727945886,-3.999640716287099 48.74111206329963,-4.000544025794788 48.740416709111294,-4.001136267195888 48.7406298896051,-4.001368908448368 48.74122164758512,-4.002332707922921 48.74159423236867,-4.003595617579232 48.74176956542878,-4.004592651518426 48.74141889869692,-4.004792058306265 48.740498386885655,-4.006021733497938 48.74052030402944,-4.007054944589484 48.740956236995665,-4.008248044892178 48.74050663082754,-4.008657107853101 48.740888796326814,-4.007157210329716 48.74122599876611,-4.00933887945464 48.7431367698581,-4.009234652034756 48.74313664396521,-4.006666897046123 48.7528720020309))" diff --git a/postgis/postgis.sql b/postgis/postgis.sql index 8657807..a0c2ce3 100644 --- a/postgis/postgis.sql +++ b/postgis/postgis.sql @@ -1,6 +1,7 @@ create table point ( id serial primary key, nom text not null, + altitude double precision, geom geometry(point, 4326) not null ); @@ -8,108 +9,44 @@ create index idx_point_geom on point using gist (geom); create table route ( id serial primary key, - source int, - target int, - cost double precision, - reverse_cost double precision, - geom geometry(linestring, 4326) not null + depart int, + arrivee int, + geom geometry(linestring, 4326) not null, + longueur double precision ); create index idx_route_geom on route using gist (geom); -create table tags ( - id serial primary key, - name text unique -); +create or replace function maj_longueur() +returns trigger as $$ +begin + new.longueur := st_length(new.geom); + return new; +end; +$$ language plpgsql; -create table route_tags ( - route_id int references roads(id) on delete cascade, - tag_id int references tags(id) on delete cascade, - primary key (route_id, tag_id) -); +create trigger trigger_longueur + before insert or update on route + for each row + execute function maj_longueur(); -create table route_costs ( - route_id int references roads(id), - mode text, - cost float, - reverse_cost float, - primary key (route_id, mode) +-- ************************************************************ + +create table route_cout ( + route_id int references route(id), + tag text, + cout float, + cout_inverse float, + primary key (route_id, tag) ); create table zone ( id serial primary key, - name text, + nom text, geom geometry(polygon, 4326) -- on choisit srid 4326 (wgs84) ); -insert into point (id, nom, geom) values -(1,'Boulangerie', ST_MakePoint(-4.01570310149135423, 48.74486669121691307)), -(2,'Salle des fêtes', ST_MakePoint(-4.01523914066345888, 48.74492186050463971)), -(3,'Crêperie', ST_MakePoint(-4.01485656953699177, 48.74436722362130325)), -(4,'Le port', ST_MakePoint(-4.01462263063635749, 48.74422250405495305)), -(5,'Marie', ST_MakePoint(-4.01292331831630555, 48.74446490379569497)), -(6,'La Poste', ST_MakePoint(-4.01297842611315758, 48.74533129595438652)), -(7, 'École primaire', ST_MakePoint(-4.01383673054336843, 48.74532080203461248)), -(8, 'Pharmacie', ST_MakePoint(-4.015872431573694, 48.74436631101314532)), -(9, 'Bibliothèque', ST_MakePoint(-4.01698025510527579, 48.74409891493710489)), -(10, 'Librairie', ST_MakePoint(-4.01666532624374639, 48.74359360390645435)), -(11, 'Poissonerie', ST_MakePoint(-4.01607549918972317, 48.74310777723044197)), -(12, 'Sémaphore', ST_MakePoint(-4.01266253446298737, 48.74636630923999547)), -(13, 'Boucherie', ST_MakePoint(-4.01149526816046631, 48.74529523306026846)), -(14, 'Bergerie', ST_MakePoint(-4.01131293956044654, 48.74748052979568769)), -(15, 'Pré Bufflon', ST_MakePoint(-4.00925737910312652, 48.74722639293891291)), -(16, 'Coiffeur', ST_MakePoint(-4.01695656484633279, 48.74578944178636419)), -(17, 'Dentiste', ST_MakePoint(-4.01820013254909014, 48.74479792341951878)), -(18, 'Barbier', ST_MakePoint(-4.01758793906357337, 48.74392848649364396)), -(19, 'Épicerie', ST_MakePoint(-4.01774795538932761, 48.74379635837768632)), -(20, 'Bijouterie', ST_MakePoint(-4.01806242225559451, 48.74378993547429673)), -(21, 'Écurie', ST_MakePoint(-4.02147447042353079, 48.74379889900189511)), -(22, 'Gendarmerie', ST_MakePoint(-4.01760408448711459, 48.74301074961061886)), -(23, 'Église', ST_MakePoint(-4.00974023695237225, 48.74437056754450026)), -(24, 'Collège', ST_MakePoint(-4.01000671584753565, 48.74422424537268483)), -(25, 'Hôtel', ST_MakePoint(-4.00708151936692136, 48.74137526128594544)), -(26, 'Cabinet médical', ST_MakePoint(-4.006265083289092, 48.74170845222292)), -(27, 'Pompier', ST_MakePoint(-4.006068894377577, 48.74217891432291)), -(28, 'Cimetière', ST_MakePoint(-4.00684574426586515, 48.74322789648684306)), -(29, 'Auberge de jeunesse', ST_MakePoint(-4.00338210183722332, 48.74299767351865142)), -(30, 'Déchetterie', ST_MakePoint(-4.003359497656666, 48.74446857837965)), -(31, 'Manoir', ST_MakePoint(-4.02409175802312014, 48.74299671587339589)), -(32, 'Vélociste', ST_MakePoint(-4.01912934818258982, 48.74268049223412191)), -(33, 'Gare maritime', ST_MakePoint(-4.01819217674779683, 48.74216778273091677)), -(34, '',ST_MakePoint (-4.01837996387577512, 48.74486077568911924)), -(35, '',ST_MakePoint (-4.01847183812000619, 48.74490975460548015)), -(36, '',ST_MakePoint (-4.01974946418712165, 48.74461924247759725)), -(37, '',ST_MakePoint (-4.01674202846954209, 48.74639773953580146)), -(38, 'Camping',ST_MakePoint (-4.02676345916091183, 48.74370038197837118)), -(39, 'Stade',ST_MakePoint (-4.03184643082272931, 48.7439405503143206)), -(40, 'Fort du Chenal',ST_MakePoint (-4.03504505063330576, 48.74215424186476753)), -(41, 'Menhir',ST_MakePoint (-4.0283457106078151, 48.74819693416072397)), -(42, 'Marre aux canards',ST_MakePoint (-4.02015407493021737, 48.74906065795587295)), -(43, '',ST_MakePoint (-4.01479791960592536, 48.74702453562415627)), -(44, '',ST_MakePoint (-4.01639547750786363, 48.74542363596422234)), -(45, '',ST_MakePoint (-4.00968237459288446, 48.74407907017207719)), -(46, '',ST_MakePoint (-4.00454687117624619, 48.74271289799514051)), -(47, '',ST_MakePoint (-4.00195445763924607, 48.74307169008736196)), -(48, 'Jardin botanique',ST_MakePoint (-3.99017657885386567, 48.74059175123832688)), -(49, '',ST_MakePoint (-4.00095090405674103, 48.74113512424731454)), -(50, '',ST_MakePoint (-4.01034636235266895, 48.75078911007821603)), -(51, 'Lande',ST_MakePoint (-4.00751796384676151, 48.74674513822930066)), -(52, '',ST_MakePoint(-4.00596435298959364, 48.74779732620555706)), -(53, '',ST_MakePoint(-3.99173705354423269, 48.74086265902959525)), -(54, '',ST_MakePoint(-4.00201087494934615, 48.74205886544121569)), -(55, '',ST_MakePoint(-4.01402240501941954, 48.74579808339848341)), -(56, '',ST_MakePoint(-4.01752262997271892, 48.74286683161378164)), -(57, '',ST_MakePoint(-4.01906847777902865, 48.74357188947293906)), -(58, '',ST_MakePoint(-4.0397601095149529, 48.74577305806607797)), -(59, '',ST_MakePoint(-4.01947006578626098, 48.74048898114416062)), -(60, '',ST_MakePoint(-4.02028886503836169, 48.74713526405361819)), -(61, '',ST_MakePoint(-4.01938373920015213, 48.75166818981730898)), -(62, '',ST_MakePoint(-4.01924319927781237, 48.74797778970009432)), -(63, '',ST_MakePoint(-4.01938373920015213, 48.75166818981730898)), -(64, '',ST_MakePoint(-4.02746179346384281, 48.74699628476702884)), -(65, '',ST_MakePoint(-4.02286843896043855, 48.74610257019231341)), -(66, '',ST_MakePoint(-4.03027566309002072, 48.74773403814539563)), -(67, '',ST_MakePoint(-4.0249746786814784, 48.74905338475223004)); +-- ************************************************************ INSERT INTO route (source, target, cost, reverse_cost, geom) SELECT @@ -122,83 +59,6 @@ FROM point a JOIN point b ON a.id = 6 and b.id = 7; -INSERT INTO zone (name, geom) -VALUES ( - 'Ouest', - ST_GeomFromText('POLYGON ((-4.04006335183021825 48.74527596273622976, -4.04018335215793201 48.74608699011085378, -4.03831415412299233 48.74688911543833569, - -4.03751306925087672 48.74790642670545537, -4.0362470851437342 48.74808419558064543, - -4.03551790379234276 48.74758836709975185, -4.0340586080325771 48.7467904270295449, -4.03277208026601119 48.74710004638985339, - -4.03200871853877363 48.74747567812632809, -4.03185064789618419 48.74792315937866505, -4.03215683350077381 48.74899320175573791, - -4.03205429237323543 48.74922608498921761, -4.03166691478030881 48.74923359733361394, -4.03114281568399679 48.74904578838667391, - -4.0308807661358399 48.7487828546816786, -4.03004941206934308 48.7486833505726338, -4.02935404268136477 48.74888051593271143, - -4.0289109984007716 48.74940133740160064, -4.02845758964104927 48.74938631330267924, -4.02691265753342709 48.75020229220042012, - -4.02646823840077861 48.74919297470383128, -4.02523374081008978 48.74919297470383128, -4.02039451025458749 48.74023846408882576, - -4.02114483756962748 48.73943626377466387, -4.02225674016294121 48.738947406438065, -4.02397754179544886 48.73962831357041381, - -4.02538065697272529 48.73975052669476327, -4.0258571866555739 48.74032667027861976, -4.02586697924350378 48.74143763666283746, - -4.02671325838233951 48.74213486863882139, -4.02861212622735732 48.7421740000776893, -4.02938354128939569 48.74270227152060642, - -4.03012480508505977 48.74181692648819109, -4.03039185283764922 48.74200016883640529, -4.0305102449984167 48.7420880017881899, - -4.03059664234290871 48.74219904469969578, -4.03077047712211556 48.74231913839474117, -4.03082014420188894 48.74250473717721377, - -4.03105192390749778 48.74257570123644712, -4.0309774232878377 48.74267395899919819, -4.03107675744738447 48.74277767531815897, - -4.03200451380450087 48.74306964535660569, -4.03283149491465931 48.74322373353422222, -4.03397398375216998 48.74287614025013937, - -4.03418472124766669 48.74247717589914686, -4.03415212522576105 48.74214384376339382, -4.03399951905647836 48.74200450145770702, - -4.03409930001331674 48.74174903956061655, -4.03396769950894019 48.74136087588372135, -4.03453195602962911 48.74114619996144881, - -4.03524812776742436 48.74134656418410572, -4.03571804574113369 48.74237943963194652, -4.03759758965444249 48.7438040319799839, - -4.0375798709083055 48.74410621576857494, -4.03824105738751626 48.74484528633763603, -4.04006335183021825 48.74527596273622976))', 4326) -); - - -INSERT INTO zone (name, geom) -VALUES ( - 'Centre', - ST_GeomFromText('POLYGON(( - -4.02523374081009 48.74919297470383, --4.02360420399038 48.753295235684185, --4.019851331314684 48.75345801690918, --4.014518301722906 48.75231853725851, --4.012641865385059 48.75323012304652, --4.006666897046123 48.7528720020309, --4.009234652034756 48.74313664396521, --4.013036904614079 48.744536828300426, --4.015604659602713 48.74349483436875, --4.01402450268663 48.741541037517905, --4.014326361007127 48.74136749047571, --4.016436329474995 48.74286326394115, --4.018177053460988 48.74218495358343, --4.016937446986115 48.740984843601765, --4.018678170972106 48.73959337586721, --4.020366145746403 48.74016736097527, --4.0203945102545875 48.740238464088826, --4.02523374081009 48.74919297470383 - ))', 4326) -); - - -INSERT INTO zone (name, geom) -VALUES ( - 'Est', - ST_GeomFromText('POLYGON(( - -4.006666897046123 48.7528720020309, --4.005870355067274 48.75026102618178, --4.003629135498721 48.748652881336724, --3.999937714914126 48.7464361648583, --3.9950927255526962 48.74493656593118, --3.9940050748797225 48.745523370840516, --3.9910057957512173 48.745762437542936, --3.9901158997460566 48.74515390188169, --3.991851437957331 48.74306933218229, --3.9887834656682424 48.7393151550319, --3.993896752679784 48.73699956468981, --3.9941353727403235 48.74093375678278, --3.9980896480292487 48.74147327911715, --4.000544025794788 48.740416709111294, --4.00364608658179 48.741630638707136, --4.005077806945022 48.740394228657095, --4.007054944589484 48.740956236995665, --4.008248044892178 48.74050663082754, --4.008657107853101 48.740888796326814, --4.007157210329716 48.74122599876611, --4.00933887945464 48.7431367698581, --4.009234652034756 48.74313664396521, --4.006666897046123 48.7528720020309 - ))', 4326) -); +\COPY point FROM '/tmp/point.csv' (FORMAT CSV, header, ENCODING 'UTF8'); +\COPY route FROM '/tmp/route.csv' (FORMAT CSV, header, ENCODING 'UTF8'); +\COPY zone FROM '/tmp/zone.csv' (FORMAT CSV, header, ENCODING 'UTF8');