Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

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

My question is this: can I store them in their original form ('TR3241', for example) or do I have to convert them to lat/lng first?

I don't know how to format them as WKT. This is what I get if I try inserting them as POINT(TR3241), which is obviously wrong:

INSERT INTO places (placeid, structidx, subidx, county, name, oscode) VALUES ('10', '1', '1', 'Kent', 'Dover', 'TR3241');
LINE 1: ...'1', 'Kent', 'D1', 'Eastry', 'Bewsbury', 'Dover', 'POINT(TR3...
                                                             ^
HINT:  "POINT(" <-- parse error at position 6 within geometry

So: is there a way that I can store points like 'TR3241' in GeoDjango, or do I have to convert them to standard lat/lng first?

I do have code to convert National Grid > lat/lng, but I was hoping GeoDjango would be able to store them in the original format, and do any conversion for me.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

As your using OSGB36 SRID 27700 - which you have set.

but your using TR3241 [OS Map Tile Ref] this needs to be OS Coordinates therefore TR3241 = 632000,141000

http://www.nearby.org.uk/coord.cgi?p=TR3241&f=full

That will solve your parse error.

share|improve this answer
    
YES. Thank you! –  AP257 Aug 20 '10 at 15:51
    
Wow, nearby.org.uk looks really useful. Thanks again. –  AP257 Aug 20 '10 at 15:52

Grid reference systems have two components: the grid reference itself, and the coordinates that reference name represents in the gridded projection. You can safely store the latter in GeoDjango (really PostGIS), which understands any coordinates in a cartesian space, but cannot perform arbitrary transformations from gridded systems into cartesian coordinates. As Mapperz mentioned, you could store your point accurately as 632000,141000.

Perhaps the simplest solution is to convert your references into their coordinates, for example in this ruby implementation, see gridrefNumToLet(e, n, digits). This will allow you to retain the coordinates precisely, and convert to and from grid references, without any conversion to lat/long. From those coordinates you can reverse the process to generate the grid reference name as needed.

share|improve this answer

As much as I know, Geodjango can't auto-magically convert UK national grid to latlong.

It would be kinda weird if it could because WKT point has specific syntax POINT(x y), which actually depends on number of spatial dimensions.

So you need to convert your text data to latlong, and then save data in database. I would assume that this data already exist in more readable form, like in Shape file, but im not from UK, nor do i know which data is available.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.