




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
3空间数据库实验指导书-PostGIS的空间数据库操作PostGIS的空间数据库操作1、SHP导入POSTGIS数据库导出sql再导入数据库方法1:以SQL文件为中间媒介实现shp导入空间数据库Stepl :shp2pgsql-s4326F:\spatial\data\cities.shpcities>D:\cities.sql说明:-s设置坐标系统;F:\spatial\data\cities.shp指定数据源;cities目标表名称。Step2:运行postgres数据库;输入登录密码:admin进入数据库;选中postgis数据库Step3:点击工具栏上的皤,弹出sql窗口
Step4:点击口,找到刚才生成的SQL文件,打开,运行》即可。方法2:通过命令行直接导入空间库Stepl :shplpgsql-s4326F:\spatial\data\cities.shppublic.citiespsql-Upostgres-padmin-dpostgis说明:-s设置坐标系统;F:\spatial\data\cities.shp指定数据源;public.cities目标表名称;-U用户名;-p密码;-d空间数据库名称。方法方法3:通过界面导入空间库审助和支持Step3:点击——Ad审助和支持Step3:点击——AdlFile一,在对话框找到需要转入空间数据库的shp文件,openStepl:在开始菜单中,运行postgis2.0下面的©MyEdipsePostGlS2.0forPostgreSQLx649.0APostGIS2.0ManualOn-LinePostGlS2.0ShapefileandDBFLoaderExporter-PostGlSDocumentationOn-LineIIPostGlSJDBCDriverOn-LineDo«PlPostGlSWebsitePostgreSQL9.0WinRARStep2:点击Viewconnectiondetails...,设置数据库连接;确定,如果成功,在前一界面上会出现"Connectionsucceeded.v的信息。
点击Step4:点击・^^点击Step4:点击・^^即可导入数据Step5:如果数据中的字段存在汉字的话,可以Optio-ns...进行编码设置。2、SHP导入POSTGIS数据库方法1:通过命令行直接导出shppgsq12shp-fd:\shop_point.shp-hlocalhost-upostgres-Padminpostgispublicities说明:-fd:\shop_point.shp导出文件的名称和路径;-h数据库的ip地址;-U用户名;-p密码;postgis空间数据库名称;publicities空间数据库表的名称方法方法2:通过命令行直接导出shp果成功,在前一界面上会出现“Connectionsucceeded.”的信息。果成功,在前一界面上会出现“Connectionsucceeded.”的信息。Step3:选择export界面QtPostGISS^i5prfileImporVExpartManagerStepl:在开始菜单中,运行postgis2.0下面的Step2:点击,设置数据库连接;确定,如工 viewconnectiondetails,设置数据库连接;确定,如Step3:点击二AddT5ble;再点击匚Export二即可3、PostGIS函数分类字段处理函数AddGeometryColumn为已有的数据表增加一个地理几何数据字段;DropGeometryColumn删除一个地理数据字段的;SetSRID设置SRID值几何关系函数这类函数目前共有10个,分别是:Distance,Equals,Disjoint,Intersects,TouchesCrosses,Within,Overlaps,Contains,Relate几何分析函数这类函数目前共有12个,分别是:Centroid,Area,Lenth,PointOnSurface,Boundary,Buffer,ConvexHull,Intersection,SymDifference,Difference,GeomUnion,MemGeomUnion读写函数这类函数很多,主要是用于在各种数据类型之间的转换,尤其是在于Geometry数据类型与其他如字符型等数据类型之间的转换,函数名如AsText、GeomFromText等。4、Geo-SQL查询Selectc1.city_nameFromCitiesC1,RiversR WhereST_Overlaps(C1.geom,ST_Buffer(R.geom,3000))Selectc1.city_nameFromCitiesC1,(Selectgeomfromriverswherename='Alabama')asm WhereST_Overlaps(C1.geom,ST_Buffer(m,3000))Selectc1.city_nameFromCitiesC1,(SelectST_Buffer(geom,3000)asddfromriverswherename='Platte')asmWhereST_Overlaps(C1.geom,m.dd)=trueSelect c1.city_name,ST_Overlaps(C1.geom,m.dd)FromCitiesC1,(SelectST_Buffer(geom,3000)asddfromriverswherename='Platte')asm做一个点查询(查询州数据)ST_Within点查询城市ST_Within查询某一州包含的城市ST_Contains查询面价大于XX的州有哪些ST_Area查询州的名字(按照面积从大到小排序)ST_Area条件查询空间数据,查询结果的空间数据,用文本显示ST_AsText与某点距离小于XX的要素有哪些(点线面分别查询一次)ST_Distance、ST_MakePoint查询名字为XX的河流,流经哪些州ST_Crosses将某个城市平移一定的距离ST_GeomFromText、ST_AsText附件:常用的Geo-SQL查询SELECTshengjie_,shijie_FROMshengjie_region,shijie_regionwhereshijie_vincena=shengjie_ andST_Within(ST_MakePoint(121.54,38.91),shengjie_region.geom)点查询某省份,并找到该省份的城市SELECTnameFROMshijie_regionwhereST_Within(ST_MakePoint(121.54,38.91),geom)SELECTshengjie_,shijie_FROMshengjie_region,shijie_regionwhereST_Within(ST_MakePoint(121.54,38.91),shijie_region.geom)andST_Within(ST_MakePoint(121.54,38.91),shengjie_region.geom)SELECTshengjie_,shijie_,xianjie_ FROMshengjie_region,shijie_region,xian_point,xianjie_region whereST_Within(ST_MakePoint(121.54,38.91),shengjie_region.geom) andST_Within(ST_MakePoint(121.54,38.91),shijie_region.geom) andST_Within(ST_MakePoint(121.54,38.91),xianjie_region.geom)SELECTnameFROMguodao_polylinewhereST_Within(ST_MakePoint(121.54,38.91),geom)selectname,st_distance(ST_MAKEPOINT(116.5640.276),geom)asdistancefromshengjie_regionwherename='天津市'orname='辽宁省'orname='北京市'selectst_point(63.573566,44.646244)fromdual;SELECTST_AsText(geom)aswktFROMshengjie_regionwherename='新疆维吾尔自治区’SELECTST_AsEWKT(geom)asbufferFROMshengjie_regionSELECTST_AsText(st_transform(st_setsrid(ST_Buffer(st_transform(st_setsrid(st_geomfromtext('"+wkt+"'),4326),2333),10800),2333),4326))FROMdualSELECTST_MakePoint(121.55223,38.86758)fromdual;SELECTst_distance(ST_MakePoint(121.55223,38.86758),geom)fromgongyuan_point;SELECTnameFROMgongyuan_pointwhereST_Within(ST_MakePoint(121.54,38.91),geom)SELECTST_SetSRID(ST_MakePoint(121.55223,38.86758),4326);SELECTname,st_distance(ST_MakePoint(12L55223,38.86758),geom)fromgongyuan_pointwherest_distance(ST_MakePoint(121.55223,38.86758),geom)<0.02;SELECTgid,name,st_setsrid(ST_MakePoint(12L55223,38.86758),4326)fromgongyuan_pointwherest_distance(ST_MakePoint(121.55223,38.86758),geom)<0.02;SELECTST_Distance(ST_Transform(ST_GeomFromText('POINT(121.5522338.86758)',4326),26986),ST_Transform(ST_GeomFromText('POINT(121.5622438.87757)',4326),26986));selectgid,POINT(geom)fromgongyuan_point wherest_distance(ST_MakePoint(121.55223,38.86758),geom)<0.02;SELECTST_Distance(ST_Transform(ST_GeomFromText('POINT(121.5522338.86758)',4326),26986),ST_Transform(ST_GeomFromText('POINT(121.5617140838.87784198)',4326),26986));SELECTST_DWithin(ST_Transform(ST_GeomFromText('POINT(121.5522338.86758)',4326),26986),ST_Transform(ST_GeomFromText('POINT(121.5617140838.87784198)',4326),26986),1500)fromdual;SELECTST_DWithin(ST_Transform(ST_GeomFromText('POINT(121.5522338.86758)',4326),26986),ST_Transform(ST_GeomFromText('POINT(121.5617140838.87784198)',4326),26986),1400)fromdual;SELECTname,st_distance(ST_MakePoint(12L55223,38.86758),geom)fromgongyuan_pointwherest_distance(ST_MakePoint(121.55223,38.86758),geom)< 0.02orderbyst_distance(ST_MakePoint(121.55223,38.86758),geom);SELECTST_Transform(ST_GeomFromText('POINT(121.5522338.86758)',4326),26986)fromdualSELECTST_Transform(point(t.geom,26986),5144)fromgongyuan_pointtSELECTpoint(gongyuan_point.geom)fromgongyuan_pointSELECTname,gidFROMgongyuan_pointORDERBYgeom<->st_setsrid(st_makepoint(121.55223,38.86758),4326)LIMIT10;selectst_extent(geom)aswgs84fromgongyuan_point;selectgid,st_x(geom),st_y(geom),st_z(geom),POINT(geom)fromgongyuan_pointwherest_distance(ST_MakePoint(121.55223,38.86758),geom)<0.02;selectgid,st_x(geom),st_y(geom),st_z(geom),POINT(geom),st_srid(geom) fromgongyuan_point wherest_distance(ST_MakePoint(121.55223,38.86758),geom)<0.02;30.selectST_Area(geom),gid,st_AsText(geom),st_x(geom),st_y(geom),st_z(geom),POINT(geom),st_srid(geom)fromgongyuan_pointwherest_distance(ST_MakePoint(121.55223,38.86758),geom)<0.02;selectST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)fromgongyuan_pointwherest_distance(ST_MakePoint(12L55223,38.86758),geom)<0.02;selectST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)fromgongyuan_pointwhereST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)<1000;selectST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)fromgongyuan_pointwhereST_distance_sphere(ST_MakePoint(121.55223,38.86758),geom)<1500;selectST_distance_sphere(ST_MakePoint(121.55223,38.86758),geom),ST_AsBinary(geom),ST_AsEWKT(geom),ST_AsEWKB(geom),ST_AsHEXEWKB(geom) fromgongyuan_point whereST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)<1500;selectname,ST_distance_sphere(ST_MakePoint(121.55223, 38.86758),geom)fromgongjiaozhan_point whereST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)<500;selectname,ST_distance_sphere(ST_MakePoint(121.55223, 38.86758),geom)fromdasha_point whereST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)<1500;selectname,ST_distance_sphere(ST_MakePoint(121.55223, 38.86758),geom)fromdasha_point whereST_distance_sphere(ST_MakePoint(121.55223,38.86758),geom)<1500orderbyST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)limit1;selectname,ST_distance_sphere(ST_MakePoint(121.55223, 38.86758),geom)fromchaoshishangcheng_point whereST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)<500orderbyST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)limit1;SELECTnameFROMshengjie_regionwhereST_Within(ST_MakePoint(121.55223,38.86758),geom)SELECTnameFROMshijie_regionwhereST_Within(ST_MakePoint(121.55223,38.86758),geom)SELECTnameFROMxianjie_regionwhereST_Within(ST_MakePoint(121.55223,38.86758),geom)selectname,ST_distance_sphere(ST_MakePoint(121.55223,38.86758),geom),st_x(geom),st_y(geom)from dasha_point whereST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)<3000orderbyST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)limit1;selectname,ST_distance_sphere(ST_MakePoint(121.55223,38.86758),geom),st_x(geom),st_y(geom)frombinguanjiudian_pointwhereST_distance_sphere(ST_MakePoint(12L55223,38.86758),geom)<3000orderbyST_distance_sphere(ST_MakePoint(121.55223,38.86758),geom)limit1;selectST_AsEWKT(ST_Difference(st_geomfromText('LINESTRING(11,2 3,3 4,31)'),st_geomfromText('LINESTRING(20,22,52,31)')))fromdual;selectST_AsEWKT(ST_Difference(st_geomfromText('POLYGON((11,23,34,3 1,11))'),st_geomfromText('POLYGON((20,22,52,13,20))')))fromdual;selectGeometryType(st_geomfromText('MULTILINESTRING((11,23,34,31,21,11),(12,23,45))'))fromdual;SELECTname,st_area(geom)asareafromshengjie_regionORDERBYareaDESCLIMIT1;SELECTst_Length2d(st_GeomFromText('MultiLineString((11,22,33),(44,55))'))fromdual;SELECTgid,name,st_astext(geom)ASLinestring,st_length(geom) FROMguodao_polylinewherename='东北路';SELECTname,st_astext(geom)FROMguodao_polylinewheregid='152415';SELECTgid,st_astext(geom)ASMULTIPOINTFROMguodao_polylineWHEREgid=152415;SELECTst_astext(geom)ASMLINESTRING FROMguodao_polyline;SELECTnameFROMguodao_polylinewheregid='152415';SELECTST_AsEWKT(ST_Line_Interpolate_Point(the_line,0.5))FROM (SELECTST_GeomFromEWKT('LINESTRING(123,456,678)')asthe_line)Asfoo;SELECTST_AsText(ST_Line_Interpolate_Point(foo.the_line,ST_Line_Locate_Point(foo.the_line,ST_GeomFromText('POINT(43)'))))FROM (SELECTST_GeomFromText('LINESTRING(12,45,67)')Asthe_line)Asfoo;SELECTST_AsText(ST_Line_SubString(ST_GeomFromText('LINESTRING(2550,100125,150190)'),0.333
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论