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

Add support for nested attribute properties #55

Open
hparkertt opened this issue Jul 13, 2020 · 6 comments
Open

Add support for nested attribute properties #55

hparkertt opened this issue Jul 13, 2020 · 6 comments

Comments

@hparkertt
Copy link
Contributor

The goal for this enhancement is to provide the ability to 'flatten' properties from the input into primitive attributes. For example:

data = {
  lat: 12.34,
  lng: 56.78,
  info: {
    name: 'Johnny Goode',
    age: 12
  }
}

GeoJSON.parse(data, {Point: ['lat', 'lng'], include: ['name']});

There is currently no way to get the 'name' property as an attribute of the resulting GeoJSON object.

In an attempt to avoid breaking existing logic, I think this may be a good solution:

function getPropFunction(params) {
  ...
  else if (params.extract) {
    func = function(properties) {
      ...
    }
  } else if (params.include) {
  ...
}
@caseycesari
Copy link
Owner

Thanks for opening this.

Specifying extract would mean to dig into a nested property and elevate it on the output? In the case of duplicate key names, it may make sense to specify the full path, for example info.name.

@hparkertt
Copy link
Contributor Author

Hey Casey,

Yes, the intent is to elevate it on the output. I think the risk of duplicate key names should be resolved a different way. Although we could use the full path name as the new property name, that would make the resulting properties object very challenging to use.

To resolve that issue, we could either say 'tough luck, you need to make sure your property names are unique', we could change the extract option from an array to a dictionary, or we could allow both options. For example:

inputOptions1 = {
  Point: [ 'lat', 'lng' ],
  extract: [ 'info.name', 'info.age' ]
};

inputOptions2 = {
  Point: [ 'lat', 'lng' ],
  mapProperties: {
    'info.name': 'name',
    'info.age': 'age'
  }
};

@caseycesari
Copy link
Owner

That makes sense. The mapProperties option seems best since it's most flexible, and would allow users to handle duplicate keys in a nice way.

@longbuibao
Copy link

so...how to get nested attribute properties to the properties field in geoJSON sir? I cant find instruction in document 👯‍♂️
For example, if I want to add time field from announcedTime to properties in geoJSON, how can I do that sir?

{ _id: 60e63c323959b25c2609da46,
    name: 'BN0004',
    yearOfBirth: 2000,
    currentLocation:
     { _id: 60e63c323959b25c2609da40,
       lat: 10.77315,
       long: 106.65753,
       detailAddress:
        '354/1/3 Đường Lý Thường Kiệt, Phường 14, Quận 10, Thành Phố Hồ Chí Minh',
       district: 'Quận 10',
       __v: 0 },
    announcedTime:
     { _id: 60e63c323959b25c2609da42,
       time: 2021-02-28T23:43:00.000Z,
       __v: 0 },
    hasDisease: 60e546662a788a8fd024e202,
    __v: 0 },

Thank you!

@hparkertt
Copy link
Contributor Author

@longbuibao Hi there! This functionality has not been implemented yet. I found a different solution to this problem in my code and did not circle back to this enhancement. If you want to try and implement this, I'm sure @caseycesari would welcome a PR!

@longbuibao
Copy link

I will try sir! :') I'm new to programming so I think I dont have enough experience to read code :')

btw my solution is pull out the property..thank you for great npm module!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants