Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle null geometry #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions model.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,50 @@ function translate (input) {

return {
type: 'FeatureCollection',
features: [ formatFeature(input) ],
features: [formatFeature(input)],
metadata: {
geometryType: geometry
}
}
} else {
const features = [];
input.features.map((feature) => {
features.push(formatFeature(feature))
})


// Or it's a feature collection
return input;
return {
type: 'FeatureCollection',
features: features
}
}
}

function formatFeature (geometry) {

const feature = {
type: 'Feature',
properties: {
"type": geometry.type
},
geometry: geometry
function formatFeature (input) {
let feature = {};
if(input.type == "Feature") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=== instead of ==

feature = input;
if(feature.geometry === undefined || feature.geometry === null) {
feature.geometry = {
type: "Point",
coordinates: [ 0, 0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on setting this as coordinates: [ null, null]. We've made some adjustments to winnow to handle null coordinates. While not valid GeoJSON, this still loads in AGOL and ArcGIS Pro. No point is rendered for the feature with null coordinates, but it does appear in the attribute table.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still kind of a hack, ideally we'd be able to handle undefined here

Copy link
Member

@rgwozdz rgwozdz May 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took some sample data and removed geometry so as to simulate feature.geometry: undefined. Passed through FeatureServer and winnow without any observable problems. However, the result in Pro was undesirable - even if only one feature had geometry undefined, the whole dataset was loaded as a table rather than a layer. And attribute table wouldn't load. I found the best all around behavior in Pro with coordinates: [ null, null].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok...oh Pro, why you so fickle?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think we should make the data conform inside Winnow or throw a warning somewhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could both, that way providers wouldn't have to do this kind of transformation, but then there would be a paper trail should questions arise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works for me

}
}
} else {
feature = {
type: 'Feature',
properties: {
type: 'no location'
}
}
if(input !== undefined && input !== null) {
feature.properties.type = input.type;
feature.geometry = geometry;
}
}


return feature
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"test": "standard && tape test/*.js | tap-spec"
},
"dependencies": {
"aws-serverless-express": "^3.0.2",
"config": "^1.25.1",
"koop": "^3.4.0",
"request": "^2.79.0"
},
"author": "Daniel Fenton",
"license": "Apache-2.0",
"devDependencies": {
"aws-serverless-express": "^3.0.2",
"nock": "^9.0.2",
"standard": "^10.0.0",
"tap-spec": "^4.1.1",
Expand Down