DataTables and Web Feature Services (WFS)
DataTables and Web Feature Services (WFS)
[Deleted User]
Posts: 0Questions: 3Answers: 0
Hi There,
I'm wondering whether DataTables can handle a WFS link at all to populate a table?
I'm looking at trying to modify this https://datatables.net/forums/discussion/62822
to work with a WFS.
Specifically https://ecat.ga.gov.au/geonetwork/srv/eng/catalog.search#/metadata/144577
and the bh:Boreholes layer within. The properties listed below should be correct based off the data dictionary PDF on this page.
<link rel="stylesheet" type="text/css"String href="https://cdn.datatables.net/v/dt/jq-3.3.1/jszip-2.5.0/dt-1.10.20/b-1.6.1/b-html5-1.6.1/r-2.2.3/datatables.min.css"/>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.3.1/jszip-2.5.0/dt-1.10.20/b-1.6.1/b-html5-1.6.1/r-2.2.3/datatables.min.js"></script>
<script type="text/javascript" class="init">
$(document).ready(function() {
$('#example').DataTable( {
"ajax":{
"url":"'link here'",
"dataSrc": "features"
},
"columns": [
{ "data": "properties.IDENTIFIER"},
{ "data": "properties.NAME" },
{ "data": "properties.STATUS" }
]
});
});
</script>
</HEAD>
<table id="example" class="display wrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>IDENTIFIER</th>
<th>NAME</th>
<th>STATUS</th>
</tr>
</thead>
<tfoot>
<tr>
<th>IDENTIFIER</th>
<th>NAME</th>
<th>STATUS</th>
</tr>
</tfoot>
</table>
Cheers
RockE
Replies
I took a quick look at the link but did not see where is discussed the format of the returned data. The Ajax docs state the Datatables supports JSON formatted data. Do you know if the WFS link supports returning JSON data?
In addition the row data is expected to be in an array. So either an array of objects or an array with each row being an array. More info in the Data source types doc.
If the data returned is not JSON then you can use the
ajax.dataSrc
option as a function to manipulate the data into a Datatables supported format.Kevin
Hi Kevin,
This "Do you know if the WFS link supports returning JSON data?" got me thinking.
So it seems WFS version 2.0 supports JSON.
I tried this but it didn't work, more digging needed and to see if that link I posted supports version 2.
Cheers
RockE
A WFS Reference
Hi Kevin,
The WFS version is 2 and the capabilities states the output can be json. 2 scrolls down on the mouse and you'll see the reference to outputFormat. paste link into a browser
https://services.ga.gov.au/gis/boreholes/wfs?&service=wfs&version=2.0.0&request=getCapabilities
I'm not sure if the data output shown in the browser is valid json for this link.
https://services.ga.gov.au/gis/boreholes/wfs?&service=wfs&version=2.0.0&request=getFeature&typeNames=bh:Boreholes&maxFeatures=50&outputFormat=application/json
And I appear to have doubled up on this question, can you delete the other pls.
https://datatables.net/forums/discussion/73209
Cheers
RockE
Hi,
That JSON file is 108MB! Yes it looks like something DataTables could use, but that large a file is going to cause problems for the browser - I wouldn't be surprised if the browser were to crash loading such a file (Firefox for me certainly had issues displaying it).
Allan
Hi Alan,
108MB ouch. thanks for looking at it.
Back to the drawing board.
Cheers
RockE
One option would be to proxy it in your own database and then use DataTables with server-side processing against it. Have a cron job or similar that will repopulate your own database from the original source once a week, or however often you think would be needed to keep it up to date (without abusing and getting banned from the source site!).
Allan
Thanks Allan good idea :-)
Hi Allan,
I saved a subset of that json file at 101kb but still can't get DT to display anything as it's just stuck on loading. Could you advise on what I'm doing wrong here please.
Here's a single entry...
Hi Alan,
I saved a subset of the data into a local file. However I still can't get DataTables to display anything as it hangs at loading. Can you advise on what I'm doing wrong here please.
Cheers
Can you pastebin or something your reduced JSON file so I can take a look at it please?
Thanks,
Allan
Here you go a single entry to save into a file.
That looks like it should work to me. Here is a little example of it: http://live.datatables.net/buyinidu/1/edit . I've used local data rather than Ajax loading, but your Ajax config looks fine there.
Perhaps you can give me a link to a page showing the error please?
Allan
Hi Allen,
You can use the example on the bottom of this page it works with the listed url. https://datatables.net/forums/discussion/67714
I've saved that url into a file and then tried it and it wouldn't work (stuck on loading). I must be missing something in the code when using a local file over a url?
Here's the table so you can copy and paste.
Cheers
RockE
Is there anything shown on your browser’s console?
Also I’m not quite clear which example to the thread you are referring to - the one from Kevin?
Allan
Hi Allan,
The code at the end where I have this comment. - "Awesome thanks Kevin it works a treat. Putting the final solution here for others to see."
I think I found a reason for it not working, I saw a post of yours stating ajax won't load a local file. I'll upload the json file to a hosting solution to see if then works. If not then back to the drawing board.
Cheers
RockE
Thanks for the clarification. Yes, Ajax doesn't work with file:// loaded pages due to the security risk of that.
Allan