PostGis and datatypes WKT - database

I dont't have any experience with the geographics databases so I hope that you be patiente with me, the thing is: I know that the datatype geography is used if all you care about is measuring distances and lengths and you have data from all over the world and the datatype geometry is used is best if you are pretty comfortable with spatial reference systems or you are dealing with localized data where
all your data fits in a single spatial reference system (SRID), or you need to do a lot of spatial processing (that's what I read in chapter 3 of the documentation of postgis) and I saw on the link https://www.tutorialspoint.com/postgresql/postgresql_data_types.htm the following datatypes: point, line, lseg, box, path, path, polygon and circle. And then I saw the documentation again of the postgis on the section 4.1.3 SQL-MM Part 3 about the following types with the extension well-know text: circularString, compoundCurve, curvePolygon, multiCurve, multiSurface. What I don't understand is: what is the difference between these datatypes?

Related

Basic interpretation of two table operations (row wise/not row wise) in Postgis

I'm new in PostGIS, I has been reading the docs, usually the docs are very good written, at least for tables of 1 row D:
Probs this will be a silly question, or obvs too all ones that know postgis, but plis help a little to can go inside from other languages.
I have checked a lot from:
https://postgis.net/workshops/postgis-intro/
Sadly, I still can't get an answer for a simple question, the behavior of a lot of functions in table-table operations.
I know R/sf, and I'm trying to learn Postgis, but usually, every function have its own way to relate the functions, as example, IIRC intersects exists in sf and geopandas, but..., the behavior of the function is different, even when they have the same name.
Lets pick an example:
https://postgis.net/docs/ST_Intersects.html
The function is defined as:
boolean ST_Intersects( geometry geomA , geometry geomB );
All the params are defined a geometry, that means it can be a column or a singular geometry, but we don't know what will be the behavior if the tables has more than 1 row, maybe when it says "geometries" will interpret the full table as one big geometry.
Then I can go to this link:
https://postgis.net/docs/geometry_overlaps.html
Where I can finally see a result that seems a matrix operation..., at some extent, here is where the possibilities starts to open.
Intersects is a row wise function?
Intersects will intersects every from from the first table over the second table? in case how would be the return...? (need a table of rows(table1)*rows(table2), this is not written in the docs)
Here above, are just the questions and what is confusing, checking intersects, now lets go back to the specific issue.
Probably, the relation of the functions is a common sense in postgis, because in the doc that is omitted, and not only in intersects in others like intersection, disjoint, etc. I think all of them has the same behavior, is just implicit.
So, postgis works in a element-element? table-element? element-table? table-table? or other interpretation? or every function have its own way but is not written or I need search on other place?
Thx!

Can the .fbx file format or the .dwf file format hold Product Manufacturing Information (PMI) data?

Is there somewhere I can find information about these 3D file formats or other ones? I am particularly interested in seeing which file formats can hold PMI data?
Product Manufacturing Information (PMI) is usually defined by the following components:
GD&T (geometrical dimensioning and tolerancing).
3D annotations / symbols.
Captured views.
These might be also represented in two ways in format:
Graphical representation (how to actually display information in 3D viewer - usually in form of pre-tessellated geometry).
Semantic representation (just marks / annotates real geometry with extra information; it is up to the application how to use / display this information to user).
There are two key ISO standardized file formats that mentions PMI explicitly:
STEP (most noticeably AP242). Here is a live example of GD&T in STEP.
JT (mostly promoted by a single vendor).
Proprietary and native file formats (specific to one product) might also support PMI (like Catia V5 / SOLIDWORKS), but they are not expected to be used for data exchange. I don't think that FBX has anything directly related to PMI.
There are might be more formats supporting PMI (3D PDF?), but I haven't seen much information about that.

Does anyone know of potential problems with st_line_substring in postGIS?

Specifically I'm getting a result that I do not understand. It is possible that my understanding is simply wrong, but I don't think so. So I'm hoping that someone will either say "yes, that's a known problem" or "no, it is working correct and here is why your understanding is wrong".
Here is my example.
To start I have the following geometry of lat/longs.
LINESTRING(-1.32007599 51.06707497,-1.31192207 51.09430508,-1.30926132 51.10206677,-1.30376816 51.11133597,-1.29261017 51.12981493,-1.27510071 51.15906713,-1.27057314 51.16440941,-1.26606703 51.16897072,-1.26235485 51.17439257,-1.26089573 51.17875111,-1.26044512 51.1833917,-1.25793457 51.19727033,-1.25669003 51.20141159,-1.25347137 51.20630532,-1.24845028 51.21110444,-1.23325825 51.22457158,-1.2274003 51.22821321,-1.22038364 51.23103494,-1.20326042 51.23596583,-1.1776185 51.24346193,-1.16356373 51.24968088,-1.13167763 51.26363353,-1.12247229 51.2659966,-1.11629248 51.26682901,-1.10906124 51.26728549,-1.09052181 51.26823871,-1.08522177 51.26885628,-1.07013702 51.27070895,-1.03683472 51.27350122,-1.00917578 51.27572955,-0.98243952 51.2779175,-0.9509182 51.28095094,-0.9267354 51.28305811,-0.90499878 51.28511151,-0.86051702 51.2883055,-0.83661318 51.29023789,-0.7534647 51.29708113,-0.74908733 51.29795323,-0.7400322 51.2988924,-0.71535587 51.30125366,-0.68475723 51.29863749,-0.65746307 51.30220618,-0.63246489 51.30380261,-0.60542822 51.30645873,-0.58150291 51.3103219,-0.57603121 51.31150225,-0.57062387 51.31317883,-0.54195642 51.32475227,-0.4855442 51.34771616,-0.4553318 51.36283147)
This is in a column called "geom" in my table, called "fibre_lines". When I run the following query,
select st_length(geography(geom), false) as full_length,
st_length(geography(st_line_substring(geom, 0, 1)), false) as full_length_2,
st_length(geography(st_line_substring(geom, 0, 0.5)), false) as first_half,
st_length(geography(st_line_substring(geom, 0.5, 1)), false) as second_half
from fibre_lines
where id = 10;
I get the following result...
76399.4939375278 76399.4939375278 41008.9667229201 35390.5272197668
The first two make sense to me, they are simply the length of my line assuming a spherical earth. The first is just using the obvious function while the second is using st_line_substring to get the length of the entire line. These two values agree.
But the last two have me puzzled. I am asking for the length of the first half of the line, then I'm asking for the length of the last half. My expectation was that these would be equal or nearly equal. Instead the first half is about 6km longer than the second half.
If you plot the geometry on the map you will see that the first third of the line is fairly north/south oriented and the remaining two thirds are more east/west. I wouldn't have thought that would make a difference when asking for the length on a spherical earth, but I am happy to be told that I'm wrong (so long as it is also explained why I'm wrong).
For reference the PostGIS I am using is 1.5.8. If this is a bug, upgrading to a newer version is possible, but not trivial, so I would prefer to only do that if it is necessary.
Anyone have ideas?
While Arunas' comments didn't directly answer my question, it did lead me to some research that I think identifies the problem. I'm posting it here in part to get it straight in my own mind and in part in case others are wondering.
It seems the key is the PostGIS distinction between a "geometry" and a "geography". A geometry is a 2D planar geometry that is typically in UTMs and used with a projection of the globe onto a flat surface (which projection is configurable). A geography, on the other hand, is designed to store latitude/longitude information specifically and is used to work either on a sphere or a spheroid. So the essential problem I have is twofold:
Perhaps not obvious from my original post is that I am using a geometry object to store lat/long information rather than UTMs. I cast that to a geography most of the time so that I get the correct answers, but it would be more correct if I actually stored it as a geography object. That would eliminate the need for a number of the casts in my code as well as allow PostGIS to tell me when I am doing something wrong.
While ST_Length will work with either a geometry or a geography, ST_Line_Substring only works with geometries. Hence when I ask it for the halfway point, I am asking it for the halfway point of a flat geometry. This will give me the correct answer for the latitude coordinate, but for the longitude it will have an error term that increases (for most projections) the farther I am from the equator.
I've looked into newer versions of PostGIS and they don't seem to have an ST_Line_Substring or anything similar that will give me the 50% point of a geography, so I will have to do it the "hard" way by using ST_Length to give me all my segment lengths and then adding them up and doing the math needed for my interpolation.
Sorry I can't add comments so will provide it as an answer.
I experienced the same problem and I resolved by transforming my lat-lon geometries to utm geometries into st_line_substring function call. The I as getting sub-geometries with proper length. Of course I had to transform them back to lat-lon afterward.

SRID meaning in postgis

I would like to find out what is the pragmatic meaning of SRID (spatial reference id) in postgis.
I really do not understand what it is for. Can anyone throw some light on the matter?
For instance I noticed that the postigs function ST_GeomFromText(text WKT, integer srid) accept such an (optional) param as second argument. Why would I need to pass it in the get postigs to turn the text representation into a binary one? What is the value it adds?
Thanks
Spatial reference ID refers to the spatial reference system being employed -- this is important when going from a a geographic view of the world to a projected view of the world, ie, what you see when you look at a 2 dimensional paper map.
Spatial reference systems contain a couple of elements.
Firstly, the geoid, is a model of the shape of the earth -- the earth is not a sphere (sh, don't tell Google), it is in fact an oblate spheroid. The geoid shape used for GPS is known as WGS84, which is a model that works faily well globally. National mapping agencies use other geoids, that might be a better fit to local geographies.
Secondly, the projection type. This is essentially the mathematical model used to go from a 3D to a 2D representation of the world. Types include Mercator, Transverse Mercator, (both cylindical), Azimuthal, Conic, etc. All of these have trade-offs between accurately measuring distance, area or direction -- you can't preserve all three.
So, essentially when you declare a SRID in Postgis you are saying use this geoid and this projection model. Under the hood, Postgis uses a library called Proj.4, and based on the SRID information, it can convert from one coordinate system to another.
So, for example, to convert from lat/lon, which is know as 4326 in SRID terms to 900913, which is spherical Mercator, as used by Google/Bing maps, and other web mapping frameworks, you could run something like:
select st_astext(st_transform(st_setsrid(st_makepoint(-.5,52),4326),900913));
This is an example of a query I use. It uses the Lambert azimuthal equal-area projection (ETRS89-LAEA, srid = 3035).
ST_GeomFromText('POINT(2843711.1098048678, 2279498.6551480694)', 3035);
If you don't pass the srid, postgis will not know which spatial reference system to use.

how to map wgs84 coordinates to sql server b-tree index (w/o using built in spatial indexes)

I would like to be able to map geographic points from WGS84, I believe, formatted for ms sql server, to the set of cells it would touch if the same coordinate pair were to be tessallated into an sql server spatial index with 4 hiearchical grids of 256 cells each.
The sql server 2008 spatial index does not ideally suit our needs because it doesn't support the use of both geographic and non-geographic data within the same index.
If we knew how to perform the translation ourselves it would seem like that would allow us to bypass the above limitation.
this page shows visually how a geography point can be mapped to planar cells which can be individually encoded as a sequence of from 1 and up to 4 positive integers. For an example of numbered cells please refer to the section "Deepest-Cell Rule" within the linked page.
I'm basically looking for pseduo-code on how to do just that.
Any help will be appreciated and if you know the algorithmic details that would be very much appreciated.
Thank you in advance.
A simple solution is to interleave x-and y co-ordinate, like in a morton curve a.k.a z curve. You can verify it by calcuting the upper bound using the most significant bit. Bing maps uses a morton curve:http://msdn.microsoft.com/en-us/library/bb259689.aspx but a hilbert curve is much more complicated but also better in most cases. In hilbert curve it's using a gray code for the co-ordinate. Here is some code example:Mapping N-dimensional value to a point on Hilbert curve.

Resources