MySQL Spatial Within function gives errors - mysql

I have a table of areas which has an AREA_ID column and an AREA column which is a Polygon type.
I am running the following query but I cannot seem to get it to work:
SELECT AREA_ID, AsText(AREA)
FROM networkmodel.sit_area
WHERE Within(AREA, Polygon((
50.913424 -1.420527,
50.915805 -1.391516,
50.898053 -1.390142,
50.895021 -1.428251,
50.913424 -1.420527)))
This query gives me an "Operand should contain 1 column" error.
If I put one less set of brackets around my coordinates I get an "Illegal non geometric '(50.913424 -1.420527)' value found during parsing" error instead. Are my coordinates the wrong format?
I am aware from the MySQL documentation that the Within function has not been implemented properly and falls back to the MBR implementation instead but I am just testing it out at the moment. I have used the Contains function in the past with success to return me records in a similar way by using a Point as the second parameter instead of a polygon and this is supposed to be the opposite of that.
It is my understanding from the documentation that this function takes two parameters and checks whether the first (my areas column in this case) falls within the given Polygon.
Any help is appreciated thanks.

Right I made it work now, Instead of using this function I had to change the Polygon declaration to:
GeomFromText('Polygon((50.913424 -1.420527, 50.915805 -1.391516, 50.898053 -1.390142, 50.895021 -1.428251, 50.913424 -1.420527))')

Related

How do I reduce the number of characters in an input string/varchar in MySQL

I basically have two tables tbl_feedback and tbl_notification that both get values inserted in them through a stored procedure whenever a person submits a feedback.
What I'm aiming for is getting a "shortened" version of a message column inserted into tbl_notification (say 60 characters max) so a notification only shows a preview of the actual message.
Is this possible using a MySQL function or do I have to resort to handling it via PHP (shortening an output string before echoing it)
The LEFT function was what I was looking for. Thanks, Paul.
I wish that google pointed me straight to this function.
w3resource on LEFT function

How do I select from a table in MySQL 8 using ST_contains?

I have a table called 'community', which has a column called coordinates, of type Point.
I have a rectangle.
I'm trying to select all the rows whose .coordinates fall within that rectangle.
Here's what I'm trying to do:
SELECT * FROM `tribemap-db`.community
WHERE ST_Contains(POLYGON(34.6002788228068 31.821252014924383,
35.21282317828298 31.821252014924383,
34.6002788228068 32.08220723021857,
35.21282317828298 32.08220723021857), community.coordinates);
This is giving me an error:
"SELECT" is not valid at this position for this server version, etc.
How do I write this query properly?
You can use the following solution:
SELECT *
FROM `tribemap-db`.`community`
WHERE ST_Contains(ST_GeomFromText('Polygon((35.21282317828298 31.821252014924383, 35.21282317828298 32.08220723021857, 34.6002788228068 32.08220723021857, 34.6002788228068 31.821252014924383, 35.21282317828298 31.821252014924383))'), `community`.`coordinates`);
demo on dbfiddle.uk
I changed the following to solve this:
You have to put the definition of the polygon as string into ST_GeomFromText to get a geometry object.
Your current definition of the polygon is not valid and not a rectangle. I changed the order of the points of the polygon to get a definition of a rectangle. I also added the first point as last point to to close the rectangle.
You can check the polygon with MySQL Workbench. There is a Spatial View and Form Editor to see the result of the definition.
Your current definition of the rectangle (with additional first point as last point too):
The changed definition of the rectangle (changed the order of points and added first point as last point too):
Are there any functions that will allow me to get a bounding rectangle from MySQL with fewer corners (say, two opposing)?
You can use ST_MakeEnvelope to create the rectangle with two opposing points:
SELECT *
FROM `tribemap-db`.`community`
WHERE ST_CONTAINS(ST_MakeEnvelope(ST_GeomFromText('Point(35.21282317828298 31.821252014924383)'), ST_GeomFromText('Point(34.6002788228068 32.08220723021857)')), `community`.`coordinates`);
-- or using syntax (without ST_GeomFromText) possible on MySQL 8.0+
SELECT *
FROM `tribemap-db`.`community`
WHERE ST_Contains(ST_MakeEnvelope(Point(35.21282317828298, 31.821252014924383), Point(34.6002788228068, 32.08220723021857)), `community`.`coordinates`);
Got it.
All I need is two opposing corners of the bounding rectangle.
And then:
SELECT *
FROM `tribemap-db`.`community`
WHERE ST_CONTAINS(ST_MakeEnvelope(
Point(34.60, 32.08),
Point(35.21, 31.82)
), community.coordinates);
That's it!

How do I take a segment of a image and check if it exists?

In Sikuli I have an image where I need to check if the 1/4 of the lower half exists and if it does, use a specific function. Right now I have:
if(image.exists())
click()
The issue with this though is the .exists will either hang the script or function incorrectly. I'm looking for a better way to do this or a solution to this problem. Any help would be appreciated
Example is there's an additional segment, so you have Select All in one version (where it ends) and then Time/Date in a newer version. Want to be able to select the additional option of Time/Date but through images.
This should be what you are looking for:
noteApp = App("notepad.exe")
click("editbutton-1.png")
region = Region(noteApp.focusedWindow())
print(region.text())
You can set the region.text() equal to the string you are looking for such as Date/Time and create a statement to run your function

Syntax Error: Comma in Query Expression of SQL Statement Access?

I've been trying to make this statement work for some time but have ultimately lost the will to live.
In essence, I am attempting to filter a report to only certain Locations (So if you want the query to only include locations "Avonmouth" and "Bedford", that's what it would include, filtering the rest out) I have done this by implementing a check box system, so you can easily add locations to the filter. Unfortunately I keep getting syntax problems with the SQL script. Its a bit of a butchery, so please forgive me, but I have included the SQL below. (CHKBE = The check box)
WHERE QryTraining IN ((IIf [Forms]![ReportDeployer]![CHKAV]<>"" ,"Avonmouth",x),(IIf [Forms]![ReportDeployer]![CHKBA]<>"" ,"Basingstoke",x),(IIf [Forms]![ReportDeployer]![CHKBT]<>"" ,"Bedford Transport",x),(IIf [Forms]![ReportDeployer]![CHKBW]<>"" ,"Bedford Warehouse",x),(IIf [Forms]![ReportDeployer]![CHKBE]<>"" ,"Belfast",x),(IIf [Forms]![ReportDeployer]![CHKCA]<>"" ,"Carluke",x),(IIf [Forms]![ReportDeployer]![CHKEX]<>"" ,"Exeter",x),(IIf [Forms]![ReportDeployer]![CHKKI]<>"" ,"Kidderminister",x),(IIf [Forms]![ReportDeployer]![CHKKN]<>"" ,
"Knowsley",x),(IIf [Forms]![ReportDeployer]![CHKTE]<>"" ,"Teva",x),(IIf [Forms]![ReportDeployer]![CHKWI]<>"" ,"Wickford",x),(IIf [Forms]![ReportDeployer]![CHKYO]<>"" ,"York",x))
Each time I attempt to run it, it throws it back with a Syntax error.
Thanks in advance, T.
Not sure this will work any better but parens are in wrong place at beginning of each IIf() and maybe need apostrophe delimiters:
WHERE QryTraining IN (IIf([Forms]![ReportDeployer]![CHKAV]<>"" ,"'Avonmouth'",x), IIf([Forms]![ReportDeployer]![CHKBA]<>"","'Basingstoke'",x), IIf([Forms]![ReportDeployer]![CHKBT]<>"","'Bedford Transport'",x), IIf([Forms]![ReportDeployer]![CHKBW]<>"","'Bedford Warehouse'",x), IIf([Forms]![ReportDeployer]![CHKBE]<>"","'Belfast'",x), IIf([Forms]![ReportDeployer]![CHKCA]<>"","'Carluke'",x), IIf([Forms]![ReportDeployer]![CHKEX]<>"","'Exeter'",x), IIf([Forms]![ReportDeployer]![CHKKI]<>"","'Kidderminister'",x), IIf([Forms]![ReportDeployer]![CHKKN]<>"","'Knowsley'",x), IIf([Forms]![ReportDeployer]![CHKTE]<>"","'Teva'",x), IIf([Forms]![ReportDeployer]![CHKWI]<>"","'Wickford'",x), IIf([Forms]![ReportDeployer]![CHKYO]<>"","'York'",x))
Probably need to use empty string or some text like "N/A" in place of the x.
A BOUND checkbox must be either True or False (Yes/No), never an empty string. An UNBOUND checkbox can be set for triple state, in which case it could return True/False/Null, again never an empty string. So I am not sure why comparison to empty string. Just test for True.
IIf([Forms]![ReportDeployer]![CHKAV], "'Avonmouth'", "")

Business Objects Generating Unexpected Query

I am having problem with BusinessObject Universum and the way it generates queries and consequently yielding the results.
Here is the background: mechanism that is functioning has already been implemented. I was trying to copy the SAME mechanism just to deliver a different field.
Here is the data model: http://tinypic.com/r/ng524g/8
The mechanism that functions is marked with BLUE color. The mechanism that I tried to implement and that is not functioning is marked with RED color.
On business layer I have defined a dimension with aggregate aware function. This function takes first VWF_Party_Collection_A.Collectionstatus_CD column (at the higher level). If a user selects an attribute from contract level, function takes VWF_Contract_Collection_A.Collectionstatus_CD column.
Problem is when I take all attributes from VWD_Kunde_A table and than add the dimension with the mentioned aggregate aware function (ie Collectionstatus_CD), the constructed query from BO side does not make any sense. Here it is:
SELECT
D_ATA_MV_FinanceTreasury.VWF_Party_Collection_A.Collectionstatus_CD,
D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Namespace_TXT,
D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Party_KEY,
D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Legacy_ID
FROM
D_ATA_MV_FinanceTreasury.VWD_Party_A
LEFT JOIN D_ATA_MV_FinanceTreasury.VWF_Party_Collection_A
ON D_ATA_MV_FinanceTreasury.VWD_Party_A.Party_KEY=D_ATA_MV_FinanceTreasury.VWF_Party_Collection_A.Party_KEY,
D_ATA_MV_FinanceTreasury.VWD_Kunde_A
WHERE
(
D_ATA_MV_FinanceTreasury.VWD_Party_A.Party_KEY=D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Party_KEY )
AND
D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Legacy_ID = 102241978
Please notice the strange conctruction in the 'FROM' part (comma has been added). Another strange and unexpected construction is in 'WHERE' part:
( D_ATA_MV_FinanceTreasury.VWD_Party_A.Party_KEY=D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Party_KEY )
The mechanism that is functioning is joining joins VWD_Kunde_A with VWF_Contract_Collection_A table and yields the correct result.
Now, I have tried to define a dimension without the mentioned aggregate aware function that contains only VWF_Contract_Collection_A.Collectionstatus_CD attribute. When I run the same query BO yields CORRECT results and it generates the CORRECT (expected) query.
This is the query I am expecting:
SELECT
D_ATA_MV_FinanceTreasury.VWF_Contract_Collection_A.Collectionstatus_CD,
D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Namespace_TXT,
D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Party_KEY,
D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Legacy_ID
FROM
D_ATA_MV_FinanceTreasury.VWD_Kunde_A LEFT JOIN D_ATA_MV_FinanceTreasury.VWF_Contract_Collection_A ON D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Namespace_TXT = D_ATA_MV_FinanceTreasury.VWF_Contract_Collection_A.Namespace_TXT AND D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Party_KEY = D_ATA_MV_FinanceTreasury.VWF_Contract_Collection_A.Party_KEY AND D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Legacy_ID = D_ATA_MV_FinanceTreasury.VWF_Contract_Collection_A.Legacy_ID
WHERE
D_ATA_MV_FinanceTreasury.VWD_Kunde_A.Legacy_ID = 102241978
Furthermore, I suspected that it can something to do with contexts. However, I did not find any context for the mechanism that already functions and that I tried to copy. Therefore, I did not implement any context for the mechanisam I am tring to implement.
At this point I am clueless since I tried everything I knew. I would appreciate help.
Thanks!
A.
UPDATE: it seems as aggragate aware function is not functioning... This is how it is defined:
#Aggregate_Aware(D_ATA_MV_FinanceTreasury.VWF_Party_Collection_A.Collectionstatus_CD,D_ATA_MV_FinanceTreasury.VWF_Contract_Collection_A.Collectionstatus_CD)
(I just copied the code from Kreditklasse and adapted it... That makes me even more confused...)
UPDATE_2: it really seems as if aggragate aware is not functioning in my case because I selected all attributes from contract_context and it still jumps to party context. Very confused because THE SAME mechasism is functioning as expected when I select Kreditklasse...
Check the aggregate navigation.
Setting up Aggregate Awareness requires two steps (in addition to correctly defining the joins between the tables, of course):
Define the objects with the Aggregate_Aware function
Set table-object incompatibilities through Actions > Set Aggregate Navigation.
It sounds like the second part is not properly configured: make sure that any objects which require the second table are marked incompatible with the first.