GithubHelp home page GithubHelp logo

tetriscode / cljts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from diogok/cljts

0.0 0.0 0.0 91 KB

A clojure wrapper of JTS, implements Simple Feature Specification of OGC

Home Page: http://sunng87.github.com/cljts/

Clojure 100.00%

cljts's Introduction

Build Status Dependency Status

cljts

A clojure library wraps JTS, implements Simple Feature Specification(OGC). cljts provides a set of clojure API to manipulate geometry objects, includes:

  • Create SFS qualified geometry objects: Point, LineString, Polygon and more
  • Spatial relationship (DE9-IM)
  • Spatial analysis
  • IO, Serialization (WKB & WKT)

Usage

Leiningen

[org.clojars.diogok/cljts "0.5.0"]

API

Check API documents.

Example

Geometry

Creating common JTS geometry objects:

(use 'cljts.geom)

;; Point
(point (c 20 30))

;; LineString
(line-string [(c 20 30) (c 20 40)])

;; LinearRing
(linear-ring [(c 20 40) (c 20 46) (c 34 56) (c 20 40)])

;; Polygon without holes
(polygon (linear-ring [(c 20 40) (c 20 46) (c 34 56) (c 20 40)]) nil)

;; Polygon with a hole
(polygon 
  (linear-ring [(c 20 30) (c 30 40) (c 40 55) (c 20 30)])
  [(linear-ring [(c 22 28) (c 28 42) (c 38 50) (c 22 28)])])

Test spatial relationship between geometry objects. (Based on DE9-IM)

(use 'cljts.relation)

(touches? l1 l2)
(within? p p2)
;; ...
;; get DE9-IM string
(relation p1 p2)

Test spatial relationship using prepared geometries. Please see this blog post for details on prepared geometries. Please note that prepared geometry should be the first argument for a relationship function.

(use 'cljts.prep)
(def prepared-polygon (prepare (polygon (linear-ring [(c 20 40) (c 20 46) (c 34 56) (c 20 40)]) nil)))
(contains? prepared-polygon point)

Basic spatial analysis functions:

(use 'cljts.analysis)
(buffer p 20)
;; ...

Serialize geometry objects to Well-Known Text and Well-Known Binary format:

(use 'cljts.io)
(write-wkt g)
(write-wkb-bytes data)
(read-wkt some-reader)

Reprojection:

(use 'cljts.transform)
(def projected
 (reproject (point (c 10.10 20.20)) "EPSG:4326" "EPSG:23032"))

Affine transformations:

(use 'cljts.transform)
(def rotate-clockwise
           (transformation [(c 0 0) (c 1 0) (c 0 1)
                            (c 0 0) (c 0 1) (c -1 0)]))
(def rotate-counterclockwise
           (inverse-transformation [(c 0 0) (c 1 0) (c 0 1)
                                    (c 0 0) (c 0 1) (c -1 0)]))
(rotate-clockwise (line-string [(c 0 0) (c 2 2)]))
;;; user> #<LineString LINESTRING (0 0, -2 2)>
(rotate-counterclockwise (line-string [(c 0 0) (c 2 2)]))
;;; user> #<LineString LINESTRING (0 0, 2 -2)>

Contributors

License

Copyright (C) 2012 Sun Ning

Distributed under the Eclipse Public License, the same as Clojure.

cljts's People

Contributors

sunng87 avatar bapehbe avatar diogok avatar bartoszradaczynski-tomtom avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.