1/*  Part of SWI-Prolog
    2
    3    Author:        Willem Robert van Hage
    4    E-mail:        W.R.van.Hage@vu.nl
    5    WWW:           http://www.few.vu.nl/~wrvhage
    6    Copyright (c)  2009-2012, Vrije Universiteit Amsterdam
    7    All rights reserved.
    8
    9    Redistribution and use in source and binary forms, with or without
   10    modification, are permitted provided that the following conditions
   11    are met:
   12
   13    1. Redistributions of source code must retain the above copyright
   14       notice, this list of conditions and the following disclaimer.
   15
   16    2. Redistributions in binary form must reproduce the above copyright
   17       notice, this list of conditions and the following disclaimer in
   18       the documentation and/or other materials provided with the
   19       distribution.
   20
   21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   32    POSSIBILITY OF SUCH DAMAGE.
   33*/
   34
   35:- module(wgs84,
   36          [  wgs84_candidate/2,
   37             wgs84_candidate/3,
   38             coordinates/3,
   39             coordinates/4,
   40             lat/2,
   41             long/2,
   42             alt/2
   43          ]).   44
   45:- use_module(library(semweb/rdf_db)).   46:- rdf_register_ns(wgs84, 'http://www.w3.org/2003/01/geo/wgs84_pos#').   47
   48:- rdf_meta(wgs84_candidate(r,?)).   49:- rdf_meta(wgs84_candidate(r,?,?)).
 wgs84_candidate(?URI, ?Point) is nondet
Finds URI-Shape pairs of RDF resources that are place-tagged with W3C WGS84 properties (i.e. lat, long, alt). Point = point(?Lat,?Long) ; Point = point(?Lat,?Long,?Alt).
   57wgs84_candidate(URI,point(Lat,Long)) :-
   58    wgs84_candidate(URI,point(Lat,Long),_).
   59
   60wgs84_candidate(URI,point(Lat,Long,Alt)) :-
   61    wgs84_candidate(URI,point(Lat,Long,Alt),_).
 wgs84_candidate(?URI, ?Point, +Source) is nondet
Finds URI-Shape pairs of RDF resources that are place-tagged with W3C WGS84 properties (i.e. lat, long, alt). From RDF that was loaded from a certain Source.
   69wgs84_candidate(URI,point(Lat,Long),Source) :-
   70    nonvar(Source),
   71    \+alt(URI,_,_),
   72    lat(URI,Lat,Source),
   73    long(URI,Long,Source).
   74wgs84_candidate(URI,point(Lat,Long),Source) :-
   75    var(Source),
   76    \+alt(URI,_,_),
   77    lat(URI,Lat,Source1),
   78    (   Source1 = Source:_
   79    ->  true
   80    ;   Source = Source1
   81    ),
   82    long(URI,Long,Source).
   83
   84wgs84_candidate(URI,point(Lat,Long,Alt),Source) :-
   85    lat(URI,Lat,Source),
   86    long(URI,Long,Source),
   87    alt(URI,Alt,Source).
 lat(?URI, ?Lat) is nondet
Finds the WGS84 latitude of resource URI (and vice versa) using the rdf_db index. Lat is a number.
   94lat(URI,Lat) :-
   95    lat(URI,Lat,_).
   96lat(URI,Lat,Source) :-
   97    rdf(URI,wgs84:lat,literal(LatAtom),Source),
   98    (   LatAtom = type(_,LatVal)
   99    ->  (   atom(LatVal)
  100        ->  atom_number(LatVal,Lat)
  101        ;   Lat = LatVal
  102        )
  103    ;   atom_number(LatAtom,Lat)
  104    ).
 long(?URI, ?Long) is nondet
Finds the WGS84 longitude of resource URI (and vice versa) using the rdf_db index. Long is a number.
  111long(URI,Long) :-
  112    long(URI,Long,_).
  113long(URI,Long,Source) :-
  114    rdf(URI,wgs84:long,literal(LongAtom),Source),
  115    (   LongAtom = type(_,LongVal)
  116    ->  (   atom(LongVal)
  117        ->  atom_number(LongVal,Long)
  118        ;   Long = LongVal
  119        )
  120    ;   atom_number(LongAtom,Long)
  121    ).
 alt(?URI, ?Alt) is nondet
Finds the WGS84 altitude of resource URI (and vice versa) using the rdf_db index. Alt is a number.
  128alt(URI,Alt) :-
  129    alt(URI,Alt,_).
  130alt(URI,Alt,Source) :-
  131    rdf(URI,wgs84:alt,literal(AltAtom),Source),
  132    (   AltAtom = type(_,AltVal)
  133    ->  (   atom(AltVal)
  134        ->  atom_number(AltVal,Alt)
  135        ;   Alt = AltVal
  136        )
  137    ;   atom_number(AltAtom,Alt)
  138    ).
 coordinates(?URI, ?Lat, ?Long) is nondet
 coordinates(?URI, ?Lat, ?Long, ?Alt) is nondet
Finds the WGS84 latitude, longitude and possibly altitude of resource URI (and vice versa) using the rdf_db index. Lat, Long, and Alt are numbers.
  147coordinates(URI,Lat,Long) :-
  148    wgs84_candidate(URI,point(Lat,Long)).
  149
  150coordinates(URI,Lat,Long,Alt) :-
  151    wgs84_candidate(URI,point(Lat,Long,Alt))