Permalink
Browse files

breaking out Terraformer-WKT-Parser into its own module

  • Loading branch information...
0 parents commit 8153dbbca131426f56f832704501758a58ced609 @JerrySievert JerrySievert committed Aug 7, 2013
@@ -0,0 +1 @@
+node_modules
@@ -0,0 +1,2 @@
+# Primary Authors / Esri
+Jerry Sievert <code@legitimatesounding.com> (http://legitimatesounding.com)
@@ -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' ]);
+};
@@ -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 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)
@@ -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"
+ }
+ }
+ }]
+}
@@ -0,0 +1,7 @@
+{
+ "type": "LineString",
+ "coordinates": [
+ [100.0, 0.0],
+ [101.0, 1.0]
+ ]
+}
@@ -0,0 +1 @@
+LINESTRING (30 10, 10 30, 40 40)
@@ -0,0 +1,13 @@
+{
+ "type": "MultiLineString",
+ "coordinates": [
+ [
+ [100.0, 0.0],
+ [101.0, 1.0]
+ ],
+ [
+ [102.0, 2.0],
+ [103.0, 3.0]
+ ]
+ ]
+}
@@ -0,0 +1,2 @@
+MULTILINESTRING ((10 10, 20 20, 10 40),
+(40 40, 30 30, 40 20, 30 10))
@@ -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]
+ ]
+ ]
+ ]
+}
@@ -0,0 +1,2 @@
+MULTIPOLYGON (((30 20, 10 40, 45 40, 30 20)),
+((15 5, 40 10, 10 20, 5 10, 15 5)))
@@ -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)))
@@ -0,0 +1,7 @@
+{
+ "type": "MultiPoint",
+ "coordinates": [
+ [100.0, 0.0],
+ [101.0, 1.0]
+ ]
+}
@@ -0,0 +1 @@
+MULTIPOINT ((10 40), (40 30), (20 20), (30 10))
@@ -0,0 +1 @@
+MULTIPOINT (10 40, 40 30, 20 20, 30 10)
@@ -0,0 +1,4 @@
+{
+ "type": "Point",
+ "coordinates": [100.0, 0.0]
+}
@@ -0,0 +1 @@
+POINT (30 10)
@@ -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]
+ ]
+ ]
+}
@@ -0,0 +1 @@
+POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))
@@ -0,0 +1 @@
+POLYGON((-122.358 47.653,-122.348 47.649,-122.348 47.658,-122.358 47.658,-122.358 47.653))
@@ -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]
+ ]
+ ]
+}
@@ -0,0 +1,2 @@
+POLYGON ((35 10, 10 20, 15 40, 45 45, 35 10),
+(20 30, 35 35, 30 20, 20 30))
@@ -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"
+ }
+}
Oops, something went wrong.

0 comments on commit 8153dbb

Please sign in to comment.