This is a migrated thread and some comments may be shown as answers.

Data Schema for GeoJson data

7 Answers 171 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Dr.YSG
Top achievements
Rank 2
Dr.YSG asked on 04 Mar 2014, 07:38 PM
I'm sorry, but after searching the DataSource API and this forum I am not finding out how to do the following:

I have a Node.JS server connected to a PostGIS database. It stores a number of rows that have a field called: outline that is a long GeoJSON object. In my model, I declare the simple fields (number, data, etc.) just fine. But is this correct for the JSON data. I will connect this to a KendoGrid, but I do not want the user to see it.

What I want him to do is sort, select, etc. based on the other fields, and then I will use the hidden GeoJSON outline (I will fetch it with the dataSource.data() method to get the values from it for map display.

But first, is this the "json" a correct type for the outline?

function buildDataModel() {
    DataModel.data = new kendo.data.DataSource({
        type:"json",
        pageSize: 5000, //change to infinite when bug fixed.
        transport:{
            read:{
              url:AppGlobals.serverURL + "Search",
                dataType:"json"
            }
        },
        schema:{
            data:"results",
            total:"count",
            model:{
                fields:{
                    pid:{ type:"number" },
                    size:{ type:"number" },
                    date:{ type:"date" },
                    type:{ type:"string" },
                    egpl_date:{ type:"date" },
                    cocom:{ type:"string" },
                    country:{ type:"string" },
                    product_name:{ type:"string" },
                    outline:{ type:"json" }
                }
            }
        },
        error:function (e) {
            alert("DataMode.js datasource error: " +
                "\nthrew: " + e.errorThrown +
                "\nstatus: " + e.status +
                "\nerrors:" + e.errors +
                "\nurl: " + e.sender.transport.options.read.url);
        },
        change:function (e) {
            newData(e);
        }
    });
}

7 Answers, 1 is accepted

Sort by
0
Dr.YSG
Top achievements
Rank 2
answered on 05 Mar 2014, 08:25 PM
So here is an example record that I am sending from the Node.JS server to the browser (to be parsed with the kendo.DataSource).

As you can see, everything but outline, is a simple string, data, or numeric. But I want the outline to be preserved in the DataSource as a JSON object. The issue is that if I say the field type is "json" or "object" I get the following back when I call grid.dataTime(<rowID>) (see second json. Note all the dt.extend.init objects).



001.{
002.  "pid": 23501,
003.  "product_name": "DTED120",
004.  "type": "DTED1",
005.  "country": "Poland",
006.  "size": 522782213,
007.  "cocom": "EUCOM",
008.  "egpl_date": "2013-03-28T06:47:56.334Z",
009.  "outline": {
010.    "type": "Polygon",
011.    "crs": {
012.      "type": "name",
013.      "properties": {
014.        "name": "EPSG:4326"
015.      }
016.    },
017.    "coordinates": [
018.      [
019.        [
020.          19.0004167,
021.          48.9995833
022.        ],
023.        [
024.          18.9995833,
025.          48.9995833
026.        ],
027.        [
028.          18.0004167,
029.          48.9995833
030.        ],
031.        [
032.          17.9995833,
033.          48.9995833
034.        ],
035.        [
036.          16.9995833,
037.          48.9995833
038.        ],
039.        [
040.          16.9995833,
041.          49.9995833
042.        ],
043.        [
044.          16.9991667,
045.          49.9995833
046.        ],
047.        [
048.          16.0008333,
049.          49.9995833
050.        ],
051.        [
052.          15.9991667,
053.          49.9995833
054.        ],
055.        [
056.          15.0008333,
057.          49.9995833
058.        ],
059.        [
060.          14.9991667,
061.          49.9995833
062.        ],
063.        [
064.          13.9991667,
065.          49.9995833
066.        ],
067.        [
068.          13.9991667,
069.          50.9995833
070.        ],
071.        [
072.          13.9991667,
073.          51.0004167
074.        ],
075.        [
076.          13.9991667,
077.          51.9995833
078.        ],
079.        [
080.          13.9991667,
081.          52.0004167
082.        ],
083.        [
084.          13.9991667,
085.          52.9995833
086.        ],
087.        [
088.          13.9991667,
089.          53.0004167
090.        ],
091.        [
092.          13.9991667,
093.          54.0004167
094.        ],
095.        [
096.          14.9991667,
097.          54.0004167
098.        ],
099.        [
100.          15.0008333,
101.          54.0004167
102.        ],
103.        [
104.          15.9991667,
105.          54.0004167
106.        ],
107.        [
108.          16.0008333,
109.          54.0004167
110.        ],
111.        [
112.          16.9991667,
113.          54.0004167
114.        ],
115.        [
116.          17.0008333,
117.          54.0004167
118.        ],
119.        [
120.          17.9991667,
121.          54.0004167
122.        ],
123.        [
124.          18.0008333,
125.          54.0004167
126.        ],
127.        [
128.          18.9991667,
129.          54.0004167
130.        ],
131.        [
132.          19.0008333,
133.          54.0004167
134.        ],
135.        [
136.          19.9991667,
137.          54.0004167
138.        ],
139.        [
140.          20.0008333,
141.          54.0004167
142.        ],
143.        [
144.          20.9991667,
145.          54.0004167
146.        ],
147.        [
148.          21.0008333,
149.          54.0004167
150.        ],
151.        [
152.          21.9991667,
153.          54.0004167
154.        ],
155.        [
156.          22.0008333,
157.          54.0004167
158.        ],
159.        [
160.          22.9991667,
161.          54.0004167
162.        ],
163.        [
164.          23.0008333,
165.          54.0004167
166.        ],
167.        [
168.          24.0008333,
169.          54.0004167
170.        ],
171.        [
172.          24.0008333,
173.          53.0004167
174.        ],
175.        [
176.          24.0008333,
177.          52.9995833
178.        ],
179.        [
180.          24.0008333,
181.          51.9995833
182.        ],
183.        [
184.          23.0008333,
185.          51.9995833
186.        ],
187.        [
188.          23.0008333,
189.          51.0004167
190.        ],
191.        [
192.          23.0008333,
193.          50.9995833
194.        ],
195.        [
196.          23.0008333,
197.          49.9995833
198.        ],
199.        [
200.          22.0008333,
201.          49.9995833
202.        ],
203.        [
204.          22.0004167,
205.          49.9995833
206.        ],
207.        [
208.          22.0004167,
209.          48.9995833
210.        ],
211.        [
212.          21.0004167,
213.          48.9995833
214.        ],
215.        [
216.          20.9995833,
217.          48.9995833
218.        ],
219.        [
220.          20.0004167,
221.          48.9995833
222.        ],
223.        [
224.          19.9995833,
225.          48.9995833
226.        ],
227.        [
228.          19.0004167,
229.          48.9995833
230.        ]
231.      ]
232.    ]
233.  }
234.},


This is what I get see if when retrieving the grid.dataItem(0).outline:

Watch Expressions
bounds: dt.extend.init
_events: Object
coordinates: dt.extend.init[1]
0: Array[53]
_events: Object
length: 1
parent: function (){return i}
type: function (e){var t,n,i=this,r=function(){return i};dt.fn.init.call(this);for(n in e)t=e[n],"_"!=n.charAt(0)&&(t=i.wrap(t,n,r)),i[n]=t;i.uid=st.guid()}
__proto__: n.extend.i
crs: dt.extend.init
_events: Object
parent: function (){return i}
properties: dt.extend.init
type: "name"
uid: "f9fd34d1-6362-47b7-91f5-8b67f7919f41"
__proto__: n.extend.i
parent: function (){return i}
type: "Polygon"
uid: "9348b924-3ea1-4531-b724-64cc7eba6a16"
__proto__: n.extend.i
0
Petur Subev
Telerik team
answered on 07 Mar 2014, 06:50 AM
Hello Yechezkal,

Basically you do not have to do anything in your case. The nested JSON field will still be available on the client when getting the dataItem from the dataSource.

Just omit specifying it and let me know y our findings.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dr.YSG
Top achievements
Rank 2
answered on 07 Mar 2014, 02:44 PM
So if I understand your correctly,

var geoJSON = dataSource[x];

will return a JSON object, with none of the dt decoration?

And that I should declare the field in the DataSource as type: "object",

is that correct?

0
Dr.YSG
Top achievements
Rank 2
answered on 07 Mar 2014, 02:45 PM
I mean to say with none of the dt.extend.init decoration,
and to get the object via

grid.dataItem(X);

Is that correct?
0
Petur Subev
Telerik team
answered on 11 Mar 2014, 09:21 AM
Hello again Yechezkal,

There is no such type definition. Just omit specifying this in the dataSource.schema configuration.

It will still be available. Take a look at the code that you shared:

coordinates: dt.extend.init[1]
0: Array[53]

You can access the nested array like this

var coordinates = grid.dataItem(X).coordinates[0];
 
// you can then iterate over the coordinates array


Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dr.YSG
Top achievements
Rank 2
answered on 12 Mar 2014, 03:05 PM
Hello Petur,

I follow that. But is this worth adding as a user voice request? Afterall, I do not want to manually go through the coordinate list to create a GeoJSON object. What I want to do is store JSON directly in the DataSource,  and then grab that JSON and create use the Leaflet create layer, which takes GeoJSON as a parameter.

Seems like an easy thing to add to the current field types (number, string, data, etc.) to add a JSON type, and then not do any interpretation on it.



0
Petur Subev
Telerik team
answered on 13 Mar 2014, 02:28 PM
Hello Yechezkal,

Feel free to share this as an idea on our feedback portal. If many users find it useful, the Dev team will consider it.

http://kendoui-feedback.telerik.com/forums/127393-telerik-kendo-ui-feedback

Kind Regards,
Petur Subev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
Dr.YSG
Top achievements
Rank 2
Answers by
Dr.YSG
Top achievements
Rank 2
Petur Subev
Telerik team
Share this question
or