我使用Postgresql和PostGIS扩展进行临时空间分析.我通常在psql中手工构造和发出SQL查询.我总是在一个事务中包装一个分析会话,所以如果我发出一个破坏性的查询,我可以回滚它.
但是,当我发出包含错误的查询时,它会取消该事务.任何进一步的查询都会引出以下警告:
错误:当前事务被中止,命令被忽略直到事务块结束
有没有办法可以解决这个问题?每次我输入错字时回滚事务并重新运行以前的查询都很烦人.
该ST_DWithin文件说,第三个参数(距离)以米为单位.但是当我执行一些查询时,它似乎将第3个参数作为'degree'?
这是我的简化表结构:
> \d+ theuser;
Table "public.theuser"
Column | Type | Modifiers | Storage | Description
----------+------------------------+-----------+----------+-------------
id | bigint | not null | plain |
point | geometry | | main |
Indexes:
"theuser_pkey" PRIMARY KEY, btree (id)
"point_index" gist (point)
Referenced by:
...
Has OIDs: no
Run Code Online (Sandbox Code Playgroud)
所有点都以SRID = 4326存储.
这是查询:
> select * from theuser where ST_DWithin(point , ST_GeomFromText('POINT(120.9982 24.788)',4326) , 100 );
Run Code Online (Sandbox Code Playgroud)
它将第3个参数(100)作为'degree',因此它返回所有数据,我必须缩小到0.001以找到附近的点.
但是如何直接传递米作为第三个参数(我不想做米/度变换)?我的查询有什么问题?为什么postgreSQL不像文件那样把它作为米?
环境:
> select version();
version
-----------------------------------------------------------------------------------------------------------
PostgreSQL 8.4.9 on i486-pc-linux-gnu, compiled …
Run Code Online (Sandbox Code Playgroud) 继我之前关于此主题的问题后,Postgres结合了多个索引:
我在Postgres 9.2(带postgis)上有下表:
CREATE TABLE updates (
update_id character varying(50) NOT NULL,
coords geography(Point,4326) NOT NULL,
user_id character varying(50) NOT NULL,
created_at timestamp without time zone NOT NULL
);
Run Code Online (Sandbox Code Playgroud)
我在桌子上运行以下查询:
select *
from updates
where ST_DWithin(coords, ST_MakePoint(-126.4, 45.32)::geography, 30000)
and user_id='3212312'
order by created_at desc
limit 60
Run Code Online (Sandbox Code Playgroud)
那么,我应该使用什么索引(coords + user_id),GIST或BTree?
CREATE INDEX ix_coords_user_id ON updates USING GIST (coords, user_id);
Run Code Online (Sandbox Code Playgroud)
要么
CREATE INDEX ix_coords_user_id ON updates (coords, user_id);
Run Code Online (Sandbox Code Playgroud)
我在读BTree的表现比GIST好,但是因为我使用postgis地理领域,我被迫使用GIST?
我想使用Osm2pgsql工具将OSM文件导入我的PostgreSQL数据库(Windows,Postgres版本9.2).
当我运行以下命令
osm2pgsql.exe --create -d mydb artyom.xml -U myuser -W --style default.style
Run Code Online (Sandbox Code Playgroud)
我收到了错误
SELECT AddGeometryColumn('planet_osm_point', 'way', 900913, 'POINT', 2 );
failed: FEHLER: Funktion addgeometrycolumn(unknown, unknown, integer, unknown,
integer) existiert nicht
LINE 1: SELECT AddGeometryColumn('planet_osm_point', 'way', 900913, ...
^
HINT: Keine Funktion stimmt mit dem angegebenen Namen und den Argumenttypen ??b
erein. Sie m??ssen m?Âglicherweise ausdr??ckliche Typumwandlungen hinzuf??gen.
Error occurred, cleaning up
Run Code Online (Sandbox Code Playgroud)
德语翻译:
SELECT AddGeometryColumn('planet_osm_point', 'way', 900913, 'POINT', 2 );
failed: ERROR: Function addgeometrycolumn(unknown, unknown, integer, unknown, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试按照以下说明安装PostGIS:
wget http://postgis.refractions.net/download/postgis-1.5.2.tar.gz
tar zxvf postgis-1.5.2.tar.gz && cd postgis-1.5.2/
sudo ./configure && make && sudo checkinstall --pkgname postgis-1.5.2 --pkgversion 1.5.2-src --default
Run Code Online (Sandbox Code Playgroud)
但它没有通过"sudo ./configure"命令.它说的最后一行:
configure: error: could not find pg_config within the current path. You may need to try re-running configure with a --with-pgconfig parameter.
Run Code Online (Sandbox Code Playgroud)
所以我在网上找到了一个地方,上面写着这样的话:
--with-pgconfig = FILE PostgreSQL提供了一个名为pg_config的实用程序,可以使PostGIS等扩展程序找到PostgreSQL安装目录.使用此参数(--with-pgconfig =/path/to/pg_config)手动指定PostGIS将构建的特定PostgreSQL安装.
我使用"whereis pg_config"搜索pg_config但我找不到它.它是指"/etc/postgresql/9.0/main/pg_hba.conf"文件还是文件夹....?我错过了什么吗?我在这一点上真的很困惑.我想真正的混乱比虚假清晰:).
我正在使用PostgreSQL 9/Ubuntu 10.10.任何帮助将不胜感激.
我有Postgres版本8.4.8
select version();
PostgreSQL 8.4.8 on i686-pc-linux-gnu, compiled by GCC gcc-4.4.real (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5, 32-bit
Run Code Online (Sandbox Code Playgroud)
通过synaptic包管理器安装Postgis,(postgis和postgresql-8.4-postgis)一切似乎都没问题.然后,当我尝试验证Postgis版本时,事情并不顺利.这两个都给出了同样的错误.
SELECT PostGIS_version();
SELECT PostGIS_full_version();
ERROR: function postgis_full_version() does not exist
LINE 1: SELECT PostGIS_full_version();
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)
软件包管理器声称已安装Postgis.如何验证安装是否有效?
嗨Stackoverflow人,
我用GeoDjango做了我的第一步,我正在寻找更好的选项来检查错误的sql语句.
到目前为止,我只是想在postgresql表中保护lng + lat点.
该模型定义为:
geolocation = models.PointField(_('Geo Location'),
geography=True,
null = True,
blank = True,
help_text=_('Geolocation with Longitude and Latitude'))
objects = models.GeoManager()
Run Code Online (Sandbox Code Playgroud)
在我看来,我尝试执行以下命令
savedProject.geolocation = GEOSGeometry('POINT(%s %s)' %(u_lng,u_lat))
Run Code Online (Sandbox Code Playgroud)
但是当我尝试保存表单时收到以下错误:
异常类型:InternalError异常值:当前事务被中止,命令被忽略,直到事务块结束
这个错误的原因是什么?我相信sql语句可能有问题,但检查的最佳方法是什么?Django只提供一般错误消息"内部错误".
感谢您的帮助和建议!
我正在使用Python 3,需要使用postGIS扩展连接到postGre.我打算使用psycopg2驱动程序.
这个PPyGIS是我发现的唯一扩展,但它适用于python 2.7而不是3.3.0.
任何人都知道在3.3.0上工作的解决方案?
例如,
class Lake(Base):
__tablename__ = 'lake'
id = Column(Integer, primary_key=True)
name = Column(String)
geom = Column(Geometry('POLYGON'))
point = Column(Geometry('Point'))
lake = Lake(name='Orta', geom='POLYGON((3 0,6 0,6 3,3 3,3 0))', point="POINT(2 9)")
query = session.query(Lake).filter(Lake.geom.ST_Contains('POINT(4 1)'))
for lake in query:
print lake.point
Run Code Online (Sandbox Code Playgroud)
它回来了 <WKBElement at 0x2720ed0; '010100000000000000000000400000000000002240'>
我也试过做lake.point.ST_X(),但它也没有给出预期的纬度
将值从WKBElement转换为可读和有用的格式的正确方法是什么,比如说(lng,lat)?
谢谢
StandardError: An error has occurred, this and all later migrations canceled:
PG::InternalError: ERROR: could not load library "/usr/local/Cellar/postgresql/9.4.5/lib/postgis-2.1.so": dlopen(/usr/local/Cellar/postgresql/9.4.5/lib/postgis-2.1.so, 10): Symbol not found: __ZN5boost7archive21basic_binary_iarchiveINS0_15binary_iarchiveEE13load_overrideERNS0_15class_name_typeEi
Referenced from: /usr/local/lib/libSFCGAL.1.dylib
Expected in: /usr/local/lib/libboost_serialization-mt.dylib
in /usr/local/lib/libSFCGAL.1.dylib
: CREATE EXTENSION IF NOT EXISTS "postgis"/Users/harshamv/Sites/clink/db/migrate/20150812164615_enable_postgis.rb:3:in `change'
-e:1:in `<main>'
ActiveRecord::StatementInvalid: PG::InternalError: ERROR: could not load library "/usr/local/Cellar/postgresql/9.4.5/lib/postgis-2.1.so": dlopen(/usr/local/Cellar/postgresql/9.4.5/lib/postgis-2.1.so, 10): Symbol not found: __ZN5boost7archive21basic_binary_iarchiveINS0_15binary_iarchiveEE13load_overrideERNS0_15class_name_typeEi
Referenced from: /usr/local/lib/libSFCGAL.1.dylib
Expected in: /usr/local/lib/libboost_serialization-mt.dylib
in /usr/local/lib/libSFCGAL.1.dylib
: CREATE EXTENSION IF NOT EXISTS "postgis"
/Users/harshamv/Sites/clink/db/migrate/20150812164615_enable_postgis.rb:3:in `change'
-e:1:in `<main>'
PG::InternalError: ERROR: could not load …
Run Code Online (Sandbox Code Playgroud) postgis ×10
postgresql ×9
python ×3
database ×1
django ×1
geoalchemy2 ×1
geodjango ×1
gis ×1
macos ×1
sqlalchemy ×1
srid ×1
ubuntu ×1
ubuntu-10.10 ×1