How to get coordinates from the PostgreSQL point object - postgresql

I have a point column in my PostgreSQL table. Is there a way to extract point's X/Y coordinates separately? I operate with native PostgreSQL data, not PostGIS.

The documentation tells you:
It is possible to access the two component numbers of a point as though the point were an array with indexes 0 and 1. For example, if t.p is a point column then SELECT p[0] FROM t retrieves the X coordinate and UPDATE t SET p[1] = ... changes the Y coordinate.

Related

Proper storage of a uniform, XYZ plane, in Postgres PostGIS

Problem Statement:
Consider a gray scale image taken of a plane. Each pixel is an intensity value (Z).
I have the position in physical space of the top left most pixel. I also have the offset of each X and Y pixel from left to right (X), and up to down (Y). Consider the image to be perfectly non-distorted, so the offset is uniform for every row.
I would like to store these image in a POSTGIS database in a way that allows the user to query a polygon from an image.
Current Implementation:
Currently I believe I am doing something stupid, I create a Multipoint geometry and store each point with ( X Y Z ) using python. Since the image is uniform, I am repeating lots of data (x and y for each point), but this works when querying the database for a polygon, but is an excessive amount of extra data.
Question:
What is the best way to store such data and allow the user to query
a polygon from the image?
Is PostGIS Geometry the correct datatype?
Is the multipoint approach reasonable?

extracting co-ordinates from table and analyzing them

I am working on spatiotemporal data which includes date time and geom columns.
I have extracted x& y co-ordinate but want to find centroid of certain attribute but was not able to do so.
Any ideas?

Use $within with a buffered MondoDB Linestring

I need to evaluate the proximity of a Point to a LineString using MongoDB.
Because the $near operator can only compare a Point to another Point, I need to generate a polygon out of the LineString, so I can use the $within operator. The distance between the LineString and the edges of the polygon should represent the radius I want to search in, such as represented in red below:
What might be a useful algorithm in order to accomplish this?
I think much easier would be to write your own function
To find (perpendicular) distance between point and line and then creating thickness of poly-line by polygon means.
Where:
P0,P1 are line endpoints
P is point
d is distance between them
Line is defined as: p(t)=P0+(P1-P0)*t where t=<0.0,1.0>
So the function should do this:
create perpendicular line
q(t)=P+DQ*u where u=(-inf,+inf)
DQ is perpendicular vector to (P1-P0)
In 2D you can obtain it easily like this (x,y) -> (y,-x). In higher dimensions use cross product with some non coplanar vectors.
compute line vs. line intersection
there are tons of stuff about this so google or solve the equation yourself here you can extract mine implementation.
now after successful intersection
just compute d as distance between P and intersection point. Do not forget that parameter t must be in range. If not (or if no intersection) then return min(|P-P0|,|P-P1|)
[hints]
t and u parameters can be obtained directly from intersection test so if the perpendicular vector to (P1-P0) is normalized to size = 1 then the abs(u) parameter of intersection point is the distance
[notes]
I am not familiar with mongodb so if you have no means to use own tests inside then this answer is of coarse obsolete.
Unfortunately, MongoDB provides very basic geospatial query, so you should create the buffer by your own. You can read how to do it here: Computing a polygon that surrounds a multi-point line
If you have longitude/latitude coordinates like WGS84 you must adjust this code; Read here how to calculate distance between point on a sphere https://en.wikipedia.org/wiki/Haversine_formula

Label names to each data points in Matlab

I have a set of data I am analyzing and I would like some help if you can. My data consist of two columns but my X column is only one point and my Y column is about 50 points . So when I plot it of course it's just just diff points along the Y axis versus one single point on the x axis.
Now those points are really closed to each other and what I would like to do is to label each point to their actual Channel name. But so far I tried to use the text() function an it gives me an error saying that my x and y value should be the same. I'm not sure which way to do this anymore. Keep in mind that I have the names of each data points in a file also. Can you help? Keep in mind using one x value and 50 Y values. Lets say I fix it and now the names are on top of each other. Is there a way I am space them out without affecting the location of the points.

creating a polygon from points around a point in postgis

I have a postgresql db using postgis 2.0 and a table of thousands of points, I would like create a polygon of the furthest points originating around a particular central location.
I haven't got a clue how this would be done, any ideas anyone??
Filter and aggregate the points, and return the convex hull of the points.
So to select the points in mytable that are within a distance of 10 from id=123, and return the enclosing polygon:
SELECT ST_ConvexHull(ST_Collect(A.geom))
FROM mytable A, mytable B
WHERE B.id=123 AND ST_DWithin(A.geom, B.geom, 10)