Difference between Geometry & Polygon functions- SQL Server - sql

Studying for the 70-461 and my book (Joes2pro Vol3) makes no mention of a difference between STGeomFromText & STPolyFromText functions, though it reads like there is a discernible difference between the two.
Examples asked to run are here
Select Geometry::STGeomFromText('Polygon ((0 0, 28 0, 28 21, 0 21, 0 0))',0)
Select Geometry::STPolyFromText('Polygon ((0 0, 28 0, 28 21, 0 21, 0 0))',0)
Which gives me exactly the same output and Microsoft docs is a little light on the subject for both these functions. All I can screen out is one is a geometry instance and the other is a geometryPolygon instance ?
Can anyone tell me when one is used over the other and what the above actually means ?
Kind regards,
SQLBoffin.

STGeomFromText() will take the WKT for any type of geometry (polygons of course but also points and lines) whereas STPolyFromText() will only do polygons.

Related

How to join/merge data tables based on close coordinates (using astropy or other methods)?

I have 2 astronomical tables, from a fits file and a csv file, that look something like this
ra, dec, val_a, val_b, ...
11.11, 22.22, 8, 9, ...
10.10, 20.20, 7, 6, ...
...
and this
ra, dec, val_x, val_y, ...
44.4, 55.55, 8, 9, ...
15.67, 23.45, 7, 6, ...
...
ra and dec are my astronomical coordinates (equivalent to latide and longitude on Earth). One table contains 15M galaxies and the other 80k. I would like to merge/cross-match the objects in these 2 tables with astropy, as long as corresponding objects have a separation smaller than a threshold distance in degrees. I know how to load the tables into astropy tables. And I know of the existence of skycoord and the join_skycoord function. But I am not able to apply them, because I don't find anywhere explained how when reading a table I specify skycoord columns or how I can later change the type of the columns to skycoord or how I can merge skycoord columns into my tables. I've tried also 2 other options presented here and here, but both resulted in my kernel crashing, because of the large amount of data.
Can someone provide me with code that can merge the 2 tables based on the sky coordinates? I would be also thankful for alternatives, that don't utilize astropy. Tnx

Unable to slice year from date column using negative indexing with pandas

I have a simple data set, where we have a Dates column from which I want to extract the year.
I am using the negative index to get the year
d0['Year'] = d0['Dates'].apply(lambda x: x[-1:-5])
This normally works, however, not on this. A blank column is created.
I sampled the column for some of the data and saw no odd characters present.
I have tried the following variations
d0['Year'] = d0['Dates'].apply(lambda x: str(x)[-1:-5]) # column is created and it is blank.
d0['Year'] = d0.Dates.str.extract('\d{4}') # gives an error "ValueError: pattern contains no capture groups"
d0['Year'] = d0['Dates'].apply(lambda x: str(x).replace('[^a-zA-Z0-9_-]','a')[-1:-5]) # same - gives a blank column
Really not sure what other options I have and where is the issue.
What possibly can be the issue?
Below is a sample dump of the data I have
Outbreak,Dates,Region,Tornadoes,Fatalities,Notes
2000 Southwest Georgia tornado outbreak,"February 13–14, 2000",Georgia,17,18,"Produced a series of strong and deadly tornadoes that struck areas in and around Camilla, Meigs, and Omega, Georgia. Weaker tornadoes impacted other states."
2000 Fort Worth tornado,"March 28, 2000",U.S. South,10,2,"Small outbreak produced an F3 that hit downtown Fort Worth, Texas, severely damaging skyscrapers and killing two. Another F3 caused major damage in Arlington and Grand Prairie."
2000 Easter Sunday tornado outbreak,"April 23, 2000","Oklahoma, Texas, Louisiana, Arkansas",33,0,
"2000 Brady, Nebraska tornado","May 17, 2000",Nebraska,1,0,"Highly photographed F3 passed near Brady, Nebraska."
2000 Granite Falls tornado,"July 25, 2000","Granite Falls, Minnesota",1,1,"F4 struck Granite Falls, causing major damage and killing one person."
To extract year from "Dates" column , as object type use
da['Year'] = da['Dates'].apply(lambda x: x[-4:])
If you want to use it as int then , you could do following operations after doing the step above
da['Year']=pd.to_numeric(da['Year'])

I need to create a finite automata

Consider the language L of all strings made of the symbols 0, 1 and 2 (Σ = {0, 1, 2}) where the last symbol is not smaller than the first symbol. E.g., the strings 0, 2012, 01231 and 102 are in the language, but 10, 2021 and 201 are not in the language.
As 0 is in the language and I don't understand why, I can't figure out if strings 1 and 2 are in the language?
So could someone please tell me if 1 and 2 as a string themselves are in the language and why?
Thank you
'0' is in the language because the first symbol and last symbol in '0' are both '0'. This satisfies the requirements that the last is not smaller than the first.
This means that the same applies for '1', '2', and for the empty string ''.

Boundary Value Analysis - When to use two value or three value?

I had a few questions regarding boundary value analysis that I was hoping someone could help me with. I am learning this for a university exam based off of the ISTQB spec, not for real world application at the moment.
The first is - when should you assume to use two and three value methods of BVA? Is there any actual distinction as to when you should use one or the other, or does it depend on the specific question asked (in terms of an examination) and I would simply need to just know how to use both? Is there a default method to use?
Secondly, consider this possible question:
A smart home app measures the average temperature in the
house and provides feedback to the occupants for different
average temperature ranges:
• Up to 10 C – Icy cool!
• 11 C to 15 C - Chilled out!
• 16 C to 19 C - Cool man!
• 20 C to 22 C –Too warm!
• Above 22 C - Hot and Sweaty!
Apply 3 point BVA to the above temperature ranges. How many test cases would you consider?
The answer that was provided was that:
For 10 - we would test 9, 10, 11.
For 11 - we would test 10 (already tested), 11 (already tested), 12
For 16 - we would test 15, 16, 17
For 20 - we would test 19, 20, 21
For 22 - we would test 21 (already tested), 22, 23
This would result in a a total of 12 test cases.
Can somebody please explain to me as to why we would test the upper boundary in the first partition (10 degrees), but not the upper boundaries in other valid partitions (such as 15, which would lead to us testing 14,15,16 or 19 leading to testing 18,19,20). Is this because the boundary of 10 is the only boundary within that partition, as the lower boundary is open?
As a follow on, assume that the boundaries were instead:
• 0 C to 10 C – Icy cool!
• 11 C to 15 C - Chilled out!
• 16 C to 19 C - Cool man!
• 20 C to 22 C –Too warm!
• 23 - 40 C - Hot and Sweaty!
Would the values that are tested then change to the below? Would we still need to test the upper boundary in the first partition, or would we now ignore this as we have a lower boundary value?
For the lower invalid partition -2, -1, 0
For the first valid partition: -1, 0, 1
For the second valid partition: 10, 11, 12
For the third valid partition: 15, 16, 17
For the fourth valid partition: 19, 20, 21
For the fifth valid partition: 22, 23, 24
For the upper invalid partition: 40, 41, 42
Thank you in advance - I think I have been over complicating things in my head and wracking my brain over this!
3-value boundaries are not strictly required. E.g. in your example 9 and 10 are from the same equivalence class. Personally I'd either skip 9 completely or randomize values across the whole partition.
In your "provided answers" the division "which cases relate to which partition" is arbitrary. Is 11 a "negative" boundary for ∞-10 range or a "positive" boundary for 11-15 range? There's no right answer. In practice you'll simply write these 8 checks w/o labelling which one is for which boundary:
* 10 - Icy
* 11, 15 - Chilled out
* 16, 19 - Cool man
* 20, 22 - Too warm
* 23 - Hot and Sweaty
If you decide to go with "3-value method" and check non-boundary values for each range you'll get additional 5 cases because there are 5 ranges.
Interestingly your "provided answer" is inconsistent. Every equivalence class has non-boundary value checked except for the "Hot and Sweaty" - it should've had 24 on the list resulting in 13 cases.
Disclaimer: this is an answer of a practitioner. I haven't read ISTQB, so if you need this info to pass a test (as opposed to using it in practice) - use it with caution.
Jordan -
You have a point and I think the authors of the question you quote made a mistake. Following the ISTQB definition (CTFL 2018, Section 4.2.2): "three boundary values per boundary: the values before, at, and just over the boundary."
The problem is that almost everywhere you look, the examples given are of a single valid range, with invalid ranges on both sides ("almost everywhere" includes Jorgensen's book, "SW testing, a Craftsman's Approach", which the ISTQB syllabus quotes as reference in this case).
Following the ISTQB definition above, for EACH boundary value, you need to repeat the "before, at, and just over" analysis. For the first example, this would give you:
For 10 - we would test 9, 10, 11.
For 11 - we would test 10 (already tested), 11 (already tested), 12
For 15 - we would test 14, 15, 16
For 16 - we would test 15 (already tested), 16 (already tested), 17
For 19 - we would test 18, 19, 20
For 20 - we would test 19 (already tested), 20 (already tested), 21
For 22 - we would test 21 (already tested), 22, 23
This would result in a a total of **14** test cases.
There is one way to explain the 12 tests in the answer, and for that you need to read "The Boundary Value Fallacy" by René Tuinhout, in the Sep 2018 issue of "Testing Experience" Magazine (good luck finding it... I tried a bit but the places I found all asked me to create an account).
Following that article, the values 12, 14 and the values 17,18 can be "merged" (that is, testing with one of them is sufficient to find the type of errors that are possible in code that defines boundaries). But I will be very surprised if the writers of the question (which I understand aims at the Foundation level) were thinking of this. It is definitely an advanced topic.

Reportviewer VB.NET about Switch Expression

Hello everyone can anyone correct my codes in rdlc tables
i have 1 tables and on that table there was a Field!ans1 that was computing for the average of the column(RED CIRCLE in IMAGE) then i want that average to filter to an if statement to identify if that average is Agree , disagree or Stronglyagree(BLACK CIRCLE IN THE IMAGE)
Here's the Picture of my RDLC Table
the Black Circle is the If Statement that will identify if the Average Below in the Red Circle if is Agree,Disagree,or Strongly Agree
but i am having a problem because the statement always stock on Disagree even its value is 3
// Here is my Code in the Black Circle in the IMAGE
=Switch(Fields!ans1.Value < 1, "Strongly Disagree ",
Fields!ans1.Value > 2, " Disagree",
Fields!ans1.Value > 3, "Agree",
Fields!ans1.Value > 4, "Strongly Agree"
)
//Here is the Code in the RedCircle
=Avg(CDbl(Fields!ans1.Value))
Remember that a switch statement of any kind is evaluated top-down. Is 3.00 greater than 2? Yes it is, so the result is " Disagree" (why you haven't noticed and removed that rogue space, I don't know). If you are going to compare using the 'greater than' operator then you need to compare the largest value first this:
=Switch(Fields!ans1.Value < 1, "Strongly Disagree",
Fields!ans1.Value > 4, "Strongly Agree",
Fields!ans1.Value > 3, "Agree",
Fields!ans1.Value > 2, "Disagree"
)
should work. That's just basic logic that you should have learned in maths class. Note that I have removed that rogue space too.
By the way, that is still going to ignore any values in the range 1.0 - 2.0.