From: Sarah Hoffmann Date: Sun, 22 Jul 2012 07:02:55 +0000 (+0200) Subject: Merge branch 'patch-1' of https://github.com/Firefishy/Nominatim X-Git-Tag: v2.0.0~42 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/d396505786ce3be105249c740e0d3365beb4ef10?hp=a7c8e8897ba93083fa829b700d78c083c025e432 Merge branch 'patch-1' of https://github.com/Firefishy/Nominatim --- diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..bc2bdd81 --- /dev/null +++ b/.gitmodules @@ -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 index 00000000..704d6bed --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Nominatim was written by Brian Quinion. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 00000000..e69de29b diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 00000000..910ebea7 --- /dev/null +++ b/Makefile.am @@ -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 index 00000000..e69de29b diff --git a/README b/README new file mode 100644 index 00000000..b7fdedca --- /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 --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 index 00000000..68341a59 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,2 @@ +#!/bin/sh +autoreconf -vfi diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..8d3a58d8 --- /dev/null +++ b/configure.ac @@ -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) diff --git a/lib/lib.php b/lib/lib.php index 74430cf7..1959ded3 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -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']) @@ -273,7 +273,7 @@ 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)); */ @@ -592,45 +592,25 @@ } - 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) { diff --git a/lib/template/address-json.php b/lib/template/address-json.php index 3c7327a3..83c8b57c 100644 --- a/lib/template/address-json.php +++ b/lib/template/address-json.php @@ -1,7 +1,4 @@ FAQ 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'])) diff --git a/lib/template/search-json.php b/lib/template/search-json.php index 7c695ea5..4eed52ae 100644 --- a/lib/template/search-json.php +++ b/lib/template/search-json.php @@ -1,7 +1,4 @@ $aPointDetails) { @@ -55,11 +52,4 @@ $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); diff --git a/lib/template/search-jsonv2.php b/lib/template/search-jsonv2.php index cb09baa4..095bfb79 100644 --- a/lib/template/search-jsonv2.php +++ b/lib/template/search-jsonv2.php @@ -1,7 +1,4 @@ $aPointDetails) { @@ -55,11 +52,4 @@ $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); diff --git a/lib/template/search-xml.php b/lib/template/search-xml.php index 0521de0e..f8e054e3 100644 --- a/lib/template/search-xml.php +++ b/lib/template/search-xml.php @@ -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 index 12d66b63..00000000 --- a/module/Makefile +++ /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 index 00000000..0bfa62cc --- /dev/null +++ b/module/Makefile.in @@ -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 index 00000000..3f65398a --- /dev/null +++ b/nominatim/Makefile.am @@ -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 index f6289d92..00000000 --- a/nominatim/Makefile.in +++ /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 index 4066e97c..00000000 --- a/nominatim/autogen.sh +++ /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 index f80de9c3..00000000 --- a/nominatim/config.h.in +++ /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 index 18e51e42..00000000 --- a/nominatim/configure.ac +++ /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 index f717b24c..00000000 --- a/nominatim/nominatim-svn.sh +++ /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 index 00000000..a5809fda --- /dev/null +++ b/osm2pgsql @@ -0,0 +1 @@ +Subproject commit a5809fdaec5e52c00a97bcdfc48b8e13acffadd2 diff --git a/sql/functions.sql b/sql/functions.sql index 554ddf32..25769785 100644 --- a/sql/functions.sql +++ b/sql/functions.sql @@ -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 ont he 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; diff --git a/sql/partitions.src.sql b/sql/partitions.src.sql index df4b3b16..324f35bb 100644 --- a/sql/partitions.src.sql +++ b/sql/partitions.src.sql @@ -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 diff --git a/utils/setup.php b/utils/setup.php index 4de5953f..07faa2df 100755 --- a/utils/setup.php +++ b/utils/setup.php @@ -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) { @@ -520,7 +520,7 @@ { 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; @@ -548,7 +548,7 @@ 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']; @@ -572,7 +572,7 @@ 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; @@ -600,7 +600,7 @@ 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; diff --git a/utils/specialphrases.php b/utils/specialphrases.php index 309c5253..4381bdfa 100755 --- a/utils/specialphrases.php +++ b/utils/specialphrases.php @@ -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); diff --git a/website/details.php b/website/details.php index ff90cd98..b7a38b2d 100755 --- a/website/details.php +++ b/website/details.php @@ -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); diff --git a/website/reverse.php b/website/reverse.php index b053d764..c155fa57 100755 --- a/website/reverse.php +++ b/website/reverse.php @@ -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); @@ -95,18 +95,18 @@ $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 diff --git a/website/search.php b/website/search.php index 71041080..5e2ff371 100755 --- a/website/search.php +++ b/website/search.php @@ -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); @@ -109,10 +109,9 @@ $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 @@ -447,7 +446,7 @@ 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; }