Create JSON for place name and coordinates - json

I have the following:
pt-PT:[Lisboa,Portugal][38.7138,9.1394];
en-GB:[London,UK][51.5072,0.1275]
So, for each culture, e.g. pt-PT and en-GB code, I would like to define one place with its coordenates.
What is the correct JSON format for this?

The interest of a JSON is that you can set your data as you want.
A good idea in your case is to follow the GeoJSON format.
http://geojson.org/
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [38.7138,9.1394]},
"properties": {"city": "Lisboa", "country": "Portugal"}
}
]
}

Related

Google Spreadsheet RE2 Regex and Geojson

I have a Geojson in a google sheet cell. I'd like to extract coordinates from that. I tried using Regexextract function but I'm really having trouble in making the regex work.
This is a sample structure:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
62.22656249999999,
61.438767493682825
],
[
54.140625,
44.33956524809713
],
[
79.453125,
48.45835188280866
],
[
62.22656249999999,
61.438767493682825
]
]
]
}
}
]
}
what I want to obtain is
[[[62.22656249999999,61.438767493682825],[54.140625,44.33956524809713],[79.453125,48.45835188280866],[62.22656249999999,61.438767493682825]]]
Can you help me with that?
Thanks
=REGEXREPLACE(A5,"[^\[\]\.\d+,]",)
Anything except []., and digits gives a close approximation.
EDIT:
=REGEXEXTRACT(A5,"(?s)(\[\s+\[\s+\[.*\]\s+\]\s+\])")

Convert JSON containing geometry to postgreSQL

I have a JSON file that contains the attribute of several parks along with location (geometry) as a point. I was wondering how to convert the JSON to postgreSQL format. Indeed, I have tried several ways such as SQLizer and MapForce, but I was not able to convert them. Is there any way to convert this JSON which has geometry, to postgreSQL format?
I appreciate any help.
Below you can find the script.
var lenneparks = {
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
{
"type": "Feature",
"properties": {
"place": "Aachen Kurpark",
"year": "1853 (Hi)",
"text": "Elisengarten, kleine Parkanlage in der Innenstadt, rückwärtig vom Elisenbrunnen"
},
"geometry": {
"type": "Point",
"coordinates": [
6.086027,
50.774247
]
}
},
{
"type": "Feature",
"properties": {
"place": "Aachen",
"year": "ca. 1862 (Hi)",
"text": "Staatsprokurator Dubusc"
},
"geometry": {
"type": "Point",
"coordinates": [
6.0838868,
50.7653455
]
}
}
]
};
EDIT 1: Corrected SQL comments
Have you tried the PostGIS extension? It comes with really handy functions to import such data, such as:
-- To create a geometry object from your GeoJSON
SELECT ST_GeomFromGeoJSON('{"type":"Point","coordinates":[-48.23456,20.12345]}') As geometry;
-- To see the WKT of your GeoJSON
SELECT ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[-48.23456,20.12345]}')) As geometry;
EDIT 2: Creating records for each geometry
This function will create a table containing one record for each json element in the array features, from there you can start parsing the data you need for creating your tables... I hope it helps:
CREATE TEMPORARY TABLE features AS
SELECT json_array_elements('{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
{
"type": "Feature",
"properties": {
"place": "Aachen Kurpark",
"year": "1853 (Hi)",
"text": "Elisengarten, kleine Parkanlage in der Innenstadt, rückwärtig vom Elisenbrunnen"
},
"geometry": {
"type": "Point",
"coordinates": [
6.086027,
50.774247
]
}
},
{
"type": "Feature",
"properties": {
"place": "Aachen",
"year": "ca. 1862 (Hi)",
"text": "Staatsprokurator Dubusc"
},
"geometry": {
"type": "Point",
"coordinates": [
6.0838868,
50.7653455
]
}
}
]
}'::JSON -> 'features') as features;
SELECT * FROM features;
EDIT 3: Query to extract info from json table
SELECT
features -> 'geometry' -> 'coordinates' -> 0 AS lat,
features -> 'geometry' -> 'coordinates' -> 1 AS lon,
features -> 'properties' -> 'place'::TEXT,
features -> 'properties' -> 'year'::TEXT,
features -> 'properties' -> 'text'::TEXT
FROM features;
EDIT 4: Extracting geometries from the json table and converting them into WKT and Geometry
SELECT ST_GeomFromGeoJSON((features -> 'geometry')::text)
FROM features;
SELECT ST_AsText(ST_GeomFromGeoJSON((features -> 'geometry')::TEXT))
FROM features;

GeoJSON object naming convention

A GeoJSON object might look something like this:
{
"type": "Point",
"coordinates": [
28.169778,
-25.886587
]
}
We may embed this into some other resource object, say a 'point of interest':
{
"id": "1266f0WqVkGB2BnnVhOvEw",
"name": "Eco Fushion, Witch-Hazel Ave",
"type": "TRANSIT",
"code": "ert222",
"point": {
"type": "Point",
"coordinates": [
28.169778,
-25.886587
]
}
}
Is there any convention as to what this GeoJSON object should be named as when embedded as a field?
In the above example, I have called it point.

Creating GeoJson from csv: How do I set geometry properties?

I have a csv file that I want to convert to GeoJson.
lon,lat,val,id
-97.1589432,25.9642008,0,2690
-97.1682294,25.9761856,0,2691
-97.1775156,25.9881704,0,2692
I run the following ogr2ogr command
ogr2ogr -f GEOJson geo_result.json source.csv
and I get this result
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "lon": "-97.1589432", "lat": "25.9642008", "val": "0", "id": "2690" }, "geometry": null },
{ "type": "Feature", "properties": { "lon": "-97.1682294", "lat": "25.9761856", "val": "0", "id": "2691" }, "geometry": null },
{ "type": "Feature", "properties": { "lon": "-97.1775156", "lat": "25.9881704", "val": "0", "id": "2692" }, "geometry": null }
]
}
Why is geometry null?
How can I tell ogr2ogr which values are lat & lon?
You need to wrap the CSV file in a VRT file which specifies the meaning of the columns.
<OGRVRTDataSource>
<OGRVRTLayer name="source">
<SrcDataSource>source.csv</SrcDataSource>
<GeometryType>wkbPoint</GeometryType>
<LayerSRS>WGS84</LayerSRS>
<GeometryField encoding="PointFromColumns" x="lon" y="lat"/>
</OGRVRTLayer>
</OGRVRTDataSource>
And then use the VRT file as the input:
ogr2ogr -f GEOJson geo_result.json source.vrt
QGIS (which uses OGR) has an interface which cleverly guesses the columns, and that works very well. So if you have to use your conversion only once it might be worth trying it with a GUI like QGIS.
See the CSV driver page from OGR for more details:
http://www.gdal.org/ogr/drv_csv.html

Can't fetching records from nested JSON objects in Sencha Touch Application

I'm stuck with issue for getting web-service response from JSON in Sencha Touch.
I'm getting response from server.
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "business_poi_en.1",
"geometry": {
"type": "Point",
"coordinates": [
28.21962354993591,
36.452844361147314
]
},
"geometry_name": "geom",
"properties": {
"status": "M",
"score": 100,
"side": "R",
"ref_id": 0,
"id": null,
"business_p": "AQUARIOUM",
}
},
{
"type": "Feature",
"id": "business_poi_en.2",
"geometry": {
"type": "Point",
"coordinates": [
28.225417523605692,
36.436470953176716
]
},
"geometry_name": "geom",
"properties": {
"status": "M",
"score": 68.44,
"match_type": "A",
"side": "L",
"ref_id": 0,
"id": null,
"business_p": "ZIGOS",
}
},
.... So On ....
I want to fetch data for coordinates from geometry tag, so I can display it on map via these coordinates.I also want to fetch data for business_p from properties tag as displaying title on map.
But, I can't get both of values for coordinates & business_p at same time from same response.
Any idea for getting values at same time ?
Any suggestion will be appreciated.
Please help with this issue.
Thanks in advance.
Your Store's proxy's reader should have correct rootProperty which is common parent of both coordinates and business_p. For that your response should be wrapped into a top level tag like this
{
"featureResponse": [
{
"type": "FeatureCollection",
"features": []
},
{
"type": "Feature",
"features": []
},
]
}
Then you can define reader like this:
reader: {
type: 'json',
rootProperty: 'featureResponse'
}
once you get record from this store, you can go to data or raw children object to fetch required data.