先将csv文件转为shp文件,再导入到postgis。
1.在csv同目录下创建vrt文件
vrt文件的内容如下:
<OGRVRTDataSource>
<OGRVRTLayer name="Global_24h">
<SrcDataSource>Global_24h.csv</SrcDataSource>
<GeometryType>wkbPoint</GeometryType>
<LayerSRS>EPSG:4326</LayerSRS>
<GeometryField encoding="PointFromColumns" x="longitude" y="latitude"/>
</OGRVRTLayer>
</OGRVRTDataSource>
2.生成shp文件
ogr2ogr global_24h.shp global_24h.vrt
生成的shp文件如下:
3.生成sql文件
shp2pgsql -G -I global_24h.shp public.global_24h_geographic >global_24h.sql
其中,参数含义如下:
?生成的global_24h.sql文件内容如下:
SET CLIENT_ENCODING TO UTF8;
SET STANDARD_CONFORMING_STRINGS TO ON;
BEGIN;
CREATE TABLE "public"."global_24h_geographic" (gid serial,
"latitude" varchar(80),
"longitude" varchar(80),
"brightness" varchar(80),
"scan" varchar(80),
"track" varchar(80),
"acq_date" varchar(80),
"acq_time" varchar(80),
"satellite" varchar(80),
"confidence" varchar(80),
"version" varchar(80),
"bright_t31" varchar(80),
"frp" varchar(80),
"geog" geography(POINT,4326));
ALTER TABLE "public"."global_24h_geographic" ADD PRIMARY KEY (gid);
INSERT INTO "public"."global_24h_geographic" ("latitude","longitude","brightness","scan","track","acq_date","acq_time","satellite","confidence","version","bright_t31","frp",geog) VALUES ('-23.386','-46.197','307.5','1.1','1','2012-08-20','0140','T','54','5.0','285.7','16.5','0101000020E6100000F0A7C64B371947C0894160E5D06237C0');
INSERT INTO "public"."global_24h_geographic" ("latitude","longitude","brightness","scan","track","acq_date","acq_time","satellite","confidence","version","bright_t31","frp",geog) VALUES ('-22.952','-47.574','330.1','1.2','1.1','2012-08-20','0140','T','100','5.0','285.2','53.9','0101000020E6100000B6F3FDD478C947C0C1CAA145B6F336C0');
INSERT INTO "public"."global_24h_geographic" ("latitude","longitude","brightness","scan","track","acq_date","acq_time","satellite","confidence","version","bright_t31","frp",geog) VALUES ('-23.726','-56.108','333.3','4.7','2','2012-08-20','0140','T','100','5.0','283.5','404.1','0101000020E6100000E7FBA9F1D20D4CC060E5D022DBB937C0');
......
INSERT INTO "public"."global_24h_geographic" ("latitude","longitude","brightness","scan","track","acq_date","acq_time","satellite","confidence","version","bright_t31","frp",geog) VALUES ('43.215','-5.124','310.5','1.3','1.1','2012-08-21','1305','A','39','5.0','298.5','13.1','0101000020E6100000E5D022DBF97E14C0EC51B81E859B4540');
INSERT INTO "public"."global_24h_geographic" ("latitude","longitude","brightness","scan","track","acq_date","acq_time","satellite","confidence","version","bright_t31","frp",geog) VALUES ('48.148','1.771','330.4','1.2','1.1','2012-08-21','1305','A','83','5.0','306','25.3','0101000020E6100000BC7493180456FC3F6DE7FBA9F1124840');
CREATE INDEX ON "public"."global_24h_geographic" USING GIST ("geog");
COMMIT;
ANALYZE "public"."global_24h_geographic";
4.执行sql文件
psql -U postgres -d postgis_32_sample -f global_24h.sql
5.查看几何数据
SELECT gid, longitude,latitude, ST_AsText(geog) AS wkt_geom
FROM public.global_24h_geographic
ORDER BY gid
LIMIT 5;
在pgAdmin中的查询结果如下:
?6.QGIS中显示几何数据
?
|