Hello All,
I was hoping that someone might have a suggestion on the best way to complete the follwoing problem.
I have a bunch of roads. Each road has a Start and end Distance (chainage in metres) and may have been sealed in multiple sections over the last 40 years. Each seal section also has a start and an end value and they may overlap each other.
I have managed to get this information into a stocck type graph which displays the seal in a distance verses year type format. From this I can visually see the age of the road and how the sections should be broken up.
I want to be able to summarize this data to automatically get the the latest seal with a start and end value for the entrire length of road.
I see this kind of done in a while loop where X = total length of road,
XS = value of start of segments
XE = Vale of end of segment
Y = year of seal
therefore
XS = 0
XE= 0
while XE<= X
get Y value
increment XE value until Y value changes
write XS XE Y to table
set XS to equal last XE
and repeat until end of road reached.
The final result that I want is a table of ROAD_ID, Start, End, Year of seal.
Hopefully that all makes sense.
I am probably just searching for the wrong words but if anyone has any examples that I can refer to that would be fantastic.
Cheers,
Laura
16 2954 Rabbit 12,516
Recognized Expert Moderator MVP
It's a little hard to follow, can you post up an example of the data before hand, and what it should look like after?
ADezii 8,834
Recognized Expert Expert
Hello All,
I was hoping that someone might have a suggestion on the best way to complete the follwoing problem.
I have a bunch of roads. Each road has a Start and end Distance (chainage in metres) and may have been sealed in multiple sections over the last 40 years. Each seal section also has a start and an end value and they may overlap each other.
I have managed to get this information into a stocck type graph which displays the seal in a distance verses year type format. From this I can visually see the age of the road and how the sections should be broken up.
I want to be able to summarize this data to automatically get the the latest seal with a start and end value for the entrire length of road.
I see this kind of done in a while loop where X = total length of road,
XS = value of start of segments
XE = Vale of end of segment
Y = year of seal
therefore
XS = 0
XE= 0
while XE<= X
get Y value
increment XE value until Y value changes
write XS XE Y to table
set XS to equal last XE
and repeat until end of road reached.
The final result that I want is a table of ROAD_ID, Start, End, Year of seal.
Hopefully that all makes sense.
I am probably just searching for the wrong words but if anyone has any examples that I can refer to that would be fantastic.
Cheers,
Laura
Just subscribing and waiting for data from OP.
Just subscribing and waiting for data from OP.
Sorry about that, I should have posted an example.
Just say that I have the following data for a road
Road_id start_Seal End_seal treatment year
100:01 0 100 primerseal 1981
100:01 0 100 finalseal 1992
100:01 50 200 reseal 1997
100:01 125 150 reseal 2001
I want to rebreak this information into logical segments which will give a linear timeline (in this case lengthline) to give distance vs age.
ie
Road_id start_Seal End_seal treatment year
100:01 0 50 final seal 1992
100:01 50 125 reseal 1997
100:01 125 150 reseal 2001
100:01 150 200 reseal 1997
segments are now 0-50, 50-125, 125-150, 150-200 with only the latest treatment and year associated with each distance along the road.
These results will be combined with other data into a formula that will be used to predict when a road will need to be rebuilt.
Hopefully that makes a little more sense....
ADezii 8,834
Recognized Expert Expert
Sorry about that, I should have posted an example.
Just say that I have the following data for a road
Road_id start_Seal End_seal treatment year
100:01 0 100 primerseal 1981
100:01 0 100 finalseal 1992
100:01 50 200 reseal 1997
100:01 125 150 reseal 2001
I want to rebreak this information into logical segments which will give a linear timeline (in this case lengthline) to give distance vs age.
ie
Road_id start_Seal End_seal treatment year
100:01 0 50 final seal 1992
100:01 50 125 reseal 1997
100:01 125 150 reseal 2001
100:01 150 200 reseal 1997
segments are now 0-50, 50-125, 125-150, 150-200 with only the latest treatment and year associated with each distance along the road.
These results will be combined with other data into a formula that will be used to predict when a road will need to be rebuilt.
Hopefully that makes a little more sense....
I'm gonna sleep on this one tonight and hopefully I'll have a solution for you soon. I'll be in touch.
Rabbit 12,516
Recognized Expert Moderator MVP
Complicated...
Gonna throw around an idea until I can get into the office and test it out. Forgive the rambling.
1) Take start, type, and year from current record.
2) Use start of next highest record as the end. Subquery.
3) If no higher record, use current end.
4) Keep record only if it's the most recent year for that start.
No... that's not gonna work. It won't give you the last record. Looks like we'll have to use VBA.
Rabbit 12,516
Recognized Expert Moderator MVP
Tested and verified. DataTable and FinalTable
Road_id; Text
start_Seal; Number
End_seal; Number
treatment; Text
year; Number -
Option Compare Database
-
Option Explicit
-
-
Public Sub RoadCondition()
-
Dim rst1 As Recordset
-
Dim rst2 As Recordset
-
Dim rst3 As Recordset
-
Dim rstart, rend, current As Integer
-
Dim cstart, cend As Integer
-
-
' Opens a record set of all unique Road_id.
-
Set rst1 = CurrentDb.OpenRecordset("SELECT DISTINCT Road_id FROM DataTable;")
-
-
Do Until rst1.EOF
-
-
' Loops through all unique Road_id and sets start and end values of the Road_id
-
rstart = DMin("start_Seal", "DataTable", "Road_id = '" & rst1!Road_id & "'")
-
rend = DMax("End_seal", "DataTable", "Road_id = '" & rst1!Road_id & "'")
-
-
' Sets current position equal to start of road
-
current = rstart
-
-
' Loops until current position reaches end of road
-
Do Until current > rend
-
-
' Sets the values of the start of the section
-
cstart = current
-
-
' Gets the most current values for the start of the road section
-
Set rst2 = CurrentDb.OpenRecordset("SELECT TOP 1 * FROM DataTable WHERE Road_id = '" & rst1!Road_id & "'" & _
-
" AND " & cstart & " BETWEEN start_Seal AND End_seal ORDER BY year DESC;")
-
-
' Retrieves the record with a start_Seal after the current position with a year later than current record's year
-
Set rst3 = CurrentDb.OpenRecordset("SELECT TOP 1 * FROM DataTable WHERE Road_id = '" & rst1!Road_id & "'" & _
-
" AND start_Seal > " & cstart & " AND start_Seal < " & rst2!End_seal & " AND year > " & rst2!Year & " ORDER BY start_Seal, year DESC;")
-
-
' If no such record exists, use the current record's End_seal, if it does, use the next record's start_Seal
-
If rst3.RecordCount = 0 Then
-
cend = rst2!End_seal
-
Else
-
cend = rst3!start_Seal - 1
-
End If
-
-
' Inserts a record into final table for that section
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL "INSERT INTO FinalTable (Road_id, start_Seal, End_seal, treatment, year) VALUES (" & _
-
"'" & rst1!Road_id & "'," & cstart & "," & cend & ",'" & rst2!treatment & "'," & rst2!Year & ");"
-
DoCmd.SetWarnings True
-
-
' Increment to next road section
-
current = cend + 1
-
Loop
-
-
' Moves to next Road_id
-
rst1.MoveNext
-
-
Loop
-
End Sub
-
-
Private Sub Command0_Click()
-
' Delete the records in the final table before calling the function
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL "DELETE * FROM FinalTable"
-
DoCmd.SetWarnings True
-
-
Call RoadCondition
-
End Sub
-
ADezii 8,834
Recognized Expert Expert
Tested and verified. DataTable and FinalTable
Road_id; Text
start_Seal; Number
End_seal; Number
treatment; Text
year; Number -
Option Compare Database
-
Option Explicit
-
-
Public Sub RoadCondition()
-
Dim rst1 As Recordset
-
Dim rst2 As Recordset
-
Dim rst3 As Recordset
-
Dim rstart, rend, current As Integer
-
Dim cstart, cend As Integer
-
-
' Opens a record set of all unique Road_id.
-
Set rst1 = CurrentDb.OpenRecordset("SELECT DISTINCT Road_id FROM DataTable;")
-
-
Do Until rst1.EOF
-
-
' Loops through all unique Road_id and sets start and end values of the Road_id
-
rstart = DMin("start_Seal", "DataTable", "Road_id = '" & rst1!Road_id & "'")
-
rend = DMax("End_seal", "DataTable", "Road_id = '" & rst1!Road_id & "'")
-
-
' Sets current position equal to start of road
-
current = rstart
-
-
' Loops until current position reaches end of road
-
Do Until current > rend
-
-
' Sets the values of the start of the section
-
cstart = current
-
-
' Gets the most current values for the start of the road section
-
Set rst2 = CurrentDb.OpenRecordset("SELECT TOP 1 * FROM DataTable WHERE Road_id = '" & rst1!Road_id & "'" & _
-
" AND " & cstart & " BETWEEN start_Seal AND End_seal ORDER BY year DESC;")
-
-
' Retrieves the record with a start_Seal after the current position with a year later than current record's year
-
Set rst3 = CurrentDb.OpenRecordset("SELECT TOP 1 * FROM DataTable WHERE Road_id = '" & rst1!Road_id & "'" & _
-
" AND start_Seal > " & cstart & " AND start_Seal < " & rst2!End_seal & " AND year > " & rst2!Year & " ORDER BY start_Seal, year DESC;")
-
-
' If no such record exists, use the current record's End_seal, if it does, use the next record's start_Seal
-
If rst3.RecordCount = 0 Then
-
cend = rst2!End_seal
-
Else
-
cend = rst3!start_Seal - 1
-
End If
-
-
' Inserts a record into final table for that section
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL "INSERT INTO FinalTable (Road_id, start_Seal, End_seal, treatment, year) VALUES (" & _
-
"'" & rst1!Road_id & "'," & cstart & "," & cend & ",'" & rst2!treatment & "'," & rst2!Year & ");"
-
DoCmd.SetWarnings True
-
-
' Increment to next road section
-
current = cend + 1
-
Loop
-
-
' Moves to next Road_id
-
rst1.MoveNext
-
-
Loop
-
End Sub
-
-
Private Sub Command0_Click()
-
' Delete the records in the final table before calling the function
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL "DELETE * FROM FinalTable"
-
DoCmd.SetWarnings True
-
-
Call RoadCondition
-
End Sub
-
Nice solution Rabbit, and thanks for saving me a lot of time especially since I was experiencing a mental block anyway, and probably would not have arrived at a solution. I am curious about one think - is there any special reason why rstart, cstart, and rend are declared as Variants?
ADezii 8,834
Recognized Expert Expert
Complicated...
Gonna throw around an idea until I can get into the office and test it out. Forgive the rambling.
1) Take start, type, and year from current record.
2) Use start of next highest record as the end. Subquery.
3) If no higher record, use current end.
4) Keep record only if it's the most recent year for that start.
No... that's not gonna work. It won't give you the last record. Looks like we'll have to use VBA.
Nice solution Rabbit, and thanks for saving me a lot of time especially since I was experiencing a mental block anyway, and probably would not have arrived at a solution. I am curious about one think - is there any special reason why rstart, cstart, and rend are declared as Variants?
Rabbit 12,516
Recognized Expert Moderator MVP
Nice solution Rabbit, and thanks for saving me a lot of time especially since I was experiencing a mental block anyway, and probably would not have arrived at a solution. I am curious about one think - is there any special reason why rstart, cstart, and rend are declared as Variants?
uhh.. the reason is that you should see an ophthalmologist ? Unless I made a mistake and you edited my post, I declared them as Integers. You were probably glancing through it and saw me declare the integers over two lines and thought the other was a different data type. I only did it over two lines on a whim.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Diez B. Roggisch |
last post by:
Hi,
today I rummaged through the language spec to see whats in the for ... else:
for me. I was sort of disappointed to learn that the else clauses simply
gets executed after the loop-body - regardless of the loop beeing entered
or not.
So where is an actual use case for that feature?
I imagined that the else-clause would only be executed if the loop body
|
by: Andrew Koenig |
last post by:
PEP 315 suggests that a statement such as
do:
x = foo()
while x != 0:
bar(x)
be equivalent to
while True:
|
by: James E Koehler |
last post by:
I can't get the WHILE statement to work in MySQL.
The version of MySQL that I am using is:
Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32)
running on Windows MX.
Here is the relevant section from the manual:
20.1.9.7 WHILE Statement
|
by: Michael B Allen |
last post by:
Should there be any preference between the following logically equivalent
statements?
while (1) {
vs.
for ( ;; ) {
I suspect the answer is "no" but I'd like to know what the consensus is
|
by: John Pass |
last post by:
What is the difference between a While and Do While/Loop repetition structure.
If they is no difference (as it seems) why do both exist?
| |
by: Howard |
last post by:
Hello everyone (total VB.NET beginner here),
I'm reading the "SAMS Teach Yourself VB.NET In 21 Days" book, and came
across an exercise that I can't get to work. The exercise asks that
you create a game that makes the user guess a number from 1-100, and
you tell the user "lower" or "higher" as they input their guesses,
until they guess the correct number, at which point you then tell the
user "Correct". I tried using the While Loop, and...
|
by: Claudio Grondi |
last post by:
Sometimes it is known in advance, that the time spent in a loop will be
in order of minutes or even hours, so it makes sense to optimize each
element in the loop to make it run faster.
One of instructions which can sure be optimized away is the check for
the break condition, at least within the time where it is known that the
loop will not reach it.
Any idea how to write such a loop?
e.g.
|
by: voger |
last post by:
Hi everyone
Can anyone please explain this strange behavior?
I have this function that is supposed to copy the contents of one array to
one other array, but sorted. I don't know if the logic is correct but when
I try to debug this the do/while loop results in an endless loop. The Two
first values of the unsorted array are
unsorted = 8
|
by: icarus |
last post by:
Hi all, i'm new to python. Learning on my own how to ask a user to
finish a loop or not.
For some reason, it behaves as infinite loop although I changed its
condition. Please tell me what I'm doing wrong. Thanks in advance.
condition = True
while ( condition ):
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |