API to calculate the number of locks between locations

Started by Greg, Sep 05, 2016, 03:06 PM

Previous topic - Next topic

ghareth

Hi, I am currently planning  a big trip from London to the North West and Canalplan is extremely helpful. I would like to throw together all my planning information in QGIS using shapefiles from CRT and OpenStreetMap.

It would be nice to also use information from the Canal Plan Gazetteer. Are you also able to make this information available through a JSON API. I am particularly interested in the mooring quality field.

Out of interest I cannot find any licence information on your website. Reading the post above it sounds like you provide on something like Creative Commons-Attribution or are you more restrictive?

Administrator

There's already a rough-and-ready API call to do that:
https://canalplan.eu/cgi-bin/api.cgi?mode=place&id=xxxx will return the information  in JSON format where xxxx is a canalplan ID.  So, for example, https://canalplan.eu/cgi-bin/api.cgi?mode=place&id=bu4s returns the info for the A6 Road Bridge in Bedford:

[{\"osx\":\"505075\",\"type\":\"2\",\"mouth\":\"\",\"changeline\":\"\",\"mooring_JSON\":{\"type\":\"0\",\"rating\":\"40\",\"detail\":\"Moorings for town by park.\"},\"name\":\"A6 Road Bridge (Bedford)\",\"roadname\":\"\",\"lock_JSON\":{},\"latitude\":\"52.1345384341288\",\"osy\":\"249580\",\"misc\":\"\",\"hlng\":\"0W27'58\\\"\",\"detail\":\"\",\"sunset\":\"4:58 PM\",\"winding_JSON\":{},\"hlat\":\"52N8'4\\\"\",\"graphic\":\"h1\",\"areas\":\"\",\"osgrid\":\"TL050495\",\"postcode\":\"MK42 0AR\",\"spur\":\"\",\"longitude\":\"-0.466232299804687\",\"access_JSON\":{\"verified\":\"yes\",\"show\":\"noshow\",\"access\":\"no\"},\"sunrise\":\"7:34 AM\",\"roadnumber\":\"\",\"attributes\":\"Z=\",\"id\":\"bu4s\",\"bridge_JSON\":{\"crossing\":\"0\",\"under\":false,\"missing\":false},\"navnote\":\"\"}]

Mooring information is in mooring_JSON.  This is all very poorly, if at all, documented but if you can make intelligent guesses you're free to use it for your own purposes for the moment.  

This database extract should help you decode the \"type\" and \"rating\" for the mooring_JSON:
INSERT INTO \"mooring_types\" VALUES(0,0,'unrated','no information available');
INSERT INTO \"mooring_types\" VALUES(0,10,'impossible','don''t try it!');
INSERT INTO \"mooring_types\" VALUES(0,20,'tolerable','it''s just about possible if really necessary');
INSERT INTO \"mooring_types\" VALUES(0,30,'ok','a perfectly adequate mooring');
INSERT INTO \"mooring_types\" VALUES(0,40,'good','a nice place to moor');
INSERT INTO \"mooring_types\" VALUES(0,50,'excellent','this is a really good mooring');
INSERT INTO \"mooring_types\" VALUES(1,0,'unrated','no information available');
INSERT INTO \"mooring_types\" VALUES(1,10,'pins','mooring pins are needed');
INSERT INTO \"mooring_types\" VALUES(1,20,'piling','piling suitable for hooks');
INSERT INTO \"mooring_types\" VALUES(1,30,'rings','mooring rings or bollards are available');

0=ratings and 1=types

I need to work out hard how to license this (it will be suitably permissive, but it does cost server load without the advertising revenue we get from normal use) and indeed all the data and code.

Note that the mooring info is still pretty patchy - it's the main reason I've not yet coded anything to use it into the route planner.

Administrator

Quote from: AegidianEasily done. Again, thank you.

That looks great.  I do reserve the right at some stage to be slightly more restrictive in terms of use at some stage in the future, but you've earned a fair amount of credit with contributions to the database for quite some time yet!

ghareth

Thank you for the details of the JSON.  Very helpful.
Hopefully we can contribute to the database on our way up.

Laurence

Posting this in an existing API thread because it seemed to be relevant to earlier questions:
   - so do start a separate thread if more appropriate
Forgive me if this has been answered as I don't know where to look:

Love CanalPlanAC and staring to think how to use it on a daily basis.

Is there a Gazetteer API to choose the sections to be displayed, instead of using preference settings?

I am setting up a route spreadsheet for our helmsperson with hyperlinks to the Gazetteer URLs
 e.g. https://canalplan.org.uk/place/tghr  etc.
I would like to set the sections to be displayed as shown in the Gazetteer configuration list:
Information
Photos
Comments
Map
Blogs
Geograph
etc.
etc.

Linking directly from a spreadsheet may mean that the users browser is not logged onto the CanalPlanAC website so preferences will not be applied, and we don't want all the photos, google search and other links.

I don't need the JSON interface as I am quite happy to display the page returned by the Gazetteer.

I was hoping for something like:
https://canalplan.org.uk/place/<4charaterid>?display=\"some string defining the list of fields\"

Thanks Laurence

Stephen Atty

That would be quite  a serious change to the url handling code so I suspect it wouldn't happen quickly


Administrator

I don't think it would be too difficult to add an interface so you can say \"link to this place as displayed\" - feel free to drop it into the issue tracker as a new idea.

Aegidian

I'm futzing around in PHP trying to get the 'mode=plan' section of the API to return a route that will accept exclusions (particularly the Tidal Severn, waterway id: mc07.)

I've been digging around and for some reason recall that you can specify pref=options when building the API call, however I can't seem to stumble on the right format for 'options'.

I've tried sending plaintext pref = 'optcheck_wex_mc07', and pref 'wex_mc07' and an associated array of values pref = { optcheck_wex_mc07 : true }

// fetch POST routine
//
// exclude optcheck_wex_m0c7 - Tidal River Severn
//
$url = 'https://canalplan.uk/cgi-bin/api.cgi';
$opts = ['optcheck_wex_m0c7' => true];
$opts = 'optcheck_wex_m0c7';
$opts = ['wex' => 'm0c7'];
$opts = 'wex_mc07';
//$opts = '';
$data = ['mode' => 'plan', 'start' => $place1['id'], 'end' => $place2['id'] , 'pref' => $opts];

var_dump($data);

// use key 'http' even if you send the request to https://...
$options = [
'http' => [
'header' => \"Content-type: application/x-www-form-urlencoded\\r\\n\",
'method' => 'POST',
'content' => http_build_query($data),
],
];

$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);


var_dump($result);

How should I be building this part of the query?

Stephen Atty

That's a good question - I think this needs nick. I think it may well be a JSON structure you need to pass in