Choosing coordinate system to store geography data for celestial coordinates

Check out pgsphere, it's specifically designed for handling astronomical data.

http://pgsphere.projects.postgresql.org/


It is possible to store celestial positions in PostGIS - you just need to create your own coordinate system!

PostGIS gets all its coordinate system and projection information from the table spatial_ref_sys which is normally populated when the database is initialized. But there is nothing stopping you adding your own projections - indeed it is practically encouraged.

In common with almost every GIS/spatial database/mapping product out there, PostGIS uses Proj4 for its projection needs, and so you need to put a Proj4 string into the spatial_ref_sys table. A simple spherical SRS in Proj4 form is: +proj=longlat +ellps=sphere +no_defs. PostGIS also requires a WKT version of the projection, but I think that's just used as pretty text.

You will also need to come up with a unique SRID for your new SRS, as well as an "authority", but this can be anything you like.

So to insert a new entry into spatial_ref_sys, just perform this SQL:

insert into spatial_ref_sys values(40000, 'ME', 1, 
'GEOGCS["Normal Sphere (r=6370997)",DATUM["unknown",SPHEROID["sphere",6370997,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]',
'+proj=longlat +ellps=sphere +no_defs');

Note that I have chosen 40000 as the SRID - this is the number you use in your celestial object table. The authroity is "ME", but this could be your name, organization, or anything really up to 256 characters. The next number, 1, is just your unique identifier for that entry, relative to the authority. In theory you could refer to this entry as ME:1, but for all PostGIS processing, its the unique SRID that counts. The WKT entry I generated with GDAL and Python:

import osgeo.osr as osr
srs = osr.SpatialReference()
srs.ImportFromProj4('+proj=longlat +ellps=sphere +no_defs')
srs.ExportToWkt()

Now the caveats:

  • Right ascension will have to be specified in degrees rather than hour-angles.
  • A number of PostGIS functions aren't designed for unprojected data, but it's the same issue if you have terrestrial data in WGS84 long/lat.
  • As it stands, the data is geocentric. If you want to do any observational work with it, I suggest using something like PyEphem.
  • I've not tried creating any data in this SRS, so YMMV.
  • I'm quite interested in this now though, so I may have to play around with importing the Hipparchos catalogue... :)