Procedural and Object-Oriented Programming

By Shahabuddin Amerudin

Procedural Programming is a programming paradigm that is based on the concept of procedures, which are essentially sets of instructions that tell a computer what to do. The focus of procedural programming is on the step-by-step execution of a series of procedures to accomplish a specific task. In this programming paradigm, the program is organized around the data, and functions are used to manipulate the data.

Object-Oriented Programming (OOP), on the other hand, is a programming paradigm that is based on the concept of objects. In OOP, data and the procedures that operate on that data are combined into a single entity known as an object. The focus of OOP is on the objects and their interactions, rather than on the procedures.

Here are some examples in C++ and VB of procedural and object-oriented programming:

Example of Procedural Programming in C++:

#include <iostream>
using namespace std;

int main()
{
   int a = 5, b = 10;
   int sum = a + b;
   cout << "The sum of " << a << " and " << b << " is " << sum << endl;
   return 0;
}

Example of Procedural Programming in VB:

Private Sub btnSum_Click()
   Dim a As Integer
   Dim b As Integer
   Dim sum As Integer
   a = Val(txtA.Text)
   b = Val(txtB.Text)
   sum = a + b
   lblResult.Caption = "The sum of " & a & " and " & b & " is " & sum
End Sub

Example of Object-Oriented Programming in C++:

#include <iostream>
using namespace std;

class Rectangle {
   private:
      int length;
      int width;

   public:
      Rectangle(int len, int wid) {
         length = len;
         width = wid;
      }

      int area() {
         return length * width;
      }
};

int main() {
   Rectangle rect(5, 10);
   cout << "The area of the rectangle is " << rect.area() << endl;
   return 0;
}

Example of Object-Oriented Programming in VB:

Public Class Rectangle
   Private length As Integer
   Private width As Integer

   Public Sub New(len As Integer, wid As Integer)
      length = len
      width = wid
   End Sub

   Public Function Area() As Integer
      Return length * width
   End Function
End Class

Private Sub btnArea_Click()
   Dim rect As Rectangle
   rect = New Rectangle(5, 10)
   lblResult.Caption = "The area of the rectangle is " & rect.Area()
End Sub

In the procedural programming examples, the focus is on the steps taken to accomplish a specific task, such as calculating the sum of two numbers. In the object-oriented programming examples, the focus is on the object and its properties and behaviors, such as a rectangle and its area.

Procedural programming can be useful in situations where the program’s functionality is relatively simple and doesn’t require a lot of complexity. However, as programs become more complex, the use of procedural programming can lead to code that is difficult to maintain and update.

Object-oriented programming, on the other hand, provides a more structured and organized approach to programming. By encapsulating data and functions into objects, the code becomes more modular and easier to maintain. Additionally, object-oriented programming provides inheritance, which allows new classes to be created based on existing classes, making it easier to reuse code.

In conclusion, both procedural and object-oriented programming have their own strengths and weaknesses, and the choice of programming paradigm depends on the specific requirements of the project. However, as programs become more complex, the benefits of object-oriented programming become more apparent, and it is often the preferred approach to programming.

Suggestion for Citation:
Amerudin, S. (2023). Procedural and Object-Oriented Programming. [Online] Available at: https://people.utm.my/shahabuddin/?p=6165 (Accessed: 28 March 2023).

Line Simplification Algorithms in VB.net

Here is an example of how the Douglas-Peucker, Visvalingam-Whyatt, and Reumann-Witkam line simplification algorithms can be implemented in VB.net:

Douglas-Peucker algorithm:


Public Function DouglasPeucker(ByVal points As List(Of PointF), ByVal tolerance As Double) As List(Of PointF)
    Dim dmax As Double = 0
    Dim index As Integer = 0
    For i As Integer = 2 To points.Count - 1
        Dim d As Double = PerpendicularDistance(points(i), New LineF(points(0), points(points.Count - 1)))
        If d > dmax Then
            index = i
            dmax = d
        End If
    Next
    If dmax > tolerance Then
        Dim recResults1 As List(Of PointF) = DouglasPeucker(points.GetRange(0, index + 1), tolerance)
        Dim recResults2 As List(Of PointF) = DouglasPeucker(points.GetRange(index, points.Count - index), tolerance)
        recResults1.AddRange(recResults2)
        Return recResults1
    Else
        Dim result As New List(Of PointF)
        result.Add(points(0))
        result.Add(points(points.Count - 1))
        Return result
    End If
End Function

Visvalingam-Whyatt algorithm:


Public Function VisvalingamWhyatt(ByVal points As List(Of PointF), ByVal tolerance As Double) As List(Of PointF)
    For i As Integer = 0 To points.Count - 3
        Dim area As Double = Area(points(i), points(i + 1), points(i + 2))
        If area < tolerance Then
            points.RemoveAt(i + 1)
        End If
    Next
    Return points
End Function

Reumann-Witkam algorithm:


Public Function ReumannWitkam(ByVal points As List(Of PointF), ByVal tolerance As Double) As List(Of PointF)
    For i As Integer = 0 To points.Count - 2
        Dim d As Double = point_line_distance(points(i), New LineF(points(0), points(points.Count - 1)))
        If d > tolerance Then
            points.RemoveAt(i)
        End If
    Next
    Return points
End Function

In these implementations, the input is a list of PointF and the tolerance value is a real number used to define the level of simplification. The output is a simplified version of the input line, represented as a list of PointF. It’s important to note that the above code examples are just a representation of the algorithm and may not be fully functional or optimized for specific use cases. They also may require additional functions such as PerpendicularDistance and point_line_distance to be defined and implemented as well. Also, as VB.net is an event-driven programming language, It’s important to consider the performance of these functions when working with large datasets, as they may be affected by the number of operations required by the algorithm. It’s also important to consider the specific requirements of your application and make any necessary adjustments to the code to ensure it meets those requirements.

Creating An Application Visual Interface

There are several programming languages that can be used to create an application interface, and the choice of which one to use will depend on the specific requirements and constraints of your project. Some of the most popular languages for creating visual interfaces include:

  1. Python: Python is a popular and versatile language that has a wide range of libraries for creating visual interfaces. Some popular libraries for creating visual interfaces in Python include Tkinter, PyQt, and wxPython. These libraries provide a simple and easy-to-use API for creating graphical user interfaces (GUIs) and can be used to create desktop applications and web applications.

  2. C#: C# is a popular language for creating Windows desktop applications and has a built-in library called Windows Forms for creating graphical user interfaces. It also has the advantage of being able to use the Microsoft Visual Studio development environment, which provides a visual designer and a wide range of tools for creating and debugging applications.

  3. Java: Java is a popular language for creating cross-platform desktop applications and has a built-in library called Swing for creating graphical user interfaces. It also has the advantage of being able to use the Eclipse development environment, which provides a visual designer and a wide range of tools for creating and debugging applications.

  4. JavaScript: JavaScript is a popular language for creating web applications and has a wide range of libraries and frameworks for creating visual interfaces. Some popular libraries for creating visual interfaces in JavaScript include React, Angular, and Vue. These libraries provide a simple and easy-to-use API for creating web user interfaces and can be used to create web applications.

It’s important to note that these are just a few examples of the many languages that can be used to create visual user interfaces, and the choice of which one to use will depend on the specific requirements and constraints of your project.

Creating a application interface using Python, C#, Java, or JavaScript may have a slightly different syntax and approach compared to Visual Basic (VB) but it can be considered as easy, depending on your experience and familiarity with the language.

Python, C#, Java, and JavaScript all have built-in libraries or frameworks for creating visual interfaces, which provide a simple and easy-to-use API for creating graphical user interfaces (GUIs) similar to Visual Basic.

For example, Tkinter in python, Windows Form in C#, Swing in Java, React, Angular and Vue in JavaScript, all provide a visual designer and a wide range of tools for creating and debugging applications, similar to the experience of using Visual Basic.

It’s worth noting that VB is a simple and easy-to-use language that is well suited for creating graphical user interfaces, and it has a built-in library called Windows Forms for creating visual interfaces.

However, the choice of language and library depends on the specific requirements and constraints of your project. If you are more familiar with one of these languages, it will probably be easier for you to create a visual interface using that language.

Malaysia Coordinate Transformation Program

Malaysia Coordinate Transformation Program

By Shahabuddin Amerudin

Geographic Information System (GIS) software has significantly advanced the way we approach mapping and spatial analysis, providing essential tools for converting between various coordinate systems. One of the key innovations in this field is the Malaysian Coordinate Transformation Program, developed in 1998 at Universiti Teknologi Malaysia (UTM). This program remains a crucial tool for professionals working with geospatial data in Malaysia. This article offers an in-depth exploration of the coordinate transformation process from the global WGS84 system to the local Malaysian systems, such as the Malayan Revised Triangulation (MRT), Rectified Skew Orthomorphic (RSO), and Cassini-Soldner systems.

Understanding Coordinate Systems and Datums

To appreciate the Malaysian Coordinate Transformation Program, it is essential to understand the coordinate systems and datums involved. The World Geodetic System 1984 (WGS84) is a global coordinate reference system used by the Global Positioning System (GPS). Developed by the U.S. Department of Defense, WGS84 is based on the GRS80 ellipsoid, which approximates the Earth’s shape (National Geospatial-Intelligence Agency, 2014). This system serves as the foundation for most GPS-based navigation and mapping activities worldwide.

In contrast, the Malayan Revised Triangulation (MRT) system is a local geodetic system used specifically in Peninsular Malaysia. Established in the mid-20th century, MRT is based on the Modified Everest ellipsoid, chosen for its suitability to the region’s topography (Ibrahim & Rashid, 1998). MRT was the standard for topographical and cadastral mapping in Malaysia before the widespread adoption of global systems like WGS84.

The Rectified Skew Orthomorphic (RSO) projection is a specialized map projection used primarily for topographical mapping in Malaysia. Developed based on Hotine’s theory in 1947, the RSO projection is an oblique Mercator projection that maintains conformality while minimizing distortion along a selected central line (Hotine, 1947). This projection is tailored for the Malaysian peninsula and is still used in many national mapping projects.

The Cassini-Soldner projection, on the other hand, is a cylindrical and transverse map projection historically used for cadastral mapping in Malaysia. Each state in Peninsular Malaysia traditionally had its own Cassini-Soldner system, with unique origins to minimize distortion within the state (Department of Survey and Mapping Malaysia [DSMM], 1974). Although its use has declined with the introduction of modern systems, it remains significant in historical cadastral records.

Coordinate Transformation Process

The process of transforming coordinates from WGS84 to the Cassini-Soldner system involves several stages. This transformation ensures the accurate integration of GPS data with local surveying systems (DSMM, 1999).

First, the transformation from WGS84 to the local Malayan Revised Triangulation (MRT) system involves the use of the Bursa-Wolf mathematical model. This model accounts for differences in translation, rotation, and scale between datums. The transformation formula can be expressed as:

XMRT=XWGS84+Tx+(1+S)⋅(Rz⋅(YWGS84−Ty)−Ry⋅(ZWGS84−Tz))
YMRT​=YWGS84​+Ty​+(1+S)⋅(Rz​⋅(ZWGS84​−Tz​)−Rx​⋅(XWGS84​−Tx​))

where Tx,Ty,Tz are translation parameters, S is the scale factor, and Rx,Ry,Rz are rotation matrices (National Geospatial-Intelligence Agency, 2014). The MRT system uses the Modified Everest ellipsoid, with specific parameters for semi-major axis and flattening (Ibrahim & Rashid, 1998). Standard algorithms based on the Bursa-Wolf model are applied to carry out this transformation.

Next, the transformation from MRT to the Rectified Skew Orthomorphic (RSO) projection involves applying formulas from the Projection Tables for Malaya. This projection uses the same Modified Everest ellipsoid, ensuring consistency with MRT. The RSO projection system is anchored to specific geographical coordinates in Kertau, Malaysia. Parameters such as central meridian, scale factor, and false easting/northing from the Projection Tables are used to perform this transformation (Hotine, 1947).

Finally, transforming coordinates from RSO to the Cassini-Soldner system involves using the Cassini projection formulas. The Cassini-Soldner projection is cylindrical and transverse, with each state in Peninsular Malaysia having its own specific origins to minimize distortion. The transformation parameters include scale factors, translations, and origin adjustments specific to each state (DSMM, 1974).

The Malaysian Coordinate Transformation Program

Developed in 1998 using Microsoft Visual Basic 6, the Malaysian Coordinate Transformation Program addresses the need for converting coordinates between different systems. Although the program was created on the Windows XP platform, it remains a valuable tool for professionals working with older datasets recorded in these local systems. The program provides a one-way transformation capability, allowing users to convert coordinates from WGS84 to MRT, RSO, and Cassini-Soldner. It also supports state-specific Cassini-Soldner coordinate retrieval, making it highly relevant for land surveying, GIS mapping, and navigation.

Despite its age, the Malaysian Coordinate Transformation Program remains remarkably user-friendly, efficient, and effective. It stands as a testament to the lasting influence of early GIS technologies on contemporary geospatial practices in Malaysia. During the late 1990s, many GIS software solutions available at that time struggled with accurate coordinate transformations due to their lack of specific Malaysian transformation parameters, often relying instead on universal formulas that were inadequate for local requirements. The Malaysian Coordinate Transformation Program, developed with an understanding of these local nuances, provided a vital solution where others fell short.

The Malaysian Coordinate Transformation Program remains an essential tool for GIS professionals, offering reliable solutions for coordinate conversion in Malaysia. Its ability to bridge the gap between global and local geodetic systems ensures its continued relevance in integrating historical and modern geospatial data.

For further information or inquiries about this program, interested individuals can contact shahabuddin@utm.my.

Important Notice

This program is not compatible with newer datums, such as GDM2000, and is specifically tailored for earlier geodetic systems utilized in Malaysia. As the program was developed in 1998 using Microsoft Visual Basic 6 and Windows XP, users may encounter compatibility issues when running it on the latest versions of Windows.

References

Department of Survey and Mapping Malaysia (DSMM). (1974). Cassini-Soldner projections for cadastral surveying in Malaysia. Technical Report No. 74-3, Kuala Lumpur.

Hotine, M. (1947). The Rectified Skew Orthomorphic projection of the sphere. The Geographical Journal, 109(2), 97-107.

Ibrahim, M. F., & Rashid, K. A. (1998). Mapping Malaysia: The evolution of geodetic datums and projections. Malaysian Surveyor, 33(4), 22-35.

Department of Survey and Mapping Malaysia (DSMM). (1999). GPS cadastral survey guidelines Semenanjung Malaysia. Retrieved from https://www.jupem.gov.my/jupem18a/assets/uploads/files/pekeliling/a9684-sg-699.pdf

National Geospatial-Intelligence Agency. (2014). World Geodetic System 1984 (WGS84) Implementation Manual. Retrieved from https://www.nga.mil


Announcement

We are pleased to announce that the program, now over 25 years old, has benefited numerous users since its initial release. Many users have reached out to me directly via email for assistance, and I have been glad to support them. To make things more convenient, I am now offering this program to the public for free. Those interested can download it from the following link: http://bit.ly/2F6O1ZS. However, please review the following important information before using the program:

Geodetic Datum Support

This program was developed in 1998, based on the geodetic datums available at that time. Therefore, it may not support newer geodetic datums, such as GDM2000, or other recent updates in geospatial reference systems. If your work requires the use of modern datum systems, you may need to use alternative software that accommodates the latest requirements.

Windows Compatibility Issues

The program was created using Microsoft Visual Basic 6 for use on Windows XP, and as such, it may encounter compatibility issues when running on more recent versions of Windows, such as Windows 10 or Windows 11. If you encounter difficulties, here are a couple of solutions:

  1. Install missing libraries: Some required system components, such as the mscomctl.ocx library, may not be included in newer versions of Windows. To resolve this, you can follow the instructions provided here: https://www.windows10free.com/repair-how-to-install-mscomctl-ocx-missing-windows-10/.
  2. Manually download the mscomctl.ocx file: If the issue persists, you can manually download the mscomctl.ocx file from https://thegeekpage.com/mscomctl-ocx/ and follow the provided steps to register it on your system.

Legal Disclaimer

While this program is now freely available to the public, we do not provide any official support or updates. The program is distributed on an “as-is” basis, with no warranties of any kind. By using the program, you acknowledge that we are not liable for any inaccuracies, errors, or damages that may result, particularly given the program’s age and the potential for compatibility issues with modern operating systems.

We hope the program proves useful to you. Please use it responsibly and at your own discretion.

Sunday, Oct. 6, 2024