Skip to content

Commit

Permalink
Merge pull request #7 from telefonicasc/improve-strtolocation
Browse files Browse the repository at this point in the history
FIX strToLocation description and tests
  • Loading branch information
arcosa authored Mar 8, 2024
2 parents 4974cdb + bccbd0a commit 05f2c9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,7 @@ Result:
# Miscelaneous transformations

- `typeOf`: returns type representation of the data (e.g. `str`, `int`, `float`, etc.)
- `strToLocation`: given a latitude and a longitude, it returns an array to build a location. Example: `"value1, value2"|strToLocation`. Example: `"value1, value2"|strToLocation` returns `[value1, value2]`, so we can use this:

```json
{
"init": null,
"type": "geo:json",
"exp": "{coordinates:(point|strToLocation),type: \"Point\"}"
}
```
- `strToLocation`: given a string with a comma separated list of decimal numbers, returns an array of such numbers. Example: `"value1, value2"|strToLocation`. Example: `"value1, value2"|strToLocation` returns `[value1, value2]`. It's name (maybe not very good :) is due to it can be useful to generate a [GeoJSON](https://geojson.org/) representing a point which coordinates are provided in a string, eg: `{coordinates:(point|strToLocation),type: "Point"}`

## Packaging

Expand Down
10 changes: 10 additions & 0 deletions tests/test_transforms_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ def test_typeOf(self):
def test_strToLocation(self):
result = self.jexl.evaluate('"-10.13,24.54"|strToLocation', {})
self.assertEqual(result, [-10.13, 24.54])

def test_strToLocation_five_elements(self):
result = self.jexl.evaluate('"-10.13,24.54,21,42,23"|strToLocation', {})
self.assertEqual(result, [-10.13, 24.54, 21, 42, 23])

def test_strToLocation_location(self):
context = {'point': '-42.13,23.11'}
result = self.jexl.evaluate('{coordinates:(point|strToLocation), type: "Point"}', context)
self.assertEqual(result, {'coordinates': [-42.13, 23.11], 'type': 'Point'})

0 comments on commit 05f2c9a

Please sign in to comment.