Skip to content

Commit

Permalink
fix exception in sql w/ null feature (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Fenton committed Nov 21, 2017
1 parent 34050b2 commit dd805fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
### Fixed
* Exception when feature is null

## [1.12.5] - 10-27-2017
### Fixed
* Converting polygons from geojson to esri json
Expand Down
8 changes: 4 additions & 4 deletions src/sql.js
Expand Up @@ -10,21 +10,21 @@ const reducePrecision = require('./geometry/reduce-precision')

sql.MAXSQLCACHESIZE = 0

sql.fn.ST_Within = function (feature, filterGeom) {
sql.fn.ST_Within = function (feature = {}, filterGeom = {}) {
if (!(feature && feature.type && feature.coordinates && feature.coordinates.length > 0)) return false
const filter = new Terraformer.Primitive(filterGeom)
const TfFeature = new Terraformer.Primitive(feature)
return filter.within(TfFeature)
}

sql.fn.ST_Contains = function (feature, filterGeom) {
sql.fn.ST_Contains = function (feature = {}, filterGeom = {}) {
if (!(feature && feature.type && feature.coordinates && feature.coordinates.length > 0)) return false
const filter = new Terraformer.Primitive(filterGeom)
const TfFeature = new Terraformer.Primitive(feature)
return filter.contains(TfFeature)
}

sql.fn.ST_Intersects = function (feature, filterGeom) {
sql.fn.ST_Intersects = function (feature = {}, filterGeom = {}) {
if (!(feature.type || feature.coordinates)) feature = convertFromEsri(feature) // TODO: remove ? temporary esri geometry conversion
if (!(feature && feature.type && feature.coordinates && feature.coordinates.length > 0)) return false
if (feature.type === 'Point') return sql.fn.ST_Contains(feature, filterGeom)
Expand All @@ -33,7 +33,7 @@ sql.fn.ST_Intersects = function (feature, filterGeom) {
return filter.intersects(TfFeature)
}

sql.fn.geohash = function (geometry, precision) {
sql.fn.geohash = function (geometry = {}, precision) {
if (!geometry || !geometry.type || !geometry.coordinates) return
precision = precision || 8
if (geometry.type !== 'Point') geometry = centroid(geometry).geometry
Expand Down

0 comments on commit dd805fb

Please sign in to comment.