What approach should I use in PostGIS to find all services that have a radius that intersect a customer - postgis

I'm new to PostGIS and looking for suggestions on a reasonable approach to solve the following problem. I have services that have a lat/lng and service radius (an area that the service is available in). I have customers that just have a lat/lng. I'd like to setup up a table(s) that support indexed queries that return all services that have a service areas where the users location is contained.
Service
- latitude
- longitude
- radius
- type
Customer
- latitude
- longitude
Bonus points if the query is easy to extend to filter services by other attributes as well *

You can create and index geography columns in both tables, then you can make use of ST_DWITHIN() which makes use of the indexes
SELECT service.*
FROM service
JOIN customer
ON ST_DWITHIN(service.geog, customer.geom, service.radius)
WHERE customer.id=123
AND service.type='abc';

Related

How to write a DAX formula on an RLS SSAS?

I have a data model that is like this:
Joins are done between tables on storenumber and storename.
I would like to give access to the stores staff but they only see the sales of their own store. I added their mail in the table Y2_Stores.
The sales data are in the table Y2_Sales.
In analysis services I added a role "Stores" in read, in Membership I added the email addresses of the stores, on the line filters I put that but I see in the microsoft documentation that it is necessary to make a formula with the functions LOOKUPVALUE() and USERNAME() but I do not know how to build this formula..
I tried this formula in Y2_Sales line:
=Y2_Sales[storenumber]=LOOKUPVALUE(Y2_Stores[storenumber],
Y2_Stores[email], USERNAME(),
Y2_Stores[storenumber],
Y2_Sales[detail_number])
I tried this too:
Y2_Stores[email] = USERPRINCIPALNAME()
Can you help me to write the correct DAX formula?
Thanks a lot
UPDATE :
I added the Y2_StoreEmployee table with storenumber | email and made a relation on storenumber in double direction to the Y2_Stores table :
Relationships:
I created a role with this formula:
There should be a table related to Store, eg StoreEmployee, with (StoreNumber,Email), configured for bidirectional cross filtering with Store. Then the RLS filter filter is on StoreEmployee and is just Email=USERPRINCIPALNAME().
So each user sees only their own rows in StoreEmployee, that creates a filter that propagates to Store, and then to the Sales, Inventory, and Images.

Address Table Scheme for Geolocation services

I have a SQL database with tables such as Stores, Users, etc.
Both Store and User, as well as other entities, have an Address.
I am considering creating an Addresses table for all Addresses:
Users
--------
UserId (PK)
AddressId (FK)
Name
Addresses
--------
AddressID (PK)
CountryID (FK) -> I have a table Countries with all Countries
Street
PostalCode
Locality
Region
Latitude
Longitude
When a user is filling the Profile I would have an input to type the address.
I would like to use Google Geocoding API to convert the typed address into its fields and save it into the database including Latitude and Longitude.
https://developers.google.com/maps/documentation/geocoding/start
https://developers.google.com/maps/documentation/javascript/geocoding
I have a few questions:
Is my Address table scheme appropriate for this?
I am planing to use Google Geocoding API so should I store the PlaceId then Google returns on my database?
My main objectives are:
Convert the address typed by the user into address fields and save to database;
By having the Latitude and Longitude of the address type by the user in my database I will be able to search them by location.
Example: Get users of my application in a radius of 20 km of a London address.
Did you thought about to separate the HouseNumber? Some external Services or API's require this. Its easier to concat this fields if required.
There is a geography Datatype for geolocations: https://learn.microsoft.com/en-us/sql/t-sql/spatial-geography/spatial-types-geography?view=sql-server-2017
With this type you can query the Database performantly with some geo functions e.g. distance between two points.
I wont save the Google-API result directly. Use your own required schema.
If you use the geography type you can query with Long/Lat and Distance by radius.

Microsoft Dynamics AX 2012 R3 XDS Security on Finacial Dimesion

I'm trying to create an AX security framework for one of my client. The key task here is to enable Branch Accounting in AX 2012 R3 environment. Which means i'm required to filter different transactions / customers / vendors / Transfer orders on the basis of Location & Financial dimension BU respectively such as Each Branch (location) should see records of there respective branch.
I created my custom security roles enabled XDS framework on them, it was easy in the case of customer, vendor etc for which I had an Location wise field.
But in case of transactions i.e 'LedgerJournalTrans' Table I am not able to filter on the basis of Financial dimension. As the field LedgerDimesion is a combination of different dimensions its hard to use it in a AOT query.
If any one give an insight on how to filter transactions or any other records on the basis of Financial dimension combinations ?
Note: I've already studied the white paper to filter through dimensions on XDS but the example mentioned there is based on the myDepartment table and methods which I cannot use in my scenario
Link to White Paper for reference
You have to create a query or view to get values for each ledger dimension.
You can get this info by joining DimensionAttributeValueGroupCombination (this has ledger dimension id), DimensionAttributeLevelValue (field DisplayValue is the dimension value), DimensionAttributeValue (DimensionAttribute RecId).
Now you can use this view or modify it to filter by dimenison values.
MyDepartments temp table has a method named XDS which is automatically called to fill the data. Refresh of this table can be per session or per invocation.
You can use this to make your own user based filter data.
You can add some code in the init() method of your Query that you use in Your XDS policy.
the code should get the ledgerdimension field and get the dimension value that you want to filter based on the user dimension mapping.

Many-to-Many-to-Many Relationship in SQL Server Analysis Services; Second Many-to-Many Relationship Not Working

Preface
SQL Server 2008 R2 Standard Edition, Multidimensional Cube
In my data warehouse I have the following tables:
Dimensions
DimPartnership - Groupings of Partners DimPartner - Groupings of
Investors (can be in multiple partnerships) DimInvestor - Individual
investors that can make up multiple partners
Facts
FactInvestments - Records related to investment activity. Contains a foreign key "InvestorKey" that relates to the DimInvestor table.
Bridges
BrInvestorPartner - Bridge table to resolve Investors to Partners
BrPartnerPartnership - Bridge table to resolve Partners to Partnerships
Problem:
I need to create a Many-To-Many-To-Many relationship in SSAS. The first many-to-many dimension is working, the second one is not.
Current Solution:
I have made two bridge tables that link the Investor dimension to the partner dimension and then the partner dimension to the partnership dimension. The cube processes and, as expected, the partner many-to-many dimension works correctly. I am able to slice measures in the fact table by partner members. However, when I apply partnership as a part of the query, it has no effect on the Investments measure group. My Investments measures group is ignoring this dimension, it seems.
Question
Can anyone point out what I'm doing incorrectly? Is this even supported by Microsoft? I can't find anything in their documentation about this, but I would assume this would be supported. I appreciate any guidance toward figuring out what's wrong. Can this be solved with scoping or doing some sort of intersection on Partner Partnership Count?
Pictures
Some pics that might help you:
Faulty results
Values and names edited to protect client privacy - same value returned for all partnerships (the total of all investments)
DSV
Cube Structure
Dimension Usage
And of course once I posted my question, I figured out the problem.
My dimension usage for the Partnership Dimension should use both v Br Investor Partner bridge and the v Br Partner Partnership bridge with Many-To-Many relationships. Everything is now working as expected.
Compare this to the Dimension Usage Screenshot in my OP:

Report Model; problem regarding many-to-many relations

I'm having trouble setting up a report model to create reports with report builder. I guess I'm doing something wrong when configuring the report model, but it might also due to change of primary entity in report builder.
I have 3 tables: Client, Address and Product. The Client has PK ClientNumber. The Address and Product both have a FK relation on ClientNumber. The relation between Client and Address is 1-to-many and also between Client and Product:
Product-(many:1)-Client-(1:many)-Address.
I've created a report model (mostly auto generate) with these 3 tables, for each table I've made an Entity.
Now on the Client Entity , I've got 2 roles, Address and Product. They both have a cardinality of 'OptionalMany', because Client can have multiple Addresses or Products. On both Address and Product I have a Client Role with cardinality 'One', because for each Address or Product, there has to be a Client (tried OptionalOne as well...).
Now I'm trying to create a report in Report Builder (2.0) where I select fields from these three entities. I'd like an overview of Clients with their main address and their products, but I don't seem to be able to create a report with fields from both Address and Products in it. I start by selecting attributes from Client, and as soon as I add Product for example the Primary entity changes as if I'm selecting Products (instead of Clients).
This is a basic example of a problem I'm facing in a much more complex model. I've tried lots of different things for 2 days, but I can't get it to work. Does anyone have an idea how to cope with this?
(Using SSRS 2008)
Edit: in T-SQL this is what i mean:
SELECT *
FROM CLIENT
INNER JOIN ADDRESS ON CLIENT.CLIENT_NUMBER = ADDRESS.CLIENT_NUMBER AND ADDRESS.TYPE = 1 --Main Address
INNER JOIN PRODUCT ON CLIENT.CLIENT_NUMBER = PRODUCT.CLIENT_NUMBER
WHERE CLIENT.CLIENT_NUMBER = 1
My experience dates back to Report Builder 1.0, but MS hasn't changed much in their report model since so it probably still applies.
As you mention, you can define many to many relations in the model, but materializing those relations in one tabular report is not possible. Once you chose one of the entities on the many side (Products), you are left without a way to bring data from the other side (Addresses).
You may have some luck with creating a "junction" table (ClientID-AddressID-ProductID) and hidding it from your users like Bob's SQL Reporting Services Blog suggests.
Ultimately this is a big limitation with MS models and it doesn't seem to improve with their latest incarnation Denali BISM many-to-many
I understand the original post is 4 years old and SSRS report models are becoming irrelevant but one solution is to define the OptionalMany relationships as OptionalOne in the model, essentially fooling the model to allow navigation and appropriate query generation.

Resources