GeoJSON file has invalid coordinates - geojson

I'm looking at public data provided by my local government, and it appears the coordinates provided in the GeoJSON data don't correspond to real latitude / longitude values. Is there a format that's being used here that I can convert to real coordinates?
"features":[
{
"type":"Feature",
"properties":{
"No":0,
"Location":"Parnell Street",
"No Spaces":"21 P&D (Total)",
"Exact Location":"At Jury's",
"Tariff":"�3.20",
"Hours of Operation":"Mon-Sat 07.00-19.00, Sun 14.00-18.00",
"Clr-Way":"FALSE",
"X_Value":315763.7318,
"Y_Value":234926.3662,
"Zone":"Yellow"
},
"geometry":{
"type":"Point",
"coordinates":[
315763.7318,
234926.366199999989476
]
}
}
]

The coordinates are in the Irish Grid Reference format:
https://en.wikipedia.org/wiki/Irish_grid_reference_system

Related

In RestAssured jsonPathEvaluator not giving correct values for double value

I have a json response as shown below :-
{
"someField": [
{
"abc": "abcdId"
}
],
"someId": "pqrsId",
"oneTier": {
"startThreshold": 25000,
"endThreshold": 74999.99
},
"nextTier": {
"startThreshold": 75000,
"endThreshold": 149999.99
}
}
When I try to print
response.getBody().asString()
I can get the see the value of nextTier.endThreshold as '14999.99'
but when I do
response.getBody().jsonPath().get("nextTier.maxThreshold").toString();
I am seeing the value as 14999.98'.
Not able to figure out why this is happening.
The default config JsonPathConfig defines NumberReturnType = FLOAT_AND_DOUBLE, this may lose the precision when converting between types.
Fortunately, RestAssured has a solution for this kind of issue. You can config NumberReturnType = BIG_DECIMAL then it saves the precision of floating-point number.
JsonPath.config = new JsonPathConfig().numberReturnType(JsonPathConfig.NumberReturnType.BIG_DECIMAL);
BigDecimal endThreshold = JsonPath.with(json).get("nextTier.endThreshold");
System.out.println(endThreshold.doubleValue());
//149999.99

how to check the json response array contains the substring

how to assert the json response array contains a substring in a string value.
I have tried this but assertion is failed response.then().body("response.content.Date", Matchers.everyItem(contains("2019-03") ));
my response body is
{
"response": {
"totalSize": 2,
"content": [
{
"requestId": " 931-f8222e",
"name": "gowtham",
"date": "2019-03-06",
"issue": "i have a cause"
},
{
"requestId": " 931-f8222e",
"name": "tharun",
"date": "2019-03-09",
"issue": "has a issue in billing"
}
]
}
}
i want to get all the records in the month(value) and assert the response showing data for given month
I found the solution. You were very close. Instead of using contains which matches full string, you can use containsString to match a substring.
Code:
response.then().body("response.content.date", Every.everyItem(Matchers.containsString("2019-03")));

Couldn't get location coordinates from JSON dataset

I'm trying to develop an app for parking using ray wenderlich iOS mapkit tutorial as a model. While parsing the JSON dataset, the dataset in the tutorial has latitudes and longitudes separately. But in my dataset, they are together and therefore could not get them properly. So how to get the location coordinates??
This is the code given:
let latitude = (json[18].string! as NSString).doubleValue
let longitude = (json[19].string! as NSString).doubleValue
let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
Since, I don't have the lat and long separately, this won't work.
My JSON dataset has it like this:
"format" : { }
}, {
"id" : 203383710,
"name" : "Latitude, Longitude",
"dataTypeName" : "text",
"fieldName" : "latitude_longitude",
"position" : 4,
"renderTypeName" : "text",
"tableColumnId" : 28269463,
"width" : 328,
"cachedContents" : {
"non_null" : 83,
"largest" : "21.316161, -157.862061",
"null" : 123,
"top" : [ {
"item" : "21.306760, -157.861027",
"count" : 20
} ],
"smallest" : "21.275168, -157.824498"
},
[ [ 1, "D8CA6E89-DA04-424A-8DE3-9620EFE0A2EF", 1, 1431455105, "906163",
1431455105, "906163", "{\n}", "000 Aloha Tower Drive", null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, [ "
{\"address\":\"\",\"city\":\"\",\"state\":\"\",\"zip\":\"\"}", null, null,
null, true ] ]
So, how to get this???
If you have a string that equals "abc, def" and you want to separate it into the part before the comma and the part after the comma, you can use string.componentsSeparatedByString(", ").
This will return an array. The first element of the array (in the example above) will be "abc" and the second element will be "def". Note that the argument in the call is ", " -- that is, not just a comma, but a comma followed by a space, since the latitude and longitude in your JSON appear to separated with a comma followed by a space.

Least data-heavy way to retrieve 5 closest users in Firebase/Swift?

Let's imagine I have a Firebase setup like this, except with 10,000 users:
"users" : {
"user 1" : {
"latitude": 1234567,
"Longitude": 7654321,
"name": "Name 1"
},
"user 2" : {
"latitude": 1234567,
"longitude": 7654321,
"name": "Name 2"
},
"user 3" : {
"latitude": 1234567,
"Longitude": 7654321,
"name": "Name 3"
},
"user 4" : {
"latitude": 1234567,
"Longitude": 7654321,
"name": "Name 4"
},
}
What would be the least data-intensive way to generate a list of the 5 users closest to me? Very new to this, so the only solutions I can think of would require querying all 10,000 users.
I am very new to this subject, therefore I can only point you in the right direction. Essentially the way you're storing user location is not optimal. The best way to do it is to use GeoFire a newish addition to the Firebase service. How it works is you should have a large location object and you store the geolocation of those users using that users key. Here's an example.
{
Locations: {
-KH35xPkJmX0UTSG8DuM : {
"g" : "randomID",
"l" : {
"0" : "latitude",
"1" : "longitude"
}
}
}
}
{
Users: {
-KH35xPkJmX0UTSG8DuM : {
"username" : "Joe Sloan"
}
}
}
Your locations object will have 10,000 users keys and geoLocations. the value of "g" and "l" object are set when you use
geoFire.setLocation(CLLocation(latitude: 37.7853889, longitude: -122.4056973), forKey: "firebase-hq")
Google has optimized the query for users within a similar location.
let center = CLLocation(latitude: 37.7832889, longitude: -122.4056973)
// Query locations at [37.7832889, -122.4056973] with a radius of 600 meters
var circleQuery = geoFire.queryAtLocation(center, withRadius: 0.6)
The circleQuery variable should contain a Firebase dictionary of the closest users. As I said I haven't had a chance to really delve deeper but this should give you a start.

Parsing JSON with unknown root element in Swift with swiftlyJSON

I am working in iOS using Swift. The service I am using returns the following JSON (cut off as the node begins to repeat):
{
"Ambler Departures: April 15, 2015, 2:57 pm": [
{
"Northbound": [
{
"direction": "N",
"path": "R5N",
"train_id": "564",
"origin": "Frazer Yard",
"destination": "Colmar-Link Belt",
"status": "On Time",
"service_type": "LOCAL",
"next_station": "North Broad St",
"sched_time": "Apr 15 2015 03:27:00:000PM",
"depart_time": "Apr 15 2015 03:27:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "N",
"path": "R5N",
"train_id": "6566",
"origin": null,
Notice that the root node is created dynamically by the service-- I don't have a way of knowing what it will be as the user can chose departures from one of fifty stations and the time is based on the time on the server, which is likely inconsistent with the time on the user's clock.
I want to extract the data from the Northbound Array, and then a Southbound Array lower in the JSON.
I am getting the data returned form the service but I can't parse correctly. I can't get past the root node (the dynamic one) to get to the structure inside.
Here's what I am trying:
let json = JSON(data:data)
var x = 0
while x < json.count
{
let track = json[0]["Northbound"][x]["track"].string
println(track)
x++
}
This results in "nil". I am stuck...
I know that json[0] is probably wrong since that level of the JSON is not an array. Thanks in advance
If json is a JSON object from SwiftyJSON but you know it's a dictionary with an unknown key, you can find this key with:
let theKey = json.dictionary!.keys.first
Then access the array:
let theArray = json[theKey] as! [[String:AnyObject]] // array of dictionaries
Then theArray[0] will be the dictionary with "Northbound" as a key, which contains an array of dictionaries containing the infos.
(Edited to reflect the correct answer specific to SwiftyJSON.)

Resources