惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
V
Visual Studio Blog
小众软件
小众软件
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
T
Tor Project blog
Jina AI
Jina AI
GbyAI
GbyAI
C
Comments on: Blog
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
A
Arctic Wolf
有赞技术团队
有赞技术团队
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
Webroot Blog
Webroot Blog
C
Cisco Blogs
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
H
Hacker News: Front Page
D
Darknet – Hacking Tools, Hacker News & Cyber Security
D
Docker
P
Palo Alto Networks Blog
The Register - Security
The Register - Security
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志

博客园 - 3echo

物联网笔记四:物联网网络及协议 物联网学习笔记三:物联网网关协议比较:MQTT 和 Modbus 物联网学习笔记二:物联网网关 物联网学习笔记一:物联网入门的必备 7 大概念和技能 ArcGIS支持MongoDB数据源 做事要趁早 产品介绍汇报模板 软件企业利润率知多少 项目管理经验谈之意外事件处理 文件数据库和关系数据库的比较 实时/历史数据库和关系型数据库的区别 ArcGIS中如何实现地图缩编(转载) 浙江省地理空间数据交换和共享管理办法 ORA-06413:连接未打开错误 - 3echo - 博客园 如何使用Nhibernate动态连接Oracle数据库 获取两点(经纬度表示)间距离 中国房市之痛 3S新闻周刊很好很专业 NET生成下面的模块时,启用了优化或没有调试信息
使用Python 将shapefile导入mongodb
3echo · 2013-08-16 · via 博客园 - 3echo

使用Python 将shapefile导入mongodb

随着big data时代的到来,各个行业都在考虑能不能把big data的思路、方法引入进来,GIS行业也不能免俗。

下面就介绍一下如何将shapefile导入mongodb中

1首先安装pyshp 和pymongo 库

2 安装mongodb,并正确运行

3 执行下面的python脚本

import pymongo

from pymongo.connection import Connection

def readSHPPoint(append):

    fileP = u'E:\\data\\supermarket_webMercator\\supermarket.shp'

    sf = shapefile.Reader(fileP)

    shapeRecs = sf.shapeRecords()

 

    mongodb_server='192.168.120.100'

    mongodb_port = 27017

    mongodb_collection ='supermarket'

    mongodb_db = 'gisdb'

    connection = Connection(mongodb_server, mongodb_port)

    print 'Getting database %s' % mongodb_db

    db = connection[mongodb_db]

    print 'Getting the collection %s' % mongodb_collection

    collection = db[mongodb_collection]

    if append == False:

        print 'Removing features from the collection...'

        collection.remove({})

    print 'Starting loading features...'

    for shaperec in shapeRecs:

        mongofeat = {}

        #'{x='',y=''}'

        strX = "%.3f" % shaperec.shape.points[0][0]

        strY = "%.3f" % shaperec.shape.points[0][1]

        mongogeom = '{x="'+strX+'",y="'+strY+'"}'

        print mongogeom

        mongofeat['geom'] = mongogeom

        mongofeat['name'] = shaperec.record[1].decode('GB2312').encode('utf-8')

        collection.insert(mongofeat)

    #create 2d index

    collection.create_index([("geom", pymongo.GEO2D)])

if __name__ == "__main__":

  readSHPPoint(False)

目前mongodb只支持点类型的数据,并提供空间索引。

使用mongodb可以很方便的满足高并发的并且简单的需求,例如POI的周边查询API查询

本文转载自:http://www.giser.net/?p=1076