Questo capitolo elenca i passi necessari all'installazione di PostGIS.
Per compilare, assumendo di avere tutte le dipendenze nel percorso di ricerca:
tar -xvzf postgis-3.4.5dev.tar.gz cd postgis-3.4.5dev ./configure make make install
Una volta installato PostGIS, bisogna abilitarlo individualmente nei database in cui si vuole usare.
![]() | |
Ormai molti sistemi operativi contengono pacchetti precompilati per PostgreSQL/PostGIS. In molti casi la compilazione è necessaria solamente se volete l'ultimissima versione o se siete uno dei manutentori dei pacchetti. This section includes general compilation instructions, if you are compiling for Windows etc or another OS, you may find additional more detailed help at PostGIS User contributed compile guides and PostGIS Dev Wiki. Pre-Built Packages for various OS are listed in PostGIS Pre-built Packages Se siete un utente Windows, potete reperire le versioni stabili tramite Stackbuilder o la pagina PostGIS Windows download. Inoltre potete scaricare le ultimissime versioni sperimentati per Windows, che vengono create una o due volte alla settimana, quando ci sono aggiornamenti interessanti. Potete utilizzare queste versioni per fare prove con le versioni in via di sviluppo di PostGIS |
The PostGIS module is an extension to the PostgreSQL backend server. As such, PostGIS 3.4.5dev requires full PostgreSQL server headers access in order to compile. It can be built against PostgreSQL versions 12 - 16. Earlier versions of PostgreSQL are not supported.
Refer to the PostgreSQL installation guides if you haven't already installed PostgreSQL. https://www.postgresql.org .
![]() | |
Per le funzionalità legate a GEOS, quando installate PostgresSQL è possibile che dobbiate esplicitamente linkare PostgreSQL con la libreria C++ standard: LDFLAGS=-lstdc++ ./configure [YOUR OPTIONS HERE] Questa è una soluzione alla buona per l'interazione con finte eccezioni C++ con gli strumenti di sviluppo più datati. Se riscontrate problemi anomali (chiusura inattesa del server o casi simili), provate questo trucco. Ciò richiederà ovviamente di ricompilare PostgreSQL da zero. |
I passaggi seguenti ripercorrono la procedura per configurare e compilare il sorgente di PostGIS. Sono scritti per utenti Linux e non funzioneranno su Windows o Mac.
Retrieve the PostGIS source archive from the downloads website https://postgis.net/stuff/postgis-3.4.5dev.tar.gz
wget https://postgis.net/stuff/postgis-3.4.5dev.tar.gz tar -xvzf postgis-3.4.5dev.tar.gz cd postgis-3.4.5dev
Questo passaggio creerà una cartella denominata postgis-3.4.5dev
nella cartella di lavoro attuale.
In alternativa, potete ottenere una copia del sorgente dalla repository git https://git.osgeo.org/gitea/postgis/postgis/ .
git clone https://git.osgeo.org/gitea/postgis/postgis.git postgis cd postgis sh autogen.sh
Entrate nella cartella appena creata, postgis-3.4.5dev
, per proseguire con l'installazione.
./configure
PostGIS necessita dei seguenti requisiti per la compilazione e l'utilizzo:
Necessari
PostgreSQL 12 - 16. A complete installation of PostgreSQL (including server headers) is required. PostgreSQL is available from https://www.postgresql.org .
For a full PostgreSQL / PostGIS support matrix and PostGIS/GEOS support matrix refer to https://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS
Compilatore GNU C (gcc
). Per la compilazione possono essere utilizzati anche altri compilatori ANSI C, ma abbiamo riscontrato molti meno problemi nella compilazione con gcc
.
GNU Make (gmake
or make
). Per molti sistem, GNU make
è la versione di default di make. Potete controllare la versione tramite il comando make -v
. Altre versioni di make
potrebbero non elaborare il Makefile
di PostGIS in modo corretto.
Proj reprojection library. Proj 6.1 or above is required. The Proj library is used to provide coordinate reprojection support within PostGIS. Proj is available for download from https://proj.org/ .
GEOS geometry library, version 3.6 or greater, but GEOS 3.12+ is required to take full advantage of all the new functions and features. GEOS is available for download from https://libgeos.org .
LibXML2, version 2.5.x or higher. LibXML2 is currently used in some imports functions (ST_GeomFromGML and ST_GeomFromKML). LibXML2 is available for download from https://gitlab.gnome.org/GNOME/libxml2/-/releases.
JSON-C, version 0.9 or higher. JSON-C is currently used to import GeoJSON via the function ST_GeomFromGeoJson. JSON-C is available for download from https://github.com/json-c/json-c/releases/.
GDAL, version 2+ is required 3+ is preferred. This is required for raster support. https://gdal.org/download.html.
Se si compila con PostgreSQL+JIT, e' necessaria una versione di LLVM >=6 https://trac.osgeo.org/postgis/ticket/4125.
Opzionali
GDAL (pseudo optional) only if you don't want raster you can leave it out. Also make sure to enable the drivers you want to use as described in Section 3.2, “Configurare il supporto raster”.
GTK (è necessario GTK+2.0, 2.8+) serve per compilare il loader shp2pgsql-gui shape. http://www.gtk.org/ .
SFCGAL, version 1.3.1 (or higher), 1.4.1 or higher is recommended and required to be able to use all functionality. SFCGAL can be used to provide additional 2D and 3D advanced analysis functions to PostGIS cf Section 7.21, “SFCGAL Functions”. And also allow to use SFCGAL rather than GEOS for some 2D functions provided by both backends (like ST_Intersection or ST_Area, for instance). A PostgreSQL configuration variable postgis.backend
allow end user to control which backend he want to use if SFCGAL is installed (GEOS by default). Nota: SFCGAL 1.2 require at least CGAL 4.3 and Boost 1.54 (cf: https://sfcgal.org) https://gitlab.com/sfcgal/SFCGAL/.
In order to build the Section 11.1, “Address Standardizer” you will also need PCRE http://www.pcre.org (which generally is already installed on nix systems). Section 11.1, “Address Standardizer” will automatically be built if it detects a PCRE library, or you pass in a valid --with-pcre-dir=/path/to/pcre
during configure.
To enable ST_AsMVT protobuf-c library 1.1.0 or higher (for usage) and the protoc-c compiler (for building) are required. Also, pkg-config is required to verify the correct minimum version of protobuf-c. See protobuf-c. By default, Postgis will use Wagyu to validate MVT polygons faster which requires a c++11 compiler. It will use CXXFLAGS and the same compiler as the PostgreSQL installation. To disable this and use GEOS instead use the --without-wagyu
during the configure step.
CUnit (CUnit
). Serve per i collaudi di regressione. http://cunit.sourceforge.net/
DocBook (xsltproc
) è necessario per creare la documentazione. Docbook è disponibile sul sito http://www.docbook.org/ .
DBLatex (dblatex
) è necessario per creare la documentazione in formato PDF. DBLatex è disponibile dal sito http://dblatex.sourceforge.net/ .
ImageMagick (convert
) viene utilizzato per generare le immagini utilizzate nella documentazione. ImageMagick è disponibile sul sito http://www.imagemagick.org/ .
Come in molte installazioni Linux, il primo passo consiste nel generare il Makefile che sarà poi utilizzato che compilare il codice sorgente. Per questo si esegue lo script da shell
./configure
Se non si specificano parametri aggiuntivi, questo comando cercherà di individuare automaticamente le componenti e le librerie necessarie per compilare il codice sorgente PostGIS sul vostro sistema. Benché questa sia la modalità di utilizzo più comune per ./configure, lo script accetta vari parametri per coloro che tengono le librerie e i programmi necessari in percorsi non standard.
La lista seguente riporta solamente i parametri usati più di frequente. Per una lista completa, utilizzate i parametri --help o --help=short.
Starting with PostGIS 3.0, the library files generated by default will no longer have the minor version as part of the file name. This means all PostGIS 3 libs will end in postgis-3
. This was done to make pg_upgrade easier, with downside that you can only install one version PostGIS 3 series in your server. To get the old behavior of file including the minor version: e.g. postgis-3.0
add this switch to your configure statement.
Questo è il percorso in cui saranno installate le librerie PostGIS e gli script SQL. Come default, questo percorso coincide con quello rilevato per l'installazione di PostgreSQL.
![]() | |
Attualmente questo parametro non funzione, dato che il pacchetto si installerà solamente nella cartella di installazione di PostgreSQL. Potete visitare la pagina http://trac.osgeo.org/postgis/ticket/635 per seguire l'evoluzione di questo bug. |
PostgreSQL fornisce una utility chiamata pg_config per consentire a estensioni quali PostGIS di individuare la cartella di installazione di PostgreSQL. Utilizzate questo parametro (--with-pgconfig=/path/to/pg_config) per specificare manualmente una particolare installazione di PostgreSQL per la quale PostGIS sarà compilato.
GDAL è una libreria necessaria per il supporto raster. Utilizzare il comando gdal-config per consentire all'installazione di individuare la cartella di installazione di GDAL, oppure utilizzare il parametro --with-gdalconfig=/path/to/gdal-config per indicare manualmente specifica installazione di GDAL con cui compilare PostGIS.
GEOS, una libreria necessaria per gestire le geometrie, fornisce una utility chiamata geos-config per consentire alla procedura di installazione di individuare la cartella di installazione di GEOS. E' possibile utilizzare questo parametro (--with-geosconfig=/path/to/geos-config) per indicare manualmente una specifica installazione di GEO da utilizzare per la compilazione.
LibXML è la libreria richiesta dai comandi GeomFromKML/GML. Se la libreria è installata, viene normalmente localizzata automaticamente, ma se non è installata, o se volete utilizzare una versione specifica, dovete rimandare PostGIS a uno specifico file di configurazione xml2-config
per consentire all'installazione di localizzare la cartella di installazione di LibXML. Utilizzate questo parametro (
>--with-xml2config=/path/to/xml2-config) per indicare manualmente il riferimento a una specifica installazione di LibXML per la compilazione di PostGIS.
Proj4 è una libreria di riproiezione richiesta da PostGIS. Utilizzate questo parametro (--with-projdir=/path/to/projdir) per indicare manualmente una specifica cartella di installazione di Proj4 per la compilazione di PostGIS.
Cartella di installazione di iconv.
JSON-C è una libreria JSON con licenza MIR utilizzata da PostGIS per supportare ST_GeomFromJSON. Utilizzare questo parametro (--with-jsondir=/path/to/jsondir) per indicare manualmente una specifica cartella di installazione che PostGIS userà per la compilazione.
PCRE is an BSD-licensed Perl Compatible Regular Expression library required by address_standardizer extension. Use this parameter (--with-pcredir=/path/to/pcredir) to manually specify a particular PCRE installation directory that PostGIS will build against.
Compilare l'interfaccia grafica per l'importazione di dati (richiede GTK+2.0). Questo passaggio creerà shp2pgsql-gui, interfaccia grafica per shp2pgsql.
Installazione del supporto raster
Disable topology support. There is no corresponding library as all logic needed for topology is in postgis-3.4.5dev library.
Normalmente PostGIS cercherà di rilevare il supporto per gettext e di utilizzarlo nella compilazione. Tuttavia, se risocontrate problemi di compatibilità che determinano interruzioni del loader, potete disabilitare il supporto con questo comando. Potete fare riferimento al ticket http://trac.osgeo.org/postgis/ticket/748 per un esempio di un caso risolto utilizzando questa particolare configurazione. NOTA: disattivanto questa opzione non vi perdete molto, dato che è utilizzata per il supporto internazionale o per le etichette nel loader, che non sono ancora ben documentate e in forma sperimentale.
By default PostGIS will not install with sfcgal support without this switch. PATH
is an optional argument that allows to specify an alternate PATH to sfcgal-config.
Disable updating postgis_revision.h to match current HEAD of the git repository.
![]() | |
Se avete ottenuto PostGIS dalla code repository , il primo passo consiste nell'eseguire lo script ./autogen.sh Questo script genererà lo script configure, che a sua volta viente utilizzato per personalizzare l'installazione di PostGIS. Se invece avete ottenuto PostGIS come file tar, non sarà necessario eseguire ./autogen.sh, dato che configure sarà già stato generato. |
Una volta creato il Makefile, compilare PostGIS è semplice come eseguire
make
L'ultima linea dei messaggi in uscita dovrebbe essere "PostGIS was built successfully. Ready to install.
"
As of PostGIS v1.4.0, all the functions have comments generated from the documentation. If you wish to install these comments into your spatial databases later, run the command which requires docbook. The postgis_comments.sql and other package comments files raster_comments.sql, topology_comments.sql are also packaged in the tar.gz distribution in the doc folder so no need to make comments if installing from the tar ball. Comments are also included as part of the CREATE EXTENSION install.
make comments
Introdotto in PostGIS 2.0. Questa opzione genera degli opuscoli riassuntivi in formato HTML, utili come riferimento speditivo o per distribuzione agli studenti. Richiede xsltproc e genererà 4 file della cartella doc: topology_cheatsheet.html
, tiger_geocoder_cheatsheet.html
, raster_cheatsheet.html
, postgis_cheatsheet.html
Ne potete scaricare alcuni già pronti sia in formato HTML che PDF dalla pagina PostGIS / PostgreSQL Study Guides
make cheatsheets
Le estensioni di PostGIS vengono compilate e installate automaticamente se state utilizzando PostgreSQL 9.1+.
Se state compilando a partire dalla repository del sorgente, dovete prima compilare le descrizioni delle funzioni. Queste vengono create se avete docbook installato. Potete anche eseguire la compilazione manualmente tramite il comando:
make comments
Creare i file dei commenti non è necessario se state compilando a partire dal file tar, dato che questi file sono inclusi nel file tar stesso.
Se state compilando per PostgreSQL 9.1, le estensioni dovrebbero essere create automaticamente nel corso del processo di make install. Se serve, potete eseguire la compilazione a partire dalle cartelle delle estensioni, o potete copiare i file se ne avete bisogno su un altro server.
cd extensions cd postgis make clean make export PGUSER=postgres #overwrite psql variables make check #to test before install make install # to test extensions make check RUNTESTFLAGS=--extension
![]() | |
|
I file delle estensioni sono sempre gli stessi a pari versione di PostGIS, a prescindere dal sistema operativo, per cui non ci sono problemi a copiare i file delle estensioni da un sistema operativo a un altro, fintanto che i file binari di PostGIS sono già installati sui vostri server.
Se volete installare le estensioni manualmente su un server separato, diverso da quello di sviluppo, dovete copiare i seguenti file dalla cartella delle estensioni nella cartella PostgreSQL / share / extension
della vostra installazione PostgreSQL, così come i file binari per la versione normale di PostGIS, se questi già non sono presenti sul server.
Questi sono i file di controllo che indicano informazioni come la versione dell'estensione da installare, se non specificata. postgis.control, postgis_topology.control
.
Tutti i file nella cartella /sql di ciascuna estensione. Da notare che quesi devono essere copiati nella cartella principale delle estensioni di PostgreSQL, share/extension extensions/postgis/sql/*.sql
, extensions/postgis_topology/sql/*.sql
Una volta eseguita questa operazione, dovreste vedere postgis
, postgis_topology
come estensioni disponibili in PgAdmin -> extensions.
Se state utilizzando psql, potete verificare l'avvenuta installazione delle estensioni tramite questa query:
SELECT name, default_version,installed_version FROM pg_available_extensions WHERE name LIKE 'postgis%' or name LIKE 'address%'; name | default_version | installed_version ------------------------------+-----------------+------------------- address_standardizer | 3.4.5dev | 3.4.5dev address_standardizer_data_us | 3.4.5dev | 3.4.5dev postgis | 3.4.5dev | 3.4.5dev postgis_raster | 3.4.5dev | 3.4.5dev postgis_sfcgal | 3.4.5dev | postgis_tiger_geocoder | 3.4.5dev | 3.4.5dev postgis_topology | 3.4.5dev | (6 rows)
Se avete le estensioni installate nel database che state interrogando, vedrete questo fatto menzionato nella colonna installed_version
. Se non vengono riportari record nel risultato, significa che non avete alcuna estensione installata sul server. PgAdmin III 1.14+ fornirà inoltre questa informazione nella sezione extensions
dell'albero di navigazione del database e consentirà anche l'aggiornamento o la disinstallazione tramite clic del tasto destro del mouse.
Se le estensioni sono disponibili, potete installare l'estensione postgis nel database da voi scelto utilizzando l'interfaccia pgAdmin per le estensioni o eseguendo i seguenti comandi SQL:
CREATE EXTENSION postgis; CREATE EXTENSION postgis_raster; CREATE EXTENSION postgis_sfcgal; CREATE EXTENSION fuzzystrmatch; --needed for postgis_tiger_geocoder --optional used by postgis_tiger_geocoder, or can be used standalone CREATE EXTENSION address_standardizer; CREATE EXTENSION address_standardizer_data_us; CREATE EXTENSION postgis_tiger_geocoder; CREATE EXTENSION postgis_topology;
In psql you can use to see what versions you have installed and also what schema they are installed.
\connect mygisdb \x \dx postgis*
List of installed extensions -[ RECORD 1 ]------------------------------------------------- Name | postgis Version | 3.4.5dev Schema | public Description | PostGIS geometry, geography, and raster spat.. -[ RECORD 2 ]------------------------------------------------- Name | postgis_raster Version | 3.0.0dev Schema | public Description | PostGIS raster types and functions -[ RECORD 3 ]------------------------------------------------- Name | postgis_tiger_geocoder Version | 3.4.5dev Schema | tiger Description | PostGIS tiger geocoder and reverse geocoder -[ RECORD 4 ]------------------------------------------------- Name | postgis_topology Version | 3.4.5dev Schema | topology Description | PostGIS topology spatial types and functions
![]() | |
Per le tabelle delle estensioni |
If you installed 3.4.5dev, without using our wonderful extension system, you can change it to be extension based by running the below commands to package the functions in their respective extension. Installing using `unpackaged` was removed in PostgreSQL 13, so you are advised to switch to an extension build before upgrading to PostgreSQL 13.
CREATE EXTENSION postgis FROM unpackaged; CREATE EXTENSION postgis_raster FROM unpackaged; CREATE EXTENSION postgis_topology FROM unpackaged; CREATE EXTENSION postgis_tiger_geocoder FROM unpackaged;
Se volete eseguire un test sul PostGIS compilato, eseguite
make check
Il comando di cui sopra eseguirà vari controlli e collaudi di regressione, utilizzando la libreria generata per un database PostgreSQL effettivo.
![]() | |
Se avete configurato PostGIS utilizzando percorsi non standard per PostgreSQL, GEOS o Proj4, potreste dover aggiungere il percorso di queste librerie nella variabile di ambiente LD_LIBRARY_PATH |
![]() | |
Attualmente il comando make check fa riferimento alle variabili di ambiente |
Se il test è positivo, l'uscita conterrà il risultato di molti test la schermata dovrebbe essere simile alla seguente (molte linee sono omesse):
CUnit - A unit testing framework for C - Version 2.1-3 http://cunit.sourceforge.net/ . . . Run Summary: Type Total Ran Passed Failed Inactive suites 44 44 n/a 0 0 tests 300 300 300 0 0 asserts 4215 4215 4215 0 n/a Elapsed time = 0.229 seconds . . . Running tests . . . Run tests: 134 Failed: 0 -- if you build with SFCGAL . . . Running tests . . . Run tests: 13 Failed: 0 -- if you built with raster support . . . Run Summary: Type Total Ran Passed Failed Inactive suites 12 12 n/a 0 0 tests 65 65 65 0 0 asserts 45896 45896 45896 0 n/a . . . Running tests . . . Run tests: 101 Failed: 0 -- topology regress . . . Running tests . . . Run tests: 51 Failed: 0 -- if you built --with-gui, you should see this too CUnit - A unit testing framework for C - Version 2.1-2 http://cunit.sourceforge.net/ . . . Run Summary: Type Total Ran Passed Failed Inactive suites 2 2 n/a 0 0 tests 4 4 4 0 0 asserts 4 4 4 0 n/a
The postgis_tiger_geocoder
and address_standardizer
extensions, currently only support the standard PostgreSQL installcheck. To test these use the below. Note: the make install is not necessary if you already did make install at root of PostGIS code folder.
For address_standardizer:
cd extensions/address_standardizer make install make installcheck
Output should look like:
============== dropping database "contrib_regression" ============== DROP DATABASE ============== creating database "contrib_regression" ============== CREATE DATABASE ALTER DATABASE ============== running regression test queries ============== test test-init-extensions ... ok test test-parseaddress ... ok test test-standardize_address_1 ... ok test test-standardize_address_2 ... ok ===================== All 4 tests passed. =====================
For tiger geocoder, make sure you have postgis and fuzzystrmatch extensions available in your PostgreSQL instance. The address_standardizer tests will also kick in if you built postgis with address_standardizer support:
cd extensions/postgis_tiger_geocoder make install make installcheck
output should look like:
============== dropping database "contrib_regression" ============== DROP DATABASE ============== creating database "contrib_regression" ============== CREATE DATABASE ALTER DATABASE ============== installing fuzzystrmatch ============== CREATE EXTENSION ============== installing postgis ============== CREATE EXTENSION ============== installing postgis_tiger_geocoder ============== CREATE EXTENSION ============== installing address_standardizer ============== CREATE EXTENSION ============== running regression test queries ============== test test-normalize_address ... ok test test-pagc_normalize_address ... ok ===================== All 2 tests passed. =====================
Per installare PostGIS, digitate
make install
Questo comando copierà i file per l'installazione di PostGIS nelle cartelle appropriate, specificate tramite il parametro di configurazione --prefix. In particolare:
I file binari del loader e del dumper vengono installati in [prefix]/bin
.
I file SQL, quali postgis.sql
, vengono installati in [prefix]/share/contrib
.
Le librerie PostGIS vengono installate in [prefix]/lib
.
Se avete eseguito il comando make comments per generare i file postgis_comments.sql
e raster_comments.sql
, installate i file SQL eseguendo
make comments-install
![]() | |
|
The address_standardizer
extension used to be a separate package that required separate download. From PostGIS 2.2 on, it is now bundled in. For more information about the address_standardize, what it does, and how to configure it for your needs, refer to Section 11.1, “Address Standardizer”.
This standardizer can be used in conjunction with the PostGIS packaged tiger geocoder extension as a replacement for the Normalize_Address discussed. To use as replacement refer to Section 2.4.2, “Using Address Standardizer Extension with Tiger geocoder”. You can also use it as a building block for your own geocoder or use it to standardize your addresses for easier compare of addresses.
The address standardizer relies on PCRE which is usually already installed on many Nix systems, but you can download the latest at: http://www.pcre.org. If during Section 2.2.3, “Configurazione”, PCRE is found, then the address standardizer extension will automatically be built. If you have a custom pcre install you want to use instead, pass to configure --with-pcredir=/path/to/pcre
where /path/to/pcre
is the root folder for your pcre include and lib directories.
For Windows users, the PostGIS 2.1+ bundle is packaged with the address_standardizer already so no need to compile and can move straight to CREATE EXTENSION
step.
Once you have installed, you can connect to your database and run the SQL:
CREATE EXTENSION address_standardizer;
The following test requires no rules, gaz, or lex tables
SELECT num, street, city, state, zip FROM parse_address('1 Devonshire Place PH301, Boston, MA 02109');
Output should be
num | street | city | state | zip -----+------------------------+--------+-------+------- 1 | Devonshire Place PH301 | Boston | MA | 02109
Extras like Tiger geocoder may not be packaged in your PostGIS distribution. If you are missing the tiger geocoder extension or want a newer version than what your install comes with, then use the share/extension/postgis_tiger_geocoder.*
files from the packages in Windows Unreleased Versions section for your version of PostgreSQL. Although these packages are for windows, the postgis_tiger_geocoder extension files will work on any OS since the extension is an SQL/plpgsql only extension.
These directions assume your PostgreSQL installation already has the postgis_tiger_geocoder extension installed.
Connect to your database via psql or pgAdmin or some other tool and run the following SQL commands. Note that if you are installing in a database that already has postgis, you don't need to do the first step. If you have fuzzystrmatch
extension already installed, you don't need to do the second step either.
CREATE EXTENSION postgis; CREATE EXTENSION fuzzystrmatch; CREATE EXTENSION postgis_tiger_geocoder; --this one is optional if you want to use the rules based standardizer (pagc_normalize_address) CREATE EXTENSION address_standardizer;
If you already have postgis_tiger_geocoder extension installed, and just want to update to the latest run:
ALTER EXTENSION postgis UPDATE; ALTER EXTENSION postgis_tiger_geocoder UPDATE;
If you made custom entries or changes to tiger.loader_platform
and tiger.loader_variables
you may need to update these.
To confirm your install is working correctly, run this sql in your database:
SELECT na.address, na.streetname,na.streettypeabbrev, na.zip FROM normalize_address('1 Devonshire Place, Boston, MA 02109') AS na;
Which should output
address | streetname | streettypeabbrev | zip ---------+------------+------------------+------- 1 | Devonshire | Pl | 02109
Create a new record in tiger.loader_platform
table with the paths of your executables and server.
So for example to create a profile called debbie that follows sh
convention. You would do:
INSERT INTO tiger.loader_platform(os, declare_sect, pgbin, wget, unzip_command, psql, path_sep, loader, environ_set_command, county_process_command) SELECT 'debbie', declare_sect, pgbin, wget, unzip_command, psql, path_sep, loader, environ_set_command, county_process_command FROM tiger.loader_platform WHERE os = 'sh';
And then edit the paths in the declare_sect column to those that fit Debbie's pg, unzip,shp2pgsql, psql, etc path locations.
If you don't edit this loader_platform
table, it will just contain common case locations of items and you'll have to edit the generated script after the script is generated.
As of PostGIS 2.4.1 the Zip code-5 digit tabulation area zcta5
load step was revised to load current zcta5 data and is part of the Loader_Generate_Nation_Script when enabled. It is turned off by default because it takes quite a bit of time to load (20 to 60 minutes), takes up quite a bit of disk space, and is not used that often.
To enable it, do the following:
UPDATE tiger.loader_lookuptables SET load = true WHERE table_name = 'zcta520';
If present the Geocode function can use it if a boundary filter is added to limit to just zips in that boundary. The Reverse_Geocode function uses it if the returned address is missing a zip, which often happens with highway reverse geocoding.
Create a folder called gisdata
on root of server or your local pc if you have a fast network connection to the server. This folder is where the tiger files will be downloaded to and processed. If you are not happy with having the folder on the root of the server, or simply want to change to a different folder for staging, then edit the field staging_fold
in the tiger.loader_variables
table.
Create a folder called temp in the gisdata
folder or wherever you designated the staging_fold
to be. This will be the folder where the loader extracts the downloaded tiger data.
Then run the Loader_Generate_Nation_Script SQL function make sure to use the name of your custom profile and copy the script to a .sh or .bat file. So for example to build the nation load:
psql -c "SELECT Loader_Generate_Nation_Script('debbie')" -d geocoder -tA > /gisdata/nation_script_load.sh
Run the generated nation load commandline scripts.
cd /gisdata sh nation_script_load.sh
After you are done running the nation script, you should have three tables in your tiger_data
schema and they should be filled with data. Confirm you do by doing the following queries from psql or pgAdmin
SELECT count(*) FROM tiger_data.county_all;
count ------- 3234 (1 row)
SELECT count(*) FROM tiger_data.state_all;
count ------- 56 (1 row)
This will only have data if you marked zcta520 to be loaded
SELECT count(*) FROM tiger_data.zcta5_all;
count ------- 37371 (1 row)
By default the tables corresponding to bg
, tract
, tabblock20
are not loaded. These tables are not used by the geocoder but are used by folks for population statistics. If you wish to load them as part of your state loads, run the following statement to enable them.
UPDATE tiger.loader_lookuptables SET load = true WHERE load = false AND lookup_name IN('tract', 'bg', 'tabblock20');
Alternatively you can load just these tables after loading state data using the Loader_Generate_Census_Script
For each state you want to load data for, generate a state script Loader_Generate_Script.
![]() | |
DO NOT Generate the state script until you have already loaded the nation data, because the state script utilizes county list loaded by nation script. |
psql -c "SELECT Loader_Generate_Script(ARRAY['MA'], 'debbie')" -d geocoder -tA > /gisdata/ma_load.sh
Run the generated commandline scripts.
cd /gisdata sh ma_load.sh
After you are done loading all data or at a stopping point, it's a good idea to analyze all the tiger tables to update the stats (include inherited stats)
SELECT install_missing_indexes(); vacuum (analyze, verbose) tiger.addr; vacuum (analyze, verbose) tiger.edges; vacuum (analyze, verbose) tiger.faces; vacuum (analyze, verbose) tiger.featnames; vacuum (analyze, verbose) tiger.place; vacuum (analyze, verbose) tiger.cousub; vacuum (analyze, verbose) tiger.county; vacuum (analyze, verbose) tiger.state; vacuum (analyze, verbose) tiger.zip_lookup_base; vacuum (analyze, verbose) tiger.zip_state; vacuum (analyze, verbose) tiger.zip_state_loc;
One of the many complaints of folks is the address normalizer function Normalize_Address function that normalizes an address for prepping before geocoding. The normalizer is far from perfect and trying to patch its imperfectness takes a vast amount of resources. As such we have integrated with another project that has a much better address standardizer engine. To use this new address_standardizer, you compile the extension as described in Section 2.3, “Installing and Using the address standardizer” and install as an extension in your database.
Once you install this extension in the same database as you have installed postgis_tiger_geocoder
, then the Pagc_Normalize_Address can be used instead of Normalize_Address. This extension is tiger agnostic, so can be used with other data sources such as international addresses. The tiger geocoder extension does come packaged with its own custom versions of rules table ( tiger.pagc_rules
) , gaz table (tiger.pagc_gaz
), and lex table (tiger.pagc_lex
). These you can add and update to improve your standardizing experience for your own needs.
Il processo di caricamento scarica i dati per ciascuno stato richiesto dal sito del censimento, estrare i file, e li carica nelle rispettive tabelle. La tabella di ogni stato eredita le proprietà dalle tabelle definite nello schema tiger
, per cui è sufficiente eseguire le interrogazioni su queste tabelle per accedere a tutti i dati. E' altresì possibile cancellare le tabelle per un dato stato tramite lo script Drop_State_Tables_Generate_Script, qualora aveste necessità di ricaricare uno stato o se questo non vi serve più.
Per caricare i dati avrete bisogno dei seguenti strumenti:
Uno strumento per decomprimere i file zip dal sito web dei censimenti.
Per sistemi tipo Unix: l'eseguibile unzip
è di soiito già installato.
Per Windows, 7-zip è uno strumento libero di compressione/decompressione, che può essere scaricato dal sito http://www.7-zip.org/
Il programam da riga di comando shp2pgsql
, che viene installato di base quando nistallate PostGIS.
wget
è uno strumento per la copia di file da web, solitamente installato nella maggior parte dei sistemi Unix/Linux.
Se siete su Windows, potete reperire i file binari precompilati da http://gnuwin32.sourceforge.net/packages/wget.htm
If you are upgrading from tiger_2010, you'll need to first generate and run Drop_Nation_Tables_Generate_Script. Before you load any state data, you need to load the nation wide data which you do with Loader_Generate_Nation_Script. Which will generate a loader script for you. Loader_Generate_Nation_Script is a one-time step that should be done for upgrading (from a prior year tiger census data) and for new installs.
To load state data refer to Loader_Generate_Script to generate a data load script for your platform for the states you desire. Note that you can install these piecemeal. You don't have to load all the states you want all at once. You can load them as you need them.
Dopo aver caricato i dati per gli stati cui siete interessati, assicuratevi di eseguire:
SELECT install_missing_indexes();
come descritto in Install_Missing_Indexes.
Per vedere se le cose funzionano come dovrebbero, provate a eseguire la geocodifica di un indirizzo nel vostro stato utilizzando Geocode
First upgrade your postgis_tiger_geocoder extension as follows:
ALTER EXTENSION postgis_tiger_geocoder UPDATE;
Poi cancellate tutte le tabelle delle nazioni e caricate quelle nuove. Potete generare uno script per la cancellazione con il codice SQL illustrato in Drop_Nation_Tables_Generate_Script
SELECT drop_nation_tables_generate_script();
Eseguite i comandi SQL DROP che vengono generati.
Generate uno script per il caricamento di uno stato con l'istruzione SELECT come illustrato in Loader_Generate_Nation_Script
Per Windows
SELECT loader_generate_nation_script('windows');
Per unix/linux
SELECT loader_generate_nation_script('sh');
Refer to Section 2.4.1, “Tiger Geocoder Enabling your PostGIS database” for instructions on how to run the generate script. This only needs to be done once.
![]() | |
You can have a mix of different year state tables and can upgrade each state separately. Before you upgrade a state you first need to drop the prior year state tables for that state using Drop_State_Tables_Generate_Script. |
Quando l'installazione o l'aggiornamento non vanno come previsto, diverse cose vanno controllate.
Controllate di aver installato PostgreSQL 12 o più recente, e che state compilando con il sorgente PostgreSQL nella versione corrispondente alla versione di PostgreSQL che sta girando. Si possono verificare casi di confusione quando la vostra distribuzione (Linux) ha PostgreSQL già installao, o quando avete installato PostgreSQL in precedenza e ve ne siete dimenticati. PostGIS funzionerà solo con PostgreSQL 12 o più recente, e si potrebbero ricevere messaggi di errore strani o inattesi se utilizzate una versione più vecchia. Per verificare quale versione di PostgreSQL sta girando, collegatevi al database utilizzando psql ed eseguite la seguente query:
SELECT version();
Se state utilizzando una distribuzione basata su RPM, potete verificare la presenza di pacchetti preinstallati utilizzando il comando rpm con la seguente sintassi: rpm -qa | grep postgresql
Se l'aggiornamento non funziona, assicuratevi di eseguire il ripristino in un database che abbia già PostGIS installato.
SELECT postgis_full_version();
Inoltre, verificate che configure abbia correttamente individuato il percorso e la versione di PostgreSQL, della libreria Proj4 e della libreria GEOS.
L'uscita da configure viene utilizzata per generare il file postgis_config.h
. Controllate che le variabili POSTGIS_PGSQL_VERSION
, POSTGIS_PROJ_VERSION
e POSTGIS_GEOS_VERSION
siano assegnate correttamente.