Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
breaking out Terraformer-WKT-Parser into its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
JerrySievert committed Aug 7, 2013
0 parents commit 8153dbb
Show file tree
Hide file tree
Showing 31 changed files with 2,170 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
2 changes: 2 additions & 0 deletions AUTHORS
@@ -0,0 +1,2 @@
# Primary Authors / Esri
Jerry Sievert <code@legitimatesounding.com> (http://legitimatesounding.com)
63 changes: 63 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,63 @@
var fs = require('fs');
var jison = require('jison');

module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

meta: {
version: '0.0.1',
banner: '/*! Terraformer JS - <%= meta.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
'* https://github.com/esri/terraformer-wkt-parser\n' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> Esri, Inc.\n' +
'* Licensed MIT */'
},

uglify: {
options: {
report: 'gzip'
},
wkt: {
src: ["terraformer-wkt-parser.js"],
dest: 'terraformer-wkt-parser.min.js'
}
},

vows: {
all: {
options: {
reporter: "spec",
verbose: true,
silent: false,
colors: true
},
src: [ "test/*.js" ]
}
}
});

grunt.registerTask('wkt-parser', 'Building WKT Parser', function() {
var grammar = fs.readFileSync('./src/wkt.yy', 'utf8');

var wrapper = fs.readFileSync('./src/module-source.js', 'utf8');

var Parser = jison.Parser;
var parser = new Parser(grammar);

// generate source, ready to be written to disk
var parserSource = parser.generate({ moduleType: "js" });

wrapper = wrapper.replace('"SOURCE";', parserSource);

fs.writeFileSync("./terraformer-wkt-parser.js", wrapper, "utf8");

grunt.log.write('Files created.\n');
});

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks("grunt-vows");


grunt.registerTask('test', [ 'wkt-parser', 'vows' ]);
grunt.registerTask('default', [ 'wkt-parser', 'vows', 'uglify' ]);
};
7 changes: 7 additions & 0 deletions LICENSE
@@ -0,0 +1,7 @@
Copyright (c) 2013 Esri, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
101 changes: 101 additions & 0 deletions README.md
@@ -0,0 +1,101 @@
# Terraformer Well-Known Text Parser

This package is part of the [Terraformer](https://github.com/Esri/Terraformer) project.

A bare-bones WKT parser. Given a WKT primitive, it parses and returns a `Terraformer Primitive`.

## Installing

### Node.js

$ npm install terraformer-wkt-parser

### Browser

In the browser, Terraformer is required to be used as well.

$ bower install terraformer-wkt-parser

## Usage

### Node.js

var wkt = require('terraformer-wkt-parser');

// parse a WKT file, convert it into a primitive
var primitive = wkt.parse('LINESTRING (30 10, 10 30, 40 40)');

// take a primitive and convert it into a WKT representation
var polygon = wkt.convert(
{
"type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
[ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
]
}
);

### Browser

The Terraformer-WKT-Parser can be used in the browser with some simple includes.

<!-- Load the main Terraformer library -->
<script src="terraformer.min.js" type="text/javascript"></script>

<!-- Load the WKT Parser -->
<script src="terraformer-wkt-parser.min.js" type="text/javascript"></script>

<!-- Use it! -->
<script>
var primitive = Terraformer.WKT.parse('LINESTRING (30 10, 10 30, 40 40)');
</script>

### AMD (Require.js and Dojo)

Terraformer also works with AMD loaders like [RequireJS](http://requirejs.org/) and [Dojo](http://dojotoolkit.org/).

##### RequireJS

First you should register the Terraformer modules with RequireJS

requirejs.config({
//In order for proper loading of depenencies in Terraformer modules set the path up in requirejs.config
paths: {
terraformer: "/the/path/to/terraformer"
}
});

Then you can load Terraformer modules in your `require` statements.

requirejs([
"terraformer/terraformer",
"terraformer/terraformer-wkt-parser"
], function (Terraformer, TerraformerWKT) {
// Do stuff with terraformer core, wkt parser
};

##### Dojo

Dojo includes a built in AMD loader. To use Terraformer with Dojo setup the path to Terraformer in your `dojoConfig`.

dojoConfig= {
async: true,
packages: [{
name: "terraformer",
location: "/the/path/to/terraformer"
}]
}

You can then include Terraformer in your Dojo code

require([
"terraformer/terraformer",
"terraformer/terraformer-wkt-parser"
], function (Terraformer, TerraformerWKT) {
// Do stuff with terraformer core, and wkt parser
});


[](Esri Tags: Terraformer GeoJSON WKT Well-Known-Text)
[](Esri Language: JavaScript)
48 changes: 48 additions & 0 deletions examples/feature_collection.json
@@ -0,0 +1,48 @@
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.0, 0.5]
},
"properties": {
"prop0": "value0"
}
}, {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[102.0, 0.0],
[103.0, 1.0],
[104.0, 0.0],
[105.0, 1.0]
]
},
"properties": {
"prop0": "value0",
"prop1": 0.0
}
}, {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
},
"properties": {
"prop0": "value0",
"prop1": {
"this": "that"
}
}
}]
}
7 changes: 7 additions & 0 deletions examples/linestring.json
@@ -0,0 +1,7 @@
{
"type": "LineString",
"coordinates": [
[100.0, 0.0],
[101.0, 1.0]
]
}
1 change: 1 addition & 0 deletions examples/linestring.wkt
@@ -0,0 +1 @@
LINESTRING (30 10, 10 30, 40 40)
13 changes: 13 additions & 0 deletions examples/multi_linestring.json
@@ -0,0 +1,13 @@
{
"type": "MultiLineString",
"coordinates": [
[
[100.0, 0.0],
[101.0, 1.0]
],
[
[102.0, 2.0],
[103.0, 3.0]
]
]
}
2 changes: 2 additions & 0 deletions examples/multi_linestring.wkt
@@ -0,0 +1,2 @@
MULTILINESTRING ((10 10, 20 20, 10 40),
(40 40, 30 30, 40 20, 30 10))
30 changes: 30 additions & 0 deletions examples/multi_polygon.json
@@ -0,0 +1,30 @@
{
"type": "MultiPolygon",
"coordinates": [
[
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0]
]
],
[
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
],
[
[100.2, 0.2],
[100.8, 0.2],
[100.8, 0.8],
[100.2, 0.8],
[100.2, 0.2]
]
]
]
}
2 changes: 2 additions & 0 deletions examples/multi_polygon.wkt
@@ -0,0 +1,2 @@
MULTIPOLYGON (((30 20, 10 40, 45 40, 30 20)),
((15 5, 40 10, 10 20, 5 10, 15 5)))
3 changes: 3 additions & 0 deletions examples/multi_polygon_with_hole.wkt
@@ -0,0 +1,3 @@
MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),
((20 35, 45 20, 30 5, 10 10, 10 30, 20 35),
(30 20, 20 25, 20 15, 30 20)))
7 changes: 7 additions & 0 deletions examples/multipoint.json
@@ -0,0 +1,7 @@
{
"type": "MultiPoint",
"coordinates": [
[100.0, 0.0],
[101.0, 1.0]
]
}
1 change: 1 addition & 0 deletions examples/multipoint.wkt
@@ -0,0 +1 @@
MULTIPOINT ((10 40), (40 30), (20 20), (30 10))
1 change: 1 addition & 0 deletions examples/multipoint_alternate.wkt
@@ -0,0 +1 @@
MULTIPOINT (10 40, 40 30, 20 20, 30 10)
4 changes: 4 additions & 0 deletions examples/point.json
@@ -0,0 +1,4 @@
{
"type": "Point",
"coordinates": [100.0, 0.0]
}
1 change: 1 addition & 0 deletions examples/point.wkt
@@ -0,0 +1 @@
POINT (30 10)
12 changes: 12 additions & 0 deletions examples/polygon.json
@@ -0,0 +1,12 @@
{
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
}
1 change: 1 addition & 0 deletions examples/polygon.wkt
@@ -0,0 +1 @@
POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))
1 change: 1 addition & 0 deletions examples/polygon_with_dots.wkt
@@ -0,0 +1 @@
POLYGON((-122.358 47.653,-122.348 47.649,-122.348 47.658,-122.358 47.658,-122.358 47.653))
19 changes: 19 additions & 0 deletions examples/polygon_with_hole.json
@@ -0,0 +1,19 @@
{
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
],
[
[100.2, 0.2],
[100.8, 0.2],
[100.8, 0.8],
[100.2, 0.8],
[100.2, 0.2]
]
]
}
2 changes: 2 additions & 0 deletions examples/polygon_with_hole.wkt
@@ -0,0 +1,2 @@
POLYGON ((35 10, 10 20, 15 40, 45 45, 35 10),
(20 30, 35 35, 30 20, 20 30))
33 changes: 33 additions & 0 deletions package.json
@@ -0,0 +1,33 @@
{
"name": "terraformer-wkt-parser",
"version": "0.1.9",
"description": "Well-Known Text parser",
"main": "terraformer-wkt-parser.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "grunt test"
},
"repository": {
"type": "git",
"url": "git@github.com:Esri/terraformer-wkt-parser.git"
},
"keywords": [
"WKT",
"GIS",
"Geography"
],
"author": "Jerry Sievert <code@legitimatesounding.com> (http://legitimatesounding.com)",
"license": "MIT",
"dependencies": {
"terraformer": "~0.1.7"
},
"devDependencies": {
"vows": "~0.7.0",
"grunt": "0.4.x",
"jison": "~0.3.12",
"grunt-contrib-uglify": "~0.2.2",
"grunt-vows": "~0.4.0"
}
}

0 comments on commit 8153dbb

Please sign in to comment.