将PostGIS转化为GeoJSON
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import psycopg2
- import json
- from geojson import loads, Feature, FeatureCollection
- # Database Connection Info
- db_host = "localhost"
- db_user = "pluto"
- db_passwd = "stars"
- db_database = "py_geoan_cb"
- db_port = ""
- # connect to DB
- conn = psycopg2.connect(host=db_host, user=db_user,
- port=db_port, password=db_passwd, database=db_database)
- # create a cursor
- cur = conn.cursor()
- # the PostGIS buffer query
- buffer_query = """SELECT ST_AsGeoJSON(ST_Transform(
- ST_Buffer(wkb_geometry, 100,'quad_segs=8'),4326))
- AS geom, name
- FROM geodata.schools"""
- # execute the query
- cur.execute(buffer_query)
- # return all the rows, we expect more than one
- dbRows = cur.fetchall()
- # an empty list to hold each feature of our feature collection
- new_geom_collection = []
- # loop through each row in result query set and add to my feature collection
- # assign name field to the GeoJSON properties
- for each_poly in dbRows:
- geom = each_poly[0]
- name = each_poly[1]
- geoj_geom = loads(geom)
- myfeat = Feature(geometry=geoj_geom, properties={'name': name})
- new_geom_collection.append(myfeat)
- # use the geojson module to create the final Feature Collection of features created from for loop above
- my_geojson = FeatureCollection(new_geom_collection)
- # define the output folder and GeoJSon file name
- output_geojson_buf = "../geodata/out_buff_100m.geojson"
- # save geojson to a file in our geodata folder
- def write_geojson():
- fo = open(output_geojson_buf, "w")
- fo.write(json.dumps(my_geojson))
- fo.close()
- # run the write function to actually create the GeoJSON file
- write_geojson()
- # close cursor
- cur.close()
- # close connection
- conn.close()
将PostGIS转化为GeoJSON的更多相关文章
- Python:Shapefile矢量转化为GeoJSON格式
在最近的项目中,完成了许多python处理矢量数据的算法程序,比如缓冲区分析.叠置分析.统计分析等,主要用到的是GDAL/OGR库,很多功能都参照了此链接中的示例:http://pcjericks.g ...
- 用shp制作geoJson格式地图数据(shp convert to geoJson)
本文紧接前文,简单说明利用shp数据制作Echarts支持的geoJson格式的地图数据.本文以北京市通州区各镇的shp数据为例进行说明. 软件环境: ArcGIS 10.2 (ArcGIS 10.2 ...
- [转]JAVA 根据经纬度算出附近的正方形的四个角的经纬度
csv文件转化为geojson文件中,涉及到路测图的打点生成,打点是由一个个正方形组成,而正方形是由四个点组成的,这四个点根据经纬度和范围生成,具体的实现代码是从网上找来的: /** * * @par ...
- OpenLayers 3 入门教程
OpenLayers 3 入门教程摘要OpenLayers 3对OpenLayers网络地图库进行了根本的重新设计.版本2虽然被广泛使用,但从JavaScript开发的早期发展阶段开始,已日益现实出它 ...
- 【GIS】postgres(postgis) --》nodejs+express --》geojson --》leaflet
一.基本架构 1.数据存储层:PostgreSQL-9.2.13 + postgis_2_0_pg92 2.业务处理层:Nodejs + Express + PG驱动 3.前端展示层:Leaflet ...
- PostgreSQL+PostGIS的使用 函数清单
一. PostgreSQL与PostGIS的关系 PostgreSQL 是世界上技术最先进的开源数据库,其前身是1977年一个源于Berkeley名为Ingres的非关系型数据库,其项目领导人为Mic ...
- geotrellis使用(三十)使用geotrellis读取PostGIS空间数据
前言 最近事情很多,各种你想不到的事情--such as singing and dancing--再加上最近又研究docker上瘾,所以geotrellis看上去似乎没有关注,其实我一直在脑中思考着 ...
- postgis几何操作函数集
管理操作函数 AddGeometryColumn - Adds a geometry column to an existing table of attributes. By default use ...
- PostGis常用函数中文介绍
记录常用PostGis常用函数: 1.OGC标准函数 管理函数: 添加几何字段 AddGeometryColumn(, , , , , ) 删除几何字段 DropGeometryColumn(, , ...
随机推荐
- struts深入理解之登录示例的源码跟踪
废话不多,直接上图:(色泽比较重的是追踪的路径)
- Network - SNMP
Simple Network Management ProtocolWikipediahttps://en.wikipedia.org/wiki/Simple_Network_Management_P ...
- 在SQL Server里为什么我们需要更新锁
今天我想讲解一个特别的问题,在我每次讲解SQL Server里的锁和阻塞(Locking & Blocking)都会碰到的问题:在SQL Server里,为什么我们需要更新锁?在我们讲解具体需 ...
- 将RichTextBox的内容直接写入数据库:
将RichTextBox的内容直接写入数据库: private void button1_Click(object sender, EventArgs e) { System.IO.Memory ...
- 使用ajax和js无刷新改变页面内容和地址栏URL
发现一个可以改变地址栏,而不导致页面刷新的东东. Chrome, FF测试通过,不支持IE. 实现目标 页面的跳转(前进后退,点击等)不重新请求页面 页面URL与页面展现内容一致(符合人们对传统网页的 ...
- 关于ExtJs4的Grid带 查询 参数 分页(baseParams-->extraParams)
(园里很多文章,美名其曰 :ExtJs GridPanel+查询条件+分页. 但是加查询条件后点击下一页,查询条件失效,求你们自己测试明白再显摆 不要误导我这种新人.) ExtJs6发布了,ExtJ ...
- 一个故事讲清楚NIO
转载请引用:一个故事讲清楚NIO 假设某银行只有10个职员.该银行的业务流程分为以下4个步骤: 1) 顾客填申请表(5分钟): 2) 职员审核(1分钟): 3) 职员叫保安去金库取钱(3分钟): 4) ...
- WPFINotifyPropertyChanged使用技巧
WPFINotifyPropertyChanged使用技巧 public class NotifyPropertyChanged : INotifyPropertyChanged { public e ...
- Ado.net 三[SQL注入,DataAdapter,sqlParameter,DataSet]
1.SQL注入:SQL注入攻击是web应用程序的一种安全漏洞,可以将不安全的数据提交给运用程序,使应用程序在服务器上执行不安全的sql命令.使用该攻击可以轻松的登录运用程序. 例如:该管理员账号密码为 ...
- 【Java每日一题】20161201
20161130问题解析请点击今日问题下方的"[Java每日一题]20161201"查看 package Dec2016; public class Ques1201 { publ ...