Changeset 34455 in project


Ignore:
Timestamp:
08/30/17 19:04:36 (3 months ago)
Author:
kon
Message:

bump ver, better make-geopolygon/geopoint-in-closed-polygon?

Location:
release/4/geo-utils/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • release/4/geo-utils/trunk/geo-utils.setup

    r34418 r34455  
    55(verify-extension-name "geo-utils")
    66
    7 (setup-shared+static-extension-module 'geopoint (extension-version "0.1.1")
     7(setup-shared+static-extension-module 'geopoint (extension-version "0.2.0")
    88  #:inline? #t
    99  #:types? #t
    1010  #:compile-options `(-scrutinize -optimize-level 3 -debug-level 1 -no-procedure-checks))
    1111
    12 (setup-shared+static-extension-module 'geobox (extension-version "0.1.1")
     12(setup-shared+static-extension-module 'geobox (extension-version "0.2.0")
    1313  #:inline? #t
    1414  #:types? #t
    1515  #:compile-options `(-scrutinize -optimize-level 3 -debug-level 1 -no-procedure-checks))
    1616
    17 (setup-shared+static-extension-module 'geopolygon (extension-version "0.1.1")
     17(setup-shared+static-extension-module 'geopolygon (extension-version "0.2.0")
    1818  #:inline? #t
    1919  #:types? #t
    2020  #:compile-options `(-scrutinize -optimize-level 3 -debug-level 1 -no-procedure-checks))
    2121
    22 (setup-shared+static-extension-module 'geopoint-utils (extension-version "0.1.1")
     22(setup-shared+static-extension-module 'geopoint-utils (extension-version "0.2.0")
    2323  #:inline? #t
    2424  #:types? #t
    2525  #:compile-options `(-scrutinize -optimize-level 3 -debug-level 1 -no-procedure-checks))
    2626
    27 (setup-shared+static-extension-module (extension-name) (extension-version "0.1.1")
     27(setup-shared+static-extension-module (extension-name) (extension-version "0.2.0")
    2828  #:inline? #t
    2929  #:types? #t
    3030  #:compile-options `(-scrutinize -optimize-level 3 -debug-level 1 -no-procedure-checks))
    3131
    32 (setup-shared+static-extension-module 'geo-dms (extension-version "0.1.1")
     32(setup-shared+static-extension-module 'geo-dms (extension-version "0.2.0")
    3333  #:inline? #t
    3434  #:types? #t
  • release/4/geo-utils/trunk/geopoint-utils.scm

    r34129 r34455  
    11;;;; geopoint-utils.scm
    22;;;; Kon Lovett, May '17
     3;;;; Kon Lovett, Aug '17
    34
    45(module geopoint-utils
    56
    67(;export
    7   geopoint-in-closed-polygon? )
     8  geopoint-in-closed-polygon?
     9  intersects?-pnp intersects?-pip)
    810
    911(import scheme)
     
    2123;;
    2224
    23 ;; Is the point inside a closed polygon?
    24 ;; Ray casting algorithm (http://en.wikipedia.org/wiki/Point_in_polygon)
    25 ;; (http://alienryderflex.com/polygon/)
    26 (define (geopoint-in-closed-polygon? gp gpoly)
    27   ;
    28   (define (intersects? pi pj lat lon)
    29     (and
    30       (or
    31         (and (< (geopoint-latitude pi) lat) (<= lat (geopoint-latitude pj) ) )
    32         (and (< (geopoint-latitude pj) lat) (<= lat (geopoint-latitude pi)) ) )
    33       (or
    34         (<= (geopoint-longitude pi) lon)
    35         (<= (geopoint-longitude pj) lon) )
    36       (>=
    37         lon
    38         (+
    39           (geopoint-longitude pi)
    40           (*
    41             (/
    42               (- lat (geopoint-latitude pi))
    43               (- (geopoint-latitude pj) (geopoint-latitude pi)))
    44             (- (geopoint-longitude pj) (geopoint-longitude pi))))) ) )
    45   ;
    46         ; test for intersection of ray with every segment of the polygon
    47         ; start with the "closing" segment, then every [i-i],[i] segment
    48   ;
    49         (let ((gpoly (if (list? gpoly) (list->vector gpoly) gpoly)))
    50           (check-geopolygon 'geopoint-in-closed-polygon? gpoly)
     25;https://github.com/substack/point-in-polygon
     26(define (geopoint-in-closed-polygon? gp gpoly #!optional (intersects? intersects?-pnp))
     27        ;test for intersection of ray with every segment of the polygon
     28        ;start with the "closing" segment, then every [i-i],[i] segment
     29        (let ((gpoly (make-geopolygon gpoly)))
    5130          (check-geopoint 'geopoint-in-closed-polygon? gp)
    52     (let ((len (vector-length gpoly) )
     31    (let ((len (vector-length (check-geopolygon 'geopoint-in-closed-polygon? gpoly)) )
    5332          (lat (geopoint-latitude gp) )
    5433          (lon (geopoint-longitude gp) ) )
    55       ; assumes an open-poly is "closed" so a closed-poly must be treated as "open"
     34      ;assumes an open-poly is "closed" so a closed-poly must be treated as "open"
    5635      (let ((len (if (geopolygon-closed? gpoly) (fx- len 1) len)))
    5736        (let loop ((i 0) (j (fx- len 1)) (poly? #f))
    5837          (if (fx= i len)
    5938            poly?
    60             (let ((pi (vector-ref gpoly i))
    61                   (pj (vector-ref gpoly j)) )
    62               (loop (fx+ i 1) i (if (intersects? pi pj lat lon) (not poly?) poly?)) ) ) ) ) ) ) )
     39            (loop
     40              (fx+ i 1)
     41              i
     42              (if (intersects? (vector-ref gpoly i) (vector-ref gpoly j) lat lon)
     43                (not poly?)
     44                poly?)) ) ) ) ) ) )
     45
     46;;
     47
     48;; Ray-casting algorithm (http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html)
     49;; (https://github.com/substack/point-in-polygon)
     50(define (intersects?-pnp pi pj lat lon)
     51  (let ((lati (geopoint-latitude pi))
     52        (loni (geopoint-longitude pi))
     53        (latj (geopoint-latitude pj))
     54        (lonj (geopoint-longitude pj)) )
     55    (and
     56      (not (eq? (> loni lon) (> lonj lon)))
     57      (< lat (+ (/ (* (- latj lati) (- lon loni)) (- lonj loni)) lati))) ) )
     58
     59;; Ray-casting algorithm (http://en.wikipedia.org/wiki/Point_in_polygon)
     60;; (http://alienryderflex.com/polygon/)
     61(define (intersects?-pip pi pj lat lon)
     62  (let ((lati (geopoint-latitude pi))
     63        (loni (geopoint-longitude pi))
     64        (latj (geopoint-latitude pj))
     65        (lonj (geopoint-longitude pj)) )
     66    (and
     67      (or (and (< lati lat) (<= lat latj ) ) (and (< latj lat) (<= lat lati)))
     68      (or (<= loni lon) (<= lonj lon))
     69      (< (+ loni (* (/ (- lat lati) (- latj lati)) (- lonj loni))) lon)) ) )
    6370
    6471) ;module geopoint-utils
  • release/4/geo-utils/trunk/geopolygon.scm

    r34129 r34455  
    11;;;; geopolygon.scm
    22;;;; Kon Lovett, May '17
     3;;;; Kon Lovett, Aug '17
    34
    45(module geopolygon
     
    2324;;;
    2425
    25 (define (make-geopolygon gps)
    26   (if (vector? gps)
    27     gps
    28     (list->vector gps) ) )
     26;not strict
     27(define make-geopolygon
     28  (case-lambda
     29    ((gps)
     30      (cond
     31        ((vector? gps)  gps )
     32        ((list? gps)    (list->vector gps) )
     33        (else
     34          (warning 'make-geopolygon "unrecognized as geopolygon" gps)
     35          gps ) ) )
     36    (rest
     37      (make-geopolygon rest) ) ) )
    2938
    3039(define (geopolygon? obj)
  • release/4/geo-utils/trunk/tests/run.scm

    r34129 r34455  
    7979)
    8080
     81(let ((geoPoly1
     82        (make-geopolygon
     83          (make-geopoint 37.8731 -122.3201)
     84          (make-geopoint 37.8827 -122.2705)
     85          (make-geopoint 37.8817 -122.2535)
     86          (make-geopoint 37.8617 -122.2413)
     87          (make-geopoint 37.8429 -122.2431)
     88          (make-geopoint 37.8350 -122.3175))) )
     89
     90  (test-assert (geopoint-in-closed-polygon? (make-geopoint 37.8429 -122.2431) geoPoly1))
     91  (test-assert (not (geopoint-in-closed-polygon? (make-geopoint -37.8429 122.2431) geoPoly1)))
     92)
     93
    8194(test-exit)
    8295
Note: See TracChangeset for help on using the changeset viewer.