- 1、本文档共25页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Postgis学习笔记Postgis学习笔记
目录
POSTGIS使用命令 1
1.1初识POSTGIS 1
1.2 数据库的一些操作 4
PostgreSQL的配置文件及用户权限 6
使用过的命令: 9
POSTGIS使用命令
1.1初识POSTGIS
创建空间数据库
CREATE DATABASE my_spatial_db TEMPLATE=template_postgis;
创建表
CREATE TABLE gtest ( ID int4, NAME varchar(20) );
创建几何体
SELECT AddGeometryColumn(’’, ’gtest’,’geom’,-1,’LINESTRING’,2);
插入数据
INSERT INTO gtest (ID, NAME, GEOM) VALUES (1,First Geometry,ST
_GeomFromText(LINESTRING(2 3,4 5,6 5,7 8), -1));
5.查看表――类似show talbes(MY SQL)
导入数据
Once you have created a spatial table, you are ready to upload GIS data to the database. Currently, there are two ways to get data into a PostGIS/PostgreSQL database: using formatted SQL statements or using the Shape ?le loader/dumper。
首先是创建表极其几何关系:
CREATE TABLE roads (road_id int4, road_name varchar(20) );
SELECT AddGeometryColumn(’’, ’ roads’,’ roads_geom’,-1,’LINESTRING’,2);
然后用导入脚本文件:
psql -U postgres -W -f E:\road.sql my_spatial_db
检验函数
SELECT
st_isvalid(LINESTRING(0 0, 1 1)),
st_isvalid(LINESTRING(0 0, 0 0));
By default, PostGIS does not apply this validity check on geometry input, because testing for validity needs lots of CPU time for complex geometries, especially polygons. If you do not trust your data sources, you can manually enforce such a check to your tables by adding a check constraint:
ALTER TABLE mytable
ADD CONSTRAINT geometry_valid_check
CHECK (isvalid(the_geom));
查询
SELECT road_id, ST_AsText(roads_geom) AS geom, road_name FROM roads;
SELECT road_id, road_name FROM roads WHERE roads_geom ~= ST_GeomFromText(LINESTRING(191232 243118,191108 243242),-1);
SELECT ST_AsText(roads_geom) AS geom FROM roads WHERE roads_geom SetSRID(BOX3D(191232 243117,191232 243119)::box3d,-1);
补充:
This operator tells whether the bounding box of one geometry intersects the bounding box of another.
~= This operators tests whether two geometries are geometrically identical. For example, if ’POLYGON((0 0,1 1,1 0,0 0))’ is
the same as ’POLYGON((0 0,1 1,1 0,0 0))’ (it is).
= This operator is a little mo
您可能关注的文档
- P2P网贷,究竟安全么?.doc
- Part 1 Understanding Passages.doc
- Part 2 - Conditions of Contract.doc
- Part 1 Multiple choices.doc
- Part 5 Skimming and Scanning.doc
- Part Five 20th century.doc
- Part III. The Literature of Romanticism.doc
- Part One Early and Medieval English Literature.doc
- Part V Twentieth-century Literature - Ezra Pound.doc
- Part V Twentieth-century Literature- William Faulkner.doc
文档评论(0)