2

I am working on web application with GeoDjango and within the model (db table) RoadAxis I have geometry field or more precisely LineStringField where I need to store different polylines (road axis) for different projects (each polyline has FK to project ID). The problem is that projects will be done in different coordinate systems (i can't know them in advance) so the polylines that I will have to store will have different coordinate systems too. I know that in PostGIS database I can have geometry column with rows in different projections but when I define my Geodjango model I need to define unique SRID for all them, or he takes 4326 by default.

There are few options that I considered but none of them really solve my problem. I will try to go through some of them and I hope some of you could tell me if I got something wrong or if there is some much better idea

1) transform data just before saving to one single coordinate system (e.g. WGS84)

Problem with this approach: I can't just tansform my geometries before saving them to database by using geodjango built in functions because I would lose survey accuracy that I need for some later calculations.

2) Dynamically create new table in runtime Idea: First having only one table where geometries would be stored and it would be all in one projection system (e.g. wgs84) and then when the new project is added - if it has different coordinate system I dynamically create new table with geom field for that projection system and then I store data for that project in that new table

Problem: dynamically creating tables in django doesn't seem like happiest and easiest solution, and it could later cause lot of additional problems.

3) Using noSQL db so instead of dynamically creating new tables in relational database I could use something like MongoDB and have it document oriented Problem: this add more complexity to application and probably it's not really necessary, beside I lose possibilities I have with PostGIS (spatial queries, eventual transformation functions,...)

4) creating geometry field with some fake epsg and put all geometries in it even though they have different projection and then create additional field where i would save real srid of geometry .. Problem: not really correct and clean solution but it could help this work

5) ?

Maybe I am just missing something obvious but I really don't have clear idea what is the best way to do this.

1 Answer 1

1

I am not sure if your concern in 1) is justified. If I am not mistaken, GeoDjango stores coordinates as a float and in Python has 16 digits precision, which is probably more precision than most observed spatial data has.

For instance, to store a longitude coordinate in WGS84, you have values between -180 and 180. This takes three digits before the comma and leaves 13 digits after the comma.

If we assume an equator circumference of 40'000km, one degree represents about 111km per degree at the equator:

 40'000 km / 360 deg = 111 km/deg

That would leave us with a precision of

111 * 10^3 m / 10^13 = 1.11 * 10^-8 m ~= 10 nm

So the numerical precision of a longitude coordinate in WGS84 stored as a double float provides a precision of 10 nanometers!

Now for spatial calculations such as distance and area, using WGS84 will indeed produce wrong results, so you could consider storing the original srid in a separate integer field, and project your data back into the original projection when performing calculations. That leaves you with a problem of organizing you code, but you can savely store all data in one projection. The loss in numerical precision from reprojecting is likely to be negligible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.