]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge branch 'patch-1' of https://github.com/Firefishy/Nominatim
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 22 Jul 2012 07:02:55 +0000 (09:02 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 22 Jul 2012 07:02:55 +0000 (09:02 +0200)
31 files changed:
.gitmodules [new file with mode: 0644]
AUTHORS [new file with mode: 0644]
ChangeLog [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
NEWS [new file with mode: 0644]
README [new file with mode: 0644]
autogen.sh [new file with mode: 0755]
configure.ac [new file with mode: 0644]
lib/lib.php
lib/template/address-json.php
lib/template/address-jsonv2.php
lib/template/search-html.php
lib/template/search-json.php
lib/template/search-jsonv2.php
lib/template/search-xml.php
module/Makefile [deleted file]
module/Makefile.in [new file with mode: 0644]
nominatim/Makefile.am [new file with mode: 0644]
nominatim/Makefile.in [deleted file]
nominatim/autogen.sh [deleted file]
nominatim/config.h.in [deleted file]
nominatim/configure.ac [deleted file]
nominatim/nominatim-svn.sh [deleted file]
osm2pgsql [new submodule]
sql/functions.sql
sql/partitions.src.sql
utils/setup.php
utils/specialphrases.php
website/details.php
website/reverse.php
website/search.php

diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..bc2bdd8
--- /dev/null
@@ -0,0 +1,4 @@
+[submodule "osm2pgsql"]
+       path = osm2pgsql
+       url = https://github.com/openstreetmap/osm2pgsql.git
+    ignore = all
diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..704d6be
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Nominatim was written by Brian Quinion.
diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..910ebea
--- /dev/null
@@ -0,0 +1,6 @@
+ACLOCAL_AMFLAGS = -I osm2pgsql/m4
+
+SUBDIRS = osm2pgsql module nominatim
+
+install:
+       @echo Nominatim needs to be executed directly from this directory. No install necessary.
diff --git a/NEWS b/NEWS
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..b7fdedc
--- /dev/null
+++ b/README
@@ -0,0 +1,56 @@
+Nominatim
+=========
+
+Nominatim (from the Latin, 'by name') is a tool to search OpenStreetMap data
+by name and address (geocoding) and to generate synthetic addresses of
+OSM points (reverse geocoding). An instance with up-to-date data can be found
+at http://nominatim.openstreetmap.org. Nominatim is also used as one of the
+sources for the Search box on the OpenStreetMap home page and powers the search
+on the MapQuest Open Initiative websites.
+
+Documentation
+=============
+
+More information about Nominatim, including usage and installation instructions,
+can be found in the OSM wiki at:
+
+http://wiki.openstreetmap.org/wiki/Nominatim
+
+Installation
+============
+
+The following instructions is a quick guide to installation. A more detailed guide
+how to set up your own instance of Nominatim can be found in the wiki:
+
+http://wiki.openstreetmap.org/wiki/Nominatim/Installation
+
+Installation steps:
+
+0. If checking out from git run:
+
+     ./autogen.sh
+
+1. Compile Nominatim:
+
+     ./configure [--enable-64bit-ids]
+     make
+
+2. Get OSM data and import:
+
+     ./utils/setup.php --osm-file <your planet file> --all
+
+3. Point your webserver to the ./website directory.
+
+License
+=======
+
+The source code is available under a GPLv2 license.
+
+Contact and Bugreports
+======================
+
+For questions you can join the geocoding mailinglist, see
+http://lists.openstreetmap.org/listinfo/geocoding
+
+Bugs may be reported on the github project site:
+https://github.com/twain47/Nominatim
diff --git a/autogen.sh b/autogen.sh
new file mode 100755 (executable)
index 0000000..68341a5
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+autoreconf -vfi
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..8d3a58d
--- /dev/null
@@ -0,0 +1,65 @@
+AC_INIT(Nominatim,1.9)
+if git rev-parse HEAD 2>/dev/null >/dev/null; then
+    AC_SUBST([PACKAGE_VERSION], [$PACKAGE_VERSION-git-`git rev-parse --short HEAD`])
+fi
+
+dnl Required autoconf version
+AC_PREREQ(2.61)
+
+AM_INIT_AUTOMAKE([1.9.6 dist-bzip2 std-options check-news])
+
+dnl Additional macro definitions are in here
+AC_CONFIG_MACRO_DIR([osm2pgsql/m4])
+
+dnl Generate configuration header file
+AC_CONFIG_HEADER(nominatim/config.h)
+
+
+dnl Find C compiler
+AC_PROG_CC
+
+dnl Find C++ compiler
+AC_PROG_CXX
+
+dnl pthread
+AX_PTHREAD([], [AC_MSG_ERROR([pthread library required])])
+
+dnl Check for Geos library
+AX_LIB_GEOS
+if test "x$GEOS_VERSION" = "x" 
+then
+  AC_MSG_ERROR([required library not found]);
+fi
+
+dnl Check for Proj library
+AX_LIB_PROJ
+if test "$HAVE_PROJ" = "no" 
+then
+  AC_MSG_ERROR([required library not found]);
+fi
+
+
+dnl Check for PostgresSQL client library
+AX_LIB_POSTGRESQL(8.4)
+if test "x$POSTGRESQL_VERSION" = "x"
+then
+    AC_MSG_ERROR([postgresql client library not found])
+fi
+if test ! -f "$POSTGRESQL_PGXS"
+then
+    AC_MSG_ERROR([postgresql server development library not found])
+fi
+
+dnl Check for bzip2 library
+AX_LIB_BZIP2
+if test "$HAVE_BZIP2" = "no" 
+then
+  AC_MSG_ERROR([required library not found]);
+fi
+
+dnl Check for libxml2 library
+AM_PATH_XML2
+
+AC_CONFIG_SUBDIRS([osm2pgsql])
+
+AC_OUTPUT(Makefile nominatim/Makefile module/Makefile)
index 74430cf7b9d3094e4dbdf00c83b98098a682826b..1959ded3d4748738215e4349f3bb35a1aad25267 100644 (file)
@@ -94,7 +94,7 @@
                return ($a['foundorder'] < $b['foundorder']?-1:1);
        }
 
-       function getPrefferedLangauges()
+       function getPreferredLanguages()
        {
                // If we have been provided the value in $_GET it overrides browser value
                if (isset($_GET['accept-language']) && $_GET['accept-language'])
                return false;
 
                /*
-                       $fTotalFac is a suprisingly good indicator of accuracy
+                       $fTotalFac is a surprisingly good indicator of accuracy
                        $iZoom = 18 + round(log($fTotalFac,32));
                        $iZoom = max(13,min(18,$iZoom));
                */
        }
        
        
-        function javascript_isarray($xVal)
-        {
-                if (!is_array($xVal)) return false;
-                for($i = 0; $i < sizeof($xVal); $i++)
-                {
-                        if (!array_key_exists($i, $xVal)) return false;
-                }
-                return true;
-        }
 
-        function javascript_renderData($xVal, $bForceHash = false)
-        {
-                if (is_array($xVal))
-                {
-                        $aVals = array();
-                        if (javascript_isarray($xVal) && !$bForceHash)
-                        {
-                                foreach($xVal as $sKey => $xData)
-                                {
-                                        $aVals[] = javascript_renderData($xData);
-                                }
-                                return '['.join(',',$aVals).']';
-                        }
-                        else
-                        {
-                                foreach($xVal as $sKey => $xData)
-                                {
-                                        $aVals[] = '"'.addslashes($sKey).'"'.':'.javascript_renderData($xData);
-                                }
-                                return '{'.join(',',$aVals).'}';
-                        }
-                }
-                else
-                {
-                        if (is_bool($xVal)) return $xVal?'true':'false';
-//                     if (is_numeric($xVal)) return $xVal;
-                        return '"'.str_replace('>','\\>',str_replace(array("\n","\r"),'\\n',str_replace(array("\n\r","\r\n"),'\\n',str_replace('"','\\"',$xVal)))).'"';
-                }
-        }
+    function javascript_renderData($xVal)
+    {
+        header("Access-Control-Allow-Origin: *");
+
+        $jsonout = json_encode($xVal);
+
+               if( ! isset($_GET['json_callback'])) {
+                       header("Content-Type: application/json; charset=UTF-8");
+                       echo $jsonout;
+               } else {
+                       if (preg_match('/^[$_\p{L}][$_\p{L}\p{Nd}.[\]]*$/u',$_GET['json_callback'])) {
+                               header("Content-Type: application/javascript; charset=UTF-8");
+                               echo $_GET['json_callback'].'('.$jsonout.')';
+                       } else {
+                               header('HTTP/1.0 400 Bad Request');
+                       }
+               }
+    }
 
        function _debugDumpGroupedSearches($aData, $aTokens)
        {
index 3c7327a32465dc0c568005b1b41d867e2d997c1d..83c8b57cb523944e739901f5994895e72db0858e 100644 (file)
@@ -1,7 +1,4 @@
 <?php
-       header ("Content-Type: application/json; charset=UTF-8");
-       header("Access-Control-Allow-Origin: *");
-
        $aFilteredPlaces = array();
 
        if (!sizeof($aPlace))
                if ($bShowAddressDetails) $aFilteredPlaces['address'] = $aAddress;
        }
 
-       if (isset($_GET['json_callback']) && preg_match('/^[-A-Za-z0-9:_.]+$/',$_GET['json_callback']))
-       {
-               echo $_GET['json_callback'].'('.javascript_renderData($aFilteredPlaces).')';
-       }
-       else
-       {
-               echo javascript_renderData($aFilteredPlaces);
-       }
-
+       javascript_renderData($aFilteredPlaces);
 
index 51d3e1a3027863c51815fccd8dd465855f6cd2fd..9624718273fadcc64679bf4a456150f1d75c9b7a 100644 (file)
@@ -1,7 +1,4 @@
 <?php
-       header ("Content-Type: application/json; charset=UTF-8");
-       header("Access-Control-Allow-Origin: *");
-
        $aFilteredPlaces = array();
 
        if (!sizeof($aPlace))
                if ($bShowAddressDetails && $aAddress && sizeof($aAddress)) $aFilteredPlaces['address'] = $aAddress;
        }
 
-       if (isset($_GET['json_callback']) && preg_match('/^[-A-Za-z0-9:_]+$/',$_GET['json_callback']))
-       {
-               echo $_GET['json_callback'].'('.javascript_renderData($aFilteredPlaces).')';
-       }
-       else
-       {
-               echo javascript_renderData($aFilteredPlaces);
-       }
-
-
+       javascript_renderData($aFilteredPlaces);
index 70ca70e018edb2cd72523859e34704e69a2f3d77..9269672d7d16e857f4af3028c683615b0ba56d17 100644 (file)
@@ -358,7 +358,7 @@ target="_blank">FAQ</a></td>
                        echo ', '.$aResult['aBoundingBox'][1];
                        echo ', '.$aResult['aBoundingBox'][2];
                        echo ', '.$aResult['aBoundingBox'][3];
-                       if (isset($aResult['aPolyPoints'])) echo ', '.javascript_renderData($aResult['aPolyPoints']);
+                       if (isset($aResult['aPolyPoints'])) echo ', '.json_encode($aResult['aPolyPoints']);
                        echo ');\'>';
                }
                elseif (isset($aResult['zoom']))
index 7c695ea5bd51573d19285d2cd21f463ee0932076..4eed52ae122490f8f8d0abbf2bdb6c16d15d12a0 100644 (file)
@@ -1,7 +1,4 @@
 <?php
-       header("Content-Type: application/json; charset=UTF-8");
-       header("Access-Control-Allow-Origin: *");
-
        $aFilteredPlaces = array();
        foreach($aSearchResults as $iResNum => $aPointDetails)
        {
                $aFilteredPlaces[] = $aPlace;
        }
 
-       if (isset($_GET['json_callback']) && preg_match('/^[-A-Za-z0-9:_.]+$/',$_GET['json_callback']))
-       {
-               echo $_GET['json_callback'].'('.javascript_renderData($aFilteredPlaces).')';
-       }
-       else
-       {
-               echo javascript_renderData($aFilteredPlaces);
-       }
+       javascript_renderData($aFilteredPlaces);
index cb09baa48dcbf7e6f634f0225cd4cce9df40c998..095bfb797a6b5b27e1aaddb14ba298bc49db7e5f 100644 (file)
@@ -1,7 +1,4 @@
 <?php
-       header("Content-Type: application/json; charset=UTF-8");
-       header("Access-Control-Allow-Origin: *");
-
        $aFilteredPlaces = array();
        foreach($aSearchResults as $iResNum => $aPointDetails)
        {
                $aFilteredPlaces[] = $aPlace;
        }
 
-       if (isset($_GET['json_callback']) && preg_match('/^[-A-Za-z0-9:_.]+$/',$_GET['json_callback']))
-       {
-               echo $_GET['json_callback'].'('.javascript_renderData($aFilteredPlaces).')';
-       }
-       else
-       {
-               echo javascript_renderData($aFilteredPlaces);
-       }
+       javascript_renderData($aFilteredPlaces);
index 0521de0ec960c1f1a9b53d18e8d6b6d31672dc9e..f8e054e3a1dd673697a35027311c02159f4b8053 100644 (file)
@@ -45,7 +45,7 @@
                        if ($bShowPolygons && isset($aResult['aPolyPoints']))
                        {
                                echo ' polygonpoints=\'';
-                               echo javascript_renderData($aResult['aPolyPoints']);
+                               echo json_encode($aResult['aPolyPoints']);
                                echo '\'';
                        }
                }
diff --git a/module/Makefile b/module/Makefile
deleted file mode 100644 (file)
index 12d66b6..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-MODULES = nominatim
-PGXS := $(shell pg_config --pgxs)
-include $(PGXS)
-
-all:
-       chmod 755 nominatim.so
diff --git a/module/Makefile.in b/module/Makefile.in
new file mode 100644 (file)
index 0000000..0bfa62c
--- /dev/null
@@ -0,0 +1,9 @@
+MODULES = nominatim
+PGXS := @POSTGRESQL_PGXS@
+include $(PGXS)
+
+all:
+       chmod 755 nominatim.so
+
+install:
+       @echo Library does not need to be installed.
diff --git a/nominatim/Makefile.am b/nominatim/Makefile.am
new file mode 100644 (file)
index 0000000..3f65398
--- /dev/null
@@ -0,0 +1,9 @@
+bin_PROGRAMS = nominatim
+
+nominatim_SOURCES = export.c geometry.cpp import.c index.c input.c nominatim.c postgresql.c sprompt.c
+
+AM_CFLAGS = @PTHREAD_CFLAGS@ @POSTGRESQL_CFLAGS@ @XML_CPPFLAGS@ @BZIP2_CFLAGS@  @GEOS_CFLAGS@ @PROJ_CFLAGS@ -DVERSION='"@PACKAGE_VERSION@"'
+AM_CPPFLAGS = @PTHREAD_CFLAGS@ @POSTGRESQL_CFLAGS@ @XML_CPPFLAGS@ @BZIP2_CFLAGS@  @GEOS_CFLAGS@ @PROJ_CFLAGS@
+
+nominatim_LDADD = @PTHREAD_CFLAGS@ @POSTGRESQL_LDFLAGS@ @POSTGRESQL_LIBS@ @XML_LIBS@ @BZIP2_LDFLAGS@ @BZIP2_LIBS@ @GEOS_LDFLAGS@ @GEOS_LIBS@ @PROJ_LDFLAGS@ @PROJ_LIBS@ -lz
+
diff --git a/nominatim/Makefile.in b/nominatim/Makefile.in
deleted file mode 100644 (file)
index f6289d9..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-bindir = @bindir@
-sysconfdir = @sysconfdir@
-datarootdir = @datarootdir@
-datadir = @datadir@
-
-PACKAGE = @PACKAGE_NAME@
-VERSION = @PACKAGE_VERSION@
-SVN:=$(shell svnversion)
-DATADIR = $(datadir)/$(PACKAGE)
-
-
-CC = @CC@ 
-CXX = @CXX@
-
-CFLAGS += -g -O2 -Wall -Wextra
-CFLAGS += $(shell xml2-config --cflags)
-CFLAGS += $(shell geos-config --cflags)
-CFLAGS += -I$(shell pg_config --includedir)
-CFLAGS += -DVERSION=\"$(VERSION)-$(SVN)\"
-CFLAGS += -DHAVE_PTHREAD
-CFLAGS += -DNOMINATIM_DATADIR=\"$(DATADIR)\"
-
-LDFLAGS += $(shell xml2-config --libs) 
-LDFLAGS += $(shell geos-config --libs)
-LDFLAGS += -L$(shell pg_config --libdir) -lpq
-LDFLAGS += -lbz2 -lz
-LDFLAGS += -g -lproj
-LDFLAGS += -lstdc++
-LDFLAGS += -lpthread
-
-SRCS:=$(wildcard *.c) $(wildcard *.cpp)
-OBJS:=$(SRCS:.c=.o)
-OBJS:=$(OBJS:.cpp=.o)
-DEPS:=$(SRCS:.c=.d)
-DEPS:=$(DEPS:.cpp=.d)
-
-APPS:=nominatim
-DATA:=default.style
-
-.PHONY: all clean $(PACKAGE).spec
-
-all: $(APPS)
-
-clean: 
-       rm -f $(APPS) $(OBJS) $(DEPS)
-       rm -f $(PACKAGE)-*.tar.bz2
-       rm -f nominatim.spec
-
-clean-all: clean
-       rm -rf autom4te.cache
-       rm -f config.h
-       rm -f config.log
-       rm -f config.status
-       rm -f configure
-       rm -f Makefile
-
-install: $(APPS)
-       mkdir -p $(DESTDIR)$(bindir)
-       install -m 0755 $(APPS) $(DESTDIR)$(bindir)
-       mkdir -p $(DESTDIR)$(DATADIR)
-       install -m 0644 $(DATA) $(DESTDIR)$(DATADIR)
-
-%.d: %.c
-       @set -e; rm -f $@; \
-       $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
-       sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
-       rm -f $@.$$$$
-
--include $(DEPS)
-
-nominatim: $(OBJS)
-       $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
-
-$(PACKAGE).spec: $(PACKAGE).spec.in
-       sed -e "s/@PACKAGE@/$(PACKAGE)/g; s/@VERSION@/$(VERSION)/g; s/@SVN@/$(SVN)/g;" $^ > $@
-
-$(PACKAGE)-$(VERSION).tar.bz2: $(PACKAGE).spec
-       rm -fR tmp
-       mkdir -p tmp/nominatim
-       cp -p Makefile *.[ch] *.cpp README.txt nominatim-svn.sh tmp/nominatim
-       cp -p nominatim.spec tmp/
-       tar cjf $@ -C tmp .
-       rm -fR tmp
-
-rpm: $(PACKAGE)-$(VERSION).tar.bz2
-       rpmbuild -ta $^
diff --git a/nominatim/autogen.sh b/nominatim/autogen.sh
deleted file mode 100755 (executable)
index 4066e97..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-autoconf
diff --git a/nominatim/config.h.in b/nominatim/config.h.in
deleted file mode 100644 (file)
index f80de9c..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/* config.h.in.  Generated from configure.ac by autoheader.  */
-
-/* Define to the address where bug reports for this package should be sent. */
-#undef PACKAGE_BUGREPORT
-
-/* Define to the full name of this package. */
-#undef PACKAGE_NAME
-
-/* Define to the full name and version of this package. */
-#undef PACKAGE_STRING
-
-/* Define to the one symbol short name of this package. */
-#undef PACKAGE_TARNAME
-
-/* Define to the home page for this package. */
-#undef PACKAGE_URL
-
-/* Define to the version of this package. */
-#undef PACKAGE_VERSION
diff --git a/nominatim/configure.ac b/nominatim/configure.ac
deleted file mode 100644 (file)
index 18e51e4..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-dnl Process this file with autoconf to produce a configure script.
-AC_INIT(nominatim, 0.1)
-
-dnl Generate configuration header file
-AC_CONFIG_HEADER(config.h)
-
-dnl Find C compiler
-AC_PROG_CC
-
-dnl Find C++ compiler
-AC_PROG_CXX
-
-dnl Generate Makefile
-AC_OUTPUT(Makefile)
-
diff --git a/nominatim/nominatim-svn.sh b/nominatim/nominatim-svn.sh
deleted file mode 100755 (executable)
index f717b24..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-
-DATE=$(date +%Y%m%d)
-MODULE="$(basename $0 -svn.sh)"
-SVNROOT=http://svn.openstreetmap.org/applications/utils/nominatim/
-
-set -x
-rm -rf $MODULE
-
-svn export $SVNROOT $MODULE/
-
-## tar it up
-tar cjf $MODULE-${DATE}svn.tar.bz2 $MODULE
-
-## cleanup
-rm -rf $MODULE
-
diff --git a/osm2pgsql b/osm2pgsql
new file mode 160000 (submodule)
index 0000000..a5809fd
--- /dev/null
+++ b/osm2pgsql
@@ -0,0 +1 @@
+Subproject commit a5809fdaec5e52c00a97bcdfc48b8e13acffadd2
index 554ddf32b22b62560325f2207f83bb2a5488948d..25769785b8bfd4fe4a1570e81ff92b369b782125 100644 (file)
@@ -769,6 +769,13 @@ BEGIN
           -- null record of right type
           select * from placex where osm_type = 'N' and osm_id = waynodes[nodeidpos]::INTEGER and type = 'house' limit 1 INTO nextnode;
           select ST_SetSRID(ST_Point(lon::float/10000000,lat::float/10000000),4326) from planet_osm_nodes where id = waynodes[nodeidpos] INTO nextnode.geometry;
+          IF nextnode.geometry IS NULL THEN
+            -- we don't have any information about this point, most likely
+            -- because an excerpt was updated and the node never imported
+            -- because the interpolation is outside the region of the excerpt.
+            -- Give up.
+            RETURN newpoints;
+          END IF;
         ELSE
           select * from placex where place_id = search_place_id INTO nextnode;
         END IF;
@@ -1213,6 +1220,8 @@ DECLARE
 
   location_rank_search INTEGER;
   location_distance FLOAT;
+  location_parent GEOMETRY;
+  location_isaddress BOOLEAN;
 
   tagpairid INTEGER;
 
@@ -1627,24 +1636,37 @@ BEGIN
 -- RAISE WARNING 'ISIN: %', isin_tokens;
 
     -- Process area matches
-    location_rank_search := 100;
+    location_rank_search := 0;
     location_distance := 0;
--- RAISE WARNING '  getNearFeatures(%,''%'',%,''%'')',NEW.partition, place_centroid, search_maxrank, isin_tokens;
+    location_parent := NULL;
+    -- RAISE WARNING '  getNearFeatures(%,''%'',%,''%'')',NEW.partition, place_centroid, search_maxrank, isin_tokens;
     FOR location IN SELECT * from getNearFeatures(NEW.partition, place_centroid, search_maxrank, isin_tokens) LOOP
 
 --RAISE WARNING '  AREA: %',location;
 
-      IF location.rank_search < location_rank_search THEN
-        location_rank_search := location.rank_search;
+      IF location.rank_address != location_rank_search THEN
+        location_rank_search := location.rank_address;
         location_distance := location.distance * 1.5;
       END IF;
 
       IF location.distance < location_distance OR NOT location.isguess THEN
 
+        location_isaddress := NOT address_havelevel[location.rank_address];
+        IF location_isaddress AND location.isguess AND location_parent IS NOT NULL THEN
+            location_isaddress := ST_Contains(location_parent,location.centroid);
+        END IF;
+
+        -- RAISE WARNING '% isaddress: %', location.place_id, location_isaddress;
         -- Add it to the list of search terms
         nameaddress_vector := array_merge(nameaddress_vector, location.keywords::integer[]);
-        INSERT INTO place_addressline VALUES (NEW.place_id, location.place_id, true, NOT address_havelevel[location.rank_address], location.distance, location.rank_address); 
-        address_havelevel[location.rank_address] := true;
+        INSERT INTO place_addressline VALUES (NEW.place_id, location.place_id, true, location_isaddress, location.distance, location.rank_address);
+
+        IF location_isaddress THEN
+            address_havelevel[location.rank_address] := true;
+            IF NOT location.isguess THEN
+                SELECT geometry FROM placex WHERE place_id = location.place_id INTO location_parent;
+            END IF;
+        END IF;
 
 --RAISE WARNING '  Terms: (%) %',location, nameaddress_vector;
 
@@ -1683,13 +1705,13 @@ BEGIN
     -- for long ways we should add search terms for the entire length
     IF st_length(NEW.geometry) > 0.05 THEN
 
-      location_rank_search := 100;
+      location_rank_search := 0;
       location_distance := 0;
 
       FOR location IN SELECT * from getNearFeatures(NEW.partition, NEW.geometry, search_maxrank, isin_tokens) LOOP
 
-        IF location.rank_search < location_rank_search THEN
-          location_rank_search := location.rank_search;
+        IF location.rank_address != location_rank_search THEN
+          location_rank_search := location.rank_address;
           location_distance := location.distance * 1.5;
         END IF;
 
@@ -1739,7 +1761,7 @@ DECLARE
   b BOOLEAN;
   classtable TEXT;
 BEGIN
-  RAISE WARNING 'placex_delete % %',OLD.osm_type,OLD.osm_id;
+  -- RAISE WARNING 'placex_delete % %',OLD.osm_type,OLD.osm_id;
 
   update placex set linked_place_id = null where linked_place_id = OLD.place_id;
   --DEBUG: RAISE WARNING 'placex_delete:01 % %',OLD.osm_type,OLD.osm_id;
@@ -1806,8 +1828,8 @@ BEGIN
 
   --DEBUG: RAISE WARNING 'delete: % % % %',OLD.osm_type,OLD.osm_id,OLD.class,OLD.type;
 
-  -- deleting large polygons can have a massive effect onhe system - require manual intervention to let them through
-  IF st_area(OLD.geometry) > 2 THEN
+  -- deleting large polygons can have a massive effect on the system - require manual intervention to let them through
+  IF st_area(OLD.geometry) > 2 and st_isvalid(OLD.geometry) THEN
     insert into import_polygon_delete values (OLD.osm_type,OLD.osm_id,OLD.class,OLD.type);
     RETURN NULL;
   END IF;
index df4b3b169338361aee77092a6efaadc9ec5e7d3b..324f35bbd22ce8777a735d9d51e93e0a8571d560 100644 (file)
@@ -13,6 +13,17 @@ create type nearfeature as (
   isguess boolean
 );
 
+drop type nearfeaturecentr cascade;
+create type nearfeaturecentr as (
+  place_id BIGINT,
+  keywords int[],
+  rank_address integer,
+  rank_search integer,
+  distance float,
+  isguess boolean,
+  centroid GEOMETRY
+);
+
 CREATE TABLE location_area_country () INHERITS (location_area_large);
 CREATE INDEX idx_location_area_country_geometry ON location_area_country USING GIST (geometry);
 
@@ -46,21 +57,21 @@ CREATE INDEX idx_location_road_-partition-_place_id ON location_road_-partition-
 
 -- end
 
-create or replace function getNearFeatures(in_partition INTEGER, point GEOMETRY, maxrank INTEGER, isin_tokens INT[]) RETURNS setof nearfeature AS $$
+create or replace function getNearFeatures(in_partition INTEGER, point GEOMETRY, maxrank INTEGER, isin_tokens INT[]) RETURNS setof nearfeaturecentr AS $$
 DECLARE
-  r nearfeature%rowtype;
+  r nearfeaturecentr%rowtype;
 BEGIN
 
 -- start
   IF in_partition = -partition- THEN
     FOR r IN 
-      SELECT place_id, keywords, rank_address, rank_search, min(ST_Distance(point, centroid)) as distance, isguess FROM (
+      SELECT place_id, keywords, rank_address, rank_search, min(ST_Distance(point, centroid)) as distance, isguess, centroid FROM (
         SELECT * FROM location_area_large_-partition- WHERE ST_Contains(geometry, point) and rank_search < maxrank
         UNION ALL
         SELECT * FROM location_area_country WHERE ST_Contains(geometry, point) and rank_search < maxrank
       ) as location_area
       GROUP BY place_id, keywords, rank_address, rank_search, isguess, centroid
-      ORDER BY rank_address desc, isin_tokens && keywords desc, isguess asc, 
+      ORDER BY rank_address, isin_tokens && keywords desc, isguess asc,
         ST_Distance(point, centroid) * 
           CASE 
                WHEN rank_address = 16 AND rank_search = 15 THEN 0.2 -- capital city
index 4de5953f7a0e935298e8d760e55ad00a83407be8..07faa2df2a92e4f878be9eba89f6a82d193fdff4 100755 (executable)
@@ -34,7 +34,7 @@
                array('osmosis-init', '', 0, 1, 0, 0, 'bool', 'Generate default osmosis configuration'),
                array('osmosis-init-date', '', 0, 1, 1, 1, 'string', 'Generate default osmosis configuration'),
                array('index', '', 0, 1, 0, 0, 'bool', 'Index the data'),
-               array('index-noanalyse', '', 0, 1, 0, 0, 'bool', 'Do not perform analyse opertions during index (EXPERT)'),
+               array('index-noanalyse', '', 0, 1, 0, 0, 'bool', 'Do not perform analyse operations during index (EXPERT)'),
                array('index-output', '', 0, 1, 1, 1, 'string', 'File to dump index information to'),
                array('create-search-indices', '', 0, 1, 0, 0, 'bool', 'Create additional indices required for search and update'),
                array('create-website', '', 0, 1, 1, 1, 'realpath', 'Create symlinks to setup web directory'),
@@ -43,7 +43,7 @@
 
        $bDidSomething = false;
 
-       // This is a pretty hard core defult - the number of processors in the box - 1
+       // This is a pretty hard core default - the number of processors in the box - 1
        $iInstances = isset($aCMDResult['threads'])?$aCMDResult['threads']:(getProcessorCount()-1);
        if ($iInstances < 1)
        {
        {
                if (!file_exists($sFilename)) fail('unable to find '.$sFilename);
 
-               // Convert database DSN to psql paramaters
+               // Convert database DSN to psql parameters
                $aDSNInfo = DB::parseDSN(CONST_Database_DSN);
                if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
                $sCMD = 'psql -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'].' -f '.$sFilename;
 
        function pgsqlRunScript($sScript)
        {
-               // Convert database DSN to psql paramaters
+               // Convert database DSN to psql parameters
                $aDSNInfo = DB::parseDSN(CONST_Database_DSN);
                if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
                $sCMD = 'psql -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'];
 
        function pgsqlRunRestoreData($sDumpFile)
        {
-               // Convert database DSN to psql paramaters
+               // Convert database DSN to psql parameters
                $aDSNInfo = DB::parseDSN(CONST_Database_DSN);
                if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
                $sCMD = 'pg_restore -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'].' -Fc -a '.$sDumpFile;
 
        function pgsqlRunDropAndRestore($sDumpFile)
        {
-               // Convert database DSN to psql paramaters
+               // Convert database DSN to psql parameters
                $aDSNInfo = DB::parseDSN(CONST_Database_DSN);
                if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
                $sCMD = 'pg_restore -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'].' -Fc --clean '.$sDumpFile;
index 309c5253325693a5c56e499ed00e17952897992b..4381bdfa37b89f6f2f70c7e76c007f11b30773eb 100755 (executable)
@@ -10,7 +10,7 @@
                 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
                 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
                 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
-                array('countries', '', 0, 1, 0, 0, 'bool', 'Create import script for coutry codes and names'),
+                array('countries', '', 0, 1, 0, 0, 'bool', 'Create import script for country codes and names'),
                 array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create import script for search phrases '),
         );
         getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
index ff90cd98ba7dd92a5d9e294c3206dabf649139db..b7a38b2d7cc7c1cea3c000835de8e68b8393475a 100755 (executable)
@@ -33,7 +33,7 @@
        $iParentPlaceID = $oDB->getOne('select parent_place_id from location_property_aux where place_id = '.$iPlaceID);
        if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
 
-       $aLangPrefOrder = getPrefferedLangauges();
+       $aLangPrefOrder = getPreferredLanguages();
        $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
 
        $hLog = logStart($oDB, 'details', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
index b053d764657b545fb1f203f9eb33e5d28aa6205e..c155fa573030fa54cb5a71629727b808dc2be972 100755 (executable)
@@ -28,8 +28,8 @@
        $bShowAddressDetails = true;
        if (isset($_GET['addressdetails'])) $bShowAddressDetails = (bool)$_GET['addressdetails'];
 
-        // Prefered language
-        $aLangPrefOrder = getPrefferedLangauges();
+        // Preferred language
+        $aLangPrefOrder = getPreferredLanguages();
         $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
 
        $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
                        $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', geometry, '.$fSearchDiam.')';
                        $sSQL .= ' and rank_search != 28 and rank_search >= '.$iMaxRank;
                        $sSQL .= ' and (name is not null or housenumber is not null)';
-                       $sSQL .= ' and class not in (\'waterway\')';
+                       $sSQL .= ' and class not in (\'waterway\',\'railway\',\'tunnel\',\'bridge\')';
                        $sSQL .= ' and (ST_GeometryType(geometry) not in (\'ST_Polygon\',\'ST_MultiPolygon\') ';
                        $sSQL .= ' OR ST_DWithin('.$sPointSQL.', ST_Centroid(geometry), '.$fSearchDiam.'))';
                        $sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', geometry) ASC limit 1';
 //var_dump($sSQL);
                        $aPlace = $oDB->getRow($sSQL);
-                       $iPlaceID = $aPlace['place_id'];
-                       $iParentPlaceID = $aPlace['parent_place_id'];
-                       if (PEAR::IsError($iPlaceID))
+                       if (PEAR::IsError($aPlace))
                        {
                                failInternalError("Could not determine closest place.", $sSQL, $iPlaceID); 
                        }
+                       $iPlaceID = $aPlace['place_id'];
+                       $iParentPlaceID = $aPlace['parent_place_id'];
                }
 
                // The point we found might be too small - use the address to find what it is a child of
index 71041080a1fb440adb7b1462c3cc5e3a8535d082..5e2ff371efdaa9ec7b0307b39809e0b4112f8970 100755 (executable)
@@ -36,8 +36,8 @@
        // Show address breakdown
        $bShowAddressDetails = isset($_GET['addressdetails']) && $_GET['addressdetails'];
 
-       // Prefered language    
-       $aLangPrefOrder = getPrefferedLangauges();
+       // Preferred language   
+       $aLangPrefOrder = getPreferredLanguages();
        if (isset($aLangPrefOrder['name:de'])) $bReverseInPlan = true;
        if (isset($aLangPrefOrder['name:ru'])) $bReverseInPlan = true;
        if (isset($aLangPrefOrder['name:ja'])) $bReverseInPlan = true;
@@ -53,7 +53,7 @@
                }
        }
 
-  // Only certain ranks of feature
+       // Only certain ranks of feature
        if (isset($_GET['featureType']) && !isset($_GET['featuretype'])) $_GET['featuretype'] = $_GET['featureType'];
 
        if (isset($_GET['featuretype']))
@@ -96,7 +96,7 @@
        {
                $sQuery = substr($_SERVER['PATH_INFO'], 1);
 
-               // reverse order of '/' seperated string
+               // reverse order of '/' separated string
                $aPhrases = explode('/', $sQuery);              
                $aPhrases = array_reverse($aPhrases); 
                $sQuery = join(', ',$aPhrases);
                 $sQuery = str_ireplace(array('New York, ny','new york, new york', 'New York ny','new york new york'), 'new york city, ny', $sQuery);
                if (isset($aLangPrefOrder['name:en']))          
                {
-                       $sQuery = preg_replace('/\\bil\\b/','illinois', $sQuery);
-                       $sQuery = preg_replace('/\\bal\\b/','alabama', $sQuery);
-                       $sQuery = preg_replace('/\\bla\\b/','louisiana', $sQuery);
-                       $sQuery = preg_replace('/\\bde louisiana\\b/','de la', $sQuery);
+                       $sQuery = preg_replace('/,\s*il\s*(,|$)/',', illinois\1', $sQuery);
+                       $sQuery = preg_replace('/,\s*al\s*(,|$)/',', alabama\1', $sQuery);
+                       $sQuery = preg_replace('/,\s*la\s*(,|$)/',', louisiana\1', $sQuery);
                }
 
                // If we have a view box create the SQL
                                                                                        if ($aSearch['sCountryCode'] === false)
                                                                                        {
                                                                                                $aSearch['sCountryCode'] = strtolower($aSearchTerm['country_code']);
-                                                                                               // Country is almost always at the end of the string - increase score for finding it anywhere else (opimisation)
+                                                                                               // Country is almost always at the end of the string - increase score for finding it anywhere else (optimisation)
                                                                                                if ($iWordset+1 != sizeof($aPhrases[$iPhrase]['wordsets']) || $iPhrase+1 != sizeof($aPhrases)) $aSearch['iSearchRank'] += 5;
                                                                                                if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch;
                                                                                        }