我正在尝试从一个 .geojson 文件中的各个区域导入地理数据和关联名称。有些几何形状是多边形,其他几何形状是多边形。
这是 .geojson 文件的开头:
{
"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 ], [...]
完整文件:https://drive.google.com/file/d/12sPpPsv_aQZFeD9qImgUmgPYZ4s9kUEn/view?usp=sharing
数据库表的结构如下:
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) | | |
问题: 几何图形未导入。为所有 38 个特征创建了条目,但“几何”内容始终为“空”。
我的命令是:
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
注:
我的设置:
只需指定几何名称以与表的几何列匹配,因为您的表有两个几何列,如下:
-sql "SELECT shapeName as region_name, geometry FROM level1_admin2" -dialect SQLite
另外添加 sql 方言,因为几何名称在不同方言中有所不同。