Page MenuHomePhabricator

Allow download of Wikidata query results in GPS-friendly format(s)
Open, Needs TriagePublic

Description

When a Wikidata Query Service query results in data that can be mapped, the user should be able to download that data in one or more format(s) suitable for import into mapping tools; such as GPS Exchange Format (GPX), Keyhole Markup Language (KML), etc.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

I can help with this too along with RDF download task

It would also be really nice if this could export to either GeoJSON or TopoJSON, because it makes it a lot easier to integrate query results in visualisation tools. For example, Vega-lite maps.

I have implemented for GeoJSON, GPX, and KML. here's the snippet. four small npm libraries are used : wicket (parsing WKT), geojson, togpx, tokml

	/**
	 * Get the result of the submitted query as GeoJSON
	 *
	 * @return {object}
	 */
	SELF.prototype._getResultAsGeoJson = function() {
		var output = [],
			data = this._rawData;
		var wkt = new Wkt.Wkt();
		output = this._processData( data, function( row, out ) {
			var newRow = {};
			for ( var rowVar in row ) {
				var binding = ( row[rowVar] || {} );
				if ( binding.type === 'literal' && binding.datatype && binding.datatype === 'http://www.opengis.net/ont/geosparql#wktLiteral' ) {
					wkt.read( binding.value );
					newRow._lat = wkt.components[0].y;
					newRow._lng = wkt.components[0].x;
				} else { 
					newRow[rowVar] = binding.value;
 				}
			}
			out.push( newRow );
			return out;
		}, output );
		return GeoJSON.parse( output, { Point: ['_lat', '_lng'] } );
	};

	/**
	 * Get the result of the submitted query as GeoJSON
	 *
	 * @return {string}
	 */
	SELF.prototype.getResultAsGeoJson = function() {
		return JSON.stringify( this._getResultAsGeoJson() );
	};

	/**
	 * Get the result of the submitted query as GPX
	 *
	 * @return {string}
	 */
	SELF.prototype.getResultAsGPX = function() {
		var gj = this._getResultAsGeoJson();
		return togpx( gj );
	};

	/**
	 * Get the result of the submitted query as KML
	 *
	 * @return {string}
	 */
	SELF.prototype.getResultAsKML = function() {
		var gj = this._getResultAsGeoJson();
		return tokml( gj );
	};

any ideas on how to enable/unhide download menu item only when the query result containing geolocation? should i make separate task on the board?

What needs to be done for this to be be deployed to the live Query Service? When might that happen?

I have implemented for GeoJSON, GPX, and KML. here's the snippet. four small npm libraries are used : wicket (parsing WKT), geojson, togpx, tokml

For those interested: @Peb’s implementation is live at https://pebbie.org/wdqs/ (example query: http://tinyurl.com/yyyo3gn5 )
The unmerged patcheset lives at https://gerrit.wikimedia.org/r/#/c/wikidata/query/gui/+/516662/

What needs to be done for this to be be deployed to the live Query Service?

I have some feedback from the Wikidata team:

the person who submitted a code snipped needs to turn it into a proper patch in Gerrit so it can be reviewed and merged and then deployed. (I don't know how much additional work is left on top of the code snippet they pasted.)

What needs to be done for this to be be deployed to the live Query Service?

I have some feedback from the Wikidata team:

the person who submitted a code snipped needs to turn it into a proper patch in Gerrit so it can be reviewed and merged and then deployed. (I don't know how much additional work is left on top of the code snippet they pasted.)

@Pigsonthewing Please see my comment just above:

@Pigsonthewing Please see my comment just above:

The unmerged patcheset lives at https://gerrit.wikimedia.org/r/#/c/wikidata/query/gui/+/516662/

This is beyond my skill set (I'm just the messenger!), but I note that that has a red label: "Cannot Merge".

@Lydia_Pintscher Please can you kindly delegate to someone who can move this forward, or at least tell us what is needed to do so?

Gehel added a subscriber: Gehel.

This was discussed by the Search Platform team. Brief summary:

Some of the download formats are managed by Blazegraph directly, via content negotiation. This is definitely not something we would like to extend as it would increase our reliance on Blazegraph. Having this implemented as part of WDQS-UI seems reasonably fine. Even better would be a dedicated service which could be reused on other SPARQL endpoint.