Exemplo n.º 1
0
 /**
  * @param array $data An array of data.
  *
  * @return \Geocoder\Model\AddressCollection
  */
 protected function returnResults(array $data = array())
 {
     if (0 < $this->getLimit()) {
         $data = array_slice($data, 0, $this->getLimit());
     }
     foreach ($data as &$resultSet) {
         $uriComune = 'urn:geocodit:comune:' . GwHelpers::encodeForUri($resultSet['locality']);
         $query = "\n\t\t\t\tPREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>\n\t\t\t\tPREFIX gco: <http://linkeddata.center/ontology/geocodit/v1#>\n\t\t\t\tPREFIX owl: <http://www.w3.org/2002/07/owl#>\n\t\t\t\tPREFIX ter: <http://datiopen.istat.it/odi/ontologia/territorio/>\n\t\t\t\tSELECT ?comune ?codIstatComune ?provincia ?codIstatProvincia ?regione ?codIstatRegione ?lat ?long \n\t\t\t\tWHERE {\n\t\t\t\t\tGRAPH <urn:istat:comuni> {\n\t\t\t\t\t\t <{$uriComune}> owl:sameAs [ \n\t\t\t\t\t\t \ta gco:Comune ;  \n\t\t\t\t\t\t \tter:haNome ?comune ;\n\t\t\t\t\t\t \tter:haCodIstat ?codIstatComune ;\n\t\t\t\t\t\t \tter:provincia_di_COM ?uriProvincia\n\t\t\t\t\t\t ] \n\t\t\t\t\t} \n\t\t\t        GRAPH <urn:istat:province> { \n\t\t\t        \t?uriProvincia\n\t\t\t            \tter:haNome ?provincia;  \n\t\t\t\t\t\t\tter:haCodIstat ?codIstatProvincia ;\n\t\t\t            \tter:regione_di_PROV ?uriRegione\n\t\t\t\t\t}\n\t\t\t\t\tGRAPH <urn:istat:regioni> {\n\t\t\t        \t?uriRegione ter:haNome ?regione ;\n\t\t\t        \tter:haCodIstat ?codIstatRegione \n\t\t\t        }\n\t\t\t\t} \n\t\t\t";
         $solutions = $this->sparql->query($query);
         if ($solutions->numRows()) {
             $row = $solutions[0];
             // Ovveride admin list
             $resultSet['adminLevels'] = array(array('name' => $row->regione->getValue(), 'code' => $row->codIstatRegione->getValue(), 'level' => 1), array('name' => $row->provincia->getValue(), 'code' => $row->codIstatProvincia->getValue(), 'level' => 2), array('name' => $row->comune->getValue(), 'code' => $row->codIstatComune->getValue(), 'level' => 3));
         }
     }
     return $this->factory->createFromArray($data);
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function geocode($query)
 {
     $searchUri = 'urn:luogo:' . GwHelpers::encodeForUri($query);
     $solutions = $this->sparql->query($this->makeSparqlQuery($searchUri));
     return $this->returnResults($this->buildResults($solutions));
 }