Re: [INTERFACES] postgres for spatial data

Поиск
Список
Период
Сортировка
От Stephen Davies
Тема Re: [INTERFACES] postgres for spatial data
Дата
Msg-id 199807120453.OAA19842@mustang.sdc.com.au
обсуждение исходный текст
Ответ на Re: [INTERFACES] postgres for spatial data  ("Thomas G. Lockhart" <lockhart@alumni.caltech.edu>)
Список pgsql-interfaces
> >         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



В списке pgsql-interfaces по дате отправления:

Предыдущее
От: "Thomas G. Lockhart"
Дата:
Сообщение: Re: [INTERFACES] postgres for spatial data
Следующее
От: Goran Thyni
Дата:
Сообщение: db/dbm-emulation