In my PostgreSQL database there is a raster table and a point table with the same projections. The point table has colums such as id, address and geom. The raster table has columns such as id, r_proj4 and rast. Each line of the raster table describes one raster tile.
How can I retrieve the raster value for each point?
I expect rough guidelines how to solve this problem and PostGIS code examples.
Right off the top of my head, I would say that st_intersection() may get you rasters encompassing geometry points of interest (if that's what you're looking for). You can use it as a criteria, while inner-joining both of your tables, like that:
select p1.*, r1.rast
from points p1
join rasters r1
on (st_intersection(r1.rast, p1.geom)).geom = p1.geom
Related
I am new to Power BI and data-base management and I want clarify for myself how Power BI works in reference to my last two questions (Database modelling Bridge Table , Power BI Report Bridge Table ). I have a main_table with firm specific information each year which is connected to an end_table that contains some quantitative information (e.g. sales data). The tables are modelled as a 1:N relationship, so that I do not have to store the same values twice, which I thought is a good thing to do in data modelling.
I want to aggregate the value column of end table over the group column Year. I am surprised that to my understanding Power BI sums up the value column within the end table when I would expect the aggregation over the group variable in the connected tables
My basic example is based on this data and data model (you need to adjust the relationship manually):
main_table<-data.frame(id=1:20, FK_id=sample(1:2,20, replace=TRUE), Jahre=2016:2020)
main_table<-rbind(main_table,data.frame(id=21:25, FK_id=sample(2:3,5, replace=TRUE), Jahre=2015) )
end_table<-data.frame(id=1:3, value=c(10,20,30))
The first 5 rows of the data including all columns looks like this:
If I take out all row specific information and sum up over value. It will always show the sum of the end table, which is 60, in each Year.
Making the connection bi-directional does not help. It just sums up for the existing values of the end_table in each year. I get the correct results, if I add the value column to the main table using Related value = RELATED(end_table[value])
I am just wondering if there is another way to model or analyse this 1:N relationship in Power BI. This comes up frequently and it feels a bit tedious to always add the column using Related() in the main table while it would be intuitive to just click both columns and expect the aggregation to be based on the grouping variable.
In any case, just asking this and my other two questions helped me a lot.
This is a bit of a weird modeling situation (even though it's not terribly uncommon). In general, it's handy to build star schemas where you have dimension tables in 1:N relationships to fact table(s). E.g.
In this setup, the items from the dimension tables (e.g. year or customer) are used in the columns and rows in a visual and measures generally aggregate columns from the fact table (e.g. sales amount).
Your example inverts this. You are trying to sum over a column in your end table using the year as a dimension. As a result, it's not automatically behaving as you'd expect.
In order to get the result that you want, where Year is treated as a dimension, you need to write a measure that sums over Year as if it were a dimension. Since main_table is essentially a dimension table for Year (one unique row per year), you can write
SumValue = SUMX ( main_table, RELATED ( end_table[value] ) )
If I had a series of Rows in a Realm database, each one containing a field that was a List [Points] of thousands of coordinate objects (p1, p2, ...pn) - and each one of those coordinates had a field for a TAG property which may not exist - would there be an efficient and inexpensive way to query for results such as the following based on TAG value (i.e. p3 below)
individual Rows (where [Points] contains point(s) that has TAG property matching a queried value)
an array of objects each containing a new [Points] list with Points from hundreds of Rows and a reference to which Row they came from (there could be several Rows with an array of [Points], certain elements of which contain the TAG property that match the value queried for. I want those points extracted from all of the Rows)
Row
Row
Row
[Points]
p1
lat
lon
p2
lat
lon
p3
lat
lon
TAG
p4
...
This article says:
Relationships in Realm are also extremely fast because they’re indexes that traverse a B‑tree–like structure to the related object. This is much faster than querying. Because of this there is no need to perform another full query as ORMs do. It simply is a native pointer to the related object.
But my concern is the size of the dataset: A query of type 2 above would involve going through hundreds of Rows each containing thousands of Points and checking each one of those points to see a) if the TAG property is present and b) if it's value matches the query.
I want to be able to specify a TAG value, then find all instances of Rows as well as coordinates containing that TAG value within a date range. This would happen locally on device, as well as on a server hosting the Realm Object Server. A request like this could happen over the network as well.
I am using PowerPivot in Excel.
I am selling products at 2 separate locations, I have a column that differentiates and is populated with the store location. I have a slicer option that separates the view based in the store location and of course the option to select both location to see the combined sales. I also have the calculated in stock for each location.
I want to bring in the amount I have in the warehouse (that serves for both lo cations) for reference at the end (right side) of the pivot table. I have that in a separate table with the unique item numbers. I can build a query from the data source (Access) to bring in the warehouse stock qty twice (labeled the location near it) but that would work only when viewing each location separately but not when combined - it will show me double.
I need a number in the sum that will always be the same no matter the slicer option.
I'm developing a web-GIS based on PostGIS. When I create a GIS-enalbled table on PostGIS I've to specify the SRID of the data, for example an UTM Zone (eg. UTM 33N SRID 32633).
Is there a way to keep the project scalable and put in the same table data of different SRID (eg. 32633 and 32632 to cover all Italy) without use a global geographic SRID (like WGS84 and similars)?
Thank you
I think you'd end up in a world of pain if you try to combine different SRIDs in one column (how do you know how to display the layer properly?).
However, you could create a table with two geometry columns. To make things more maintainable you could e.g. have triggers that update the "other" column's geometry when one column changes...
create table table_with_2_geoms (
geom_32633 geometry(geometry,32633),
geom_32632 geometry(geometry,32632)
);
Here is my case. I had 2 geodatabases. Second one is created later. And i import all tables in geodatabase-1 to geodatabase-2 by using ArcCatolog. I use srid 6 for my geodatabase 1 and its kind of a standart. But in geodatabase 2 the tables and indexes are imported with an different srid. I have to change srid of all geometry collumns and spatial indexes to 6.
First i checked ST_spatial_references table for srid 6 and couldnt find it. There is srid 30002 with same content with srid 6 in geodatabase 1.
Then i create an entry in ST_Spatial_references table manually for srid 6. After that I tried to create a spatial index with following query.
CREATE INDEX SDE.INDEX_NAME ON SDE.TABLE_NAME (SHAPE)
INDEXTYPE IS SDE.ST_SPATIAL_INDEX
PARAMETERS('st_grids=1:0:0 st_srid=6')
NOPARALLEL;
and get this error. ORA-20085: Different SRID '6' do not match.
I need to create and srid entry with id 6 properly. And change all the tables and spatial indexes set to srid 6. Can anyone help me?
Note: srid 30002 and 6 has exactly same content in ST_SPATIAL_REFERENCES table except the id collumn.
Thank You.
The reason you're seeing that error is that the SRID of a table (defined in the ST_GEOMETRY_COLUMNS table) doesn't match with the one of the geometries contained in it (defined in the geometry field of each record).
If you really need to change the SRID of a table (even though you shouldn't mess with SRIDs, as they are internally managed by SDE), follow this procedure:
Create the entry in the ST_SPATIAL_REFERENCE table with SRID=6
Remove with ArcCatalog any existing spatial index on the table. If it doesn't work try to recreate it and then remove it.
Update the geometries contained in the table with the following SQL command:
UPDATE b SET b.shape.srid = 6
Update to 6 the SRID of the table in the ST_GEOMETRY_COLUMNS table
Create the spatial index with ArcCatalog
This has to be done for each table (except of course for the first step which has to be done only once).