Introduction to computational geometry

Computational geometry has a wide range of applications and yet it is rarely discussed in tutorials. So I’m starting this series as an introduction to this interesting topic. I’m going to start from the very basics like point representation, standard formats, simple operations to complex topics like hyper plane routing in convex hulls. The rest of the post is organized as follows:

  • What is Computational geometry and it’s applications
  • Standard representations of computational geometry objects
  • Types of simple geometries
  • Simple operations on geometrical objects

What is Computational geometries

Computational geometry is a branch of computer science concerned with the representation, standardization, and making operations on geometrical objects like road networks, classification of point clouds or building simple models like human skeletons. Rarely any application that requires simulation of models such as building games, tracking, spacial data analysis or viewing customized maps does not depend heavily on computational geometry.

Standard Representations of Computational Geometries

There are several standards when it comes to computational geometries. Each of which is best fit a different situation. For example the representation used to serve a map can be quite different than the one used to communicate data throw an API and neither are suited for performing database operations.

For example most databases are familiar with both the WKT and WKB, While GEOJSON format is an API friendly. For map viewing there are several protocols such as WFS and MVT for serving vector data and WMS, WTMS and TMS are widely used for serving raster images. For serving large data files the commonly used formats are SHP, KML, etc….

Upcoming posts will explore each and everyone of these techniques as well as comparisons and implementations. keep tuned.

Types of Simple Geometries

Simple geometries start always with a point. A point can be identified by a vector which contain n elements, where n is the number of dimensions. For example, if we consider a 1D plain, then a point is simply a vector contains one number (coordinate) and in this special case only can a point represented as a scaler. If you were operating in a 2D space, a point will contain two elements p=[x, y], and in 3D it would be p=[x, y, z] and so on.

The second is lines, lines can be represented as two points, Lines extend beyond these points to span an infinite length while keeping its orientation. So in short a line is an ordered pair of points L=[p1,p2]. If the line has finite length, it can be represented as a set of points having the same orientation.

Lines that does not conform with the above discreption, such as roads are called line strings or poly lines, this kind of line is composed of a vector of lines where each line end connects to the next one beginning.

Triangles, squares, hexagons and polygon are all considered polygons. A polygon is represented as a set of lines, where each all the lines forms a closed shape.

Shapes where its inside is emptied or form more complex type of shape can be considered either multi-polygons or geometry collection, where geometry collection are used to define an object or more than one of the aforementioned types fused together.

Simple Operations on Geometries

Operations on geometries varies from calculating the distance of a line, or between two points. To smart grouping of points into clusters, investigating the center of a propagating signal, deciding whether a point, line, etc.. crosses or fits into another. To more complicated tasks such as routing, calculating shortest path, and more. If you are interested please like the post, and our page light syntax so you do not miss any go it

C# SELECT

It has been frustrating time working with several types of filters in dotnet framework specially while dealing with EFCore. So I made my decision to provide a library for generating those queries. Automating query generation and yet puts the developer in the front seat. Enjoy.

SELECT

Introducing our SELECT dotnet nuget package which is an IQueryable selection automation library for c#

LinQ query generator for c#

Applies to DB queries as well as dictionaries, lists, etc… (any class that implements IQueryable or IEnumerable)

Build Status

Features

  • Extremly easy to use
  • Light weight
  • Unify and simplfy Apis
  • Multi-platform
  • Works with relations, nested objectes, and Enums
  • Geometry Support
  • Pure c#
  • Opensource
  • MIT License

Markdown is an opensource free platform for automating search APIs while keeping the developer in control. It is built using the powerful features of Expressions in c#. Please feel free to contriute.

Installation

Using package manager

Install-Package SELECT -Version 1.0.0

Using DOTNET CLI

dotnet add package SELECT --version 1.0.0

Using PackageReference


Usage

  1. Create new Console Project in c# with name "test"
  2. Install SELECT
    dotnet add package SELECT --version 1.0.0
    
  3. Add class "Grade"
    public class Grade
    {
        public string subject { get; set; }
        public int grade { get; set; }
    }
    
  4. Add class "branch"
    public class branch
    {
        public string name { get; set; }
        public Grade grade { get; set; }
    }
    
  5. Add class "user"
    public class User
    {
        public string name { get; set; }
        public int age { get; set; }
        public branch branch { get; set; }
    }
    
  6. In the Main function, lets add some users
            List users = new();
            for (int i = 0; i < 10; i++)
            {
                User user = new();
                user.name = i.ToString();
                user.age = i;
                user.branch = new branch
                {
                    grade = new()
                    {
                        subject = user.name + i.ToString(),
                        grade = user.age
                    },
                    name = "test"
    
                };
                users.Add(user);
            }
    
  7. Finally, lets use the package Lets make a request that select users who are 5 years old or younger, get their age, thier grade, and thier branch name Then order the results in a descending manner using the user’s age.
            Request request = new()
            {
                Items = "age,branch.grade,branch.name",
                Order = new()
                {
                    IsAsc = false,
                    Name = "age"
                },
                Filters = new Filter[]
                {
                    new Filter(Operator.LtE,"age",5)
                }
            };
    
  8. Retrive and print the results
          IQueryable result = users.AsQueryable().Construct(request);
          Console.WriteLine(JsonConvert.SerializeObject(result));
    

The complete example code

using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using SELECT;
using SELECT.Entities;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            List users = new();
            for (int i = 0; i < 10; i++)
            {
                User user = new();
                user.name = i.ToString();
                user.age = i;
                user.branch = new branch
                {
                    grade = new()
                    {
                        subject = user.name + i.ToString(),
                        grade = user.age
                    },
                    name = "test"

                };
                users.Add(user);
            }
            Request request = new()
            {
                Items = "age,branch.grade,branch.name",
                order = new()
                {
                    IsAsc = false,
                    name = "age"
                },
                filters = new Filter[]
                {
                    new Filter(Operator.LtE,"age",5)
                }
            };
            IQueryable result = users.AsQueryable().Construct(request);
            Console.WriteLine(JsonConvert.SerializeObject(result));
        }
    }

    public class User
    {
        public string name { get; set; }
        public int age { get; set; }
        public branch branch { get; set; }
    }
    public class branch
    {
        public string name { get; set; }
        public Grade grade { get; set; }
    }
    public class Grade
    {
        public string subject { get; set; }
        public int grade { get; set; }
    }
}

The Construct Method

This method acts on IQueryable objects, and recives a Request Object the Reuest Object consists of 3 Properties:

  1. Items is a comma separated string, where each substing contains a field name Nested Objectes can be accessed using the ".". For example; if you need to select ID, Name and Car model, the items string should be

     Items = "Id,Name,Car.Model"
    
  2. The order property is an object of type Order. This Object is resposable for ordering the result. This Object Contains 2 Properties

    Property Type Description
    name string The name of the property that is selected to order the reslts by
    IsAsc bool If true The order is ascending, else the order is descending
  3. The Filters Property is an array of the filter object. This specifies what result to reurn. Ie Applies its filters to the IQueryable object that acts on it. The filter Object is composed of 3 Components:

    Property Type Description
    fieldName string The field name we are setting a filter condition to
    value object The value we filtering againest
    op Operator The Operator used for filtring

    The operator object is an Enum Contains these operators

    Operator Description
    Eq Equal
    Lt Less Than
    Gt Greater Than
    In In
    Contains Contains
    GtE Greater Than or Equal
    LtE Less Than or Equal

    For Example If we need users Whos Id’s is less than 5, The Filter object will be:

    filters = new Filter[]
    {
        new Filter(Operator.Lt,"Id",5)
    }
    

    Or:

    filters = new Filter[]
    {
       new Filter(Operator.In,"Id",new long[]{1,2,3,4})
    }
    

    IF we need to get the Users Whos were last seen in a Egypt

            filters = new Filter[]
            {
                new Filter(Operator.In,
                "Location",
                "POLYGON((-335.1708984375 29.382175075145298,-334.9951171875 31.54108987958584,-325.7666015625 31.35363694150098,-325.01953125 29.535229562948473,-326.03027343749994 26.980828590472115,-323.0419921875 21.902277966668635,-334.9951171875 21.902277966668635,-335.1708984375 29.382175075145298))")
            }