如何向 GeoDjango 提供英国国家电网参考(WKT)?

发布于 2024-09-14 14:46:00 字数 1028 浏览 6 评论 0原文

我正在尝试将一些国家网格引用插入到定义如下的 Django PointField 中:

oscode = models.PointField(srid=27700, null=True, blank=True)

但是,我不知道如何在 WKT 中正确设置它们的格式。如果我尝试简单地使用基本的国家电网参考 TR3241,这就是我得到的结果:

INSERT INTO places (placeid, structidx, subidx, county, name, oscode) VALUES ('10', '1', '1', 'Kent', 'Dover', 'TR3241');
psycopg2.InternalError: parse error - invalid geometry
LINE 1: ...'1', 'Kent', 'D1', 'Eastry', 'Bewsbury', 'Dover', 'TR3241', ...
                                                             ^
HINT:  You must specify a valid OGC WKT geometry type such as POINT, LINESTRING or POLYGON

这就是如果我(在阅读 WKT 后疯狂猜测!)使用 POINT(TR3241) 得到的结果)

psycopg2.InternalError: parse error - invalid geometry
LINE 1: ...'1', 'Kent', 'D1', 'Eastry', 'Bewsbury', 'Dover', 'POINT(TR3...
                                                             ^
HINT:  "POINT(" <-- parse error at position 6 within geometry

如何正确格式化网格引用?

I'm trying to insert some National Grid references into a Django PointField defined as follows:

oscode = models.PointField(srid=27700, null=True, blank=True)

However, I don't know how to format them correctly in WKT. This is what I get if I try simply using a basic National Grid reference, TR3241:

INSERT INTO places (placeid, structidx, subidx, county, name, oscode) VALUES ('10', '1', '1', 'Kent', 'Dover', 'TR3241');
psycopg2.InternalError: parse error - invalid geometry
LINE 1: ...'1', 'Kent', 'D1', 'Eastry', 'Bewsbury', 'Dover', 'TR3241', ...
                                                             ^
HINT:  You must specify a valid OGC WKT geometry type such as POINT, LINESTRING or POLYGON

And this is what I get if I (guessing wildly after reading up on WKT!) use POINT(TR3241):

psycopg2.InternalError: parse error - invalid geometry
LINE 1: ...'1', 'Kent', 'D1', 'Eastry', 'Bewsbury', 'Dover', 'POINT(TR3...
                                                             ^
HINT:  "POINT(" <-- parse error at position 6 within geometry

How do I format the grid ref correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞琼窗梦回ˉ 2024-09-21 14:46:00

你只需要这样的东西,假设一个带有 lon1 lat1 的点:

 insert into geography_table (name, geometry_field) values ('Chez Francois',\
 ST_GeomFromText('POINT(lon1 lat1)', 27700));

看起来你的几何列被称为 oscode;要检查,请使用 psql mydb 并点击 \d。您应该看到所有表格的列表,您感兴趣的表格将被列为几何类型。底部应该有一行类似 "enforce_srid_oscode" CHECK (st_srid(oscode) = 27700) 的内容。

可能会让您感到困惑的大局是,这些记录只是常规数据库表,至少有一列包含有关地球上某些几何形状的详细信息。这些几何值上的插入必须是几何类型,并且从(相对)简单的英语到这些几何的方式是使用 几何构造函数

You would just need something like this, assuming a point with lon1 lat1:

 insert into geography_table (name, geometry_field) values ('Chez Francois',\
 ST_GeomFromText('POINT(lon1 lat1)', 27700));

It looks like your geometry column is called oscode; to check use psql mydb and hit \d. You should see a list of all tables, the one(s) you are interested in will be listed as type geometry. There should be a line at the bottom something like "enforce_srid_oscode" CHECK (st_srid(oscode) = 27700).

The big picture bit that may be throwing you off is that these records are just regular database tables, with at least one column containing details about some geometry on Earth. The inserts on these geometric values must be geometric types, and the way you get from (relatively) plain English to these geometries is with a geometry constructor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文