--- /dev/null
+[submodule "osm2pgsql"]
+ path = osm2pgsql
+ url = https://github.com/openstreetmap/osm2pgsql.git
+ ignore = all
--- /dev/null
+Nominatim was written by Brian Quinion.
--- /dev/null
+ACLOCAL_AMFLAGS = -I osm2pgsql/m4
+
+SUBDIRS = osm2pgsql module nominatim
+
+install:
+ @echo Nominatim needs to be executed directly from this directory. No install necessary.
--- /dev/null
+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
--- /dev/null
+#!/bin/sh
+autoreconf -vfi
--- /dev/null
+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)
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)
{
<?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);
<?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);
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']))
<?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);
<?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);
if ($bShowPolygons && isset($aResult['aPolyPoints']))
{
echo ' polygonpoints=\'';
- echo javascript_renderData($aResult['aPolyPoints']);
+ echo json_encode($aResult['aPolyPoints']);
echo '\'';
}
}
+++ /dev/null
-MODULES = nominatim
-PGXS := $(shell pg_config --pgxs)
-include $(PGXS)
-
-all:
- chmod 755 nominatim.so
--- /dev/null
+MODULES = nominatim
+PGXS := @POSTGRESQL_PGXS@
+include $(PGXS)
+
+all:
+ chmod 755 nominatim.so
+
+install:
+ @echo Library does not need to be installed.
--- /dev/null
+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
+
+++ /dev/null
-
-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 $^
+++ /dev/null
-#!/bin/sh
-autoconf
+++ /dev/null
-/* 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
+++ /dev/null
-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)
-
+++ /dev/null
-#!/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
-
--- /dev/null
+Subproject commit a5809fdaec5e52c00a97bcdfc48b8e13acffadd2
-- 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;
location_rank_search INTEGER;
location_distance FLOAT;
+ location_parent GEOMETRY;
+ location_isaddress BOOLEAN;
tagpairid INTEGER;
-- 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;
-- 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;
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;
--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;
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);
-- 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
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'),
$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;
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);
$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);
$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
// 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;
}
}
- // 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']))
{
$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;
}