Unable to import .geojson Geometry to PostGis Database (null)

I`m trying to import geodata and the associated names from various regions within one .geojson file. Some geometries are Polygons, other Multipolygons.

Here is the start of the .geojson file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature",
"properties": { "shapeName": "Stuttgart", "shapeISO": "", "shapeID": "9070358B86745718691241", "shapeGroup": "DEU", "shapeType": "ADM2" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 8.768902291000074, 48.521841109000036 ], [ 8.769527448000076, 48.523685716000045 ], [ 8.771349093000026, 48.523480333000066 ], [ 8.771833428000036, 48.524333358000035 ], [ 8.777268014000072, 48.522360651000042 ], [ 8.781038882000075, 48.521310749000065 ], [ 8.784831049000047, 48.520892894000042 ], [...]
</code>
<code>{ "type": "FeatureCollection", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, "features": [ { "type": "Feature", "properties": { "shapeName": "Stuttgart", "shapeISO": "", "shapeID": "9070358B86745718691241", "shapeGroup": "DEU", "shapeType": "ADM2" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 8.768902291000074, 48.521841109000036 ], [ 8.769527448000076, 48.523685716000045 ], [ 8.771349093000026, 48.523480333000066 ], [ 8.771833428000036, 48.524333358000035 ], [ 8.777268014000072, 48.522360651000042 ], [ 8.781038882000075, 48.521310749000065 ], [ 8.784831049000047, 48.520892894000042 ], [...] </code>
{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", 
"properties": { "shapeName": "Stuttgart", "shapeISO": "", "shapeID": "9070358B86745718691241", "shapeGroup": "DEU", "shapeType": "ADM2" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 8.768902291000074, 48.521841109000036 ], [ 8.769527448000076, 48.523685716000045 ], [ 8.771349093000026, 48.523480333000066 ], [ 8.771833428000036, 48.524333358000035 ], [ 8.777268014000072, 48.522360651000042 ], [ 8.781038882000075, 48.521310749000065 ], [ 8.784831049000047, 48.520892894000042 ], [...]

Full File: https://drive.google.com/file/d/12sPpPsv_aQZFeD9qImgUmgPYZ4s9kUEn/view?usp=sharing

The Database Table is structured this way:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> Table "public.polygons_level_1"
Column | Type | Collation | Nullable | Default
-------------+-----------------------------+-----------+----------+----------------------------
polygon_id | bigint | | not null | nextval('polygons_level_1_polygon_id_seq'::regclass)
region_name | character varying(150) | | |
geometry | geometry(MultiPolygon,4326) | | |
created_at | timestamp without time zone | | | CURRENT_TIMESTAMP
updated_at | timestamp without time zone | | | CURRENT_TIMESTAMP
centroid | geometry(Point,4326) | | |
</code>
<code> Table "public.polygons_level_1" Column | Type | Collation | Nullable | Default -------------+-----------------------------+-----------+----------+---------------------------- polygon_id | bigint | | not null | nextval('polygons_level_1_polygon_id_seq'::regclass) region_name | character varying(150) | | | geometry | geometry(MultiPolygon,4326) | | | created_at | timestamp without time zone | | | CURRENT_TIMESTAMP updated_at | timestamp without time zone | | | CURRENT_TIMESTAMP centroid | geometry(Point,4326) | | | </code>
                                             Table "public.polygons_level_1"
   Column    |            Type             | Collation | Nullable |         Default
-------------+-----------------------------+-----------+----------+----------------------------
 polygon_id  | bigint                      |           | not null | nextval('polygons_level_1_polygon_id_seq'::regclass)
 region_name | character varying(150)      |           |          |
 geometry    | geometry(MultiPolygon,4326) |           |          |
 created_at  | timestamp without time zone |           |          | CURRENT_TIMESTAMP
 updated_at  | timestamp without time zone |           |          | CURRENT_TIMESTAMP
 centroid    | geometry(Point,4326)        |           |          | 

The issue:
The geometries are not imported. There are entries created for all 38 features, yet the “geometry” content is always “null”.

My command is:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>ogr2ogr -append -f "PostgreSQL" PG:"dbname=XXX user=XXX password=XXX port=XXX"
-nln polygons_level_1
-nlt PROMOTE_TO_MULTI
-sql "SELECT shapeName AS region_name FROM level1_admin2"
./level1_admin2.geojson
</code>
<code>ogr2ogr -append -f "PostgreSQL" PG:"dbname=XXX user=XXX password=XXX port=XXX" -nln polygons_level_1 -nlt PROMOTE_TO_MULTI -sql "SELECT shapeName AS region_name FROM level1_admin2" ./level1_admin2.geojson </code>
ogr2ogr -append -f "PostgreSQL" PG:"dbname=XXX user=XXX password=XXX port=XXX" 
-nln polygons_level_1 
-nlt PROMOTE_TO_MULTI 
-sql "SELECT shapeName AS region_name FROM level1_admin2" 
./level1_admin2.geojson

Note:

  • I`ve tried it both with and without the sql command for the region names – no difference to the main issue
  • The geodata is supposed to be stored in the database to be transmitted to MapBox when requested, as polygons.
    -lco GEOMETRY_NAME=geometry does not fix the issue

My Setup:

  • MacBook Pro M1 Pro
  • PostgreSQL 16.4

TLDR: Solution

  • Change SQL Prompt:

-sql "SELECT shapeName as region_name, geometry FROM level1_admin2" -dialect SQLite

  • Delete Index and create it again in database with USING GIST(geometry)clause, as before the byte size of the geodata would have been too large.

3

Just specify the geometry name to serve as match to your table’s geometry column, since your table has two geometry columns, as:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>-sql "SELECT shapeName as region_name, geometry FROM level1_admin2" -dialect SQLite
</code>
<code>-sql "SELECT shapeName as region_name, geometry FROM level1_admin2" -dialect SQLite </code>
-sql "SELECT shapeName as region_name, geometry FROM level1_admin2" -dialect SQLite

adding additionally the sql dialect, because geometry name varies in different dialects.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật