extracting co-ordinates from table and analyzing them - postgresql

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?

Related

How to plot earthquake data with magnitude proportional to size of the data point in Matlab?

I am importing different csv files, using readmatrix(), from the USGS website that includes the latitude, longitude, and magnitude of earthquakes during a certain time period. I am uing the geoscatter command which can take vectors for lat, lon and marker size (and color scale) but the problem is that the marker size is a value with points^2 units. Magnitude is given on the richter scale (0-9 or so) which is logarithmic, so as shown in the code, I tried to convert the values back by taking the square root of 10 raised to the magnitude and rescaling but it's still not great. I dont want to have to use the rescale as a quick-fix. Im just not sure what I'm doing wrong, any help would be greatly appreciated! Also, if any one is familiar with geoscatter I would also like to explore the idea of the user being able to limit the view to only one continent or country, as well as possibly creating a time lapse of the earthquakes because the time data is included in the csv.
Here is the website with the data I'm using: https://earthquake.usgs.gov/earthquakes/feed/v1.0/csv.php
Here is the code I have so far:
(I am using a live script and have utilized a drop down box to switch between time frames, so only the data for the past month is used to simply the helping process)
clc
clear all
close all
data = readmatrix("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv") % Pulls .csv for selected time from USGS website
lat = data(:,2);
lon = data(:,3);
mag = sqrt(10.^(abs(data(:,5))));
mag = rescale(mag,0,180);
C = cosd(1:length(lat));
for i = 1:length(mag) % Converts all zeros to nonzeros
if mag(i) == 0
mag(i) = 1;
end
end
A = geoscatter(lat,lon,mag,C,'filled');
geobasemap grayland;
As stated above, I am trying to plot the magnitudes correctly because the magnitude data is from the richter scale but the marker sizes in matlab are in points^2. As you can tell I did a quick-fix by rescaling the data from 0 to 180 which make the data appear correct but I don't believe this is the right way to do it.

How to get coordinates from the PostgreSQL point object

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.

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?

shapefile mask for georaster in MATLAB

I am trying to make a mask for a georaster (netCDN file) using a shp file. This is similar to what is described in this thread (How to limit the raster processing extent using a spatial mask?), but since my georaster is not an image I do not have an R variable, so the solution presented there does not work for me.
I first load my shapefile into MATLAB:
S1 = shaperead('Export_Output_3.shp');
The data has a Lambert Conformal Conical projection and the units is meters.
Then I load the netCDF file and extract the first slice of data. I get a matrixx with one valu for each cell. It also has a Lambert Conformal Conic projection with the same parameter values, but the data is in “degrees north” and “degrees east”.
So how can I put this data together? I tried the utm2deg function for converting the units of the shapefile from meters to degrees, but I do not know the UTM zone, so I got stuck with that.
I think that I first need to have both datasets in the same units and then to convert the shapefile into a matrix with the same resolution as the netCDF. I am unable to perform any of these steps.
Can anyone help?

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.