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..
Related
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
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')
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
]
}
},
...
I'm having an issue getting a json file I'm trying to create to use the json schema I've made so that I can make use of both intellisense and validation to ensure the json I have to hand-jam is good. I'm not sure if it's my schema that's wrong, or how I'm trying to get VS2015 to use it.
For now I've thrown all the schema stuff into one file (was having issues trying to split it up).
{
"$schema": "http://json-schema.org/schema#",
"id": "http://savatronix.com/jsonschemas/losthaven1/MainSchemaV1.json",
"title": "Lost Haven Common JSON",
"description": "A schema for json types that will be common across many different object types. V1",
"definitions": {
"gameDateTime": {
"type": "object",
"properties": {
"year": {
"type": "integer",
"minimum": 0
},
"month": {
"type": "string",
"enum": [ "Nil", "Spring", "Summer", "Autumn", "Winter" ]
},
"weekday": {
"type": "string",
"enum": [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
},
"day": {
"type": "integer",
"minimum": 0,
"maximum": 30
},
"hour": {
"type": "integer",
"minimum": 0,
"maximum": 23
},
"minute": {
"type": "integer",
"minimum": 0,
"maximum": 59
},
"second": {
"type": "integer",
"minimum": 0,
"maximum": 59
}
}
},
"characterAttributes": {
"type": "object",
"properties": {
"strength": {
"type": "integer",
"minimum": 0
},
"agility": {
"type": "integer",
"minimum": 0
},
"dexterity": {
"type": "integer",
"minimum": 0
},
"intelligence": {
"type": "integer",
"minimum": 0
},
"endurance": {
"type": "integer",
"minimum": 0
},
"charisma": {
"type": "integer",
"minimum": 0
},
"luck": {
"type": "integer",
"minimum": 0
}
}
},
"characterElements": {
"type": "object",
"properties": {
"earth": { "type": "integer" },
"wind": { "type": "integer" },
"fire": { "type": "integer" },
"water": { "type": "integer" },
"lightning": { "type": "integer" },
"light": { "type": "integer" },
"dark": { "type": "integer" }
}
},
"characterStatus": {
"type": "object",
"properties": {
"poison": { "type": "integer" },
"paralyze": { "type": "integer" },
"sleep": { "type": "integer" },
"fatigue": { "type": "integer" },
"charm": { "type": "integer" },
"confusion": { "type": "integer" }
}
},
"characterStats": {
"type": "object",
"properties": {
"attackPower": {
"type": "integer",
"minimum": 0
},
"block": {
"type": "integer",
"minimum": 0
},
"health": {
"type": "integer",
"minimum": 0
},
"defense": {
"type": "integer",
"minimum": 0
},
"evade": {
"type": "integer",
"minimum": 0
},
"attackSpeed": {
"type": "integer",
"minimum": 0
},
"parry": {
"type": "integer",
"minimum": 0
},
"stamina": {
"type": "integer",
"minimum": 0
},
"movementSpeedModifier": { "type": "integer" },
"elementalPower": { "$ref": "#/definitions/characterElements" },
"statusPower": { "$ref": "#/definitions/characterStatus" }
}
},
"attributesAndStatsContainer": {
"type": "object",
"properties": {
"attributes": { "$ref": "#/definitions/characterAttributes" },
"stats": { "$ref": "#/definitions/characterStats" }
}
},
"characterEquipmentState": {
"type": "object",
"properties": {
"weaponId": { "type": "string" },
"headgearId": { "type": "string" },
"chestId": { "type": "string" },
"legsId": { "type": "string" },
"bootsId": { "type": "string" },
"glovesId": { "type": "string" },
"firstAccessoryId": { "type": "string" },
"secondAccessoryId": { "type": "string" }
}
},
"baseObjectState": {
"type": "object",
"properties": {
"baseId": { "type": "string" },
"referenceId": { "type": "string" }
}
},
"characterState": {
"type": "object",
"allOf": [
{ "$ref": "#/definitions/baseObjectState" },
{
"properties": {
"characterName": { "type": "string" },
"characterSex": {
"type": "string",
"enum": [ "Unknown", "Male", "Female" ]
},
"race": {
"type": "string",
"enum": [ "Unknown", "Human", "Yokai" ]
},
"baseStats": { "$ref": "#/definitions/attributesAndStatsContainer" },
"currentHealth": {
"type": "integer",
"minimum": 0
},
"birthday": { "$ref": "#/definitions/gameDateTime" },
"equippedItems": { "$ref": "#/definitions/characterEquipmentState" }
}
}
]
},
"enemyStateObject": {
"type": "object",
"allOf": [
{ "$ref": "#/definitions/characterState" },
{
"properties": {
"isBoss": { "type": "boolean" }
}
}
]
},
"enemyState": {
"type": "object",
"properties": {
"enemies": {
"type": "array",
"items": { "$ref": "#/definitions/enemyStateObject" },
"minItems": 1
}
}
},
"NpcState": {
"type": "object",
"allOf": [
{ "$ref": "#/definitions/characterState" },
{
"properties": {
"backgroundInfo": { "type": "string" },
"history": { "type": "string" },
"personalityDescription": { "type": "string" },
"job": {
"type": "string",
"enum": [ "None" ]
},
"isRecruitable": { "type": "boolean" },
"isEligableSignificantOther": { "type": "boolean" },
"significantOtherId": { "type": "string" },
"wallet": {
"type": "integer",
"minimum": 0
},
"inventory": {
"type": "array",
"items": { "type": "string" }
}
}
}
]
}
}
}
I'm trying to use the enemyState definition to create an object that contains an array of enemies (doing this because the MSDN blog recommends using $schema so VS will auto-detect the desired schema).
"enemyState": {
"type": "object",
"properties": {
"enemies": {
"type": "array",
"items": { "$ref": "#/definitions/enemyStateObject" },
"minItems": 1
}
}
},
In my Enemies.json I've tried:
{
"$schema": "../../../JsonSchemas/MainSchema.json#/definitions/enemyState"
}
That's the "msdn blog post" recommended way to do it: Intellisense for JSON Schema in the JSON Editor
I've also tried omitting that, and copying the link straight into the schema location bar in the editor.
When typing the $Schema part, it is the correct location, as the #/defintions/enemyState part gets working intellisense.
However that's the extent of it. I get no intellisense or validation when trying to create the actual json. I've tried closing and re-opening the file, as well as restarting visual studio.
The desired effect I'd like to have is getting intellisense and validation so I can create an array of enemy state objects (which is the definition of various enemies in the game I'm making, and gets read and loaded into Unity) and ensure required properties are there (not yet created in the schema, figure I'd add the required properties stuff after I get it working at least), as well as making sure everything is within the ranges, and that it validates so I know there are no errors.
Any help here would be appreciated.
Thanks much!
Ok, so I finally got it working and here's how.
I created a test json file using Solution Explorer -> json schema and dragged that over to the JSON file, and it worked.
I then modified it to look exactly like the relevant part of my schema (tweaking the $ref's so they pointed to the main schema file where needed).
That worked.
So, for whatever reason, manually creating a json file (new -> text file -> rename) seems to throw Visual Studio off and make it think it's not a json file when being directly set as the schema in a json file (but VS is able to read it just fine, as evidenced by how it's pulling information from my main schema file, through my "test" json schema file, and on into the actual json file that's using the schema).
Go figure...
The rest service response I am working with is similar to following example, I have only included 3 fields here but there are many more:
{
"results": [
{
"type": "Person",
"name": "Mr Bean",
"dateOfBirth": "14 Dec 1981"
},
{
"type": "Company",
"name": "Pi",
"tradingName": "Pi Engineering Limited"
}
]
}
I want to write a JSON schema file for above (draft-04) which will explicitly specify that:
if type == Person then list of required properties is ["type", "name", "dateOfBirth", etc]
OR
if type == "Company" then list of required properties is ["type", "name", "tradingName", etc]
However am unable to find any documentation or example of how to do it.
Currently my JSON schema looks like following:
{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"required": ["results" ],
"properties": {
"results": {
"type": "array",
"items": {
"type": "object",
"required": ["type", "name"],
"properties": {
"type": { "type": "string" },
"name": { "type": "string" },
"dateOfBirth": { "type": "string" },
"tradingName": { "type": "string" }
}
}
}
}
}
Any pointers/examples of how I should handle this.
I think the recommended approach is the one shown in Json-Schema web, Example2. You need to use an enum to select schemas "by value". In your case it would be something like:
{
"type": "object",
"required": [ "results" ],
"properties": {
"results": {
"type": "array",
"items": {
"oneOf": [
{ "$ref": "#/definitions/person" },
{ "$ref": "#/definitions/company" }
]
}
}
},
"definitions": {
"person": {
"properties": {
"type": { "enum": [ "person" ] },
"name": {"type": "string" },
"dateOfBirth": {"type":"string"}
},
"required": [ "type", "name", "dateOfBirth" ],
"additionalProperties": false
},
"company": {
"properties": {
"type": { "enum": [ "company" ] },
. . .
}
}
}
}
Sorry,
I don't get the point. The question is about the 'dependencies' keyword which is part of the last JSON Schema specification, right?
I do not find 'dependencies' in the accepted answer (?)
It is briefly explained in the last draft.
But http://usingjsonschema.com explained both property and definition dependencies in the book:
http://usingjsonschema.com/assets/UsingJsonSchema_20140814.pdf
start at page 29 (see, explained at page 30)
"dependencies": {
"shipTo":["shipAddress"],
"loyaltyId":["loyaltyBonus"]
}