PostgreSQL (shp2pgsql) AddGeometryColumn 给出“没有函数匹配给定的名称”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7323857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:17:06  来源:igfitidea点击:

PostgreSQL (shp2pgsql) AddGeometryColumn gives "No function matches the given name"

postgresqlpostgis

提问by Richard

I'm working with the PADUS OBI shape file, not that that's probably important.

我正在使用PADUS OBI 形状文件,这可能并不重要。

I'm running the shape file through shp2pgsql using the default options, as in:

我正在使用默认选项通过 shp2pgsql 运行形状文件,如下所示:

shp2pgsql PADUS_1_1_CBI_Edition.shp > PADUS.sql

Then I'm trying to import the SQL into Postgres by doing:

然后我尝试通过执行以下操作将 SQL 导入 Postgres:

psql -d padusdb -f PADUS.sql

And getting the following error:

并收到以下错误:

psql:PADUS.sql:36: ERROR:  function addgeometrycolumn(unknown, unknown, unknown, unknown, unknown, integer) does not exist
LINE 1: SELECT AddGeometryColumn('','padus_1_1_cbi_edition','the_geo...
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

I have PostGIS installed.

我已经安装了 PostGIS。

The SQL commands leading to the error (being put into an otherwise empty database) are:

导致错误的 SQL 命令(被放入一个空的数据库中)是:

SET CLIENT_ENCODING TO UTF8;
SET STANDARD_CONFORMING_STRINGS TO ON;
BEGIN;
CREATE TABLE "padus_1_1_cbi_edition" (gid serial PRIMARY KEY,
"us_id" int4,
"category" varchar(10),
"gis_acres" numeric,
...
BUNCH OF COLUMNS, none of which is called "the_geom"
...
"comments" varchar(200),
"shape_leng" numeric,
"shape_area" numeric);
SELECT AddGeometryColumn('','padus_1_1_cbi_edition','the_geom','-1','MULTIPOLYGON',2);
COMMIT;

Any thoughts on what this might mean and how to resolve the problem?

关于这可能意味着什么以及如何解决问题的任何想法?

回答by Richard

So, as it turns out, it is not enough to simply have installed PostGIS on one's machine.

因此,事实证明,仅仅在自己的机器上安装 PostGIS 是不够的。

Originally, I'd chosen sudo apt-get install postgresql postgison Ubuntu 10.10. This left me with a working version of PostGRE 8.4, but no sign of PostGIS.

最初,我选择sudo apt-get install postgresql postgis了 Ubuntu 10.10。这给我留下了 PostGRE 8.4 的工作版本,但没有 PostGIS 的迹象。

Therefore, I tried sudo apt-get install postgresql-8.4-postgis.

因此,我尝试了sudo apt-get install postgresql-8.4-postgis.

But one's work doesn't end there! You need to set up the PostGIS database.

但一个人的工作并不止于此!您需要设置 PostGIS 数据库。

Thiswebsite provides instructions on doing this and using the database afterwards.

网站提供有关执行此操作和之后使用数据库的说明。

回答by atorres757

It also sounds like the database needs to be spatially enabled. The reason it's throwing that errors is because the function is missing. This resourcehas a quick and easy answer and solution.

听起来数据库也需要在空间上启用。它抛出错误的原因是因为缺少该函数。该资源有一个快速简便的答案和解决方案。

回答by R.D. Harles

Thanks atorres757! Your answer solved my problem in minutes. I deleted my database and created a new database and choose the template_postgis as my template. All shapefiles are importing fine with my python script like this:

感谢atorres757!您的回答在几分钟内解决了我的问题。我删除了我的数据库并创建了一个新数据库并选择了 template_postgis 作为我的模板。所有 shapefile 都可以通过我的 python 脚本正常导入,如下所示:

for lyr in iList:

os.system("shp2pgsql -c -s 4326 -k -I -W UTF-8 "+lyr[:-4]+" "+lyr[:-4]+" | psql -d AWM -p 5432 -U postgres")

对于 iList 中的 lyr:

os.system("shp2pgsql -c -s 4326 -k -I -W UTF-8 "+lyr[:-4]+" "+lyr[:-4]+" | psql -d AWM -p 5432 -U postgres")

回答by David Chan

this error indicates that the function cannot be recognized (either function name or parameters types are incorrect)

此错误表示无法识别该函数(函数名称或参数类型不正确)

this is the definitions for AddGeometryColumnin v7.2

这是v7.2 中AddGeometryColumn定义

text AddGeometryColumn(varchar table_name, varchar column_name, integer srid, varchar type, integer dimension);

text AddGeometryColumn(varchar schema_name, varchar table_name, varchar column_name, integer srid, varchar type, integer dimension);

text AddGeometryColumn(varchar catalog_name, varchar schema_name, varchar table_name, varchar column_name, integer srid, varchar type, integer dimension);

it looks to me like you're trying to use the 2nd definition, try changing it to use the first definition (no schema) and try unquote the srid (-1) since it should be passed as an integer.

在我看来,您正在尝试使用第二个定义,尝试将其更改为使用第一个定义(无架构)并尝试取消引用 srid (-1),因为它应该作为整数传递。

You may need to cast everything...

您可能需要投射所有内容...