Peb added a comment.

  I have implemented for GeoJSON, GPX, and KML. here's the snippet. three small 
npm libraries are used : wicket (parsing WKT), 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 );
        };

TASK DETAIL
  https://phabricator.wikimedia.org/T216601

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Peb
Cc: Husky, Peb, Frettie, Geertivp, Salgo60, Pigsonthewing, Aklapper, 
darthmon_wmde, alaa_wmde, Ferenczy, sarhan.alaa, Samuditha24, IM3847, 
Dinadineke, Nandana, kostajh, tabish.shaikh91, Lahi, Gq86, 
Lucas_Werkmeister_WMDE, GoranSMilovanovic, Soteriaspace, Jayprakash12345, 
Chicocvenancio, JakeTheDeveloper, MichaelSchoenitzer_WMDE, QZanden, EBjune, 
merbst, LawExplorer, Jogi_don, _jensen, rosalieper, D3r1ck01, Jonas, Xmlizer, 
jkroll, Smalyshev, Wikidata-bugs, Jdouglas, Jdlrobson, aude, Tobias1984, 
Manybubbles, Lydia_Pintscher, TheDJ, Mbch331, Rxy
_______________________________________________
Wikidata-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs

Reply via email to