[GIS] Using geometry rather than geography data types in SQL Server Spatial

coordinate systemgeography-data-typegeometry-data-typesql-server-spatial

Historically I've mainly worked with simple latitude and longitude coordinates in a SQL Server. I stored them as a geography datatype in SQL Server, and rendered them on a variety of displays (primarily Google Maps).

Recently I've started working with shapefile datasets from various sources, and almost exclusively they are geometry. Further, they use a variety of coordinate reference systems.

It's pretty maddening to work with.

Are there really some advantages to these particular spatial reference systems that cannot be achieved by sticking with WGS84, considering that the VAST majority of people viewing and consuming will want it in that format?

Best Answer

There's a good answer over at Stack Overflow, which goes a little something like this:

The geography type is a little bit more restrictive than geometry. It can't cross different hemispheres and the outer ring must be drawn counter-clockwise.

The rest can be found in Geography data type vs. Geometry data type in SQL Server.

A Geometry vs Geography article at the SQL from the Trenches blog goes into more detail:

If you’re looking for the biggest difference between the two datatypes, you’ll see it’s the functionality. A Geometry object is just a 2D, flat polygon. This means, it doesn’t matter if you take a country on top of the earth (for example Canada, which is “curved”), or a country close to the Equator (for example Brazil, which is “flat”).

A Geography object on the other hand, is a 3D (or even 4D) polygon, that has the same curve as the shape of the earth. That means that the difference between 2 point isn’t calculated in a straight line, but it’s need to consider the curvature of the earth.

Another crucial difference is the ability store your data in standard coordinate systems, such as NAD_1983_StatePlane_California Zone 5, and use all the capabilities of the spatial database, spatial functions, etc. and most importantly the spatial accuracy of a localized coordinate system - whereas sticking with geography as your data type, you can only store your data in WGS84.

So I'd say if you have the option, go with geometry, use EPSG: 102645/102245 (you'll have to check what is the standard 'state plane zone 5' for SoCal) and you'd be all set for any analysis you want to undertake. If you want to share, export your datasets to WGS84 if that is preferred for sharing.