Why does this code work
Because you don’t send the result to the Geo Module.
JSON and XML are different data formats with different semantics. For example, JSON provides no support for namespaces. This is why colons in the JSON key will not be interpreted as namespace delimiters. See the following valid example:
json:parse('{ ":::": "a" }')
It would raise errors if we always assumed that strings before colons are to be interpreted as namespace prefixes.
If you want to process JSON data as valid GEO data, you’ll need to post-process your parsed input, e.g. via XQuery Update.
On Fri, Nov 24, 2017 at 6:15 PM, E. Wray Johnson wray.johnson@gmail.com wrote:
declare namespace gml="http://www.opengis.net/gml"; import module namespace geo = "http://expath.org/ns/geo"; declare option output:method 'json'; let $x := element json { attribute type {'object'}, element coords {attribute type {'object'}, element gml:Point {attribute type {'object'}, element gml:coordinates { "0,0" } } } } let $y := json:serialize($x) return json:parse($y)
I tried without success, adding declare option output:method 'json';
On Fri, Nov 24, 2017 at 11:45 AM, Christian Grün christian.gruen@gmail.com wrote:
Run…
let $opt := map { "lax": true() } return json:parse('{ "coords":{ "gml:Point":{ "gml:coordinates":"0,0" } } }', $opt )/json/coords/*
…and I’m pretty sure you’ll see what is wrong if you compare the result with the examples in the documentation (http://docs.basex.org/wiki/Geo_Module#geo:distance).
On Fri, Nov 24, 2017 at 5:31 PM, E. Wray Johnson wray.johnson@gmail.com wrote:
What is wrong with this code?
import module namespace geo = 'http://expath.org/ns/geo'; declare namespace gml='http://www.opengis.net/gml';
let $opt := map { "lax": true() } let $y := json:parse('{ "coords":{ "gml:Point":{ "gml:coordinates":"0,0" } } }', $opt )
let $x := json:parse('{ "coords":{ "gml:Point":{ "gml:coordinates":"-123.45,45.343" } } }', $opt )
return geo:distance($x/json/coords/*, $y/json/coords/*)