Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Commit

Permalink
udpated geojsonhint fix #42 added geojsonhint license file into js fo…
Browse files Browse the repository at this point in the history
…lder

started new helper function for checking feature type, not finished yet, for next milestone
  • Loading branch information
sckott committed Mar 4, 2016
1 parent 6129c70 commit 6914fde
Show file tree
Hide file tree
Showing 5 changed files with 565 additions and 415 deletions.
2 changes: 1 addition & 1 deletion R/centroid.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#' ]]
#' }
#' }'
#' lawn_centroid(poly)
#' lawn_centroid(features = poly)
lawn_centroid <- function(features, lint = FALSE) {
fts <- convert(features)
lawnlint(fts, lint)
Expand Down
43 changes: 42 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,48 @@ lawnlint <- function(x, lint = FALSE) {
}

# helper fxn

#' check for correct feature type
#'
#' @noRd
#' @examples
#' x <- '{
#' "type": "Feature",
#' "properties": {
#' "fill": "#0f0"
#' },
#' "geometry": {
#' "type": "Polygon",
#' "coordinates": [[
#' [-46.738586, -23.596711],
#' [-46.738586, -23.458207],
#' [-46.560058, -23.458207],
#' [-46.560058, -23.596711],
#' [-46.738586, -23.596711]
#' ]]
#' }
#' }'
#' is_type(x, type = "Point")
#'
#' is_type(lawn_data$points_average, type = "")
is_type <- function(x, type) {
ht$eval(sprintf("var keys = Object.keys(%s);", jsonlite::minify(x)))
keys <- ht$get('keys')
if ("geometry" %in% keys) {
ht$eval(sprintf("var val = %s.geometry.type;", jsonlite::minify(x)))
xtype <- ht$get('val')
} else if ("features" %in% keys) {
ht$eval(sprintf("var val = %s.type;", jsonlite::minify(x)))
top <- ht$get('val')
ht$eval(sprintf("var vals = %s.features.map(function(x) {return x.geometry.type});", jsonlite::minify(x)))
lower <- ht$get('vals')
xtype <- list(top = top, lower = lower)
}

if (xtype != type) stop(sprintf("input should be of type '%s'", type), call. = FALSE)
}

## use geojsonhint to lint geojson input
lintit <- function(z) {
ht$eval(sprintf("var out = geojsonhint.hint('%s');", jsonlite::minify(z)))
tmp_ <- ht$get("out")
Expand All @@ -35,7 +77,6 @@ lintit <- function(z) {
return(TRUE)
} else {
stop(tmp, call. = FALSE)
# stop("Line ", tmp$line, " - ", tmp$message, call. = FALSE)
}
}

Expand Down
28 changes: 28 additions & 0 deletions inst/js/LICENSE-geojsonhint
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright (c) 2014, Tom MacWright


All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of geojsonhint nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit 6914fde

Please sign in to comment.