我是这个的新手,所以任何建议都表示赞赏.
我正在运行以下版本:
> Postgresql:9.2
> PostGIS:2.0
这是架构:
-- ------------------------------ table structure for "citIEs-usa"-- ----------------------------DROP table IF EXISTS "citIEs-usa";CREATE table "citIEs-usa" ("gID" int4 NOT NulL DEFAulT nextval('"citIEs-usa_gID_seq"'::regclass),"st_fips" varchar(4),"sfips" varchar(2),"county_fip" varchar(4),"cfips" varchar(4),"pl_fips" varchar(7),"ID" varchar(20),"name" varchar(39),"elevation" varchar(60),"pop_1990" numeric,"population" varchar(30),"st" varchar(6),"state" varchar(16),"warngenlev" varchar(16),"warngentyp" varchar(16),"watch_warn" varchar(3),"zwatch_war" float8,"prog_disc" int4,"zprog_disc" float8,"comboflag" float8,"land_water" varchar(16),"recnum" float8,"lon" float8,"lat" float8,"geom" "geometry")WITH (OIDS=FALSE);ALTER table "citIEs-usa" OWNER TO "postgres";-- ------------------------------ Primary key structure for table "citIEs-usa"-- ----------------------------ALTER table "citIEs-usa" ADD CONSTRAINT "citIEs-usa_pkey" PRIMARY KEY ("gID") NOT DEFERRABLE INITIALLY IMMEDIATE;逻辑可以包装到一个函数中,但我建议使用查询来测试逻辑.您将遇到的困难是线性距离(英里)与角度坐标(纬度和经度)相结合.此外,上面指定的几何类型没有SRID或几何类型.我猜它应该是几何(Point,4326).
您可以尝试一些策略,例如使用地理类型,它可以自动使用仪表来处理ST_distance或ST_DWithin等功能.下面的示例只使用ST_distance_Sphere,从英里到米的转换让你前进.或者,如果您需要演奏,可以尝试使用< - >功能为indexed nearest neighbour search.
您可以尝试以下方法:
CREATE OR REPLACE FUNCTION WhatAminear(lat float8,lon float8,radius_mi float8,num int DEFAulT 10) RETURNS SetoF "citIEs-usa" AS$body$SELECT *FROM "citIEs-usa"WHERE ST_distance_Sphere(geom,ST_MakePoint(lon,lat)) <= radius_mi * 1609.34liMIT num;$body$LANGUAGE sql VolATILE;
然后:
SELECT WhatAminear(44.9,-93.1,100);总结
以上是内存溢出为你收集整理的postgresql – PostGIS:找到最接近给定点的几何体全部内容,希望文章能够帮你解决postgresql – PostGIS:找到最接近给定点的几何体所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)