
GeoTypes 

A package of classes for working with basic 2d geometric types.

These classes were designed for use with the geometric functions
supported by Postgresql (http://www.postgresql.com) although they
do not need Postgresql to be present for them to be used.

The types implemented are those listed in the Postgresql documentation
at http://www.postgresql.org/docs/7.3/static/datatype-geometric.html with
the exception of 'line' which, as the documentation is says, is 'not fully
implemented yet'.

The package exports the following classes:

    (class Point)
    (class LineSeg)
    (class Path)
    (class Polygon)
    (class Circle)
    (class box)

In addition the following factory methods are provided to make construction
of these classes easier:

    (func pointFromValues)
    (func pointFromSequence)
    (func lineSegFromPoints)
    (func lineSegFromSequence)
    (func pathFromPoints)
    (func pathFromSequence)
    (func boxFromPoints)
    (func boxFromSequence)
    (func circleFromCentreAndRadius)
    (func circelFromSequence)
    (func polygonFromPoints)
    (func polygonFromSequence)

One final method is provided to help with linking these classes into the 
psycopg (http://initd.org/software/initd/psycopg) database wrapper:

    (func initialisePsycopgTypes)


Example usage:


    import psycopg
    import GeoTypes

    GeoTypes.initialisePsycopgTypes(psycopg_module=psycopg)

    conn = psycopg.connect('dbname=schema_test user=postgres')
    curs = conn.cursor()

    curs.execute("CREATE TABLE table_name (p1 point, b box)")

    p = GeoTypes.pointFromValues(5.0,7.0)
    b = GeoTypes.boxFromPoints(p,GeoTypes.pointFromValues(1.0,1.0))

    curs.execute("INSERT INTO table_name VALUES (%(p)s,%(b)s)", {'p':p, 'b':b})


    curs.execute("SELECT p1, b FROM table_name WHERE (p1 ~= %(p)s)", {'p':p})

    ret = curs.fetchall()[0]

    new_point = ret[0]
    new_box   = ret[1]

    if new_box == b:
        print "We have the same box!"

