pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephen Davies <scldad@sdc.com.au>
To: Thomas G. Lockhart <lockhart@alumni.caltech.edu>
Cc: dgross@lri.fr, Postgres Interfaces Mailing List <pgsql-interfaces@postgreSQL.org>
Subject: Re: [INTERFACES] postgres for spatial data
Date: Sun, 12 Jul 1998 14:23:21 +0930
Message-ID: <199807120453.OAA19842@mustang.sdc.com.au> (raw)
In-Reply-To: <35A7720C.B254F09@alumni.caltech.edu>

> >         I'm looking for a graphical interface that can display the
> > geometric types like polygon,...
> 
> Don't know about pre-built utilities for graphical display of geometric
> objects. Let us know what you discover.
> 
> >         I'm also looking for SQL extension in order to make
> > spatial queries (for example, a function that tells if a point
> > belongs to the interior of a polygon)
> 
> There are already some operators available; for example, the "@"
> operator is for "on or inside":
> 
> postgres=> select '(0,0)'::point
> postgres->  @ '((0,1),(1,0),(0,-1),(-1,0))'::polygon;
> ?column?
> --------
> t
> (1 row)
> 
> Look in the hardcopy or html doc set which is included in v6.3.x. You
> need to do a "make install" from the doc directory to get them unpacked.
> Good luck...
> 
>                          - Tom

The "point in poly" code in the release package looks rather complicated and 
uses lots of calls. The fastest PinP that I have found is the following (coded 
here in basic but readily translatable to anything else).
(The underlying algorithms are the same - just the coding differs).

Cheers,
Stephen.

Function TestPoly(X As Double, Y As Double) As Boolean
' check if point X,Y is inside a polygon. Return true if ins%<>0
'
' Polygon coordinates are in global arrays PX and PY.
' The number of coordinates is in global nP.
'
Dim X1 As Double, X2 As Double, Y1 As Double, Y2 As Double
Dim ins As Boolean

    ins = False
    j% = nP - 1
    For i% = 0 To nP - 1
        X1 = PX(j%)
        X2 = PX(i%)
        Y1 = PY(j%)
        Y2 = PY(i%)
        If X1 < X And X <= X2 Then
                If (Y - Y1) * (X2 - X1) < (Y2 - Y1) * (X - X1) Then
                    ins = Not ins
                End If
        ElseIf X2 < X And X <= X1 Then
            If (Y - Y2) * (X1 - X2) < (Y1 - Y2) * (X - X2) Then
                ins = Not ins
            End If
        End If
        j% = i%
    Next i%
    TestPoly = ins
End Function


========================================================================
Stephen Davies Consulting	    		                            scldad@sdc.com.au
Adelaide, South Australia.     			                            Voice: 61-8-82728863
Computing & Network solutions.	 	                            Fax: 61-8-82741015





view thread (4+ messages)

Message-ID: <199807120453.OAA19842@mustang.sdc.com.au>
Permalink:  ../199807120453.OAA19842@mustang.sdc.com.au/
Also on:    postgresql.org/message-id/199807120453.OAA19842@mustang.sdc.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: scldad@sdc.com.au, lockhart@alumni.caltech.edu
  Subject: Re: [INTERFACES] postgres for spatial data
  In-Reply-To: <199807120453.OAA19842@mustang.sdc.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox