如何向 GeoDjango 提供英国国家电网参考(WKT)?
我正在尝试将一些国家网格引用插入到定义如下的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你只需要这样的东西,假设一个带有 lon1 lat1 的点:
看起来你的几何列被称为 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:
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.