Filtering on GeoJSON data - gis

I was wondering how filtering is normally done on a FeatureCollection for GeoJSON data. For example, take the following earthquake data:
{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "id": "ak16994521", "mag": 2.3, "time": 1507425650893, "felt": null, "tsunami": 0 }, "geometry": { "type": "Point", "coordinates": [ -151.5129, 63.1016, 0.0 ] } },
{ "type": "Feature", "properties": { "id": "ak16994519", "mag": 1.7, "time": 1507425289659, "felt": null, "tsunami": 0 }, "geometry": { "type": "Point", "coordinates": [ -150.4048, 63.1224, 105.5 ] } },
{ "type": "Feature", "properties": { "id": "ak16994517", "mag": 1.6, "time": 1507424832518, "felt": null, "tsunami": 0 }, "geometry": { "type": "Point", "coordinates": [ -151.3597, 63.0781, 0.0 ] } },
{ "type": "Feature", "properties": { "id": "ci38021336", "mag": 1.42, "time": 1507423898710, "felt": null, "tsunami": 0 }, "geometry": { "type": "Point", "coordinates": [ -118.497, 34.299667, 7.64 ] } },
{ "type": "Feature", "properties": { "id": "hv61900626", "mag": 2.91, "time": 1504833891990, "felt": null, "tsunami": 0 }, "geometry": { "type": "Point", "coordinates": [ -155.011833, 19.399333, 2.609 ] } }
]
}
Now, if this data is all within a single FeatureCollection, how would anyone filter the data, for example to view earthquakes with magnitude > 2.5 ? It seems like when dealing with a FeatureCollection the first thing to do would be to extract each of the features into its own item: is that what is usually done, so that individual properties may be queried?

GeoJSON is a transfer format and as you have noticed any operation on it requires you to read and parse the whole file every time. If you plan to do anything with the data you should translate it into a more useful format which supports indexes. If you need to keep to a file based format then I recommend GeoPackage which is supported by the majority of modern GIS. Alternatively, you could use a spatially enabled database such as PostGIS.
In either case the easiest way to convert the data is to use ogr2ogr

Related

geoJSON formatting needs to be nested more deeply

I'm have an exported geoJSON format containing a long series of polygon coordinates. Attaching the first few rows, it continues in the same way:
{
"Type": 8,
"Features": [
{
"Type": 7,
"Id": null,
"Geometry": {
"Type": 4,
"Coordinates": [
{
"Type": 2,
"Coordinates": [
{
"Altitude": null,
"Latitude": 85.683948266763423,
"Longitude": 100.62897140939768
},
{
"Altitude": null,
"Latitude": 86.183185093020128,
"Longitude": 100.62897140939695
},
{
"Altitude": null,
"Latitude": 86.183185093020128,
"Longitude": 102.58500571589823
},
{
"Altitude": null,
"Latitude": 97.662303996119974,
"Longitude": 102.58500571589828
},
{
"Altitude": null,
"Latitude": 97.662303996119988,
"Longitude": 97.853903401585853
},
{
"Altitude": null,
"Latitude": 85.683948266763423,
"Longitude": 97.853903401585839
},
{
"Altitude": null,
"Latitude": 85.683948266763423,
"Longitude": 100.62897140939768
}
],
"BoundingBoxes": null,
"CRS": null
}
],
"BoundingBoxes": null,
"CRS": null
},
"Properties": {
"Name": "Shop",
"Area": 572.15969696515185
},
"BoundingBoxes": null,
"CRS": null
},
{
"Type": 7,
"Id": null,
"Geometry": {
"Type": 4,
"Coordinates": [
{
"Type": 2,
"Coordinates": [
{
"Altitude": null,
"Latitude": 91.298364266763443,
"Longitude": 86.631773715898134
},
{
I tried looking at various explanations of the geoJSON format online, but haven't found info about why the "Type" is numeric and not matching the actual type such as "Polygon".
In addition, while testing on GeoJSON Viewer & Validator, I tried debugging and converted some of the initial lines to:
{
"type": "MultiPolygon",
"coordinates": [
{
"type": 7,
"Id": null,
"Geometry": {
"Type": "Polygon",
"Coordinates": [
{
"Type": 2,
"Coordinates": [
{
"Altitude": null,
"Latitude": 85.683948266763423,
"Longitude": 100.62897140939768
},
I replaced Type with type and 8 with MultiPolygon etc.
With the above situation in place, I get the following error for each Polygon:
Line 5: a number was found where a coordinate array should have been
found: this needs to be nested more deeply
I'm not sure what to change in the format in order to make it coherent for the validator. I think the export format might be old but I'm not the one that built it so perhaps a manual replacement of some fields can solve the issue.
Any tips?
A bit late to the party, but it seems like it's not valid GeoJSON, you can find the official JSON schemas that describe the specification here:
https://github.com/geojson/schema.
It is for instance specified that type of a feature should be a JSON object and not an integer, that for each feature, type, properties and geometry are required, etc.
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://geojson.org/schema/Feature.json",
"title": "GeoJSON Feature",
"type": "object",
"required": [
"type",
"properties",
"geometry"
]
(etc.)
For a MultiPolygon here is the schema : https://geojson.org/schema/MultiPolygon.json
The way that coordinates are stored in your file aren't standard GeoJSON either, as they should be written as array of numbers:
"coordinates": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "array",
"minItems": 4,
"items": {
"type": "array",
"minItems": 2,
"items": {
"type": "number"
}
}
}
}
}

Flutter: Unexpected character (at character 1)

In Flutter, no matter what json file i try to decode I get the same above titled error.
Originally I thought it was something with my project but after starting a new template Flutter project I still receive the same error. I have the json file in my root folder and have added them to the pubspec.yaml file:
assets:
- Sample-JSON-data.json
- Sample-employee-JSON-data.json
Main.dart code at the moment:
var jsonString = 'Sample-JSON-data.json';
var response = jsonDecode(jsonString);
print(response);
I have verified my json data on multiple test sites as well as tried various methods in the Flutter Documentation. Json data:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.0763783444317,
-33.98045132346684
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.0763783444317,
-33.98045132346684
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.0763783444317,
-33.98045132346684
]
}
}
]
}
jsonDecode expects an input to be valid JSON serialized into String fe.
{ "message": "Hello World!" }. So this would work: jsonDecode('{"message": "Hello World!"}').
What you are passing to it is a file name, it won't automatically read the file for you. You can check how to do that here:
Flutter - Read text file from assets
Actually you are not loading the data from the json file.
Try:
var jsonString = await rootBundle.loadString('Sample-JSON-data.json')

Multiple items for a single coordinate in GeoJSON

I've set up a rest API that is supplying geojson data from a database. The issue is each coordinate could/does have multiple items associated to it.
Currently troubleshooting the application's javascript file to load, and plot - but looking for feedback on best practice. Any information is appreciated. Thanks!
var foo = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"item": "A",
},
"geometry": {
"type": "Point",
"coordinates": [
90,
135
]
}
},
{
"type": "Feature",
"properties": {
"item": "B",
},
"geometry": {
"type": "Point",
"coordinates": [
90,
135
]
}
},
{
"type": "Feature",
"properties": {
"item": "C",
},
"geometry": {
"type": "Point",
"coordinates": [
90,
135
]
}
},
...

Fiware Context Broker with entities geolocated

I have a problem in retrieving entities using georeferenced queries.
Use the v2 syntax.
This is my query:
GET /v2/entities?georel=near;maxDistance:1000&geometry=point&coords=13.52,43.61
and this is my entity:
{
"id": "p1",
"type": "pm",
"address": {
"type": "Text",
"value": "Via Roma "
},
"allowedVehicleType": {
"type": "Text",
"value": "car"
},
"category": {
"type": "Text",
"value": "onstreet"
},
"location": {
"type": "geo:json",
"value": {
"type": "Point",
"coordinates": [ 13.5094, 43.6246 ]
}
},
"name": {
"type": "Text",
"value": "p1"
},
"totalSpotNumber": {
"type": "Number",
"value": 32
}
}
What is wrong?
I followed the official documentation but I can not get any results as well.
I also tried to reverse the coordinates, but the result does not change.
Any suggestion is welcome.
Note that longitude comes before latitude in GeoJSON coordinates, while the coords parameters does in the opposite way.
Thus, assuming that your entity is located in Ancona city, I think that using "coordinates": [ 43.6246, 13.5094 ] will solve the problem.

TileMill and Geojson; Datasource could not be loaded

Im following this article to get a geojson file from an excel using Google Refine.
http://support.mapbox.com/kb/tilemill/converting-addresses-in-spreadsheets-to-custom-maps-in-tilemill
Now I've got the weird issue that I sometimes get the error message that the Datasource could not be loaded, while I'm using the exact same template everytime. The only thing different seems to be the data I'm loading.
Also if I compare the 2 geojson files (1 that is working and 1 that is not) I can see no difference.
Does anyone know what the problem could be? .. is it the use of spaces/breaks or whatever perhaps??
This one is working:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": 25.019909,
"geometry": { "type": "Point", "coordinates": [121.365599, 25.019909] },
"properties":
{
"Users" : 1
}
},
{
"type": "Feature",
"id": 24.446706,
"geometry": { "type": "Point", "coordinates": [117.818197, 24.446706] },
"properties":
{
"Users" : 1
}
},
{
"type": "Feature",
"id": 25.100632,
"geometry": { "type": "Point", "coordinates": [117.03403, 25.100632] },
"properties":
{
"Users" : 1
}
},
{
"type": "Feature",
"id": 47.354348,
"geometry": { "type": "Point", "coordinates": [123.918186, 47.354348] },
"properties":
{
"Users" : 1
}
},
{
"type": "Feature",
"id": 30.199652,
"geometry": { "type": "Point", "coordinates": [115.03852, 30.199652] },
"properties":
{
"Users" : 3
}
},
...
...
...
}
]
}
While this one is giving me the error;
{
"type": "FeatureCollection",
"features": [ {
"type": "Feature",
"id": 25.019909,
"geometry": { "type": "Point", "coordinates": [121.365599, 25.019909] },
"properties":
{
"Users" : 1
}
},
{
"type": "Feature",
"id": 24.446706,
"geometry": { "type": "Point", "coordinates": [117.818197, 24.446706] },
"properties":
{
"Users" : 1
}
},
{
"type": "Feature",
"id": 25.100632,
"geometry": { "type": "Point", "coordinates": [117.03403, 25.100632] },
"properties":
{
"Users" : 1
}
},
...
...
...
}
]
}
You have an extra '}' in the second one. But, of course this may only look this way because of what you removed when adding the ..., so its impossible to say unless you post the whole thing that is not working.
Hint: find a text editor that highlights matching braces - most should do this if you tell the editor you are viewing javascript or json code.
I'm sorry.. it was something in the data after all :( .. tilemill is very strict in what it accepts and what not apparently..