azavea / noaa-hydro-data

NOAA Phase 2 Hydrological Data Processing
11 stars 3 forks source link

Recommend installing PostGIS before data import #59

Closed rajadain closed 2 years ago

rajadain commented 2 years ago

Overview

If the data is imported before the postgis extension exists, the table's wkb_geometry column is of the type bytea. When the import is done with postgis already installed, the type is geometry(MultiPolygon,4269).

Demo

Before:

nhdplushr=# \d wbdhu12;
                                                 Table "public.wbdhu12"
          Column          |           Type           | Collation | Nullable |                  Default

--------------------------+--------------------------+-----------+----------+-------------------------------------------
 objectid                 | integer                  |           | not null | nextval('wbdhu12_objectid_seq'::regclass)
 wkb_geometry             | bytea                    |           |          |
 tnmid                    | character varying(40)    |           |          |
 metasourceid             | character varying(40)    |           |          |
 sourcedatadesc           | character varying(100)   |           |          |
 sourceoriginator         | character varying(130)   |           |          |
 sourcefeatureid          | character varying(40)    |           |          |
 loaddate                 | timestamp with time zone |           |          |
 noncontributingareaacres | double precision         |           |          |
 noncontributingareasqkm  | double precision         |           |          |
 areasqkm                 | double precision         |           |          |
 areaacres                | double precision         |           |          |
 gnis_id                  | integer                  |           |          |
 name                     | character varying(120)   |           |          |
 states                   | character varying(50)    |           |          |
 huc12                    | character varying(12)    |           |          |
 hutype                   | character varying(255)   |           |          |
 humod                    | character varying(30)    |           |          |
 tohuc                    | character varying(16)    |           |          |
 shape_length             | double precision         |           |          |
 shape_area               | double precision         |           |          |
 nhdplusid                | double precision         |           |          |
 vpuid                    | character varying(8)     |           |          |
Indexes:
    "wbdhu12_pkey" PRIMARY KEY, btree (objectid)

After:

nhdplushr=# \d wbdhu12;
                                                  Table "public.wbdhu12"
          Column          |            Type             | Collation | Nullable |                  Default

--------------------------+-----------------------------+-----------+----------+-------------------------------------------
 objectid                 | integer                     |           | not null | nextval('wbdhu12_objectid_seq'::regclass)
 tnmid                    | character varying(40)       |           |          |
 metasourceid             | character varying(40)       |           |          |
 sourcedatadesc           | character varying(100)      |           |          |
 sourceoriginator         | character varying(130)      |           |          |
 sourcefeatureid          | character varying(40)       |           |          |
 loaddate                 | timestamp with time zone    |           |          |
 noncontributingareaacres | double precision            |           |          |
 noncontributingareasqkm  | double precision            |           |          |
 areasqkm                 | double precision            |           |          |
 areaacres                | double precision            |           |          |
 gnis_id                  | integer                     |           |          |
 name                     | character varying(120)      |           |          |
 states                   | character varying(50)       |           |          |
 huc12                    | character varying(12)       |           |          |
 hutype                   | character varying(255)      |           |          |
 humod                    | character varying(30)       |           |          |
 tohuc                    | character varying(16)       |           |          |
 shape_length             | double precision            |           |          |
 shape_area               | double precision            |           |          |
 nhdplusid                | double precision            |           |          |
 vpuid                    | character varying(8)        |           |          |
 wkb_geometry             | geometry(MultiPolygon,4269) |           |          |
Indexes:
    "wbdhu12_pkey" PRIMARY KEY, btree (objectid)
    "wbdhu12_wkb_geometry_geom_idx" gist (wkb_geometry)
vlulla commented 2 years ago

Terence, you are correct! It is definitely advisable to install postgis extension before running the ogr2ogr. In fact, the first paragraph of the PostgreSQL / PostGIS vector driver states that without postgis there will be reduced functionalities.

I have an ingrained habit of installing postgis, along with a few other extensions, whenever I create a new database/schema that I did not notice the ordering in the readme. Good catch!