PostGIS

PostGIS安装使用

一个人想着一个人 提交于 2020-01-07 02:44:54
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 一、安装 sudo apt install postgis postgresql-11-postgis-3 这里需要根据服务器版本选择对应的包,如服务器是最新的12则: sudo apt install postgis postgresql-12-postgis-3 二、创建数据库mygis使之具备Postgis功能 使你的OS登陆用户(这里mymotif),成为postgers数据库用户并具备建库权限: sudo -u postgres psql -c "CREATE USER mymotif WITH PASSWORD 'wxwpxh' CREATEDB ;" 建立mygis数据库: mymotif@DESKTOP-PRH2A6F:~$ createdb mygis 安装postgis以及其它的一些扩展: mymotif@DESKTOP-PRH2A6F:~$ sudo -i -u postgres psql mygis psql (12.0 (Ubuntu 12.0-2.pgdg18.04+1), 服务器 11.5 (Ubuntu 11.5-3.pgdg18.04+1)) 输入 "help" 来获取帮助信息. mygis=# CREATE EXTENSION postgis; CREATE

How could I transfer the value of point's X and Y?

梦想的初衷 提交于 2020-01-06 23:42:14
问题 The function as follows: create or replace function point_to_M(x float,y float, i integer) returns float AS $$ DECLARE geo geometry; geo1 geometry; begin select testo.geom into geo from testo where lineid=i; geo1=st_astext(st_line_interpolate_point(st_geometryN(geo,1),'point(x y)')'); return st_X(geo1); end; $$ language plpgsql; when I input the SQL: select point_to_M(80,0,0); The error is: ERROR: invalid input syntax for type double precision: "point(x y)" LINE 1: ...ext(st_line_interpolate

Regular query results in syntax error with specific attribute

最后都变了- 提交于 2020-01-06 08:06:01
问题 I run a postgres database with postgis extention. With imposm3 openstreetmap data is loaded into the scheme import. The tables are called osm_point, osm_linestring and osm_polygon. Imposm is storing NULL as empty fields . To query a specific attribute of the table, I usually write select * from import.osm_point where highway <> '' But only with the attribute natural this query is not working. As seen in this picture, the attribute natural contains some filled lines and some empty lines. When

How to switch between an indexed and non-indexed operation depending on the input?

♀尐吖头ヾ 提交于 2020-01-06 07:40:25
问题 My previous question discovered that the cause of my performance troubles is because using the indexed distance operator in Postgis is very slow on large areas that return many rows. As a result, it seems the ideal solution may be to pick some arbitrary miles distance amount and then use the indexed distance operator ( ST_DWithin ) when it's in that range (let's say, below 75 miles), and then to use the non-indexed distance operator ( <-> ) when it's above that range (so, 75 miles or above)

How to switch between an indexed and non-indexed operation depending on the input?

牧云@^-^@ 提交于 2020-01-06 07:39:30
问题 My previous question discovered that the cause of my performance troubles is because using the indexed distance operator in Postgis is very slow on large areas that return many rows. As a result, it seems the ideal solution may be to pick some arbitrary miles distance amount and then use the indexed distance operator ( ST_DWithin ) when it's in that range (let's say, below 75 miles), and then to use the non-indexed distance operator ( <-> ) when it's above that range (so, 75 miles or above)

ST_3DClosestPoint returning multiple points

痞子三分冷 提交于 2020-01-06 06:11:59
问题 Data I have 2 tables - 3D point geometries (obs.geom), n=10 - a single 3D point (target.geom), n=1 Problem - part 1 When I run the following code it lists all 10 of the obs geoms rather than just the closest point to the target.geom. Can anyone give me some pointers? SELECT ST_3DClosestPoint(target.geom, obs.geom) FROM target, obs Part 2 I then want to add in the Distance3D SELECT ST_3DDistance(ST_3DClosestPoint(target.geom, obs.geom) as dist_closest, obs.geom) as distance FROM target, obs

ST_3DClosestPoint returning multiple points

天涯浪子 提交于 2020-01-06 06:11:32
问题 Data I have 2 tables - 3D point geometries (obs.geom), n=10 - a single 3D point (target.geom), n=1 Problem - part 1 When I run the following code it lists all 10 of the obs geoms rather than just the closest point to the target.geom. Can anyone give me some pointers? SELECT ST_3DClosestPoint(target.geom, obs.geom) FROM target, obs Part 2 I then want to add in the Distance3D SELECT ST_3DDistance(ST_3DClosestPoint(target.geom, obs.geom) as dist_closest, obs.geom) as distance FROM target, obs

PHP To Retrieve PostGIS Geography Types

萝らか妹 提交于 2020-01-06 03:26:14
问题 I have a PostGIS database with a geography column. I'd like to be able to use PHP to SELECT the geography so then I could run another query using ST_Distance to get the distance between the points. However, when I run SELECT geog from locations; I get a weird value of 6 instead of the HEX output (something like 0101000020E6100000C442AD69DEAD5740575BB1BFEC6E3D40 is what I'm expecting). When I use the same query in phpPgAdmin I get the expected output, but not from my PHP script :( I'd really

How do I satisfy “enforce_srid_coordinate” constraint with GeoDjango/PostGIS?

落爺英雄遲暮 提交于 2020-01-05 09:14:59
问题 I'm using GeoDjango and have a Django model with a PointField: class ArchivrItem(models.Model): ... coordinate = models.PointField(srid=4326) When I try to insert a new ArchivrItem, using latitude and longitude, I get this error: ERROR: new row for relation "archivr_archivritem" violates check constraint "enforce_srid_coordinate" I can avoid Django and get the same error in postgresql directly by trying to do this: INSERT INTO archivr_archivritem (coordinate) VALUES ('POINT(51.520667 -0

PostGIS Error: Could not choose a best candidate function

£可爱£侵袭症+ 提交于 2020-01-05 07:38:09
问题 When creating a View, I get the error function populate_geometry_columns(unknown) is not unique . A book that I'm reading used this, but its giving me an error. What could have gone wrong for me? Query: CREATE OR REPLACE VIEW ch03.vw_paris_points AS SELECT gid, osm_id, ar_num, geom, tags->'name' As place_name, tags->'tourism' As tourist_attraction FROM ch03.paris_hetero WHERE ST_GeometryType(geom) = 'ST_Point'; SELECT populate_geometry_columns('ch03.vw_paris_points'); Error: ERROR: function