我有3个文件。 1个shapefile和2个DBF文件。对于那些不熟悉shapefile(GIS数据格式)的人来说,它们本质上是一个数据库表,其列和行具有空间几何,如点,线,多边形等。它们可以直观地显示并用于计算中GIS软件
shapefile - trucknetwork:564条记录(列表sri链接到table1) - 新泽西州的特定卡车道路网络,没有道路名称
gid integer NOT NULL DEFAULT nextval('trucknetwork_gid_seq'::regclass),
id numeric(10,0),
sri character varying(20),
mp_start double precision,
mp_end double precision,
descriptio character varying(50),
road_type character varying(50),
geom geometry(MultiLineStringM),
CONSTRAINT trucknetwork_pkey PRIMARY KEY (gid)
表1 - 488715条记录(带有sri列的shapefile链接和带有seg_guid列的table2) - 所有新泽西州道路的起点和终点,其中seg_guid链接到table2
gid integer NOT NULL DEFAULT nextval('table1_gid_seq'::regclass),
objectid integer,
seg_guid character varying(38),
sri character varying(20),
route_type numeric,
sld_mp_st numeric,
sld_mp_end numeric,
CONSTRAINT table1_pkey PRIMARY KEY (gid)
表2 - 669557条记录(带有seg_guid列的table1链接) - 所有NJ道路名称
gid integer NOT NULL DEFAULT nextval('table2_gid_seq'::regclass),
objectid integer,
seg_guid character varying(38),
s_name character varying(254),
CONSTRAINT table2_pkey PRIMARY KEY (gid)
我想将这3个表加入到1个表中 - 结果是每个路段的564条记录及其正确的名称。这是一对多关系。
我已经在GIS stackexchange上发布了这个问题,但我没有得到很多反馈,我想在SQL中执行此任务而不是GIS软件
我尝试了左连接,内部连接 - 我尝试过该组,但是对于每个查询我都会获得超过100,000条记录
select shp.descriptio as descr, shp.road_type as road_type, shp.geom as geom, t2.s_name as street_name
into networkEX
from trucknetwork as shp
join table1 as t1 on shp.sri = t1.sri
join table2 as t2 on t1.seg_guid = t2.seg_guid;
我不确定逻辑应该是什么,子查询?我是否必须将其分解为更小的步骤?