-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparking.js
140 lines (107 loc) · 4.72 KB
/
parking.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//var wfs = require('wfs')
var fs = require('fs')
var gdal = require('gdal')
//var child_process = require('child_process');
var request = require('request')
var file = __dirname + '/data/parking_slots.json';
var parkingWFSFeatures = null;
parkingWFSFeatures = JSON.parse(fs.readFileSync(file, 'utf8')).features;
// http://tampere.navici.com/tampere_wfs_geoserver/opendata/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=opendata:KESKUSTAN_PYSAKOINTI_VIEW&outputFormat=json&srsName=EPSG:4326&Filter=%3CFilter%20xmlns:gml=%22http://www.opengis.net/gml%22%3E%3CDWithin%3E%3CPropertyName%3Eopendata:GEOLOC%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E24486813.517,6821119.113%3C/gml:coordinates%3E%3C/gml:Point%3E%3CDistance%3E1000%3C/Distance%3E%3C/DWithin%3E%3C/Filter%3E
//Filter=<Filter xmlns:gml="http://www.opengis.net/gml"><DWithin><PropertyName>opendata:GEOLOC</PropertyName><gml:Point><gml:coordinates>24486813.517,6821119.113</gml:coordinates></gml:Point><Distance>1000<Distance></DWithin></Filter>
//child_process.spawn('gdaltransform') -s
var wgs84 = gdal.SpatialReference.fromEPSG(4326);
var gk24 = gdal.SpatialReference.fromEPSG(3878);
var coord_transform = new gdal.CoordinateTransformation(wgs84, gk24);
exports.getParkingJSONData = function getParkingJSONData(req, res) {
var point_orig = {
x: parseFloat(req.query.lon),
y: parseFloat(req.query.lat)
}
var pt_gk24 = coord_transform.transformPoint(point_orig);
console.log ("pt_gk24 - lat: " + pt_gk24.x + ", lon: " + pt_gk24.y);
request('http://tampere.navici.com/tampere_wfs_geoserver/opendata/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=opendata:KESKUSTAN_PYSAKOINTI_VIEW&outputFormat=json&srsName=EPSG:4326&Filter=%3CFilter%20xmlns:gml=%22http://www.opengis.net/gml%22%3E%3CDWithin%3E%3CPropertyName%3Eopendata:GEOLOC%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E' + pt_gk24.x + ',' + pt_gk24.y + '%3C/gml:coordinates%3E%3C/gml:Point%3E%3CDistance%3E' + req.query.radius + '%3C/Distance%3E%3C/DWithin%3E%3C/Filter%3E', function (error, response, body) {
if (error) {
return console.log('ERROR: ', error);
}
else if (!error && response.statusCode == 200) {
//console.log(body)
res.json(body)
}
else {
// TODO
}
})
/*wfs.getFeature({
url: 'http://tampere.navici.com/tampere_wfs_geoserver/opendata/ows',
typeName: 'opendata:KESKUSTAN_PYSAKOINTI_VIEW',
srsName : 'EPSG:4326',
outputFormat: 'json',
filter: '<Filter xmlns:gml="http://www.opengis.net/gml"><DWithin><PropertyName>opendata:GEOLOC</PropertyName><gml:Point>' +
'<gml:coordinates>' + pt_gk24.x + ',' + pt_gk24.y + '</gml:coordinates>' +
'</gml:Point><Distance>' + req.query.radius + '</Distance></DWithin></Filter>'
}, function(err, results) {
if (err) {
return console.log('ERROR: ', err);
}
//console.log(JSON.parse(results).features)
res.json(results)
// if (results.features) {
// console.log('found ' + results.features.length + ' parking places');
// results.features.forEach(function(feature) {
// //console.log('found feature: ' + feature.id);
// });
// // var jsonData = {
// // "jee": "jaa"
// // }
// res.json(jsonData)
// }
})*/
}
exports.showParkingMap = function showParkingMap(re, res) {
res.render('index',
{title: 'Etusivu',
parkingWFSFeatures: JSON.stringify(parkingWFSFeatures)})
/* wfs.getFeature({
url: 'http://tampere.navici.com/tampere_wfs_geoserver/opendata/ows',
typeName: 'opendata:KESKUSTAN_PYSAKOINTI_VIEW',
srsName : 'EPSG:4326'
}, function(err, results) {
if (err) {
return console.log('ERROR: ', err);
}
if (results.features) {
console.log('found ' + results.features.length + ' parking places');
results.features.forEach(function(feature) {
//console.log('found feature: ' + feature.id);
});
res.render('index',
{title: 'Etusivu',
parkingWFSFeatures: JSON.stringify(results.features)}
)
}
})*/
}
exports.showParkingCharts = function showParkingCharts(re, res) {
res.render('charts',
{title: 'Tilastoja',
parkingWFSFeatures: JSON.stringify(parkingWFSFeatures)})
/* wfs.getFeature({
url: 'http://tampere.navici.com/tampere_wfs_geoserver/opendata/ows',
typeName: 'opendata:KESKUSTAN_PYSAKOINTI_VIEW',
srsName : 'EPSG:4326'
}, function(err, results) {
if (err) {
return console.log('ERROR: ', err);
}
if (results.features) {
console.log('found ' + results.features.length + ' parking places');
results.features.forEach(function(feature) {
//console.log('found feature: ' + feature.id);
});
res.render('index',
{title: 'Etusivu',
parkingWFSFeatures: JSON.stringify(results.features)}
)
}
})*/
}