请问kont,node.js,point有什...

Node.js, MariaDB and GIS - 推酷
Node.js, MariaDB and GIS
The availability of the node.js binding for
together with the
inspired me to make an example of using node.js and MariaDB to import so-called GPX tracks to a MariaDB database and then show them on a map. GPX tracks are what are stored by many GPS devices including running watches and smartphones.
My project makes use of MariaDB’s non-blocking client library together with the node.js platform and on top of that uses the GIS functionality found in MariaDB 5.5 and 10.0.
To start with let’s go through the software and components I’m using:
– The popular Node.js platform built on Chrome’s JavaScript runtime. An event-driven and non-blocking architecture
– a web application framework for node.js (similar to Sinatra in Ruby). Puts a nice structure on the application and makes configuration easy.
– A node.js template engine for outputting in most cases HTML, but can also be used for other XML structured languages
– A node.js binding to MariaDB’s non-blocking (MySQL-compatible) client library created by Brian White
– Node module for parsing XML
– To show the end result on a map
The source code for my application can be found on Github:&
I’ve licensed it under the MIT license, so feel free to grab it, copy it, reuse it or distribute it. If you build on top of it, it would of course be nice to know and it would appreciated if you dropped an email to me or added a comment here.
Installing the platform
I chose to use Ubuntu 13.10 x64 as the OS for the application. Below is outlined the steps for installing each of the components needed for this application. Before I begin going through them it’s always good to create a new OS user and not run as root. adduser is handy for the purpose. Remember also to add the user to the sudo group if you’re going to make the installation with this new user. In my case I chose to “
sudo adduser rasmus sudo
Install MariaDB 10.0 by following the instructions found on the
Remember to choose the right Ubuntu release on that page, which in my case is 13.10 “saucy”. Then follow the instructions on the page. While doing this tutorial the version of MariaDB getting installed was 10.0.7. The application uses MariaDB’s root user with password password1 so you might want to do the same to get this example working without code changes. Create a database named running with the following commands:
mysql -u root -p
MariaDB [(none)]& cre
&you’ll find
running.sql
in the root. Run that with the following command on the server to create the schema for the running -database:
mysql -u root -p running & running.sql
Prepare the environment:
Update the apt repository:
sudo apt-get update
Install a compiler:
sudo apt-get install build-essential
Install curl which will be needed when installing node.js:
sudo apt-get install curl
Install node.js and Node Package Manager (NPM):
sudo apt-get install nodejs
sudo apt-get install nodejs-legacy
sudo apt-get install npm
Install Express.js and Jade:
npm install express
npm install jade
Install the MariaDB non-blocking client:
npm install mariasql
(there might be a few compiler warnings, I at least had a few)
Finally install the xml2js module which we will need:
npm install xml2js
With that done, the platform is set up and the next step is to create an Express.js web application by running the command
express nodegpxmariadb
nodegpxmariadb
is the name of the web application. I did it in the home directory of my user. Go to the
nodegpxmariadb
-directory and make sure all required modules are installed by running
npm install
Configuring the application
In app.js a few different things are specified.
All module dependencies are listed. For my application the two additions to the normal modules set up by express.js is a data.js and a common.js module in which I’ve put all the database handling. The module dependency is defined by adding these rows:
var common = require('./routes/common');
var data = require('./data.js');
'./routes/common'
'./data.js'
Now the common and data modules are available throughout the application. Common follows the principles of the express.js framework and is done as a so-called route which include the logic for url path mappings mentioned below.
The default &express.js environment configurations are in use like the server running on port 3000. Make sure JSON support is on. It should be there by default:
app.use(express.json());
Another configuration needed is to tell express.js where to store uploaded files:
app.use(express.bodyParser({ keepExtensions: true, uploadDir: __dirname + '/public/uploads' }));
bodyParser
keepExtensions:
uploadDir:
'/public/uploads'
In addition app.js is the place where all the URL path mappings are defined. The following are needed:
app.get('/upload', common.fileForm);
app.post('/upload', common.fileUpload);
app.get('/readfile', common.readFile);
app.get('/parsegpx', common.parseGPX);
app.get('/track', common.listPoints);
app.get('/showmap', function (req, res) {
res.sendfile(__dirname + '/views/maps.html');
fileUpload
'/readfile'
'/parsegpx'
listPoints
'/showmap'
'/views/maps.html'
As you can see most of the url path mappings point to the common module, where it’s defined what to do when there is an incoming request for the url path. For
there is no server side logic needed so an html file can just be read and sent to the client.
Start the application
With the configuration in place the application can be started:
rasmus@rasdo1:~$ cd nodegpxmariadb/
rasmus@rasdo1:~/nodegpxmariadb$ node app
connect.multipart() will be removed in connect 3.0
visit /senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Express server listening on port 3000
nodegpxmariadb
nodegpxmariadb
.multipart
///senchalabs/connect/wiki/Connect-3.0 for alternatives
You should see a “Welcome to Express” -message if you open up the http://[server ip]:3000 in a browser.
Upload GPX file
Let’s take a closer look at what actually is done in the common.js module. Let’s start with the upload part. Exports.fileForm and exports.fileUpload are handling the displaying of an upload form and respectively actually doing the upload of the file chosen by the user.
Screenshot 1: File upload
Parse GPX file
Once a file has been uploaded it gets more interesting. This is when the parsing of a GPX file starts. GPX files are full of tracking points with a certain interval. For example:
&trkpt lon=&24.6009& lat=&60.9034&&
&ele&4.5&/ele&
&time&T12:00:11.000Z&/time&
&extensions&
&gpxtpx:TrackPointExtension&
&gpxtpx:hr&137&/gpxtpx:hr&
&/gpxtpx:TrackPointExtension&
&/extensions&
&trkpt lon=&24.9986& lat=&60.5000&&
&ele&4.5&/ele&
&time&T12:00:14.000Z&/time&
&extensions&
&gpxtpx:TrackPointExtension&
&gpxtpx:hr&146&/gpxtpx:hr&
&/gpxtpx:TrackPointExtension&
&/extensions&
T12:00:11.000Z
&extensions&
&gpxtpx:TrackPointExtension&
&&&&&&&&&&&&
&gpxtpx:hr&
&/gpxtpx:hr&
&/gpxtpx:TrackPointExtension&
&/extensions&
T12:00:14.000Z
&extensions&
&gpxtpx:TrackPointExtension&
&&&&&&&&&&&&
&gpxtpx:hr&
&/gpxtpx:hr&
&/gpxtpx:TrackPointExtension&
&/extensions&
As seen above each track point is its own XML node, which holds the longitude and latitude coordinates, elevation, time and some other interesting information such as heart rate. An easy way to handle XML of this type (or in general) is to make use of the node.js library xml2js which parses XML and outputs JSON. It’s very straightforward. I make use of it in in the
–function.
When we have the GPX content in JSON it’s time to extract the track points and insert them into a MariaDB database. We start by calling the connect –method of the data –module to get a connection to MariaDB. After that we iterate over the JSON contents:
for(var i in json.gpx.trk[0].trkseg[0].trkpt) {
lon = json.gpx.trk[0].trkseg[0].trkpt[i].$.
lat = json.gpx.trk[0].trkseg[0].trkpt[i].$.
data.insertPoint(lon, lat);
insertPoint
The lon variable holds the longitude coordinate of the trackpoint and lat the latitude. Unfortunately MariaDB doesn’t yet support the 3rd coordinate in GIS, elevation, otherwise we could have added it also. The lon and lat are given to the data.insertPoint –method which stores them as a GIS Point in the database:
client.query('INSERT INTO trackpoints (gpsPoint) VALUES (PointFromText(:loc))', { loc: 'POINT(' + lon + & & + lat +
'INSERT INTO trackpoints (gpsPoint) VALUES (PointFromText(:loc))'
Make sure you check out the data.js file for how to connect and disconnect to MariaDB.
Screenshot 2: Parsing the GPX file
Show on map
The final thing I wanted to do was to see how easily I could plot the stored GIS points on a map. To start with we need to retrieve all the GIS points from the database, which is done is data.js in the following way:
exports.getTrackPoints = function(trackId, httpRes) {
var xys = [];
client.query('SELECT X(GeomFromText(AsText(gpsPoint))) AS X, Y(GeomFromText(AsText(gpsPoint))) AS Y FROM trackpoints WHERE trackId = :pTrackId', { pTrackId: trackId })
.on('result', function(res) {
res.on('row', function(row) {
xys.push(row);
.on('error', function(err) {
console.log('Result error: ' + inspect(err));
.on('end', function(info) {
console.log('Result finished successfully');
.on('end', function() {
httpRes.send(xys);
getTrackPoints
'SELECT X(GeomFromText(AsText(gpsPoint))) AS X, Y(GeomFromText(AsText(gpsPoint))) AS Y FROM trackpoints WHERE trackId = :pTrackId'
&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&
'Result error: '
&&&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&
'Result finished successfully'
&&&&&&&&&&&&&&
&&&&&&&&&&
From the above we can see that an array is built which is passed directly as an http response and of course by default in JSON format. This is very good for Google Maps which now can point to a URL, which in this case is
and read the JSON formatted array of points from there and plot a so-called
connecting each of the points to a nice track.
Screenshot 3: The GPX track shown on Google Maps
A lot more could of course be done when having the GIS points stored in the database, including:
distances could be counted
I could view which of my runs that intersect with each other (well this is actually a MariaDB 10.1 feature since INTERSECT will be introduced there)
count how many of my runs are inside a certain area
time could be added so that duration and pace could be measured
To sum it up, I would say that whenever you think about creating your next app, being it a web application or a smartphone app with the need of a back-end node.js + MariaDB is a great choice and all the pieces needed are available. You’ll have a full blown and proven RDBMS backing up your application.
Also location awareness and other geographical functionality seems to be almost mandatory in new development. MariaDB includes quite a nice (and properly implemented) set of spatial data types, GIS functions and other relevant functionality.
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致NodeJS 模块开发及发布详解分享
字体:[ ] 类型:转载 时间:
NodeJS 是一门年轻的语言,扩展模块并不太全,经常我们想用某个模块但是却找不到合适的
比如前两天我需要使用hmac和sha1来做签名,就没有找到一个比较好用的模块,这时候就需要我们自己来实现相应的功能了。自己写完之后,再把它打包成一个模块分享给大家来用,即方便了其他人,又能让自己有点小小的成就感,实在是一件一举多得的好事情。接下来,我就为大家介绍一下如何封装一个NodeJS模块并把它分享给其他人。 NPM (Node Package Manager, http://npmjs.org ) 是 NodeJS 的模块管理软件,除 NodeJS 内置的核心模块外,其他模块的安装、卸载等管理操作都要通过 NPM 来进行,我们自己写的模块,就要发布到NPM上来供其他人使用。 接下来,我们做一个非常简单的模块 “hello”,这个模块的功能只有一个:提供一个参数 “name” ,它在控制台输出 “Hello name”。在开始之前,我们首先要把node和npm装好,安装方法在其官方网站都有介绍,这里就不再多说了。 首先,我们创建一个名为”hello”的目录,作为模块的主目录。进入该目录,开始我们的工作。 然后,写模块的核心代码,很简单,只有以下三行:
代码如下: exports.Hello = function ( name ) { console.log( "Hello " + name ); }
把它保存为 hello.js。 NodeJS每个扩展模块中都有一个package.json文件,用来描述模块的一些基本属性,比如模块名称、作者、版本号等等。关于package.json写法的详细说明,可以使用 “npm help json” 命令来查看。 我们可以在模块主目录下执行 npm init 来生成一个最基本的package.json。按照命令的提示依次输入信息即可。以下是在 hello 目录下执行 npm init 并填入相关信息后的结果:
代码如下: $ npm init Package name: (hello) //模块名字,npm init会自动取当前目录名作为默认名字,这里不需要改,直接确认即可 Description: A example for write a module //模块说明 Package version: (0.0.0) 0.0.1 //模块版本号,这个大家按自己习惯来定就可以 Project homepage: (none) //模块的主页,如果有的话可以填在这里,也可以不填 Project git repository: (none) //模块的git仓库,选填。npm的用户一般都使用github做为自己的git仓库 Author name: Elmer Zhang //模块作者名字 Author email: (none)
//模块作者邮箱 Author url: (none)
//模块作者URL Main module/entry point: (none) hello.js //模块的入口文件,我们这里是hello.js Test command: (none) //测试脚本,选填 What versions of node does it run on? (~v0.5.7) * //依赖的node版本号,我们这个脚本可以运行在任何版本的node上,因此填 * About to write to /home/elmer/hello/package.json // 以下是生成的package.json文件内容预览 { "author": "Elmer Zhang && ()", "name": "hello", "description": "A example for write a module", "version": "0.0.1", "repository": { "url": "" }, "main": "hello.js", "engines": { "node": "*" }, "dependencies": {}, "devDependencies": {} } Is this ok? (yes) //对以上内容确认无误后,就可以直接回车确认了
到此为止,我们这个模块就写完了。这时hello目录下应该有两个文件:hello.js和package.json。 我们可以返回到hello的上级目录,来测试安装一下这个模块:
代码如下: $ npm install hello/ hello@0.0.1 ./node_modules/hello
显示安装成功。简单的测试一下:
代码如下: $ node & var Hello = require('hello').H & Hello('world');
Hello world正确输出了”Hello world”。 接下来我们把它发布到NPM上。 首先,我们需要有一个NPM帐号,可以使用npm adduser来注册一个:
代码如下: $ npm adduser Username: elmerzhang Password: Email:
简单三步,一个NPM用户注册成功。 最后回到 hello 根目录,执行一下npm publish,如果没有任何错误提示,那么就发布成功了。去 http://search.npmjs.org/上看一下吧,你的模块应该已经显示在”Latest Updates”一栏里了。 至此,一个NodeJS模块成功发布到NPM,以后就可以在任何能访问npm库的地方通过npm install来安装你的模块了。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具帐号:密码:下次自动登录{url:/nForum/slist.json?uid=guest&root=list-section}{url:/nForum/nlist.json?uid=guest&root=list-section}
贴数:1&分页:醒掌天下权,醉卧美人膝发信人: Lee2002hu (醒掌天下权,醉卧美人膝), 信区: FEA
标&&题: [合集] 弱问一下,ansys里的node和keypoint有什么区别啊?
发信站: 水木社区 (Wed Sep 16 09:16:05 2009), 站内 && ☆─────────────────────────────────────☆ &&
MSC0NFIG (TMD就不信了!) 于
(Mon Jun 26 23:28:12 2006)
提到: &&&&&&&&&&&&&&&& ☆─────────────────────────────────────☆ &&
wsjxaut (没籽的葡萄好吃) 于
(Tue Jun 27 00:09:46 2006)
提到: && 一个是有限元里的点,一个是几何里的点,嗯?
【 在 MSC0NFIG (TMD就不信了!) 的大作中提到: 】 &&&&&&&& ☆─────────────────────────────────────☆ &&
ustb0471 (九儿) 于
(Tue Jul 11 10:19:59 2006)
提到: &&&&&& 对,节点是对有限元模型的,而关键点是对几何模型来说的.
【 在 wsjxaut (没籽的葡萄好吃) 的大作中提到: 】
: 一个是有限元里的点,一个是几何里的点,嗯?
&&&&&&&&&& 文章数:1&分页:
抽奖到手软!将狂欢进行到底!您所在位置: &
&nbsp&&nbsp&nbsp&&nbsp
原发性乳腺癌染色体不稳定性相关应用研究.pdf109页
本文档一共被下载:
次 ,您可全文免费在线阅读后下载本文档。
文档加载中...广告还剩秒
需要金币:200 &&
原发性乳腺癌染色体不稳定性相关应用研究.pdf
你可能关注的文档:
··········
··········
山东大学 博士学位论文
原发性乳腺癌染色体不稳定性的相关研究 姓名:李丽 申请学位级别:博士 专业:病理学与病理生理学 指导教师:周庚寅;Anders Zetterberg 座机电话号码 山东大学博士学位论文 原发性乳腺癌染色体不稳定性的研究 博士研究生李丽 博士生导师周庚寅教授 Prof.Anders Zetterberg 专 业病理学与病理生理学 中文摘要 【研究背景】 乳腺癌目前已经成为全球女性发病率最高的恶性肿瘤,严重影响着女性的生
命和健康。乳腺癌是一种多基因参与的复杂疾病,参与调控细胞生长、分化与凋
亡的一系列染色体异常导致了肿瘤的发生。更好的认识其基因改变能为患者提供
更为精确的诊断和合理的治疗。 染色体不稳定性是指癌细胞较之于正常细胞,在细胞分裂时丧失和 或 获得
整条染色体或染色体片段频率的升高,可以具体的分为数目改变和结构改变。染
色体不稳定是恶性肿瘤的最基本特征,几乎所有人类肿瘤都存在染色体不稳定,
对肿瘤恶性生物学行为的判断具有重要价值。 过去大批基因表达图谱分析发现了一系列的乳腺癌分子异常和一些对临床
诊断治疗有用的基因表达亚型。但是由于分辨率的不足,比较基因组杂交 comparative genomic 的能力受到限制。最新的细胞分子遗传学技术进展为我们提供了高分辨率检测细
oligonucleotide microarrayanalysis,ROMA 和定量多基因荧光原位杂交 multi―geneFISH,QM-FISH 使得对肿瘤基因组进行高分辨率分析成 quantitative
为可能。ROMA是迄今为止敏感性和特异性最强的微阵列杂交技术。QM―FISH
技术可在同一细胞核内检测多个不同基因,并且可用于石蜡包埋组织。使用ROMA
技术,可以寻找有意义的染色体异常,确定研究靶向,而使用QM.FISH技术
正在加载中,请稍后...}

我要回帖

更多关于 node.js 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信