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 project: Wikidata. · View Herald TranscriptFeb 20 2019, 9:57 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Peb added a subscriber: Peb.May 15 2019, 12:56 PM

I can help with this too along with RDF download task

Husky added a subscriber: Husky.May 17 2019, 10:53 AM

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.

Peb added a comment.EditedMay 18 2019, 3:51 PM

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 );
	};
Peb added a comment.May 18 2019, 3:54 PM

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?

For uMap https://umap.openstreetmap.fr/ , see an example workflow some people currently use: https://bylg.hypotheses.org/543 .